码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-05-23 12:08:17      阅读:381      评论:0      收藏:0      [点我收藏+]

标签:imp   mono   场景   nbsp   obj   自定义   脚本   man   event   

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("射线进入物体");
    }
}

技术图片

 

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

标签:imp   mono   场景   nbsp   obj   自定义   脚本   man   event   

原文地址:https://www.cnblogs.com/myunity/p/10911096.html

(1)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!