How do u freeze the cursor like in fps games

How do u freeze the cursor so it doesn’t go at of the window.

Can you show me an example. :smile:

Just follow the link offered above.

You will realize that the script reference isn’t there just for fun, decoration and linking :wink:

Sorry should have paid closer attention. :frowning:

I’m curious about this too. I followed the link, I see the script, but it doesn’t tell you what to do with the script.

Best I can gather is that I have to create a new empty script in Unity and paste that text into it, then drag that script file onto an object. I read in another thread about putting it on an empty game object. But I don’t know what kind of script file to make. Is it a Javascript? C#? Boo?

Everything in the documentation is javascript.

Thank you. So is this right?

  1. Right click Scripts in the Project tab and select create > JavaScript
  2. Hit Edit in the Inspector.
  3. Paste the code in and hit Save.
  4. Drag the JavaScript from the project tab to my empty game Object in the Hierarchy.

Does it need the “function” bit that is already in there when I create the JaveScript file?

Make a javascript file and make it look like this:

function Start()
{
    Screen.lockCursor = true;
}

Add that script to an empty GO in your scene.

Done.

That’s nice but the other stuff in the original script sounded nicer, like hitting Esc. to show it again. This is going on the web for the general public (even non-gamers) to use, so I don’t want to confuse them.

For web applications, it is automatically unlocked when the user presses escape.

Yes, that’s what I said. I like the detailed script for that reason, and the rest too. I don’t know if there’s something you’re supposed to do besides the steps I described or what, but this doesn’t seem to be doing anything.

3 steps

  1. Menu, Game Object, create other, GUIText
  2. In component, under GUIText, look the field Text
  3. Where you see Gui Text, double click and type +

Run your game.
:wink:

I don’t think putting a + in the middle of the screen will help anyone.

Having a static object in the middle of the screen stops a lot of people from getting motion sickness in first-person games.

I do not fall into this category. :wink:

Even in a HUD-less game like Mirror’s Edge, they put a little dot in.

OK then it might be useful, but it’s not relevant to the question at hand. That being how to hide and freeze the cursor.

BTW these instructions gave me an error:

Assets/Standard Assets/Scripts/CursorLock.js(2,23): BCE0044: expecting :, found '='.

Are you sure you have it exactly like that in your script? It compiles fine for me because this is what I use in my applications.

function Start()
{
	Screen.lockCursor = true;
}

function Update()
{   
   if (Input.GetKeyDown(KeyCode.Escape)) 
   {
      Screen.lockCursor = false;
   }
}

Compiles? All I did was copy and paste what you put in your post.

BTW I made a separate thread so I’m not taking over X-Developer’s thread any more.

http://forum.unity3d.com/viewtopic.php?p=233200#233200

**Edit:**OK the new code you gave in your last post worked, hitting Esc brings back the cursor, but the cursor is there for good now. Is that supposed to happen?

Edit again: It works for the stand alone player, but not the web player where I really need it.