예제 #1
0
    // Start is called before the first frame update
    void Start()
    {
        if (ScoreText != null)
        {
            ScoreText.text = "Score: " + GameObject.FindObjectOfType <Globals>().returnScore();
        }

        if (LevelSelect != null)
        {
            LevelSelect.GetComponent <Button>().onClick.AddListener(PlayOnClick);
        }

        if (Level1 != null)
        {
            Level1.GetComponent <Button>().onClick.AddListener(delegate { LoadLevel(1); });
            Level2.GetComponent <Button>().onClick.AddListener(delegate { LoadLevel(2); });
            Level3.GetComponent <Button>().onClick.AddListener(delegate { LoadLevel(3); });
            Level4.GetComponent <Button>().onClick.AddListener(delegate { LoadLevel(4); });

            SetLevelsInteractable();
        }

        if (Quit != null)
        {
            Quit.GetComponent <Button>().onClick.AddListener(QuitOnClick);
        }

        if (Credits != null)
        {
            Credits.GetComponent <Button>().onClick.AddListener(CreditsOnClick);
        }

        if (MainMenu != null)
        {
            MainMenu.GetComponent <Button>().onClick.AddListener(MainMenuOnClick);
        }

        if (ResetProgress != null)
        {
            ResetProgress.GetComponent <Button>().onClick.AddListener(ResetProgressOnClick);
        }

        if (UnlockLevelsCheat != null)
        {
            UnlockLevelsCheat.GetComponent <Button>().onClick.AddListener(UnlockLevelsOnClick);
        }

        if (RestartCurrLevel != null)
        {
            RestartCurrLevel.GetComponent <Button>().onClick.AddListener(delegate { LoadLevel(GameObject.FindObjectOfType <Globals>().returnCurrentLevel()); });
        }

        if (NextLevel != null)
        {
            Globals globals   = GameObject.FindObjectOfType <Globals>();
            ushort  nextLevel = globals.returnCurrentLevel(); // Current level is increased by touching the end portal
            nextLevel++;
            globals.setMaxLevel(nextLevel);
            NextLevel.GetComponent <Button>().onClick.AddListener(delegate { LoadLevel(nextLevel); }); // Loads next level
        }
    }