private void RespawnTimer_OnCompleted(IClockTimer sender, TimeEventArgs e) { Debug.Log("Respawn Timer completed"); // Reset the clock RespawnTimer.StopClockTimer(); // If the player is completely dead, dont respawn if (!Lives.HasLives) { return; } // Otherwise, Reset stats and Respawn the Player m_rigidbody2D.velocity = Vector3.zero; var spawnPoint = Game.Level.GetRandomSpawn(); transform.position = spawnPoint.transform.position; Stamina.SetMaxStamina(); // Enable the players scripts //var colliderPlayerScripts = new List<MonoBehaviour>(); //colliderPlayerScripts.AddRange(gameObject.GetComponents<MonoBehaviour>()); //colliderPlayerScripts.AddRange(gameObject.GetComponentsInChildren<MonoBehaviour>()); //foreach (var script in colliderPlayerScripts) //{ // script.enabled = true; //} // Show the Player Lives.IsAlive = true; }
// Use this for initialization void Start() { // Unity Components m_rigidbody2D = GetComponent <Rigidbody2D>(); m_spriteRenderer = GetComponent <SpriteRenderer>(); // Custom Components Stamina = GetComponent <PlayerStamina>(); Lives = GetComponent <PlayerLives>(); // Setup the Respawn Timer RespawnTimer = GetComponent <CountdownTimer>(); RespawnTimer.StopClockTimer(); RespawnTimer.OnCompleted += RespawnTimer_OnCompleted; }