0

I wanna SetOnClick for UnityEngine.UI.Text and UnityEngine.UI.Image, but I try following code, and click Text or Image, not available data in PointerEventData

public class TestClickText : MonoBehaviour, IPointerClickHandler
{
    // Use this for initialization
    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        var r = eventData;
    }
}

I know I can in Button object add Image or Text to make them clickable, but its too tedious, so I hope a way to implement like UnityEngine.UI.Text#SetOnClick

chikadance
  • 3,591
  • 4
  • 41
  • 73
  • Your current code should work on Buttons, Images, Texts and other UI components. You have to attach it to that Object or the Canvas to detect the click on all child objects. See the troubleshooting section from the duplicate if it's not working. Make sure to use simple `Debug.Log` to verify – Programmer Oct 09 '18 at 08:14
  • @Programmer how to get clicked Text or Image with PointerEventData? – chikadance Oct 09 '18 at 09:37
  • `eventData.pointerCurrentRaycast.gameObject.GetComponent()` – Programmer Oct 09 '18 at 09:43

0 Answers0