Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. We're running great holiday deals on subscriptions, swag and Asset Store packages! Take a peek at this blog for more information!
    Dismiss Notice
  3. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  4. Unity 2017.2 is now released.
    Dismiss Notice
  5. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  6. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  8. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Show mouse pointer in the screen game

Discussion in 'Scripting' started by Fernando77Cc, Mar 19, 2017.

  1. Fernando77Cc

    Fernando77Cc

    Joined:
    Feb 1, 2017
    Posts:
    9
    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.
     
    Last edited: Mar 19, 2017
  2. Songroom

    Songroom

    Joined:
    Jan 27, 2014
    Posts:
    71
    Assuming that you're coding in C# the following should work. You only need to add the line to one script.

    Code (csharp):
    1.  
    2. void Start () {
    3.         Cursor.visible = true;
    4.     }
    5.  
    Also note that in 'CursorLockMode.Locked', the cursor will be invisible regardless of the above setting.
     
  3. Fernando77Cc

    Fernando77Cc

    Joined:
    Feb 1, 2017
    Posts:
    9
    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<Prop>() !=null) {
    currentNode.GetComponent<Prop>().loc.Arrive();
    }

    }
    }
     
    Last edited: Mar 19, 2017
  4. IndieForger

    IndieForger

    Joined:
    Dec 31, 2012
    Posts:
    42
    Fernando77Cc likes this.
  5. Fernando77Cc

    Fernando77Cc

    Joined:
    Feb 1, 2017
    Posts:
    9
  6. Fernando77Cc

    Fernando77Cc

    Joined:
    Feb 1, 2017
    Posts:
    9
    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 ..
     
    Last edited: Mar 19, 2017
  7. IndieForger

    IndieForger

    Joined:
    Dec 31, 2012
    Posts:
    42
    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.
     
  8. okba28mca

    okba28mca

    Joined:
    Aug 22, 2010
    Posts:
    72
    I have the same issue with Unity 2017 , the mouse keep blinking and looked on the center .
     
  9. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    3,550
    @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.
     
  10. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    609
    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.