Hello,
I have a scene with 3 Objects (all of the same Prefab type):
The prefab has a script that checks if the player clicked on the object:
void Update() {
if(Input.GetMouseButtonDown(0)) {
Debug.Log("MouseDown");
Ray ray = camera.ScreenPointToRay(Input.mousePosition);
RaycastHit raycastHit;
if(Physics.Raycast(ray, out raycastHit) && raycastHit.collider.gameObject.tag == "Magnet") {
GameObject go = raycastHit.collider.gameObject;
Debug.Log("Hit object: " + go.name);
...
The problem is: When I click ONCE on ONE object, I get the hit 3 times! This is the output when I click ONCE on one object:
How is it possible that I hit all 3 objects (when the ray clearly only intersects the geometry of ONE object)?