- Home /
Turn based game, view the moves of the computer controlling enemys turn
Hi everybody!
Im developing a turn based game. Its based on a boardgame where you controll some character that are survivours an the enemy (computer) controls zombies. I`ve made a function that controls the zombies in enemies turn and moves them to reach the survivous. It does it automatically. What i need to perform is the following:
In enemis turn instead of procesing all automaticalli and show me the zombies already moved at the end of the turn, i want the camera tu focus one by one all the zombies and show the movement, one by one! until all the zombies have moved.
i have a funcion that uses a "foreach (zombie) do Move " .
How can i do this? any idea? Ive tried moving the camera to the location of each zombie before they move but it all happens very fast and im not able to see it.
Thanks to all!
https://www.youtube.com/watch?v=gj07BISWs0U
The turn of the enemy should look like in this game, they move one by one making their stuff
Probably want to use coroutines which will allow you force the "move handler" to pause while the zombies animate or do their thing"
Why don't you just re-use the move function that is used for the player characters for your zombies?
Slev: Yes i have tried using coroutine but it seems that with the foreach statement it doesnt work. $$anonymous$$aybe using for?
ahmedbenlakhdhar : The foreach is trigerred by a function that is called when i end my turn not in update. Ins$$anonymous$$d of foreach what should i use?
Thanks to all!!
Off topic note: Learning to spell correctly when typing on a computer will help immensely in reducing accidental errors in your code.
This is a little vague in my opinion. We can give suggestions as to going about doing it but I suggest you at least try some code and post it here if you encounter difficulties. Until you write some actual code, there's no way to tell where you went wrong or what you are missing.
Answer by Kiwasi · Dec 02, 2014 at 06:30 AM
You information is very sparse. But here is some pseudo code.
IEnumerator DoEnemyTurn (){
foreach (Enemy enemy in allEnemys){
yield return StartCoroutine(enemy.DoTurn());
yield return new WaitForSeconds(0.1f);
}
}
IEnumerator DoTurn (){
Debug.Log("Starting turn " + name);
yield return new WaitForSeconds(1);
Debug.Log("Finished turn " + name);
}
Without more details I can't give you more then that. Please note that the forums are better suited for general design questions. UA is for specific technical details.
Answer by AritzCoplas · Dec 02, 2014 at 12:17 PM
Thanks to all! Ill post some code and explain it better:
When i finish my turn making click on a button (finish turn) it goes to the following:
void StartZombiesTurn (){
PerformZombieActions (); //the zombies move or attack
ActivateSpawners (); //the zombies appear in the spawners
}
Here is the code of perform actions:
void PerformZombieActions(){
zombies = null; //Sets "zombies" (List<Zombie>) to null
zombies = boardManager.GetAllZombiesInGame ();
if (zombies.Count != null) {
foreach (Zombie z in zombies){
//each zombie has an amount of actions;
//this for is to make one action for each action available
for(int x = 0; x< z.GetActions(); x++){
z.MakeAction();
}
}
}
}
All this works correctly, excepting that i cant see it step by step. Thanks to all of you!
Your answer
![](https://koobas.hobune.stream/wayback/20220613172929im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
TPS camera in multiplayer... 2 Answers
FPS weapon natural look 0 Answers
AddForce to Camera 1 Answer
Game preview incorrect! 0 Answers