Using a cursor within a Virtual Reality application to click on buttons

4.9k views Asked by At

I'm developing a VR application for Oculus Rift within Unity (4.6.5f1) that is basically a building walkthrough. I have a Menu Scene that has buttons that can be clicked to take you to various spots within the building.

What I can't seem to get working is using the cursor to click on these buttons. The mouse is linked to the Oculus Rift head movement and does not show on screen when the application is in use. It just moves the image view in the headset.

I have tried creating a 3D cursor, which works and is able to click on the buttons, but the buttons then do not do what they're supposed to do i.e. go to the next scene. The buttons work perfectly when it is a simple scene without any of the OR cameras etc

I have also tried the "World Space Cursor" asset (http://www.makeorbreakgames.com/world-space-cursor/) which does the same thing - will click the buttons but the buttons will not then work.

Is there something else I should be doing in order to have the cursor fully interact with the buttons?

This is the code on the buttons to take the user to the next scene when clicked:

using UnityEngine;
using System.Collections;

public class LoadOnClick : MonoBehaviour {

public GameObject loadingImage;

public void LoadScene(int level)
{
    loadingImage.SetActive(true);
    Application.LoadLevel(level);
}
}

Code on cursor (Not World Scene Cursor) - This cursor is then linked to the EventsSystem.

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class IgnoreRaycast : MonoBehaviour, ICanvasRaycastFilter 
{
public bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
{
    return false;
}
}

And on the EventsSystem I have LookInputModule which is rather long but can be seen here: Dropbox Link

2

There are 2 answers

1
peterept On

I wrote up a blog tutorial that shows how to do clickable UI elements and 3d scene objects in Unity VR:

VR Gaze Input

0
K.L. On

Just use fuse buttons - when you look at one, a progress bar is displayed. If you don't stop looking at the button until the bar is full, the button gets activated. It's pretty standard in VR by now.