Home > other >  Unity3D for help, run and then click the button, the time has been 00:00:00 motionless
Unity3D for help, run and then click the button, the time has been 00:00:00 motionless

Time:09-27

Using UnityEngine;
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 (a);

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 Update

CodePudding 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 update

CodePudding user response:

For the Time of deltaTime need Update
  • Related