Show mouse pointer in the screen game

Hello and thanks for the forum.
I am beginnig in the unity programming and I wanted to ask you a question. I am developing a game with unity (5.5), it is a first person point and click. Well, i want when i run the game the cursor or pointer mouse be shown in the game screen to be able to have a reference to click in some objets. Without cursor i dont know where i am doing click. I have looked around forums and i have seen about “Cursor.Visible=true”, i have tried write it in the scripts (i dont know which and i have written it in alls) in the start function but i doesnt work.

Assuming that you’re coding in C# the following should work. You only need to add the line to one script.

void Start () {
        Cursor.visible = true;
    }

Also note that in ‘CursorLockMode.Locked’, the cursor will be invisible regardless of the above setting.

2 Likes

yes i am using C#. But it doesnt work. I have already tried it.
this is my script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{

//creamos variable de la propia clase
public static GameManager ins;
//variable que almacena el objeto con el que se esta interactuando en el momento
[HideInInspector]
public Node currentNode;
//variable que hace referencia al objeto cameraRig que genera el movimiento de la camara
public CameraRig rig;

void Start()
{

Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}

void Awake()
{
ins = this;
}

void Update()
{
//si hacemos clic con el boton derecho y el nodo con el script prop (bola o cubo) no sea nulo
//llamamos al metodo arrive para ir hacia atras por medio de la variable loc que almacena
//la posicion de la mesa, con lo que volvemos a la mesa
if (Input.GetMouseButtonDown(1) && currentNode.GetComponent() !=null) {
currentNode.GetComponent().loc.Arrive();
}

}
}

Hey @Fernando77Cc . Have you tried this topic?

Looks like you are not the only one with a cursor issue :slight_smile:

Also which object you are attaching your script to?

1 Like

Hello ! i have attached the script to an object called GameManager. If you want i can send a capture from unity scene.
i m going to look topic you have send me.
Thanks

i have achieved it !!

i had to write it in this function:

void OnGUI()
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}

Now it makes some strange, cursor blinks if i move it. Even so, it is more than nothing …

Hey @Fernando77Cc . It is pretty weird. I am not sure if that would be right guess but my guess is that you might have Cursor.lockState or Cursor.visible modified from different places. If you still have the issue please try to global search for those two. It seems to me that the blink occurs because you are switching it ON / OFF in different places in your code perhaps.

I have the same issue with Unity 2017 , the mouse keep blinking and looked on the center .

@okba28mca : I would have to ‘guess’ that this is almost certainly because of a script(s) you are using – blocking the cursor. Often FPS games do that so you can move around… if it’s blinking, maybe you wrote code to show the cursor? I’m not sure.
The most appropriate solution would be to find the script and modify it so you can get out of that mode.
I have seen a number of examples where hitting ‘escape’ (in FPS scripts) brings you out of that hidden cursor mode until you click back in the game (not the UI, usually)… Hopefully that makes sense.

Do a search in your code for any instances using the Cursor namespace. There’s got to be something that’s trying to mess with the cursor. I.e. do a solution-wide search for “Cursor”.

I know for sure the cursor behaves fine in my Windows standalone app, and it’s on (visible) by default. The only time anything weird happens is when separate code start trying to modify the Cursor.visible state, and step on each others toes.

I had the same issue. I found the following code in the MouseLook.cs script and commended out the lines that made the cursor invisible. Works fine , cursor is visible and not blinking.

private void InternalLockUpdate()
{
if(Input.GetKeyUp(KeyCode.Escape))
{
m_cursorIsLocked = false;
}
else if(Input.GetMouseButtonUp(0))
{
m_cursorIsLocked = true;
}

if (m_cursorIsLocked)
{
//Cursor.lockState = CursorLockMode.Locked;
//Cursor.visible = false;
}
else if (!m_cursorIsLocked)
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
}

Also … Just un checking “Lock Cursor” in the FPS script is a nicer way of achieving the same thing as the script above.
3352499--262330--upload_2018-1-13_0-10-52.png

5 Likes

The cursor is now also in the player screen. How do you remove it to be only visible on, let’s say, a panel/menu?

cooooolllll WORKS !

hey just use
Cursor.lockState = CursorLockMode.Locked;
to hide your mouse