-1

I'm trying to display 3 times at once for a turn based game. The first time is total time being counted down. The other two timers shows countdown time for each player. I also have a boolean value being checked from another class to see which turn it is(myplayerturn)

Right now I can show total time and player time all counting down effectively, but when one player time is running i want to pause the other player timer. So far my code is as follows

public class countDown : MonoBehaviour {

public Text timerText;
public Text PlayerTime;
public Text OpponentTime;
public float myTimer = 3600;



// Use this for initialization
void Start () {
    timerText = GetComponent<Text>();
    PlayerTime = GetComponent<Text>();
    OpponentTime = GetComponent<Text>();

}

// Update is called once per frame
void Update () {

    if (GetComponent<differentclass>().myplayerturn)
    {
        //I'm gueussing this is where i need to pause OpponentTime;
        // and start PlayerTime
    } 
    else{
        // pause PlayerTime
        }

    int minutes = Mathf.FloorToInt(myTimer / 60F);
    int seconds = Mathf.FloorToInt(myTimer - minutes * 60);
    string rTime = string.Format("{0:00}:{1:00}", minutes, seconds);

    myTimer -= Time.deltaTime;
    timerText.text = rTime;
    PlayerTime.text = rTime;
    OpponentTime.text = rTime;


}

}

1 Answers1

0

I would store minutes and seconds in a small class and give every player a class and when its paused just dont increment the time. That would look like this:

public class PlayerTime {
    public int seconds = 0;
    public int minutes = 0;
    public float myTimer = 3600;
}

Then inside of the update I would just use the persons class variable.

JQluv
  • 244
  • 1
  • 6