Search Unity

Mouse clicks not detected - resolved

Discussion in 'Editor & General Support' started by Dayradon, Mar 24, 2017.

  1. Dayradon

    Dayradon

    Joined:
    Mar 27, 2016
    Posts:
    19
    EDIT: RESOLVED


    Yes this has been asked a number of times, and I'm sorry but I'm out of idea's

    I have been working through the 3d survival tutorial (but working with my own assets).

    For the life of me I can not get my player model to move on a mouse click. With the original PlayerMovement script, my player would rotate to face the mouse. So I know at least the mouse x/y is detected via rayCast.
    I also was able to set it to mouse movement and testing would adjust my model depending on if I moved my mouse up/down left/right etc.

    The tutorials code i've tried:

    Code (CSharp):
    1.     // Update is called once per frame
    2.         void Update ()
    3.         {
    4.             Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    5.             RaycastHit hit;
    6.             if (Input.GetButtonDown ("Fire2"))
    7.             {
    8.                 if (Physics.Raycast(ray, out hit, 100))
    9.                 {
    10.                     if (hit.collider.CompareTag("Enemy"))
    11.                     {
    12.                         targetedEnemy = hit.transform;
    13.                         enemyClicked = true;
    14.                     }
    15.  
    16.                     else
    17.                     {
    18.                         walking = true;
    19.                         enemyClicked = false;
    20.                         navMeshAgent.destination = hit.point;
    21.                         navMeshAgent.Resume();
    22.                     }
    23.                 }
    24.             }
    25.  
    No dice. Since then I have reset the Input Manager, ensured "mouse 0" "mouse 1" "mouse 2" are assigned under "Fire 1-3". No Dice.

    I have since put some debug lines at the start of void Update (). And have hard coded the mouse 0 press.
    Debug log while playing accurately reflects the changes of my mouses cursor position. but always reports that my mouse 0 button is not pressed. I should note that I pressed (and released) and held all mouse buttons on my mouse to get it to report a press (in case "mouse 0" in unity is not my left mouse button".


    Code (CSharp):
    1.         // Update is called once per frame
    2.         void Update ()
    3.         {
    4.             Debug.Log(Input.mousePosition.ToString());
    5.             if (Input.GetMouseButtonDown(0))
    6.             {
    7.                 Debug.Log("Pressed left click.");
    8.             }
    9.             else
    10.             {
    11.                 Debug.Log("Not Clicked Mouse LEFT");
    12.             }
    13.          
    14.              Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    15.              RaycastHit hit;
    16.              if (Input.GetMouseButtonDown(0))
    17.             {
    18.                 if (Physics.Raycast(ray, out hit, 100))
    19.                 {
    20.                     if (hit.collider.CompareTag("Enemy"))
    21.                     {
    22.                         targetedEnemy = hit.transform;
    23.                         enemyClicked = true;
    24.                                            
    25.                      
    26.                     }
    27.                     else
    28.                     {
    29.                         walking = true;
    30.                         enemyClicked = false;
    31.                         navMeshAgent.destination = hit.point;
    32.                         navMeshAgent.Resume();
    33.                      
    34.                      
    35.                     }

    All I can get back is:

    (930.0, 960.0, 0.0)
    UnityEngine.Debug:Log(Object)
    CompleteProject.ClickToMove:Update() (at Assets/Scripts/ClickToMove.cs:45)

    Not Clicked Mouse LEFT
    UnityEngine.Debug:Log(Object)
    CompleteProject.ClickToMove:Update() (at Assets/Scripts/ClickToMove.cs:52)

    Any ideas? Lastly my mouse is not a generic no name, it's a Wired USB Mad Cat Z Rat 4.
     
    Last edited: Mar 24, 2017
  2. Dayradon

    Dayradon

    Joined:
    Mar 27, 2016
    Posts:
    19
    Update: it seems that I must have missed some layer mask changes between the two tutorials, namely 'floor' vs 'shootable' and changed some references but not all.