attack targeted enemy

sorry i know i post a lot here … and i solve a lot of my own threads through the rubber duck effect … this forum is really helping me out though and i hope i am making it easier for future developers through my solved thread content.

“enemy” is a gameobject tag. all enemies will be tagged enemy, or so far that is the plan. attacking is a state in a finite state machine, along with approach enemy, idle, move to point, and that’s all so far. attacking has an animation based on the angle of the hero to the enemy, and tests whether it hits or misses (then if it hits deals damage). pretty simple.

so far this only works with one enemy and that is my problem. how can i make it so it “targets” only the enemy that is clicked on? so far i have no ideas but don’t be surprised if i come back with an edit in like 2 minutes lol

edit: here’s some code -

void Attack(GameObject enemy1)  // again, this just refers to one enemy. need to fix!
        {
            if (enemy_clicked == true)
            {
                AttackEnemy(enemy1);
            }
        }

so far i figured out that i need to have the damage taken on a script that is on the enemy game object. i always try to bump with an update, to show that i am working on this too. i’m just stuck.

I would setup an interface (e.g. IDamageable) for the enemies. If you click on the enemy and it has the tag ‘enemy,’ then you can check to see if they have the interface. If so, then add damage to the enemy on the enemy’s script that implements the interface.

1 Like