我创建了两个定时器,它们以00:00(Mins:Secs)的格式运行。我想将这两个定时器添加到一起,最终的定时器也应该是00:00的格式。我如何以这种方式创建最后的计时器?
eg. Timer 1 = 02:00,
Timer 2 = 03:30,
Final Timer = 05:30
public float Time_1;
public string Time_1_format = "00:00";
public float Time_2;
public string Time_2_format = "00:00";
string a_1_minutes;
string a_1_seconds;
string a_2_minutes;
string a_2_seconds;
string final_Time;
public string Time_3_format = "00:00";
void Update()
{
Time_1 += Time.deltaTime;
a_1_minutes = Mathf.Floor(Time_1 / 60).ToString("00");
a_1_seconds = (Time_1 % 60).ToString("00");
Time_1_format = string.Format("{0}:{1}", a_1_minutes, a_1_seconds);
Time_2 += Time.deltaTime;
a_2_minutes = Mathf.Floor(Time_2 / 60).ToString("00");
a_2_seconds = (Time_2 % 60).ToString("00");
Time_2_format = string.Format("{0}:{1}", a_2_minutes, a_2_seconds);
}
你需要做的就是Time_Sum = Time_1 + Time_2;
你能做的就是因为 Time_1
和 Time_2
是浮动的。
public float Time_Sum;
public string Time_Sum_format = "00:00";
string sum_minutes;
string sum_seconds;
Time_Sum = Time_1 + Time_2;
sum_minutes = Mathf.Floor(Time_Sum / 60).ToString("00");
sum_seconds = (Time_Sum % 60).ToString("00");
Time_Sum_format = string.Format("{0}:{1}", sum_minutes, sum_seconds);