Hello!
I feel I’m going crazy. OnMouseDown (and relatives events: OnMouseDrag, OnMouseEnter, etc) simply won’t trigger on my project (let’s call it Main).
What is worse, I have tried creating a new project, doing the same setup and it does work on it (called this project Test).
Here’s my code, and what I tried so far:
using UnityEngine;
public class Draggable : MonoBehaviour {
void Start() {
Debug.Log("start"); // <- This triggers
}
void OnMouseDown() {
Debug.Log("mouse down"); // <- This does not
}
void OnMouseEnter() {
Debug.Log("mouse enter"); // <- This does not
}
}
Simple enough, should work.
- Both in Main and in Test, I’m just using a default white square with the same dimensions and position (Z axis position in both is 0), created from GameObject → 2d Object → Sprites → Square
- Both have a BoxCollider2D with default properties (0,0 offset; 1,1 size, etc). Switching to regular BoxColliders still won’t work on Main (but it does still work on Test)
- Camera is default in both (Orthographic, depth is -1, Z Position is -10)
- As per the documentation, Physics.queriesHitTriggers is set to true in both (the default)
- Everything is on the Default layer
- Nothing was changed in Project Settings → Physics/Physics2D that could mess up with the raycasting. As mentioned, QueriesHitTriggers is true.
- There is nothing else in the scene but the square and the camera that could block the raycasting.
Creating a new scene in Main, and putting just a camera and a square still doesn’t work, so this is leading me to believe it is some global configuration, rather than something wrong with the script or scene setup, but I cannot think what could that be, nor I’m finding information googling on requirments I could be missing.
At this point I’m close to just moving everything in my Main folder to a new project, but I would rather avoid that.
Any ideas?
Thanks in advance