x


Lock Cursor Doesnt Work

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

  1. lock in the middle
  2. 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

more ▼

asked Jan 16 '12 at 11:18 PM

CursedScripter gravatar image

CursedScripter
31 10 13 14

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x21

asked: Jan 16 '12 at 11:18 PM

Seen: 376 times

Last Updated: Jan 16 '12 at 11:18 PM