- Home /
function OnMouseOver() ignore selected raycast
I want when I call function OnMouseOver() or function OnMouseDown()... I want my mouse point ignore selected raycast to do something like this:
For example,I have object A, B, and D,
I attach this script to my object D
function OnMouseDown(){
//my mouse pointer ignores object A
//do something
}
And I also attach another script to my object D:
function OnMouseOver(){
//my mouse pointer ignores object B
//do other things
}
I mean from the position of the screen, you will see object A and then D in the line (so D is hidden). And if my mouse pointer is at object A (of course Object D is right after object A ), I click object A, but object D will be clicked, and this script is done.
I know that I must put my object A into the layer "ignore raycast", but there are other thing I want to do with object A; so I want to a script to ignore selected raycast, not put into that layer.
And it's similarity with my object B
Can someone answer this for me please? Sorry for my bad english :(
Thanks a lot, regards
It is not really clear from your question what you're trying to do, or how we can help with it. You'll need to explain the pseudocode comments more, what do you mean by "my mouse point ignores object A/B?"
You are trying to make your mouse pointer ignore object A as soon as object D is clicked? Or are you trying to ignore object A because both A and D have this same script?
I fixed, is it clear? sorry again for my bad english :(
I was afraid you meant something like this; there's nothing you could put in a script exclusively on object D that would prevent a raycast from hitting object A, if object A is in front of object D. If object A blocks object D, object A is going to get the On$$anonymous$$ouseOver events, not object D. If you need this kind of finer functionality, you may have to abandon On$$anonymous$$ouseOver and implement your own system that makes manual calls to Raycast in an Update() function, either filtering what is hit by putting A, B, D, etc in separate layers and calling Raycast against those only, or by using RaycastAll and deciding which object to affect based on the set of objects that the mouse is over. That is ... rather more involved than I'm prepared to go into right now, I'm afraid.
Answer by milali · Nov 29, 2011 at 12:46 AM
so are you raycasting the target? And you get object A when you want object B?
Try disabling the collision meshs on those objects when you do what you want, so ignore by enable = false
Yes, this is what I need. I feel embarrassed, this is easier than my complex thoughts. Thank u a lot :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613055540im_/https://answers.unity.com/themes/thub/images/avi.jpg)