Search Unity

Newbie : GetMouseButtonDown not working

Discussion in 'Scripting' started by m0rpheling, Aug 18, 2017.

  1. m0rpheling

    m0rpheling

    Joined:
    Aug 18, 2017
    Posts:
    4
    Hello,

    I'm new to unity and scripting in general.

    In a script attached to a sprite, i try to detect my mouse left button click with this :

    1. void Update() {
    2. if (Input.GetMouseButtonDown(0)) {
    3. Debug.Log("Left Mouse Button Down");
    4. }
    5. }
    but it doesn't detect it at all. Any explanation why?

    I'm using Unity 2017.1 and monodevelop

    EDIT : forgot to paste one of the curly braces
     
    Last edited: Aug 20, 2017
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    If the above is your entire script minus the using statements, then it is certainly not compiling, and hence it is not running.

    Look at the console window for error details. You have two open braces and one close brace.
     
  3. m0rpheling

    m0rpheling

    Joined:
    Aug 18, 2017
    Posts:
    4
    The entire script looks like this :

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

    public class PlayerController : MonoBehaviour {

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {
    if (Input.GetMouseButtonDown(0)) {
    Debug.Log("Left mouse button clicked!");
    }
    }
    }
    https://imagebin.ca/v/3XWtdUxYyBx2
     
  4. m0rpheling

    m0rpheling

    Joined:
    Aug 18, 2017
    Posts:
    4
    Obviously it is because the component is greyed out but I don't understand why is it so :/ help plz
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    In the upper right corner of the console window of the above screenshot you have unchecked the normal log messages, causing them to be hidden.

    In the above shot there are 153 log messages, probably some of them saying "Left mouse button clicked!" that are being hidden from you.

    Click on that 153 button (in the screenshot above) and see your messages coming out.
     
    Kiwasi likes this.
  6. m0rpheling

    m0rpheling

    Joined:
    Aug 18, 2017
    Posts:
    4
    Oh yes, you are right xD thank you :)