VRTK3.3.0-003发出一条简单射线和监听


1丶在Right下继续添加脚本VRTK_PointerVRTK_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("射线进入物体");
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM