Hello,
I am currently developing a Unity application for Samsung Gear VR and I recently imported the Oculus Utilities into my project (I started a new project to test it out) to be able to support the Gear VR Controller.
I am now faced with the strangest thing I’ve never experienced before, one of my script does not recognize OVRInput :
The problem occurs on line 92 from this script (I’ve removed other code from this for readability).
using System;
using UnityEngine;
using UnityEngine.VR;
using UnityStandardAssets.CrossPlatformInput;
using UnityStandardAssets.Utility;
using Random = UnityEngine.Random;
namespace UnityStandardAssets.Characters.FirstPerson {
[RequireComponent(typeof(CharacterController))]
[RequireComponent(typeof(AudioSource))]
public class FirstPersonController : MonoBehaviour {
[SerializeField]
private bool m_IsWalking;
[SerializeField]
private float m_WalkSpeed;
[SerializeField]
private float m_RunSpeed;
[SerializeField]
[Range(0f, 1f)]
private float m_RunstepLenghten;
[SerializeField]
private float m_JumpSpeed;
[SerializeField]
private float m_StickToGroundForce;
[SerializeField]
private float m_GravityMultiplier;
[SerializeField]
private UnityStandardAssets.Characters.FirstPerson.MouseLook m_MouseLook;
[SerializeField]
private bool m_UseFovKick;
[SerializeField]
private FOVKick m_FovKick = new FOVKick();
[SerializeField]
private bool m_UseHeadBob;
[SerializeField]
private CurveControlledBob m_HeadBob = new CurveControlledBob();
[SerializeField]
private LerpControlledBob m_JumpBob = new LerpControlledBob();
[SerializeField]
private float m_StepInterval;
[SerializeField]
private AudioClip[] m_FootstepSounds; // an array of footstep sounds that will be randomly selected from.
[SerializeField]
private AudioClip m_JumpSound; // the sound played when character leaves the ground.
[SerializeField]
private AudioClip m_LandSound; // the sound played when character touches back on ground.
[SerializeField]
private Camera m_Camera;
private bool m_Jump;
private float m_YRotation;
private Vector2 m_Input;
private Vector3 m_MoveDir = Vector3.zero;
private CharacterController m_CharacterController;
private CollisionFlags m_CollisionFlags;
private bool m_PreviouslyGrounded;
private Vector3 m_OriginalCameraPosition;
private float m_StepCycle;
private float m_NextStep;
private bool m_Jumping;
private AudioSource m_AudioSource;
// ...
private void GetInput(out float speed) {
// Move on click down
float mouse = 0;
if (Input.GetButton("Fire1")) {
mouse = 0.1F;
}
bool waswalking = m_IsWalking;
#if !MOBILE_INPUT
// On standalone builds, walk/run speed is modified by a key press.
// keep track of whether or not the character is walking or running
m_IsWalking = !Input.GetKey(KeyCode.LeftShift);
#endif
// set the desired speed to be walking or running
speed = m_IsWalking ? m_WalkSpeed : m_RunSpeed;
// m_Input = new Vector2(horizontal, vertical);
// Get movement direction
m_Input = new Vector2(0, mouse);
/*
* This does not work for some reason: OVRInput is not recognized in FPC ???
* But this is required for GearVR Controller interaction. It works like a charm in VRInput.
*/
if (OVRInput.Get(OVRInput.Button.PrimaryTouchpad)) {
// button is pressed, handle the touch.
Vector2 touchPosition = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad);
m_Input = touchPosition;
const float scalingFactor = 0.1f;
m_Input *= scalingFactor;
} else {
m_Input = new Vector2(0, mouse);
}
// normalize input if it exceeds 1 in combined length:
if (m_Input.sqrMagnitude > 1) {
m_Input.Normalize();
}
// handle speed change to give an fov kick
// only if the player is going to a run, is running and the fovkick is to be used
if (m_IsWalking != waswalking && m_UseFovKick && m_CharacterController.velocity.sqrMagnitude > 0) {
StopAllCoroutines();
StartCoroutine(!m_IsWalking ? m_FovKick.FOVKickUp() : m_FovKick.FOVKickDown());
}
}
private void RotateView() {
if (VRDevice.isPresent)
return;
m_MouseLook.LookRotation(transform, m_Camera.transform);
}
}
}
Whereas I can use it without problems in other scripts. OVRInput is not in any namespace so I shouldn’t have to define a using statement and Visual Studio can’t help with the problem (it suggests creating a new type). Without the lines 92-101 the script works like a charm.
I’ve run out of ideas what this could be.
I am running Unity 5.6.0f3 on Windows 10 64-bit.
Thanks for your help !