- Home /
Click Object under another Object
I have an issue where objects appear in the game world that player can click on to collect, however these appear randomly and enemies can wander over them so they cannot be clicked.
I have tried putting them on different layers but I cannot have them on the IgnoreRaycast layer as the player has to drag them into the game world and then they are effected by different physics relevant to them, so just changing their layer is not going to work.
Is there a way that once the object was placed that you could do something like.
Code I wish existed
"gameObject.IgnoreRayCasting = true;"
Or can anyone think of a way round this issue. My desk has a head shaped indent in it.
Do you need to drag the enemies around or drag the objects to collect around?
I have 3 kinds of object in my game, Enemies(the player never clicks them), Helper Objects( When Instantiated they follow the raycast until the player clicks them to place them), Collectible Objects(They spawn at random positions and the player then clicks them).
If I only have the Collectibles visible to the raycast then this stops the Helper Objects following the mouse until they are clicked.
Or is there something about layer masks I am overlooking?
$$anonymous$$y comment (reply) also got deleted when you deleted your answer. XD
Anyway, short version of my previous comment:
layermask = layermask1 | layermask2; // combines 2 layermasks into 1
Thanks for the code that helped a lot. And sorry for deleting your last comment, I got the e-mail though.
Answer by Dreamblur · Jun 21, 2011 at 05:42 PM
Why would changing their layer not work? You just have to force the raycast to only detect a particular layer (the collectible's layer) and ignore all other layers. You can do that by simply passing a layermask parameter into the Raycast method.
Your answer
Follow this Question
Related Questions
Ignore Raycast not detecting collision?? 1 Answer
How to make constant click position ? 0 Answers
How do you use a queuing mechanism in Unity? 1 Answer
Detect if object clicked on 2 Answers