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!
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;
}
}
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?