- Home /
Question by
col000r · May 26, 2016 at 04:14 PM ·
c#guieventsystemeventlistener
UGUI Event won't trigger on empty object
I made a script that brings a UGUI element to the front:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class MoveToFront : UIBehaviour, IPointerDownHandler {
public void OnPointerDown( PointerEventData eventData ) {
Debug.Log("Move to front");
transform.SetAsLastSibling(); //move to front
eventData.Use();
}
}
This works beautifully if I put it on an image, but if I put it on an empty gameObject then it doesn't work. What do I have to add to make an empty gameObject catch the event?
Comment
$$anonymous$$ay be this link can be helpful to you : https://docs.unity3d.com/ScriptReference/Input.Get$$anonymous$$ouseButtonDown.html
Answer by Munchy2007 · Jun 10, 2016 at 11:46 AM
Add a Collider to the object and a Physics Raycaster to the camera (choose the 3D or 2D variants depending on your requirements).
Also ensure there is an EventSystem in the scene.