Very simple mouse lock question!

Sorry, I expect the answer to this is blindingly obvious, but I’ve now spent nearly an hour messing around and not solved it!

I’m trying to use the Screen.lockCursor script (Unity - Scripting API: Screen.lockCursor), but I have no idea where to put it. I tried attaching it to the camera but nothing happened. I assume there’s some way to run it without putting it on an object?

When it comes to code I’m mentally retarded, so if anyone could help out that would be great!

Have you tried attaching it to the character controller you are using? That or camera would be my thoughts.

olivepixel,

You can attach the script the way it is to any object in the scene. The way the script is written expects you to attach a GUI Texture to this object as well and the cursor will be locked when you click on this object.

You could make it work without the GUI Texture portion and just lock anytime you click on your window with something like this:

public class LockCursorOnClickScript : MonoBehaviour 
{ 
    void Update() 
    {
        if (Input.GetKeyDown("escape"))
            Screen.lockCursor = false;
        else if (Input.GetMouseButtonDown(0)  Screen.lockCursor == false)
            Screen.lockCursor = true;
    }
}

[quote=Shawn[QS];471937]
olivepixel,

You can attach the script the way it is to any object in the scene. The way the script is written expects you to attach a GUI Texture to this object as well and the cursor will be locked when you click on this object.

You could make it work without the GUI Texture portion and just lock anytime you click on your window with something like this:

public class LockCursorOnClickScript : MonoBehaviour 
{ 
    void Update() 
    {
        if (Input.GetKeyDown("escape"))
            Screen.lockCursor = false;
        else if (Input.GetMouseButtonDown(0)  Screen.lockCursor == false)
            Screen.lockCursor = true;
    }
}

[/quote]

Thanks, sounds like that’s just what I need. To be extra dim, where do I put it? Do I simply paste that into a new script and then add it to any scene object, or do I need something else?

Here’s the project so far: MACAUSLOT88 Deposit Pulsa 3

I get 4 errors at the moment, I’ve tried simply putting it into a new java script:

Assets/NewBehaviourScript.js(1,1): BCE0043: Unexpected token: public.
Assets/NewBehaviourScript.js(1,38): BCE0043: Unexpected token: :.
Assets/NewBehaviourScript.js(1,53): UCE0001: ‘;’ expected. Insert a semicolon at the end.
Assets/NewBehaviourScript.js(3,10): BCE0044: expecting :, found ‘Update’.

I assume that means I’m doing something wrong with it?

It’s not actually a ‘java script’; rather, ‘javascript’ (or more accurately UnityScript) is the name of the programming language in question.

Also, the code Shawn[QS] posted is in C#, not UnityScript, which is probably why you’re getting compiler errors.