I took the code that was offered here
http://unity3d.com/support/documentation/ScriptReference/Screen-lockCursor.html
Code:
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void DidLockCursor() {
Debug.Log("Locking cursor");
guiTexture.enabled = false;
}
void DidUnlockCursor() {
Debug.Log("Unlocking cursor");
guiTexture.enabled = true;
}
void OnMouseDown() {
Screen.lockCursor = true;
}
private bool wasLocked = false;
void Update() {
if (Input.GetKeyDown("escape"))
Screen.lockCursor = false;
if (!Screen.lockCursor && wasLocked) {
wasLocked = false;
DidUnlockCursor();
} else
if (Screen.lockCursor && !wasLocked) {
wasLocked = true;
DidLockCursor();
}
}
}
Ive tried to apply this to the Player, the Players Camera but the cursor doesnt
- lock in the middle
- disable the cursor gui
This is required for my game because i have a raycast that picks up items where the mouse position is for my game but if im looking at it the mouse has to be in the center to pick it up and i dont really want them to see the cursor either.
All help is appreciated
asked
Jan 16 '12 at 11:18 PM
CursedScripter
31
●
10
●
13
●
14