Ejemplo n.º 1
0
    private IEnumerator PlayerDeath()
    {
        // Turn everything off
        DisablePlayer(true);

        if (MainCollider.enabled)
        {
            MainCollider.enabled = false;
        }

        if (!isDead)
        {
            isDead = !isDead;
            switch (currentState)
            {
            case PlayerStates.SPIKE_DEAD:
                PlayerAudioSource.PlayOneShot(spikeDeathClip);
                break;

            case PlayerStates.BOOM_DEAD:
                PlayerAudioSource.PlayOneShot(boomDeathClip);
                break;
            }

            // If the player is dead, stop the level music.
            if (SoundManager.MusicSource.isPlaying)
            {
                SoundManager.MusicSource.Stop();
            }

            yield return(new WaitForSeconds(1.5f));

            OnPlayerIsDead?.Invoke(isDead);
            enabled = false;
        }
    }
 private void OnCollisionEnter(Collision other)
 {
     OnPlayerIsDead?.Invoke();
     Destroy(gameObject);
 }