Home Game Development unity – Triple harm however i would like solely as soon as

unity – Triple harm however i would like solely as soon as

0
unity – Triple harm however i would like solely as soon as

[ad_1]

i’m making an attempt to make a sport on unity. I’m kinda new, so this is likely to be a silly query idk. Right now i’m making an attempt to wreck the enemy. The Damage works. The drawback is it is going to repeat it till the enemy died however i solely need it to wreck it as soon as.

    void Update()
    { 
        if(Input.GetMouseButton(0) && !isCooldown){
            StartCoroutine(Cooldown());
            Attack();                                                       //ATTACK
        }
    personal void Attack() {
        anim.SetTrigger("assault");

        Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.place, attackRange, enemyLayers);

        foreach(Collider2D enemy in hitEnemies)
        {
            Enemy.GetComponent<EnemyHP>().TakeDamageEnemy(harm);
            Debug.Log("DamageENEMYYYYYYY");
        }
    }

Damage is a public float with 1. the EnemyHP part has code to take away the hp with the harm. Tested the code out with a debug.log and it certainly does take away the hp with the quantity of injury. But it repeats the TakeDamageEnemy perform
The complete hp = 3. So it repeats the code 3 occasions (console reveals the log 3 occasions.)
How can i alter it so it is going to solely play it as soon as.

This is my first put up on Stack change, so sorry if i pass over any necessary data. Reply and i’ll add it

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here