- Home /
Start Something on Main Scene Start Up
Ok I know we can use the void Start to make something happen right away or on the void Awake but what if I want to do something when my main scene loads in something like this with a toggle button:
IEnumerator AutoStartTimer(){
yield return new WaitForSeconds(1.5f); // wait time
//Starts Auto Timer After Time
GoTimerStart();
//Option for Main Screen Message Centre Message that Auto Device Timer Has Started
//MessageCentreManager STM = FindObjectOfType<MessageCentreManager> ();
//STM.GoAutoStartTimerMessage ();
}
I have this on a toggle but when I turn on the toggle my timer naturally starts right away because it just sort of views it like a button press, which is fine if I had to live with it because all I would need to do is stop and reset the timer. I figure there is probably a better way to do it with something like:
When scene loads if the toggle "isOn" && level 01 has started then start the timer? It's funny in my head I can sort of see it just a little fuzzy on how to execute that ;)
void OnLevelWasLoaded(int level) {
if (level == 01 && isOn) {
StartCoroutine(AutoStartTimer());
}
}
This method is called after a level is loaded.
Thanks @ShadyProductions, yeah I knew about that but I was wondering if I would be able to call it in something like this sos that when I turn on my toggle that the timer would not just start right away ;) ?
//Toggle for Auto Selected Times Timer
public void ToggleAutoStartTimer(){
autoStartTimerToggleState = !autoStartTimerToggleState;
DataHolder DH = FindObjectOfType<DataHolder> ();
DH.autoStartTimerOnOff();
if (autoStartTimerToggleState == true) {
StartCoroutine (AutoStartTimer());
//Option For $$anonymous$$ain Screen $$anonymous$$essage Centre $$anonymous$$essage
//$$anonymous$$essageCentre$$anonymous$$anager AsTOn = FindObjectOfType<$$anonymous$$essageCentre$$anonymous$$anager> ();
//AsTOn.GoAutoStartTimer$$anonymous$$essage ();
} else {
autoStartTimerToggleState = false;
//Option For $$anonymous$$ain Screen $$anonymous$$essage Centre $$anonymous$$essage
//$$anonymous$$essageCentre$$anonymous$$anager AsTOff = FindObjectOfType<$$anonymous$$essageCentre$$anonymous$$anager> ();
//AsTOff.GoAutoStartTimerOff$$anonymous$$essage ();
}
}
IEnumerator AutoStartTimer(){
yield return new WaitForSeconds(1.5f); // wait time
//Starts Auto Timer After Time
GoTimerStart();
//Option for $$anonymous$$ain Screen $$anonymous$$essage Centre $$anonymous$$essage that Auto Device Timer Has Started
//$$anonymous$$essageCentre$$anonymous$$anager ST$$anonymous$$ = FindObjectOfType<$$anonymous$$essageCentre$$anonymous$$anager> ();
//ST$$anonymous$$.GoAutoStartTimer$$anonymous$$essage ();
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
put a void in an if statement? 1 Answer