标签:imp mono 场景 nbsp obj 自定义 脚本 man event
1丶在Right下继续添加脚本VRTK_Pointer和VRTK_StraightPointerRenderer
运行后默认是按住圆盘键出现射线,松开消失,大家可以自定义
2丶射线的监听事件
(1)在场景中创建一个Cube用来触发射线检测用,位于相机前方([VRTK_SDKManager]的Z轴方向)
(2)在Right上新建脚本SimplePointerEvents,通过得到VRTK_DestinationMarker组件注册方法,就可以监听射线的触发了
注意:VRTK_Pointer组件是继承于VRTK_DestinationMarker组件
using UnityEngine; using VRTK;// 引用VRTK命名空间 public class SimplePointerEvents : MonoBehaviour { private VRTK_DestinationMarker destinationMarker; private void Awake() { destinationMarker = GetComponent<VRTK_DestinationMarker>(); destinationMarker.DestinationMarkerEnter += DestinationMarker_DestinationMarkerEnter; destinationMarker.DestinationMarkerExit += DestinationMarker_DestinationMarkerExit; destinationMarker.DestinationMarkerHover += DestinationMarker_DestinationMarkerHover; destinationMarker.DestinationMarkerSet += DestinationMarker_DestinationMarkerSet; } private void DestinationMarker_DestinationMarkerSet(object sender, DestinationMarkerEventArgs e) { Debug.Log("与物体交互"); } private void DestinationMarker_DestinationMarkerHover(object sender, DestinationMarkerEventArgs e) { Debug.Log("射线悬停物体"); } private void DestinationMarker_DestinationMarkerExit(object sender, DestinationMarkerEventArgs e) { Debug.Log("射线退出物体"); } private void DestinationMarker_DestinationMarkerEnter(object sender, DestinationMarkerEventArgs e) { Debug.Log("射线进入物体"); } }
标签:imp mono 场景 nbsp obj 自定义 脚本 man event
原文地址:https://www.cnblogs.com/myunity/p/10911096.html