IEnumerator LoadGame() { yield return(new WaitForSeconds(3)); GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy"); for (int i = 0; i < enemies.Length; i++) { Destroy(enemies[i]); } Instantiate(PlayerPrefab, PlayerPrefab.transform.position, Quaternion.identity); GameLoaded.Invoke(); CurrentWave = 0; _player = GameObject.FindWithTag("Player"); _playerDamage = _player.GetComponent <DamageFromContactWithTag>(); _playerHealth = _player.GetComponent <Health>(); _playerDamage.DamageTaken.AddListener(OnPlayerDamageTaken); _playerDamage.DamageIntervalHalf.AddListener(OnPlayerDamageHalfTaken); _playerDamage.DamageReset.AddListener(OnPlayerDamageReset); _playerHealth.Died.AddListener(OnPlayerDied); ProCamera2D.Instance.AddCameraTarget(_player.transform); }
void OnSceneLoaded(Scene scene, LoadSceneMode mode) { if (scene.name == "game") { GameLoaded.Invoke(); CurrentWave = 0; _player = GameObject.FindWithTag("Player"); _playerDamage = _player.GetComponent <DamageFromContactWithTag>(); _playerHealth = _player.GetComponent <Health>(); _playerDamage.DamageTaken.AddListener(OnPlayerDamageTaken); _playerDamage.DamageIntervalHalf.AddListener(OnPlayerDamageHalfTaken); _playerDamage.DamageReset.AddListener(OnPlayerDamageReset); _playerHealth.Died.AddListener(OnPlayerDied); ProCamera2D.Instance.AddCameraTarget(_player.transform); } }