0

So, in Unity3d, when I use this following script below, the console does not say the message given by the Debug.Log. Here is the script:

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

public class Gui : MonoBehaviour
{

   void OnMouseDown()
   {
       Debug.Log("It Works");
   }
}

However, when I click on the object that includes this script, nothing shows up on the console. What am I doing wrong? Any help would be appreciated.

Aykut Karaca
  • 350
  • 3
  • 15
Random User
  • 11
  • 1
  • 4
  • 1
    Try following these instructions: https://answers.unity.com/questions/486847/onmousedown-doesnt-work-1.html – Immorality Aug 16 '18 at 12:43
  • Just a thing: the instruction with debug.log has no semicolon at the end. Is it a copy&paste error from your C# file? It should not compile this way. – Andrea Aug 16 '18 at 12:51

1 Answers1

1

According to the documentation, OnMouseDown works on GUI elements or objects with colliders. Add a collider to your object and it should work fine.

Unity OnMouseDown()

Aykut Karaca
  • 350
  • 3
  • 15