Example #1
0
    /// <summary>
    /// Switches level options
    /// </summary>
    public void NextLevel()
    {
        if (LevelOptions.NextLevel != null)
        {
            _levelGamescore = 0;
            LevelOptions    = LevelOptions.NextLevel;
            Spawner.GetComponent <EnemySpawner>().SetLevelSettings(LevelOptions);


            Spawner.SetActive(false);
            PlayerObject.SetActive(false);
            if (StartGameBtn != null && !StartGameBtn.activeSelf)
            {
                StartGameBtn.SetActive(true);
            }
            if (ControlsUI != null)
            {
                ControlsUI.SetActive(true);
            }
            if (WinnerUI != null)
            {
                if (NextTargetUI != null)
                {
                    NextTargetUI.GetComponent <Text>().text = LevelOptions.Score.ToString();
                    WinnerUI.SetActive(true);
                }
            }
        }
    }
Example #2
0
 /// <summary>
 /// Restart button click event listener. Starts game
 /// </summary>
 public void Restart()
 {
     ControlsUI.SetActive(false);
     WinnerUI.SetActive(false);
     PlayerObject.GetComponent <Player>().Restart();
     Spawner.GetComponent <EnemySpawner>().Restart();
     BackgroundUI.GetComponent <Image>().sprite = LevelOptions.Background;
     StartGameBtn.SetActive(false);
     if (_playerDead)
     {
         GameOverUI.SetActive(false);
         _playerDead = false;
     }
     OnHealthsUpdate(PlayerObject.GetComponent <Player>().hPoints);
 }
Example #3
0
    /// <summary>
    /// Initialize component
    /// </summary>
    private void Start()
    {
        if (!PlayerPrefs.HasKey("soundOff"))
        {
            PlayerPrefs.SetInt("soundOff", 1);
            PlayerPrefs.Save();
        }

        audioSource = gameObject.GetComponent <AudioSource>();

        if (PlayerObject != null)
        {
            Player.OnPlayerDead += GameOver;
            Player.OnScoreSet   += OnScoreUpdate;
            Player.OnHealthsSet += OnHealthsUpdate;
            Player.OnBuyBonus   += OnBuyBonus;
            PlayerObject.SetActive(false);
        }

        if (Spawner != null)
        {
            Spawner.GetComponent <EnemySpawner>().SetLevelSettings(LevelOptions);
            Spawner.SetActive(false);
        }

        if (GameOverUI != null)
        {
            GameOverUI.SetActive(false);
        }

        if (WinnerUI != null)
        {
            WinnerUI.SetActive(false);
        }

        if (MusicToggleUI != null)
        {
            musicToggleUI.GetComponent <Toggle>().isOn = PlayerPrefs.GetInt("soundOff") == 1;
            if (!musicToggleUI.GetComponent <Toggle>().isOn)
            {
                var clip = Soundtrack.ElementAt(0);
                audioSource.clip = clip;
                audioSource.loop = true;
                audioSource.Play();
            }
        }
    }