2016-07-22 81 views
-1

我试图一次显示3次回合制游戏。 第一次是总计倒计时。 另外两个计时器显示每个玩家的倒计时时间。 我也有一个布尔值被检查从另一个类,看看它是哪一轮(myplayerturn)停止增量时间c#

现在我可以显示总的时间和球员的时间都有效地倒计时,但是当一个球员的时间运行我想暂停其他玩家计时器。到目前为止,我的代码如下

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; 


} 

}

回答

0

我会存储在一个小班分钟和秒钟,并给每个球员一个类和它暂停时只是不增加的时间。 这将是这样的:

public class PlayerTime { 
    public int seconds = 0; 
    public int minutes = 0; 
    public float myTimer = 3600; 
} 
更新我只想用的人类变量的内部

然后。