UnityGameProjectsCode / InTheDarkGame / Level / ExitDoor.cs
ExitDoor.cs
Raw
using UnityEngine;
using UnityEngine.SceneManagement;

public class ExitDoor : MonoBehaviour
{
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            ProgressTracker.SetLevelCompleteState(SceneManager.GetActiveScene().buildIndex, true);

            IntroOutroInfo inOutInfo = null;
            IntroOutroInfo inOutInfoPost = null;

            if (GameObject.Find("Intro_Outro UI"))
                inOutInfo = GameObject.Find("Intro_Outro UI").GetComponent<IntroOutroInfo>();

            if(GameObject.Find("Intro_Outro UI Post Lvl 1"))
                inOutInfoPost = GameObject.Find("Intro_Outro UI Post Lvl 1").GetComponent<IntroOutroInfo>();

            if (inOutInfo != null)
            {
                inOutInfo.GetOutroPanel().SetActive(true);
            }
            else if (inOutInfoPost != null)
            {
                inOutInfoPost.GetOutroPanel().SetActive(true);

                if (SceneManager.GetActiveScene().buildIndex == 20)
                {
                    if (ProgressTracker.GetGoodEndingTriggered() == true)
                    {
                        inOutInfoPost.SetGoodOrBadText();
                    }
                }
            }

            GameObject.Find("GamePlay UI").SetActive(false);
            Debug.Log("Level Complete!");
        }
    }
}