- Home /
Question by
impurekind · Aug 11, 2018 at 10:57 PM ·
raycastvirtualenabledrealityplayer settings
Am I using the PlayerSettings.virtualRealitySupported check wrong?
using UnityEngine;
using UnityEditor;
public class GunController : MonoBehaviour
{
public Transform gunBarrelTransform;
Camera playerCam;
bool GameInVRMode;
void Start()
{
if (PlayerSettings.virtualRealitySupported == true)
{
GameInVRMode = true;
}
else
{
GameInVRMode = false;
}
}
void Update()
{
if (OVRInput.GetDown(OVRInput.Button.SecondaryIndexTrigger) || Input.GetMouseButtonDown(0))
{
RaycastGun();
}
}
private void RaycastGun()
{
playerCam = Camera.main;
RaycastHit hit;
if (GameInVRMode)
{
if (Physics.Raycast(gunBarrelTransform.position, gunBarrelTransform.forward, out hit))
{
if (hit.collider.gameObject.CompareTag("Enemy"))
{
Destroy(hit.collider.gameObject);
}
}
}
else
{
if (Physics.Raycast(playerCam.transform.position, playerCam.transform.forward, out hit))
{
if (hit.collider.gameObject.CompareTag("Enemy"))
{
Destroy(hit.collider.gameObject);
}
}
}
}
}
The script above is causing the build to fail with multiple errors since I added in the "if (PlayerSettings.virtualRealitySupported == true)" and the other stuff to do with it. So am I using it wrong? And if I am then what's the correct way to go about checking if my game is in either PC or VR mode so I can make the gun use the specific raycast check in each case?
Comment