portal A takes me to new scene but i cant get back to old scene from portal B
i have right scenes to load and destinations.
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.AI;
namespace RPG.SceneManagement
{
public class Portal : MonoBehaviour
{
enum DestinationIdentifier
{
A, B, C, D, E
}
[SerializeField] int sceneToLoad = -1;
[SerializeField] Transform spawnPoint;
[SerializeField] DestinationIdentifier destination;
[SerializeField] float fadeOutTime = 1f;
[SerializeField] float fadeInTime = 2f;
[SerializeField] float fadeWaitTime = 0.5f;
private void OnTriggerEnter(Collider other) {
if (other.tag == “Player”)
{
StartCoroutine(Transition());
}
}
private IEnumerator Transition()
{
if (sceneToLoad < 0)
{
Debug.LogError(“Scene to load not set.”);
yield break;
}
DontDestroyOnLoad(gameObject);
Fader fader = FindObjectOfType();
yield return fader.FadeOut(fadeOutTime);
SavingWrapper wrapper = FindObjectOfType();
wrapper.Save();
yield return SceneManager.LoadSceneAsync(sceneToLoad);
wrapper.Load();
Portal otherPortal = GetOtherPortal();
UpdatePlayer(otherPortal);
wrapper.Save();
yield return new WaitForSeconds(fadeWaitTime);
yield return fader.FadeIn(fadeInTime);
Destroy(gameObject);
}
private void UpdatePlayer(Portal otherPortal)
{
GameObject player = GameObject.FindWithTag(“Player”);
player.GetComponent().enabled = false;
player.GetComponent().Warp(otherPortal.spawnPoint.position);
player.transform.rotation = otherPortal.spawnPoint.rotation;
player.GetComponent().enabled = true;
}
private Portal GetOtherPortal()
{
foreach (Portal portal in FindObjectsOfType())
{
if (portal == this) continue;
if (portal.destination != destination) continue;
return portal;
}
return null;
}
}
}