Example #1
0
    public virtual void Die()
    {
        if (state != DamagableState.Alive)
        {
            return;
        }

        state = DamagableState.Dying;
        _deathCounter = 0;

        if (deathSound)
        {
            AudioSource.PlayClipAtPoint(deathSound, transform.position);
        }
    }
Example #2
0
 // Update is called once per frame
 protected virtual void Update()
 {
     switch (state)
     {
         case DamagableState.Dead:
             return;
         case DamagableState.Dying:
             _deathCounter += Time.deltaTime;
             if (_deathCounter > deathTime)
             {
                 state = DamagableState.Dead;
                 OnDeath();
             }
             break;
         case DamagableState.Alive:
             UpdateAlive();
             break;
     }
 }