ViveInputUtility-handle touches 3D objects (6)

It is very simple to implement the function of the handle touching the 3D object. There are ready-made related interfaces in VIU, and you only need to inherit the interface and implement it.

1. Pre-preparation
Create a new scene 05-3DTouch, delete the default camera, create an empty node Player at the origin, and drag the required modules into the Player node. This chapter will continue to use the teleportation scene in Chapter 2 as the basis for explanation, using stairs and walls To test the touch function of the handle.
insert image description here
2. The handle enters and leaves the 3D object
. Write the Demo5_VRTouch script and mount it on the stairs and the wall at the same time. The triggering condition: Collider has been mounted on the object

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HTC.UnityPlugin.ColliderEvent;

public class Demo5_VRTouch : MonoBehaviour,
    IColliderEventHoverEnterHandler,
    IColliderEventHoverExitHandler
{
    
    
    public void OnColliderEventHoverEnter(ColliderHoverEventData eventData) 
    {
    
    
        Debug.Log($"{
      
      transform.name} 开始触摸");
    }

    public void OnColliderEventHoverExit(ColliderHoverEventData eventData) 
    {
    
    
        Debug.Log($"{
      
      transform.name} 离开触摸");
    }
}

In the actual development process, we can use a separate script for monitoring to ensure that all 3D objects are common, and then customize two events to assign the actual logic of the event externally.
insert image description here

Guess you like

Origin blog.csdn.net/weixin_38484443/article/details/127320533