- Home /
OnMouseOver() OnMouseDown() button raycast help
Hello I was wondering if there was a way to detect two object's colliders that are in front of one another.
I am trying to create a simple GUI system using two planes attached to bones (to save draw calls). The root bone is in a Group called GUI MESH.The bones work fine and my hideGUI script below works. What i'm trying to do is have the buttons float up off screen when your cursor is not hovering over the top left area (where the buttons will be). The hideGUI script does its job and uses:
function OnMouseExit(){
hover = false;
}
function OnMouseOver(){
hover = true;
}
and my quitScript uses
function OnMouseDown(){
Application.Quit();
}
So my hierarchy goes:
GUI MESH (has a collider, attached hideGUI)
--GUI_ROOT (rootBone)
--restartButtonBone (have collider, attached restartScript)
--quitButtonBone (have collider, attached quitScript)
Both scripts work individually but when the buttons float back onto screen their colliders get in the way so i can now click on the buttons but they are floating away (as if the hideGUI script no longer detects the mouse hovering over).
Any ways to have both of them function even though one collider my be infront of the other?
Answer by Skjalg · Mar 21, 2011 at 10:02 AM
If you are using raycast to detect the buttons, then it wont work since the raycast will only detect the first one.
Thank you for your answer. Hmm well how do you suppose there might be another way? Perhaps an object parented to the X and Y movement of the cursor but offset behind the hideGUI collider so it comes in contact with the buttons still. then write a code like if(contact && mouseclicked) quit.application(); actually what i ended up doing was moving the center of GUI$$anonymous$$ESH's collider and scaled it to cover up as much as the screen except the area with the buttons and switch (!hover) to (hover) and vice versa. i may just end up writing script that when On$$anonymous$$ouseDown move the buttons' colliders infront.
Your answer
![](https://koobas.hobune.stream/wayback/20220613113944im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Hide/show GUI Buion 1 Answer
Adding Force with a GUI button 5 Answers
OnMouseOver not working.. ? 2 Answers
Check if a button is NOT pressed? 3 Answers
GUI click through? 3 Answers