Hello,
I’ve got a litte game where the player is able to control a group of soldiers, each soldier is individual. There are enemy soldiers on the battlefield which could been attacked by moving the group of soldiers to the position of the enemy.
Each soldier should attack only one enemy approx. every 1 sec. And there is the thing i struggle with.
**Question:**How do I get the soldiers to attack only one enemy at a time and not every soldier they are colliding with?
void OnCollisionStay2D(Collision2D coll)
{
if ((coll.gameObject.tag == "Enemy" && this.tag == "Friend") || (coll.gameObject.tag == "Friend" && this.tag == "Enemy")) //The if, because friendly and enemy soldiers are controlled by same script
{
HitTimer += Time.deltaTime;
if (HitTimer > HitTime)
{
coll.gameObject.GetComponent<SoldierLogic>().Health -= 30;
HitTimer = 0f;
}
}
}
Im thankful for every hint!
Best regards