【发布时间】:2016-03-15 16:59:40
【问题描述】:
我有一个初始化为 true 的切换按钮,当它被关闭时,它应该触发一个函数,该函数对经过的每一秒进行减法。
要减去的变量名为 TEMPERATURE,它应该每秒减去 1,直到达到 0。为了计算秒数,我使用名为 TimeSinceLevelLoad 的 Monobehaviour 变量。
我构建了 I 函数,但减法永远不会发生,你能帮帮我吗?
using UnityEngine;
using System.Collections;
using Assets.Code.PowerPlants;
public class thermoPowerControlPanel : MonoBehaviour {
private ThermoElectric thermo;
public bool t1= true;
int temperature;
private int tempUP = 10;
private int tempDOWN = 1;
private int mark;
private int i =0;
public thermoPowerControlPanel (){
temperature = 100;
}
public void turbine1State (bool t1) {
Debug.Log (temperature);
if (i ==0) {
mark = (int)Time.timeSinceLevelLoad;
i = 1;
}
if (t1 == false) {
ThermoElectric.t1Bool = t1;
if (temperature != 0) {
if (mark + 1 == (int)Time.timeSinceLevelLoad ) {
temperature = temperature - tempDOWN;
i = 0;
Debug.Log (temperature);
}
}
}
}
}
bool t1 工作正常,我已经检查过了,它变为 False。
【问题讨论】: