Search Unity

How to use OVRinput in c# script?

Discussion in 'Scripting' started by Hectorastacio1, Dec 13, 2017.

  1. Hectorastacio1

    Hectorastacio1

    Joined:
    Sep 11, 2017
    Posts:
    60
    I'm currently trying to load a scene when the button B is pressed in a touch controller does anyone know what is wrong here. I'm getting errors here "OVRInput.Get(OVRInput.Button.two);" the rest seems to be fine
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3.  
    4.  
    5. public class SceneLoader : MonoBehaviour
    6. {
    7.     void Update()
    8.     {
    9.         if OVRInput.Get(OVRInput.Button.two);
    10.  
    11.         {
    12.          
    13.             SceneManager.LoadScene("Cups");
    14.         }
    15.     }
    16. }
     
  2. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
    Your project might not have the OVR plugin set up correctly, so it doesn't understand where to find OVRInput.

    I'd try looking at a couple of Oculus for Unity tutorials (like maybe this one) until the OVR setup is better understood.
     
    Hectorastacio1 likes this.
  3. TheHighGround

    TheHighGround

    Joined:
    Nov 19, 2017
    Posts:
    68
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    I don't use that API but I can tell from your example, that if it's pasted from your source code, the syntax is invalid. You're missing an opening and closing brace in your if statement. :)
     
    Hectorastacio1 likes this.
  5. Hectorastacio1

    Hectorastacio1

    Joined:
    Sep 11, 2017
    Posts:
    60
    Fixed it
    Code (CSharp):
    1. using System.Collections.Generic;
    2. using System.Collections;
    3. using UnityEngine;
    4. using OVRTouchSample;
    5. using System;
    6.  
    7. using UnityEngine.SceneManagement;
    8.  
    9.  
    10. public class SceneLoader : MonoBehaviour
    11. {
    12.     void Update()
    13.     {
    14.         if (OVRInput.GetDown(OVRInput.Button.Two))
    15.  
    16.         {
    17.  
    18.             SceneManager.LoadScene("name");
    19.         }
    20.     }
    21. }
    22.  
     
  6. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Excellent :)
     
    Hectorastacio1 likes this.
  7. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Can someone please update this with button press and haptics?
     
  8. codemaker2015

    codemaker2015

    Joined:
    Aug 19, 2018
    Posts:
    27
    Ensure that Oculus Integration package is imported in your project.

    Code (CSharp):
    1. using UnityEngine;
    2.  using UnityEngine.SceneManagement;
    3.  
    4.  public class SceneLoader : MonoBehaviour {
    5.      void Update() {
    6.          if (OVRInput.Get(OVRInput.Button.Two))
    7.              SceneManager.LoadScene("name");
    8.      }
    9.  }
    Refer to Input for Oculus to know more about the Oculus controllers.