Hi I am new to unity 3D and scripting/coding,I need help! I am trying to make a fps (first person shooter) game and I want to hide my cursor but .visible is not working Here is my script: Code (CSharp): using UnityEngine; using System.Collections; public class Cursor : MonoBehaviour { void Start () { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = (false); } void Update () { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = (false); } visible is marked as red in the script and I don't know why anybody that knows what is the problem please tell me. Thank you BSimow
Having a class called the same as a build in class in not such a smart idea. How should unity / monodevelop know if you man your class Cursor or the builtin class. Rename your class to something else and it should work fine.
Oh my god I am an idiot thanks for telling me. And yes I am trying to do it within the editor. Edit: I tried it right now but it still isn't working, here is my new script Code (CSharp): using UnityEngine; using System.Collections; public class Cursordelete : MonoBehaviour { // Use this for initialization void Start () { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = (false); } void Update () { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = (false); } }
For one, when you renamed your class, did you rename the script file to be the same as well? And have you checked to make sure that the reference on the component to the script is not broken? (which can happen when you rename them)
Try building your project and running it outside of the editor. If I recall correctly the editor has a tendency to force it visible.
We also found that sometimes you have to click the mouse button in the scene (when running it from the editor & not a build) to sort of switch it from being able to be used by the editor to it being "in the game".
I deleted the project i just raged quit because there was another script the didnt want to work P.s thanks for the help