- Home /
How to hide cursor for amount of time?
I want to hide the cursor for 4 seconds and show it back, because my main menu has a fade out intro and I don't want to show the cursor when the screen is still black. Thanks for any help. I'm new to code. Doesn't matter if is javaScript or C#.
From beggining of the scene. Should be in void Start(){} I believe.
Answer by JoaoOliveira · Jan 15, 2014 at 12:52 PM
How about this?
public float HideTime;
void Start() {
Screen.showCursor = false;
StartCoroutine(ShowCursorAfter(HideTime));
}
IEnumerator ShowCursorAfter(float hideTime) {
yield return new WaitForSeconds(hideTime);
Screen.showCursor = true;
}
IT WOR$$anonymous$$ED! Thank you, this effect is really useful. And thank you Quillicit as well.
No problem man, here's more info on Coroutines, they are really useful in Unity.
Answer by Quillicit · Jan 15, 2014 at 07:19 AM
You could probably create a variable and set it equal to Time.time, then have the cursor come back when Time.time equals the variable plus 4. So something like this should get you started (C#):
Screen.showCursor = false;
private float momentFadeStart = Time.time;
if(momentFadeStart >= Time.time + 4){
Screen.showCursor = true;
}
I'm not sure what I do wrong. I declare the float and I put the statement in the void Start, because I felt it was the case. But it says: "get_time can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, ins$$anonymous$$d move initialization code to the Awake or Start function."
So I movie everything up the void Start just below the float, like you wrote. But it gives me a parse error, saying unexpected + and =.
using UnityEngine;
using System.Collections;
public class CursorIntro : $$anonymous$$onoBehaviour {
private float momentFadeStart = Time.time;
void Start () { //If I call it Awake, won't fix anything.
Screen.showCursor = false;
if(momentFadeStart >= Time.time + 4)
{
Screen.showCursor = true;
}
}