1. 程式人生 > >UGUI點選響應事件

UGUI點選響應事件

只需要在對應的UGUI物件上掛個指令碼,實現IPointerClickHandler(引用 using UnityEngine.EventSystems)介面,在類裡面實現

public  void OnPointerClick(PointerEventData eventData)

    {

DoSomething();

        Debug.Log("Click Me!");

    }

方法就可以響應你想要處理的事件了

using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
public class BasePointer : MonoBehaviour,IPointerClickHandler {


    public  void OnPointerClick(PointerEventData eventData)
    {
        Debug.Log("Click Me!");
    }
}