Search Unity

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

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

  1. Achim

    Achim

    Joined:
    Dec 19, 2007
    Posts:
    199
    Hallo,
    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.
    http://achimkinzelmann.homepage.t-online.de/Webseite/WebGL/UNITY/BUILD Test/index.html