1.在Main Camera上 添加 Physics Raycaster组件 2.场景里需要有 EventSystem (Create - UI- EventSystem) 3.物体需要有Collider 4.在需要点击的物体上挂脚本 并根据需求实现以下接口 以及方法 IPointerClickHandler IPointerDownHandler IPointerEnterHandler IPointerExitHandler IPointerUpHandler
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class ColorPickerController : MonoBehaviour,IPointerClickHandler {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
#region IPointerClickHandler implementation
public void OnPointerClick (PointerEventData eventData)
{
Debug.Log ("点击");
}
#endregion
}
!