Search Unity

World Space UI and Raycast

Discussion in 'Scripting' started by Black_Raptor, Aug 20, 2020.

  1. Black_Raptor

    Black_Raptor

    Joined:
    Nov 3, 2014
    Posts:
    181
    Hi,

    I got an problem, i wanna use an raycast from the center off my camera to use it for activate the onclick function have an World Space Canvas Button :



    Like that the little white red hot in the middle of screen will be an fake cursor and have to remplace the mouse cursor for interact the UI button ( It's for an web app so i can't use the mouse otherwise the cursor will always be out of the screen so i have too hide and lock the real mouse ).

    I make many research but i found nothing everything i found is totaly out dated ( I use Unity 2019.3 ).

    Please help me
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Hi @Black_Raptor

    "i wanna use an raycast from the center off my camera to use it for activate the onclick function have an World Space Canvas Button :"

    Not sure what you are exactly looking for. World space buttons work just as fine as screen space canvas buttons. Buttons should also work with touch IIRC.

    But if you want to raycast for UI elements, use this and simply replace the mouse position with center of screen:
    https://docs.unity3d.com/2018.1/Documentation/ScriptReference/UI.GraphicRaycaster.Raycast.html
     
  3. Black_Raptor

    Black_Raptor

    Joined:
    Nov 3, 2014
    Posts:
    181
    Thanks you with your help i finally find an temporary way. With that way, the problem is i can't really interact with the button ( Like the color transition the onClick function etc ).
     
    Last edited: Aug 20, 2020
  4. enricovicari

    enricovicari

    Joined:
    Jun 11, 2020
    Posts:
    3
    @Black_Raptor how did you fix your issue? (I'm having the same problem with world space canvas!)