- Home /
Invoke remaining time display on GUIText
How can I detect remaining time of an Invoke to display on GUIText?
Answer by aldonaletto · Nov 20, 2011 at 05:33 PM
You can't read the remaining time, but you can calculate it, like this:
var gText: GUIText; // drag the GUIText here from Hierarchy var timeToInvoke: float = 5.0; // time to invoke the function private var remTime: float;
Invoke("SomeFunction", timeToInvoke); remTime = timeToInvoke; // start the timer when Invoke is called
function Update(){ if (remTime >= 0){ // only count time while it has not finished remTime -= Time.deltaTime; // decrement timer if (remTime >= 0){ // if timer still > 0... gText.text = remTime.ToString("F1"); // show it } else { // but if time ended... gText.text = ""; // display nothing } } }
I need C#, forgot to tell it in question, but I figured it out with this. Thanks very much!
Your answer
![](https://koobas.hobune.stream/wayback/20220613050639im_/https://answers.unity.com/themes/thub/images/avi.jpg)