- Home /
OVRInput does not work in my script
Hi!
So, I want a GameObject to appear when I touch the A or B button on my right controller. I have an Oculus Quest. I've made a script to make this work, but OVRInput can not be found, Unity doesn't recognize it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AppearInventory : MonoBehaviour
{
public GameObject Object;
void Update()
{
Object.SetActive(false);
if (OVRInput.GetDown(OVRInput.Button.Two))
{
StartCoroutine(ShowAndHide(2.0f));
}
}
IEnumerator ShowAndHide(float delay)
{
yield return new WaitForSeconds(delay);
Object.SetActive(true);
}
}
Does someone help me with my problem? I just want a object to appear after a couple of seconds when I press the A (or B, doesn't matter). I have the Oculus Integration installed as well as the XR Plugin Management. Please someone help me!
Answer by davidcox70 · Jul 30, 2020 at 06:22 PM
If OVRInput isn't found, you probably need to install the Oculus Integration asset. However, you should probably be steered towards using Unity's XR input instead, as this is designed to work with multiple platforms. It will make it easier then to make your app work with non-Oculus products.
Just an observation on your code: you have setActive(false) as the first line on your update routine. This means that the first thing that will happen on every frame is that the referenced object will be made invisible. Although it will be set to be visible after the delay, it will immediately be made invisible again, so you might never see it.
I have the Oculus Integration installed and I'm aware of the XR input, but I want to stick with the Oculus integration for now. Anyway, it still doesn't work and my script is still not familiair with OVRInput.
As for the script, it works fine for me actually, don't have problems with that. I set the objects in first instance on false in the hierarchy, so you won't be able to see them in first place.
Did you install Oculus for Android from the Unity Package $$anonymous$$anager window? The way you have your script at the moment, the object will only be visible for one frame at most.