Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

make panel pass raycasts, but still respond to onDrag

Discussion in 'UGUI & TextMesh Pro' started by koffis, Mar 14, 2015.

  1. koffis

    koffis

    Joined:
    Feb 26, 2015
    Posts:
    4
    hi there!

    in my 3d project for mobile decives, i have a ui panel stretched over the entire screen, which allows the player to drag on it to turn the character around.

    now i also want to make objects in the world clickable (imagine just like in minecraft).
    so this is what i did:
    - i attached a new script to a gameobject
    - in this script i added a IPointerClickHandler, to do something when it is clicked
    - i added a Physics Raycaster to the main camera (which is obviously behind the panel i use for looking around)

    so the problem now is, that i cant actually click on objects, because the panel blocks all the raycasting coming from the camera.
    when i remove the panel, it works fine.
    when i add a Canvas Group to the panel and disable "blocks raycasts", i can click on gameobjects through the panel, but the dragging on the panel doesnt work anymore.

    what can i do?
    any ideas?
    thanks in advance!!
     
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,685
    The panel shouldn't block raycasts. the only reason it could block is if you have a CanvasGroup with "Block Raycasts" turned on.

    Raycasts pas complete through the screen unless blocked by a CanvasGroup by default
     
  3. koffis

    koffis

    Joined:
    Feb 26, 2015
    Posts:
    4
    yes, but i need the panel to recieve the raycasts, otherwise i cant use it for rotating my character by onDrag.

    at this point, im pretty sure that its a stupid idea to stretch a panel over the entire screen since i also want to click on gameobjects in the world. a panel just blocks everything behind it.
    i think i have to capture drag movements from the eventsystem directly in order to make the character rotate when the player drags over the screen. unfortunately, i have no idea how to do that.
    while testing my game, i can see that in the inspector for eventsystem, touches are registered even when they are not on an ui element.
    anybody any idea how to get these informations for my scripts??

    Unbenannt.PNG
     
  4. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,685