コード例 #1
0
    public void TakeDamage(int damage)
    {
        health -= damage;

        if (characterType == 5)
        {
            if (Random.Range(0, 2) == 0)
            {
                DropPotion(manaPotion, 50f);
            }
            if (Random.Range(0, 2) == 1)
            {
                DropPotion(healthPotion, 30f);
            }
        }

        HealthUI.text        = health.ToString();
        HealthBar.fillAmount = health / maxHealth;

        if (health <= 0)
        {
            if (manaPotion != null && characterType != 0 && characterType != 5)
            {
                int randomInt = Random.Range(0, 2);
                if (randomInt == 0)
                {
                    DropPotion(manaPotion, 101f);
                }
                if (randomInt == 1)
                {
                    DropPotion(healthPotion, 101f);
                }
            }

            if (characterType == 0)
            {
                GetComponent <PlayerController>().OnGameEnd(false);
                DeathManager.Death();
                MusicManager.PlaySound("youdied");
            }

            if (characterType > 0)
            {
                GameObject.FindWithTag("Player").GetComponent <PlayerController>().gaStats.Mobkills++;
                Debug.Log("Mobs killed: " + GameObject.FindWithTag("Player").GetComponent <PlayerController>().gaStats.Mobkills);
                if (characterType == 5)
                {
                    GameObject.FindWithTag("Player").GetComponent <PlayerController>().OnGameEnd(true);
                    WinManager.Win();
                    MusicManager.PlaySound("win");
                }
                else
                {
                    SoundManagerScript.PlaySound("enemydeath1");
                }
            }
            Destroy(gameObject);
        }
    }