- Home /
How to hide the cursor
Hello,
I want to hide the cursor as I am using a gamepad instead of mouse and keyboard.
Would this code work for that:
Screen.showCursor = false;
and if so where show it go?
I am really new, and have no experience coding (dont really know how i made it this far)
Cheers,
Sabrina
hello I have made a menu in unity and need to implement this code into it void Start () { Screen.showCursor = false; }
I need to put it in this:
void Start ()
{
Screen.showCursor = false;
}
using UnityEngine;
using System.Collections;
public class pause$$anonymous$$enu : $$anonymous$$onoBehaviour
{
public GUISkin myskin;
private Rect windowRect;
private bool paused = false , waited = true;
private void Start()
{
windowRect = new Rect(Screen.width / 2 - 100, Screen.height / 2 - 100, 200, 200);
}
private void waiting()
{
waited = true;
}
private void Update()
{
if (waited)
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.Escape) || Input.Get$$anonymous$$ey($$anonymous$$eyCode.P))
{
if (paused)
paused = false;
else
paused = true;
waited = false;
Invoke("waiting",0.3f);
}
}
private void OnGUI()
{
if (paused)
windowRect = GUI.Window(0, windowRect, windowFunc, "Pause $$anonymous$$enu");
}
private void windowFunc(int id)
{
if (GUILayout.Button("Resume"))
{
paused = false;
}
if (GUILayout.Button("Options"))
{
}
if (GUILayout.Button("Quit"))
{
}
}
}
@Spy4812 please don't post a new question as a comment or answer.
Answer by Yoerick · Nov 11, 2010 at 11:27 AM
If you want to hide the cursor through the entire game you should add the "Screen.showCursor = false"-code inside the Start function ;)
like so:
void Start ()
{
Screen.showCursor = false;
}
(in C#)
or:
function Start ()
{
Screen.showCursor = false;
}
(in JavaScript)
Answer by sillyjake · Jun 28, 2015 at 08:50 PM
For those using unity 5 or above, Its "Cursor.visble = false;" (C#) to hide the cursor.
Answer by waqar1world · Aug 27, 2015 at 02:28 PM
//for Unity3d 5 using UnityEngine; using System.Collections;
public class CurserRemove : MonoBehaviour {
// Use this for initialization
void Start () {
Cursor.visible = false;
}
// Update is called once per frame
void Update () {
}
}
Answer by Al-Anselmo · Dec 27, 2010 at 02:01 AM
If you also want to hide the cursor AND lock it in the center of the screen, you should use
Screen.lockCursor = true;
Answer by BearMan11 · Dec 23, 2012 at 10:33 AM
ive never coded can some one tell me where to add this script or how to please
If you are new watch and read a few guides, like http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-%28long%29
Here is code to hide/show mouse with an explanation:
var showing$$anonymous$$ouse : boolean;//for checking if mouse is shown or not
function Start(){
showing$$anonymous$$ouse = false;
Screen.showCursor = false;
Screen.lockCursor = true;
}
//executed every frame
function Update(){
//if you press "r" and the mouse is not shown then the mouse is shown and movable then execute code
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.R) && showing$$anonymous$$ouse == false){
showing$$anonymous$$ouse = true;
Screen.showCursor =true;
Screen.lockCursor = false;
}
//if you press "r" and the mouse is shown then make it not shown
else if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.R) && showing$$anonymous$$ouse == true){
showing$$anonymous$$ouse = false;
Screen.showCursor =false;
Screen.lockCursor = true;
}
}
thanks thats exactly what i wanted to do, to show and hide the mouse by one button
Your answer

Follow this Question
Related Questions
Can I lock a cursor without hiding it? 0 Answers
first person - hide mouse 1 Answer
cursor problem?? 0 Answers
Kinect Hand Smoothing 0 Answers
cursor on textfield 0 Answers