Example #1
0
    public void ReduceHealth(int redHealth)
    {
        currHealth -= redHealth;

        if (currHealth < 0)
        {
            currHealth = 0;
        }
        if (gameObject.CompareTag("Player"))
        {
            woundAnim.SetTrigger("IsWounded");
            myUI.SetHealth(currHealth);
            myVEC.MakeMinus(transform.position);
        }
        if (gameObject.CompareTag("Enemy"))
        {
            woundAnim.SetTrigger("isWounded");
            myVEC.MakeEnemyMinus(transform.position);
            EnemyUIController eUIC = gameObject.GetComponent <EnemyUIController>();            // Improve this place(!)
            eUIC.SetHealthRes(currHealth, maxHealth);
        }
        if (currHealth == 0)
        {
            if (gameObject.CompareTag("Player"))
            {
                gameObject.GetComponent <PlayerControllerScript>().OnDeath();
                //Destroy(gameObject);
            }
            if (gameObject.CompareTag("Enemy"))
            {
                Debug.Log("Enemy dies");
                GameObject go = GameObject.Find("Player");
                Destroy(gameObject.transform.parent.gameObject);
            }
        }
    }