Using Unity 2017.1.
I just can’t get it to work; even with the simplest scenes. Here is what I did:
- Create a new 2D project.
- Add a sprite to the project and drag it to Hierarchy to create a GameObject.
- Add RigidBody2D component to this GameObject (not doing this step doesn’t make a difference though).
Now I want it to do something on MouseDown. I tried the following two ways:
-
Add a script to this object. Add the following function to it:
void OnMouseDown()
{
}
Place a breakpoint and run the project. Click on the GameObject. No mouse down.
-
Add a new EventTrigger component. Add the following method to the script:
public void Strike(BaseEventData d)
{
}
Link this function to the EventTrigger component using Pointer Down event. Place a breakpoint on the function and run. Click on the GameObject. Still no mouse down.
Can anyone help me figure out what’s wrong here?
Edit
Here is the complete script:
using UnityEngine;
using UnityEngine.EventSystems;
public class BoardController : MonoBehaviour
{
void OnMouseDown() //breakpoint on this line
{
}
public void Strike(BaseEventData d) //breakpoint on this line
{
}
}