停止增量时间 c#
stopping delta time c#
我正在尝试一次显示 3 次回合制游戏。
第一次是总时间倒计时。
另外两个计时器显示每个玩家的倒计时时间。
我还有一个布尔值正在从另一个 class 检查以查看它是哪一回合 (myplayerturn)
现在我可以显示总时间和玩家时间都有效倒计时,但是当一个玩家时间是 运行 我想暂停另一个玩家计时器。至此我的代码如下
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;
}
}
我会将分钟和秒存储在一个小的 class 中,并给每个玩家一个 class 并且当它暂停时不要增加时间。
看起来像这样:
public class PlayerTime {
public int seconds = 0;
public int minutes = 0;
public float myTimer = 3600;
}
然后在更新中我将只使用 persons class 变量。
我正在尝试一次显示 3 次回合制游戏。 第一次是总时间倒计时。 另外两个计时器显示每个玩家的倒计时时间。 我还有一个布尔值正在从另一个 class 检查以查看它是哪一回合 (myplayerturn)
现在我可以显示总时间和玩家时间都有效倒计时,但是当一个玩家时间是 运行 我想暂停另一个玩家计时器。至此我的代码如下
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;
}
}
我会将分钟和秒存储在一个小的 class 中,并给每个玩家一个 class 并且当它暂停时不要增加时间。 看起来像这样:
public class PlayerTime {
public int seconds = 0;
public int minutes = 0;
public float myTimer = 3600;
}
然后在更新中我将只使用 persons class 变量。