Search Unity

How to use GraphicRaycaster.Raycast?

Discussion in 'Immediate Mode GUI (IMGUI)' started by ShuuGames, Oct 16, 2014.

  1. ShuuGames

    ShuuGames

    Joined:
    Jun 25, 2013
    Posts:
    188
    I'm writing a selection manager for a 2D sprite based game and want the new UI to block raycasts. Idea is to Raycast against UI and there is a method for that, but how do I use it. Where do I get eventData to feed into it?

    Code (csharp):
    1. public void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList);
    http://docs.unity3d.com/460/Documentation/ScriptReference/UI.GraphicRaycaster.Raycast.html

    EDIT:
    A workaround I'm using right now is having 2D trigger colliders attached to stuff under Canvas. Then I use Physics2D.OverlapPointAll(Camera.main.ScreenToWorldPoint(Input.mousePosition)) and block click processing in selection manager if that hit some collider under Canvas.
     
    Last edited: Oct 16, 2014
    Nihao likes this.
  2. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    I want to raycast against a worldspace UI in VR with Oculus Touch controllers and also need GraphicRaycaster.Raycast.
    Also need an example.
     
  3. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Wappenull likes this.