Exemple #1
0
    public void OnDamaged(float damage, int ID)
    {
        if (ragdollControl.shotByBullet || Dead || IsInvincible)
        {
            return;
        }
        if (IsAxe)
        {
            damage /= 2;
        }

        float oldH = Health;

        Health -= damage;
        Health  = Mathf.Max(0, Health);

        if (ID != playerIdentity.PlayerID)
        {
            BattleData.AddDamage(ID, damage);
            LastDamagedID = ID;
        }

        OnHealthChanged?.Invoke(this, oldH, Health);

        if (Health <= 0)
        {
            if (Dead)
            {
                return;
            }
            audioSource.PlayOneShot(deathSound, 0.5f);

            StartCoroutine(Respawn(2));
            OnDeath?.Invoke(this);
            Dead = true;
        }
        else if (damage > 1)
        {
            int r = Random.Range(0, hurtSound.Length);
            audioSource.PlayOneShot(hurtSound[r], 1f);
        }
        else if (damage < 1)
        {
            if (!audioSource.isPlaying)
            {
                int r = Random.Range(0, hurtSound.Length);
                audioSource.clip = hurtSound[r];
                audioSource.Play();
            }
        }
    }