0
\$\begingroup\$

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?

\$\endgroup\$
2
  • \$\begingroup\$ Is this still solving the same core problem as your previous question? If so, would you like to edit that question to update it with the latest details, instead of posting a new question? \$\endgroup\$ Commented Aug 9, 2021 at 21:26
  • \$\begingroup\$ Does this answer your question? How Do I add turn based combat on these scripts in unity 2d? \$\endgroup\$ Commented Aug 11, 2021 at 20:06

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.