U3D事件系统用于3D物体
U3D的事件系统用于3D物体,首先需要太场景中要有EventSystem(引物体在UI中有)这个物体,然后摄像机上需要挂载组件///此脚本挂载在要被点击的物体上,凡是挂载此脚本的物体都可以接收点击事件
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
public class NewBehaviourScript : MonoBehaviour, IPointerClickHandler
{
public class My_UnityEvent : UnityEvent<string, PointerEventData> { }
//声明静态的字段
public static My_UnityEvent M_UnityEvent = new My_UnityEvent();
//实现点击接口
public void OnPointerClick(PointerEventData eventData)
{
//点击时,调用事件
M_UnityEvent.Invoke(gameObject.name, eventData);
}
}
///此脚本随便挂载在一个物体上。
sing System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class NewBehaviourScript1 : MonoBehaviour {
void Start () {
NewBehaviourScript.M_UnityEvent.AddListener((str, pointerevent) => { Debug.Log(str+pointerevent.ToString()); });
}
}
点击物体效果如下,
元素帖子强,满满正能量! 路过看看 感谢分享 路过看看 感谢分享 路过看看 感谢分享 路过看看 感谢分享 路过看看 感谢分享 我觉得此贴可以解决窝目前遇到的问题 超级棒棒棒 看着像是unity的监听 路过看看 感谢分享 路过看看 感谢分享
感谢楼主分享资源
感谢楼主分享资源 路过看看 感谢分享 路过看看 感谢分享 谢谢分享 分享快乐,谢谢分享这么好的资源 想要成大触,天天上元素! 想要成大触,天天上元素!
页:
[1]
2