- Home /
Cursor Visible
Hello ! I would like to get a cursor that is only visible when i press a letter, but i need to keep it enabled until a tell to disable but the code :
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.C))
{
Cursor.visible = true;
}
}
}
Is not working.
Thank you for your help!
Answer by Legend_Bacon · Nov 21, 2017 at 06:30 PM
Hello there, On Start() you probably want to set your cursor visibility to false. Then, when you press "C", it makes it visible, then invisible if you press "C" again. This is what the code below does:
void Start ()
{
Cursor.visible = false;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.C))
{
Cursor.visible = !Cursor.visible;
}
}
I hope that helps!
~LegendBacon
It's getting near of my objective ! Thank you for your help !
But it only shows the cursor for half a second or so ^^' , i think i have to lock it but i dont see any state for this ?
Thank you again for your help !
Hello there, It is very strange that the cursor would go back to invisible without you pressing "C" again. Do you control the cursor's visibility anywhere outside of this class?
Or could it be that your Start() is called multiple times? Could you change your code to this and tell me how many logs you get, and in what order?
private int i_logCount = 0;
void Start ()
{
Cursor.visible = false;
Debug.Log((++i_logCount).ToString() + ": START => " + Cursor.visible);
}
// Update is called once per frame
void Update()
{
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.C))
{
Cursor.visible = !Cursor.visible;
Debug.Log((++i_logCount).ToString() + ": UPDATE => " + Cursor.visible);
}
}
This will help figure out what your problem is.
I hope that helps! ~LegendBacon
Answer by Spymoi · Nov 21, 2017 at 06:42 PM
We're getting near ! You were really fast ^^ Thank you !
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Artifacts on cursor when using CursorMode.Auto 0 Answers
CursorLockMode.Locked doesnt work 1 Answer
Unity Cursor changing back 1 Answer