Exemplo n.º 1
0
    public void DamageHealth(int Attack)
    {
        int damage = DamageCalc.CalcDamage(Attack, _enemy.Defense, DamageType.Energy);

        _health -= damage;
        if (_health < 0)
        {
            _health = 0;
        }

        UpdateHealthBar();
    }
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Enemy"))
        {
            health -= DamageCalc.CalcDamage(base_damage, type, other.GetComponent <UnitController>().type);
        }

        if (other.gameObject.CompareTag("Player"))
        {
            health -= DamageCalc.CalcDamage(base_damage, type, other.GetComponent <UnitController>().type);
        }

        if (health < 0)
        {
            health = 0;
        }

        if (health <= 0)
        {
            this.gameObject.SetActive(false);
        }
    }
Exemplo n.º 3
0
    public void TakeDamage(int Attack)
    {
        // Create a vector that's from the enemy to the player with an upwards boost.
        //Vector3 hurtVector = transform.position - enemy.position + Vector3.up * 5f;

        // Add a force to the player in the direction of the vector and multiply by the hurtForce.
        //GetComponent<Rigidbody2D>().AddForce(hurtVector * hurtForce);

        int damage = DamageCalc.CalcDamage(Attack, _playerControl.playerStats.Armor + _playerControl.playerStats.Defense, DamageType.Energy);

        _playerControl.playerStats.Health -= damage;

        if (_playerControl.playerStats.Health < 0)
        {
            _playerControl.playerStats.Health = 0;
        }

        // Update what the health bar looks like.
        UpdateHealthBar();

        // Play a random clip of the player getting hurt.
        int i = Random.Range(0, ouchClips.Length);
        //AudioSource.PlayClipAtPoint(ouchClips[i], transform.position);
    }