- Home /
A.I. Pressing next turn after 1 second.
Hello I'm working on a turn-based strategy game. But I can't seem to make my A.I. "press" next turn. I thought about making it so that it does it after 1 second. So what I basically need is a timer that goes of when it is the A.I. turn.
I have a variable that tells the turn. (turnNumber) which tells it who's turn it is. Then I need it to add 1 to turnNumber. "turnNumber ++;" How can I do so that it does that after 1 second?
Thanks for your time.
[EDIT]: I use JavaScript.
Answer by tw1st3d · Oct 01, 2013 at 05:44 PM
Use StartCoroutine. This code will not work without proper construction. This is an example.
int playerUp, rounds;
public void Start()
{
StartCoroutine(CheckPlayerState());
}
public void OnGUI()
{
GUI.Label(new Rect(20, 20, 100, 20), "" + rounds);
}
public IEnumerator CheckPlayerState()
{
if(playerUp == 2)
{
yield return new EnemyPlay();
}else if(playerUp == 1){
yield return new YouPlay();
}
}
public IEnumerator EnemyPlay()
{
// AI System;
yield return new WaitForSeconds(1);
if(AI.Strategy == null) // PSEUDO-CODE
{
playerUp = 1;
rounds++;
}
yield return null;
}
Your answer
Follow this Question
Related Questions
Do something every each multiple of 1000.. 2 Answers
Switch turns between the Player and AI 0 Answers
How can I get my pathfinding algorithm to know that it cant go through certain sides of tiles 1 Answer
Astar Pathfinding ai moves more nodes than it should 0 Answers
Can you use NavMesh agents to vary driving/handling model? 0 Answers