I am making a turn based game and I want to switch turns after a user is done back and forth. I cant use update as it will restart the turn every frame. My code is:
public enum gameState { Start,p1Turn,p2Turn,Won,Lost} public class battleSsystem : MonoBehaviour { public gameState state; int randomTurn = 0;
int p1TurnCount = 5; int p2TurnCount = 5; bool flag = true; // Start is called before the first frame update void Start() { state = gameState.Start; StartCoroutine(setupBattle()); randomTurn = Random.Range(1, 3); if (randomTurn == 1) { state = gameState.p1Turn; } else if (randomTurn == 2) { state = gameState.p2Turn; } if (state == gameState.p1Turn) { Debug.Log("P1 Turn start"); p1Turn(); } if (state == gameState.p2Turn) { Debug.Log("P2 Turn start"); p2Turn(); } } IEnumerator setupBattle() { yield return new WaitForSeconds(0f); } void p1Turn() { Debug.Log("inside p1 turn"); p1Enable();//enables the player 1 controller p2Disable();//disables player 2 controller } void p2Turn() { Debug.Log("inside p2 turn"); p2Enable();//enables the player 2 controller p1Disable();//disables player 1 controller } So now this code at start will setup the battles. For now the function is empty. Then it will select a random turn and change the state according to it. This will only work once but i want it to work until p1TurnCount and p2TurnCount is 0. How can i run this back and forth?