Esempio n. 1
0
    public void GetAttacked(int enemyStrength, bool playAnimation)
    {
        var popupText = Instantiate(popupTextPrefab);

        popupText.transform.SetParent(GameObject.Find("MainCanvas").transform, false);
        popupText.SetText(enemyStrength.ToString());
        popupText.transform.position = Camera.main.WorldToScreenPoint(transform.position);
        Health = Math.Max(0, Health - enemyStrength);
        healthbar.Set(Health, MaxHealth);

        if (Health > 0)
        {
            if (playAnimation)
            {
                BeatenRunning = 0.8f;
                if (BeatenAudioClip != null)
                {
                    GetComponent <IGameUnit>().audioSource.PlayOneShot(BeatenAudioClip, 0.3f);
                }
            }
        }
        else
        {
            GetComponent <IGameUnit>().RemoveCharacter(2f);
            if (playAnimation)
            {
                // play a death animation and remove the gameobject
                DeathRunning = 1.2f;
                if (DieAudioClip != null)
                {
                    GetComponent <IGameUnit>().audioSource.PlayOneShot(DieAudioClip, 0.3f);
                }
            }
        }
    }