I researched before posting this…
So basically I don’t know why, but when I was making/editing my game, suddenly when I play it, the mouse is visible and it’s not locked…
So I researched how to lock my cursor and I tried everything! Like this (I created a JS Script and just tried these little codes)
1st try
function Start ()
Cursor.visible = false;
2nd try
function Start ()
Cursor.lockState = CursorLockMode.Locked
3rd try
function Start ()
Cursor.visible = false;
function Update ()
Cursor.lockState = CursorLockMode.Locked
None of these worked can someone help?
Did you actually attach this script to an object in your scene?
Try adding a Debug.Log to the Start so you can see if it is actually getting called.
Just to make sure you used this code right?
function Start()
{
Cursor.visible = false;
Debug.Log("Cursor should now be hidden!");
}
(Insert obligatory use C# because JS/US is being deprecated (Abandoned))
Ryiah
August 11, 2017, 10:13am
3
GameCodeEdit:
So basically I don’t know why, but when I was making/editing my game, suddenly when I play it, the mouse is visible and it’s not locked…
So I researched how to lock my cursor and I tried everything! Like this (I created a JS Script and just tried these little codes)
Unfortunately Unity’s documentation neglects the most important part. Unity’s editor is overriding them. They will work just fine from a build, but the editor won’t allow them to function in Edit mode or in Play mode.
2 Likes
So when if I finish the game and export it… the cursor will not be visible? But only in edit or play mode it’s unlocked and visible?
Ryiah
August 11, 2017, 1:24pm
5
1 Like
orb
August 11, 2017, 2:39pm
6
You don’t need to finish it - sometimes it’s a good idea to export the standalone player when something is acting up
2 Likes
So I built my game and my cursor was visible and was not locked…
Then it must be something else that’s changing its state, I’d say.
wait… I still have to make a script for the cursor to be locked and visible right?
E.g:
Function Start ()
Cursor.lockState = CursorLockMode.Locked
If so then I’m dumb.
lol… I hear ya, kindly. I got it a little backwards, too. Yep, gotta lock + hide it then test unlocking/unhiding it .