Both colliders getting mouse down event

I’m working on video:
152. One Defender Per Square

My defender collider and core game area collider are both getting the mouse down event. I did everything Rick said. What’s going on! The core game area collider is behind the defenders on z-axis. I even moved the defenders well in front of everything else. I put in a print statement to console and can see both colliders get the mouse down event. The goal of this video was that the defender collider would get mouse down and the core game area collider would not… I am stuck. Any ideas?

Thanks in advance!

Core game area is transparent in the back. See Cactus defender in front:



image

I fixed it by using a dictionary. But I still want to know why this doesn’t work with colliders:

Hi Aaron,

Welcome to our forum. :slight_smile:

Which scripts does the defender have got assigned? And does one of the scripts contain an OnMouseDown method?

Defender has Defender script with OnMouseDown. Core game area has DefenderSpawner script with OnMouseDown. The Defender is in front of the core game area and has a collider. So it’s OnMouseDown should be called and not core game area’s. I added print statements and I can see that both are being called. I’ll attach some screen shots.

What happens when you move the core game area above the cactus in the Hierarchy?

The same behaviour. I.E. both Defender and Core game area scripts get OnMouseDown event.

Actually, the collider of the cactus is supposed to block the collider of the core game area.

Sometimes the components are buggy. You could try to remove the colliders and to readd them.

Maybe something has changed in Unity 2018.3 or it is a bug. Which exact version do you use? Have you already tried to update?

Nina, you rock! I removed and re-added the colliders and now it is working! Thank you for your help.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms