Hello! I would like to have some kind of UI (like panel) start up within 2 seconds when you start a new level. Fairley need at scripting still and could use a lead. Thank you all. (i need it to pause game also when it pops up) Codeing is C#
Remember the time at start of the scene. Use Update() to check if some predefined time value (2s for you) has passed. If so, then call a function that does what you want. In your case, it would enable some UI and pause the game. It’s probably also a good idea to only do this once. To keep track of that we can use a bool.
Code example:
// Involved objects and variables
[SerializeField] private GameObject yourGui = null; // set in inspector
[SerializeField] private float uiTimeDelay = 2.0f;
private float sceneLaunchTime = 0;
private bool launchDelayedGui = true;
void Awake(){
sceneLaunchTime = Time.realTimeSinceStartup;
}
void Update(){
if(launchDelayedGui && (sceneLaunchTime + uiTimeDelay) < Time.realTimeSinceStartup){
launchDelayedGui = false; // we did it once and dont want it to get called every frame
YourFunction(); // do whatever once your time limit passed
}
}
private void YourFunction(){
yourGui.SetActive(true);
Time.timeScale = 0; // pauses the game
}
That should do what you want. Keep in mind that i typed the above in this editor, so i probably included some typos.
To return to normal you need to reverse what ‘YourFunction()’ does. So disable the GUI and return timeScale to 1.