Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

UI Button and Raycast (raycast hits object behind UI button)

Discussion in 'UGUI & TextMesh Pro' started by Achim, Dec 5, 2018.

  1. Achim


    Dec 19, 2007
    when I pick the green cube in my project with the mousepointer and click left mouse button, then it is selected and I can shoot a rocket at the cube by clicking the UI button.
    When I click on the water, the cube is deselected again.
    The problem is, that if I click the UI button, the raycast goes thru the UI button and hits the water and the cube is deselected, because the UI button doesn´t hinder the raycast from hitting the water too.
    How can I make the UI button "solid", that the raycast doesnt hit the water ? Or is it possible to set the raycast script inactive while the mouse hovers above the UI button ?

    Here is the webplayer with the problem. Test/index.html