Using System. The Collections;
Using UnityEngine. UI;
Public class GetTime: MonoBehaviour
{
Int hour;
Int minute;
Int second;
Public Button m_Button;
Float timeSpend=0.0 f;
The Text text_timeSpend;
Void the Start ()
{
Text_timeSpend=GetComponent
M_Button. OnClick. AddListener (ButtonOnClickEvent);
}
Public void ButtonOnClickEvent ()
{
TimeSpend +=Time. DeltaTime;
Hour=(int) timeSpend/3600;
Minute=((int) timeSpend - hour * 3600)/60;
Second=(int) timeSpend - hour * 3600 - minute * 60;
Text_timeSpend. Text=the string. Format (" {0: D2}, {1: D2}, {2: D2} ", hour, minute, second);
}
}
CodePudding user response:
Time. DeltaTime need UpdateCodePudding user response:
TimeSpend +=Time. DeltaTime;Hour=(int) timeSpend/3600;
Minute=((int) timeSpend - hour * 3600)/60;
Second=(int) timeSpend - hour * 3600 - minute * 60;
Text_timeSpend. Text=the string. Format (" {0: D2}, {1: D2}, {2: D2} ", hour, minute, second);
Write the above content in the update method,
CodePudding user response:
Brothers did this writing to you not click button timeSpend increase only once? You should write the time increase the code inside the fixedupdate or updateCodePudding user response:
For the Time of deltaTime need Update