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

Quick Observation: How to navigate the new Raycasting Wizardy

Discussion in 'UGUI & TextMesh Pro' started by SweetBro, Aug 22, 2014.

  1. SweetBro


    Jan 14, 2013
    Okay, so 4.6 uses another raycasting system that essentially deals with click on stuff, IE raycast from screen to point. Using the old method of raycasting from camera is not recommended with the new GUI system since it will always cast through GUI element, which from a user perspective almost always undesirable.

    So first of all you need to add an Raycaster component to whichever camera you want to raycast. It's under Events.

    Second of all, any object that you want to be affected by this raycaster will need to implementing the IPointerClickHandler interface, which will allow you to have the OnPointerClick callback has
    PointerEventData as a parameter. The PointerEventData is the payload of the raycast hit and you can extrapolate whatever data is there to whatever it is you were doing previously.

    And obviously you still need to have a collider for the game object you want to click on.
  2. CelestinLoup


    Aug 24, 2014
    It also seems that you can block raycast on UI elements using CanvasGroup.

    Would there be any recommendable practice between the two methods ?C