The fader wont FadeIn after the player loads into scene2 form a portal. So the tele works but i cant see anything untill i manually change the faders alpha to 0 in scene2. althuogh when i take the portal back to scene1 the fader works fine and everything visibly working
here is my portal.cs, please tell what else you need to see.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.AI;
namespace RPG.SceneManagement
{
public class Portal : MonoBehaviour
{
enum DestinationIdentifier
{
A,B,C,D
}
[SerializeField] int sceneToLoad = -1;
[SerializeField] Transform spawnPoint;
[SerializeField] DestinationIdentifier destination;
[SerializeField] float fadeOutTime = 1f;
[SerializeField] float fadeInTime = 0.5f;
[SerializeField] float fadeWaitTime = 0.5f;
// [SerializeField] string enemyTag;
// List<GameObject> enemiesToKill = new List<GameObject>();
// private void Start()
// {
// Scene scene = SceneManager.GetActiveScene();
// DontDestroyOnLoad(gameObject);
// if(scene.name == "SandBox")
// {
// enemiesToKill.AddRange(GameObject.FindGameObjectsWithTag(enemyTag));
// foreach(GameObject i in enemiesToKill)
// {
// print(i);
// }
// }
// print(enemyTag);
// }
private void OnTriggerEnter(Collider other) {
if (other.tag == "Player")
{
// if (enemiesToKill != null)
// {
// if (enemiesToKill.Count == 0)
// {
StartCoroutine(Transition());
// }
// }
}
}
private IEnumerator Transition()
{
DontDestroyOnLoad(gameObject);
Fader fader = FindObjectOfType<Fader>();
SavingWrapper wrapper = FindObjectOfType<SavingWrapper>();
yield return fader.FadeOut(fadeOutTime);
print("FADEOUT COMPLETE");
wrapper.Save();
yield return SceneManager.LoadSceneAsync(sceneToLoad);
wrapper.Load();
Portal matchingPortal = GetMatchingPortal();
UpdatePlayer(matchingPortal);
wrapper.Save();
yield return new WaitForSeconds(fadeWaitTime);
yield return fader.FadeIn(fadeInTime);
print("FADEIN COMOPLETE");
// yield return fader.FadeOutImmediate();
//matchingPortal = null;
Destroy(gameObject);
}
private Portal GetMatchingPortal()
{
foreach (Portal portal in FindObjectsOfType<Portal>())
{
if(portal == this) continue;
if(portal.destination != destination) continue;
return portal;
}
return null;
}
private void UpdatePlayer(Portal destPortal)
{
GameObject player = GameObject.FindWithTag("Player");
player.GetComponent<NavMeshAgent>().enabled = false;
player.transform.position = destPortal.spawnPoint.position;
player.transform.rotation = destPortal.spawnPoint.rotation;
player.GetComponent<NavMeshAgent>().enabled = true;
}
// public void UpdateEnemyList(GameObject enemy)
// {
// enemiesToKill.Remove(enemy);
// }
}
}