WaveVR_Raycast

Contents

Introduction

This script WaveVR_Raycast.cs is used to shot a ray from object looks like:

_images/raycast01.png

This script has features:

  1. Create a LineRenderer: developer can see a ray being shown on screen.
  2. Cast a invisible ray: can be used to detect 3D or 2D GameObject in world space.

How to use

Just add component WaveVR_Raycast to object you want to add ray like:

_images/raycast02.png

In editor mode, developer can play scene to see the effect.

Use “right alt” and mouse to controll the rotation.

Script

Developer can see four public variables:

  1. Device Index: index of connected device. It is for use with next variable - Listen To Device.
  2. Listen To Device: if checked, the LineRenderer is only generated when controller with specified Device Index is connected. Otherwise the LineRenderer is always created.
  3. Add LineRenderer: if unchecked, the LineRender will never be created. This can be unchecked if developer does NOT wanna use LineRenderer. (eq. use Mesh)

When device is connected or disconnected, OnDeviceConnected will enable / disable the LineRenderer.

private void OnDeviceConnected(params object[] args)
{
    var device = (WVR_DeviceType)args[0];
    var connected = (bool)args[1];

    if (index != device)    // check if the role of connected device is equivalent to developer specified index.
        return;
    if (lr != null)
    {
        lr.enabled = connected;
    }
}