- Home /
The question is answered, right answer was accepted
Invoke Method Not Working Properly!
I am trying to make a Simple Turn-Based Combat and have almost achieved it. However, I wanted some delay between the Enemy Turns and so I introduced a Delay between their attack scripts using INVOKE() Function. But this results in an overall Delay between the Player and the Enemy Turns, and not between the Enemy Turns (i.e) Once The player completes his/her turn, the Enemy Attack Scripts Fire TOGETHER after the delay I gave in INVOKE.
What am I doing wrong here?
case ENEMYTURN:
GameObject[] EnemyObjects = GameObject.FindGameObjectsWithTag ("Enemy");
foreach (GameObject EnemyObject in EnemyObjects)
EnemyObject.GetComponent<SkeletonWarrior> ().Invoke("attackPlayer", 3f);
nTurnMode = PLAYERTURN;
break;
I'm guessing the 3 seconds is based on the current time, so I would replace the foreach loop with a for loop, and multiply the delay by the index
Answer by TheMannyzaur · Sep 24, 2017 at 03:07 PM
trying using a bool that the player script can access so that when the player's move is done it calls on the bool in the enemy's script to be true. if the bool is true then you Invoke the function! hope that helps
I did exactly that after posting this Question! Thank you very $$anonymous$$uch!!
Follow this Question
Related Questions
Why won't invoke work in my script to delay the scene change? 1 Answer
Delay If statement in Update c# 2 Answers
Repeating after variable delay 1 Answer
Access to float seconds ago 2 Answers