Interscene portals stopped functioning

Not sure if we’re going to fix this in a later video or not but I have three portals in my second scene. Two of which are given the destination “B” from the enum.
The third is the one to go back to scene 0
Was working previously

Since we’re reusing portal methods for saving I believe we need to run a check to see if the portals are in the same scene or not and if they are don’t call loadscene? or perhaps break the transition into two groups, same scene and different scene to call different methods.

Thoughts? Suggestions?

In this case, I think you might be better off creating a new portal script, something along the lines of LocalPortal. Since these portals will be local, you should be able to drag a destination Local Porter into a field. The OnTrigger will have much less to do.

public class LocalPortal
{
     [SerializeField] LocalPortal destination;
     [SerializeField] Transform spawnPoint;
     [SerializeField] float fadeOutTime = 1f;
     [SerializeField] float fadeInTime = 2f;

     void OnTriggerEnter(Collider other)
     {
          if(other="Player")
          {
                StartCoroutine(Transition());
          }
     }

    IEnumerator Transition()
   {
         Fader fader = FindObjectOfType<Fader>();
         PlayerController playerController = GameObject.FindWithTag("Player").GetComponent<PlayerController>();
            playerController.enabled = false;
            
            yield return fader.FadeOut(fadeOutTime);
         playerController.GetComponent<NavMeshAgent>().enabled=false;
         player.transform.position = destination.spawnPoint.transform.position;
         player.transform.rotation = destination.spawnPoint.transform.rotation;
         playerController.GetComponent<NavMeshAgent().enabled=true;
         yield return fader.FadeIn(fadeInTime);
         playerController.enabled=true;
   }
1 Like

Awesome! Thank you so much for the reply! It’s so obvious when you think about it but not after hours of coding haha.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms