【问题标题】:stopping delta time c#停止增量时间c#
【发布时间】:2016-07-22 04:39:59
【问题描述】:

对于回合制游戏,我尝试一次显示 3 次。 第一次是倒计时的总时间。 其他两个计时器显示每个玩家的倒计时时间。 我还从另一个类中检查了一个布尔值,以查看它是哪一回合(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;


}

}

【问题讨论】:

    标签: c# timedelta


    【解决方案1】:

    我会将分钟和秒存储在一个小类中,并给每个玩家一个类,当它暂停时不要增加时间。 看起来像这样:

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

    然后在更新内部我将只使用 people 类变量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多