Good Day! I have this code but I had an error
, for example (I set two players me, and 1 computer). I take the first turn, and the dice respawn with a value of 4 (just an example), the game piece then move from 1st to 4th tile when I touch the screen, when computer turns, it also move from 1st to 4th tile (because I set the result to 4 just an example). Now its my turn again, the dice never respawn and never wait to touch the screen if (Input.GetMouseButtonDown(0))and move again by 4...
void Update () { if (giveturn == true) { int h = 0; Giveturn(h); giveturn = false; }
if (play == true) {
if (pieces == true){
SpawnPlayer();
pieces = false;
}
if (myturn == true){
compturn = false;
if(diceSpawn == true) {
dice.transform.position = new Vector3(0,0,-1);
diceclone = Instantiate(dice, dice.transform.position, Quaternion.identity) as GameObject;
diceSpawn = false;
}
if (Input.GetMouseButtonDown(0))
{
Debug.Log("click");
diceresult = 4;
Destroy(diceclone);
moving = true;
Updateposition(diceresult);
}
}
else
{
Debug.Log("comp");
myturn = false;
diceresult = 4;
moving = true;
Updateposition(diceresult);
}
}
}
void Giveturn(int k) { Debug.Log("" + k); currentPlayer = k; if (k == playerTurn) { Debug.Log("Yes"); compturn = false; myturn = true; diceSpawn = true; moving = false; } else
{ Debug.Log("No"); compturn = true; myturn = false; moving = false; } }
void Updateposition(int diceresult) { if (moving == true) { playerTileUp[currentPlayer] = playerTile[currentPlayer] + diceresult; Debug.Log("" + playerTileUp[currentPlayer]+ " " +currentPlayer); routine = true; StartCoroutine(MyMethod()); } moving = false; }
IEnumerator MyMethod() { if (routine == true) { if (myturn == true) { compturn = false; } else { myturn = false; }
int f = playerTile[currentPlayer] + 1;
Debug.Log(" " + currentPlayer );
while (f <= playerTileUp[currentPlayer]) {
Debug.Log("waiting");
yield return new WaitForSeconds(1);
Debug.Log(" " + Tile[f]);
playerprefabC[currentPlayer].transform.position = Tile[f].transform.position;
Debug.Log(" " + currentPlayer);
f++;
}
checking = true;
TrapCheck();
}
routine = false;
}
void TrapCheck(){ if (checking == true) { if (playerTileUp[currentPlayer] == 8) { Debug.Log("Trap spawning"); Instantiate(situationCard[0], situationCard[0].transform.position, Quaternion.identity); population[currentPlayer] = population[currentPlayer] -1; }
playerTile[currentPlayer] = playerTileUp[currentPlayer];
Endturn();
myturn = false;
compturn = false;
checking = false;
}
}
void Endturn(){ currentPlayer++; Debug.Log(" " + currentPlayer); if (currentPlayer > compPlayer) { currentPlayer = 0; } Giveturn(currentPlayer); }
Your answer
![](https://koobas.hobune.stream/wayback/20220612055534im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Coroutine is called twice less time than update 1 Answer
3d Text update. How its work? 1 Answer
My Unity.exe deleted (Unity 2019.3.11),My Unity.exe was deleted (Unity 2019.3.11) 1 Answer
Execute coroutine in Update() 8 Answers
Code acts differently in new project than in old project; Cursor.lockState issue 1 Answer