- Home /
OnMouseEnter through colliders
EDIT (FIXED): I fixed it , it was due to the fact that the tower inherited the layer of the tile, being a child of it.(Another solution was to click on the physcis settings and set the raycast to ignore triggers, it will then ignore the range sphere which is trigger) Thanks for the answers :)
Hello all! I'm making a tower defense game in unity indie , and i've set up all the turret system and the grid system (there's no free placement of the towers) and I met a big problem. Each square of the grid highlights and is selected when you hover it , and creates a tower when you click on it. This works fine. But on my tower there is a sphere collider, it's the range of the tower . It's pretty big and all ennemies who enter it are shot at ( it's a "is trigger"). As soon as the tower is created, this collider is obviously created with it, it's part of the tower. This collider being big, it seems to block the access to the tile around it ( the tiles of the grid a bit further works still fine ) , meaning I can't hover any tiles around it , cause the mouse gets on the sphere first , which is in front of the tile. It's logical, but is there a way to get around this? I tried ignorelayercollision , but no luck with that. (Oh and the tower is child of the tile) Thanks for reading, I hope you can help me :) Edit: Here's a screenshot ;
Answer by Vonni · Feb 03, 2013 at 04:18 AM
Ignore layer should work just fine, but I dont like using it :S
If you use PhysicsRaycastAll it returns an array of hits. This makes it very easy to mask out the sphere collider.
Thank you very much. I used ignore layer , it didn't worked, but I finally got why ; As the turret was the child of the tile , it takes the same layer . So the tile had to ignore a layer (turret layer) which was empty, because the turret when instantiated as a child , inherits the effects on the layer of the parent. Now it works, I have changed the layer to default and made the hover part on the layer tile , but as a child of the tile object, exactly like the turret, but the turret on layer turret. Hope i'm clear :P
Answer by DryTear · Feb 03, 2013 at 04:09 AM
if your camera is orthographic, replace sphere collider with capsule collider, and set it to Y and the height to 10.
Then the orthographic camera's Y to 9 so the camera is inside the trigger.
Your answer
Follow this Question
Related Questions
GUI flashing on hover 0 Answers
Check if tower is already placed 1 Answer
Sound won't PLAY!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1 Answer
object collision does not work 2 Answers
How do you detect OnMouseEnter on a collider that is behind a GUI element? 1 Answer