I have basic countdown based on turn system. When changing turns. Oponent or player timer get faster countdown. If i close unity and open again it works nomal. After 1-2 plays countdown gets faster again. I dont know if it is bug or script error?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TurnSystem : MonoBehaviour
{
public static bool isYourTurn;
public int yourTurn;
public int yourOponentTurn;
public Text turnText;
public int maxMana;
public static int currentMana;
public Text manaText;
public static bool startTurn;
//----Random turn start---//
public int random;
//---- timer ----//
public bool turnEnd;
public Text timerText;
public int seconds;
public bool timerStart;
void Start()
{
/*isYourTurn = true;
yourTurn = 1;
yourOponentTurn = 0;
maxMana = 1;
currentMana = 1;
startTurn = false; */ //------ turn system temiz hali <----
seconds = 60;
timerStart = true;
StartGame();
}
void Update()
{
if (isYourTurn == true)
{
turnText.text = "Your Turn";
}
else turnText.text = "Oponent Turn";
manaText.text = currentMana + "/" + maxMana;
if(isYourTurn == true && seconds>0 && timerStart == true)
{
StartCoroutine(Timer());
timerStart = false;
}
if(seconds == 0 && isYourTurn== true)
{
EndYourTurn();
timerStart = true;
seconds = 60;
}
timerText.text = seconds + "";
if(isYourTurn == false && seconds>0 && timerStart == true)
{
StartCoroutine(EnemyTimer());
timerStart = false;
}
if(seconds == 0 && isYourTurn==false)
{
EndYourOponentTurn();
timerStart = true;
seconds = 60;
}
}
public void EndYourTurn()
{
isYourTurn = false;
yourOponentTurn += 1;
timerStart = true;
seconds = 60;
}
public void EndYourOponentTurn()
{
isYourTurn =true;
yourTurn =+1;
maxMana += 1;
currentMana = maxMana;
startTurn = true;
timerStart = true;
seconds = 60;
}
public void StartGame()
{
random = Random.Range(0, 2);
if(random == 0)
{
isYourTurn = true;
yourTurn = 1;
yourOponentTurn = 0;
maxMana = 1;
currentMana = 1;
startTurn = false;
}
if(random == 1)
{
isYourTurn = false;
yourTurn = 0;
yourOponentTurn = 1;
maxMana = 0;
currentMana = 0;
}
}
IEnumerator Timer()
{
yield return new WaitForSeconds(1);
if (isYourTurn == true && seconds >0)
seconds--;
StartCoroutine(Timer());
}
IEnumerator EnemyTimer()
{
yield return new WaitForSeconds(1);
if (isYourTurn == false && seconds >0)
seconds--;
StartCoroutine(EnemyTimer());
}
}