- Home /
where should i put this script
I have a mouse lock script in JavaScript and I don't know where to put it. what object should I put it on?`// Called when the cursor is actually being locked PS, I did get it from the scripting API or whatever it's called
// Called when the cursor is actually being locked
function DidLockCursor () {
Debug.Log("Locking cursor");
// Disable the button
guiTexture.enabled = false;
}
// Called when the cursor is being unlocked
// or by a script calling Screen.lockCursor = false;
function DidUnlockCursor () {
Debug.Log("Unlocking cursor");
// Show the button again
guiTexture.enabled = true;
}
function OnMouseDown () {
// Lock the cursor
Screen.lockCursor = true;
}
private var wasLocked = false;
function Update () {
// In standalone player we have to provide our own key
// input for unlocking the cursor
if (Input.GetKeyDown ("escape"))
Screen.lockCursor = false;
// Did we lose cursor locking?
// eg. because the user pressed escape
// or because he switched to another application
// or because some script set Screen.lockCursor = false;
if (!Screen.lockCursor && wasLocked) {
wasLocked = false;
DidUnlockCursor();
}
// Did we gain cursor locking?
else if (Screen.lockCursor && !wasLocked) {
wasLocked = true;
DidLockCursor ();
}
}
A link to where you got this script from would give some context to the question.
But it looks like it can be on any game object. try the main camera...
Answer by Kiwasi · Oct 22, 2014 at 03:00 AM
Attach it to any GameObject in your scene. It really doesn't matter. You could even create a new GameObject just to put this on.
Answer by Melvin8D · Oct 22, 2014 at 11:45 PM
guys I got a script now
function Update () {
if (Input.GetKey ("1"))
Screen.lockCursor = true;
if (Input.GetKey ("2"))
Screen.lockCursor = false;
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Cursor Locks/Hides but Will Not Reappear? 1 Answer
Screen.lockCursor messes my rotation 1 Answer
Locking cursor/mouse on an object 1 Answer