I have fish gameObjects that have colliders2D so that I can click and move them. I added fish food with Collider2D’s but it was hard for me to click on the fish. After I disabled the fish food collider2D it was easier to click on the fish. Is there an alternative when detecting two gameObjeccts without colliders?
So far I got this. But its not working well when I tried the drag version
public class FishClicker : MonoBehaviour {
public LayerMask whatIsFish;
public float clickRadius = 0.1f;
void Update() {
if (Input.GetMouseButtonDown(0)) {
var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
var hit = Physics2D.OverlapCircle(mousePos, clickRadius, whatIsFish);
if (hit != null) {
var fish = hit.GetComponentInParent<Fish>();
if (fish != null) { fish.DoClickThing(); }
}
}
}
}