this seems to be related to the raycast emitting from the MainCamera which is being controlled by the oculus rift. That’s how this is VR related.
Here’s the piece of the script that is giving me trouble:
void Update () {
Vector3 forward = WalkingCamera.transform.forward;
Debug.DrawRay(WalkingCamera.transform.position, forward, Color.red);
Here’s the entire script:
using UnityEngine;
using System.Collections;
public class PlayerReach : MonoBehaviour {
AudioSource audio;
private bool AudioPlaying = false;
private float AudioPosition = 0.0f;
//public GameObject Radio_old;
public Material RadioBody;
public bool IsSitting = false;
private GameObject Player;
private GameObject Fireplace;
//public Camera SeatCamera;
public Camera WalkingCamera;
//public GameObject Spectre;
public GameObject DeadMarley;
public GameObject DeadMarleyLight;
private GameObject DeadMarley_go;
private GameObject DeadMarleyLight_go;
public Light RoomLight;
public Light MoonLight;
private float RoomLightMaxIntensity = .25f;
private float RoomLightMinIntensity = 0.0f;
private float MoonLightMaxIntensity = 0.25f;
private float MoonLightMinIntensity = 0.1f;
public GameObject FireLightObject;
public GameObject Fire;
public GameObject Sparks;
private bool SpectreExists = false;
public Material RadioBodyHighlight;
float RoomLightCurrentIntensity;
float MoonLightCurrentIntensity;
float FireEmitterSize;
bool SparksActive = true;
public RaycastHit hitInfo;
Animator SpectreAnimator;
private bool DeadMarleyExists = false;
public GameObject Stage;
public GameObject AChristmasCarolTitle;
public GameObject AChristmasCarolTitle2;
public GameObject AChristmasCarolTitle3;
public GameObject AChristmasCarolTitle4;
private void BringLightsDown()
{
if (SparksActive == true)
{
Sparks.SetActive(false);
SparksActive = false;
}
if (RoomLightCurrentIntensity > RoomLightMinIntensity)
{
RoomLight.GetComponent().intensity = RoomLightCurrentIntensity - .001f;
}
if (MoonLightCurrentIntensity > MoonLightMinIntensity)
{
MoonLight.GetComponent().intensity = MoonLightCurrentIntensity - .001f;
}
if (FireLightObject.GetComponent().IntensityMultiplier > .4f)
{
FireLightObject.GetComponent().IntensityMultiplier = FireLightObject.GetComponent().IntensityMultiplier - .01f;
if (FireEmitterSize > .06f)
{
Fire.GetComponent().startSize = Fire.GetComponent().startSize - .007f;
}
}
}
private void BringLightsUp()
{
if (SparksActive == false)
{
Sparks.SetActive(true);
SparksActive = true;
}
if (RoomLightCurrentIntensity < RoomLightMaxIntensity)
{
RoomLight.GetComponent().intensity = RoomLightCurrentIntensity + .001f;
}
if (MoonLightCurrentIntensity < MoonLightMaxIntensity)
{
MoonLight.GetComponent().intensity = MoonLightCurrentIntensity + .001f;
}
if (FireLightObject.GetComponent().IntensityMultiplier < 2.0f)
{
FireLightObject.GetComponent().IntensityMultiplier = FireLightObject.GetComponent().IntensityMultiplier + .01f;
if (FireEmitterSize < .74f)
{
Fire.GetComponent().startSize = Fire.GetComponent().startSize + .007f;
}
}
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Vector3 forward = WalkingCamera.transform.forward;
Debug.DrawRay(WalkingCamera.transform.position, forward, Color.red);
RaycastHit hitInfo;
Ray MyRay = new Ray(transform.position, forward);
if(Physics.Raycast(transform.position, forward, out hitInfo, 2.0f))
{
//print("You can touch the " + hitInfo.collider.gameObject.name);
/*if (hitInfo.collider.gameObject.name == “Radio_old”)
{
Renderer rend = Radio_old.GetComponent();
rend.material.shader = Shader.Find(“RadioBody”);
rend.material.SetColor(“Color”, Color.yellow);
}
else
{
Renderer rend = Radio_old.GetComponent();
rend.material.shader = Shader.Find(“RadioBody”);
rend.material.SetColor(“Color”, Color.white);
}*/
if (hitInfo.collider.gameObject.name == “Radio_old”)
{
if (AudioPlaying == false)
{
GameObject.Find(“RadioText”).GetComponent().text = “Click to Play”;
}
else
{
GameObject.Find(“RadioText”).GetComponent().text = “Click to Pause”;
}
} else
{
GameObject.Find(“RadioText”).GetComponent().text = “”;
}
if (Input.GetMouseButtonDown(0))
{
if (hitInfo.collider.gameObject.name == “Radio_old”)
{
if (AudioPlaying == true)
{
audio = hitInfo.collider.gameObject.GetComponent();
audio.Pause();
AudioPosition = audio.time;
AudioPlaying = false;
//Debug.Log(audio.time);
}
else
{
audio = hitInfo.collider.gameObject.GetComponent();
audio.Play();
AudioPlaying = true;
//Debug.Log(“AudioPlaying =” + AudioPlaying);
}
}
}
}
//DreamSequence
if (AudioPlaying == true)
{
RoomLightCurrentIntensity = RoomLight.GetComponent().intensity;
MoonLightCurrentIntensity = MoonLight.GetComponent().intensity;
FireEmitterSize = Fire.GetComponent().startSize;
AudioPosition = audio.time;
//Debug.Log(RoomLightCurrentIntensity);
if (audio.time > 67 & audio.time < 78)
{
BringLightsDown();
}
if (audio.time > 120 & audio.time < 130)
{
BringLightsUp();
}
//ENTER Title!
if (audio.time > 34 && audio.time < 38)
//31
{
if (GameObject.Find(“A Christmas Carol Title(Clone)”) == null)
{
GameObject AChristmasCaorlTitle = Instantiate(AChristmasCarolTitle, new Vector3(0.0F, 0.0f, 0.0f), Quaternion.Euler(0f, 180f, 0f)) as GameObject;
}
}
//ENTER Title!
if (audio.time > 43 && audio.time < 48)
//31
{
if (GameObject.Find(“A Christmas Carol Title2(Clone)”) == null)
{
GameObject AChristmasCaorlTitle2 = Instantiate(AChristmasCarolTitle2, new Vector3(0.0f, 0.0f, 0.0f), Quaternion.Euler(0f, 180f, 0f)) as GameObject;
}
}
//ENTER Title!
if (audio.time > 52 && audio.time < 58)
//31
{
if (GameObject.Find(“A Christmas Carol Title3(Clone)”) == null)
{
GameObject AChristmasCaorlTitle3 = Instantiate(AChristmasCarolTitle3, new Vector3(0.0f, 0.0f, 0.0f), Quaternion.Euler(0f, 180f, 0f)) as GameObject;
}
}
//ENTER Title!
if (audio.time > 61 && audio.time < 68)
//31
{
if (GameObject.Find(“A Christmas Carol Title4(Clone)”) == null)
{
GameObject AChristmasCaorlTitle4 = Instantiate(AChristmasCarolTitle4, new Vector3(0.0f, 0.0f, 0.0f), Quaternion.Euler(0f, 180f, 0f)) as GameObject;
}
}
//ENTER Dead Marley!
if (DeadMarleyExists == false)
{
if (audio.time > 72 && audio.time < 84)
//74
{
DeadMarleyExists = true;
GameObject DeadMarley_go = Instantiate(DeadMarley, new Vector3(123.3f, -.14f, 271.0f), Quaternion.Euler(0f,0f,0f)) as GameObject;
GameObject DeadMarleyLight_go = Instantiate(DeadMarleyLight, new Vector3(121.914f, 3.816f, 269.461f), Quaternion.Euler(45.803f, 88.078f, -8.315f)) as GameObject;
DeadMarley_go.transform.parent = GameObject.Find(“Stage”).transform;
DeadMarleyLight_go.transform.parent = GameObject.Find(“Stage”).transform;
DeadMarley_go = GameObject.Find(“coffin_prefab(Clone)”);
DeadMarleyLight_go = GameObject.Find(“DeadmarleyLight(Clone)”);
DeadMarley_go.GetComponent().SetTrigger(“Coffin_Open”);
}
}
else
{
if (audio.time > 122)
//122
{
GameObject.Find(“coffin_prefab(Clone)”).GetComponent().SetTrigger(“Coffin_Sink”);
if (audio.time > 129)
{
Destroy(GameObject.Find(“Marley_Dead(Clone)”));
Destroy(GameObject.Find(“DeadmarleyLight(Clone)”));
DeadMarleyExists = false;
}
}
}
//ENTER THE SPECTRE!
/*if (SpectreExists == false)
{
if (audio.time > 78)
{
GameObject Spectre_go = Instantiate(Spectre, new Vector3(123.83f, 1.27f, 266.13f), Quaternion.identity) as GameObject;
Spectre_go.transform.parent = GameObject.Find(“Stage”).transform;
SpectreExists = true;
}
}
else
{
Vector3 SeatCamForward = SeatCamera.transform.forward;
//Debug.DrawRay(SeatCamera.transform.position, SeatCamForward, Color.green);
if (Physics.Raycast(transform.position, forward, out hitInfo, 10.0f))
{
if (hitInfo.collider.gameObject.name == “HouseWindows”)
{
if (audio.time > 10)
{
SpectreAnimator = GameObject.Find(“spectre_prefab(Clone)”).GetComponent();
int SpectreMoveHash = GameObject.Find(“spectre_prefab(Clone)”).GetComponent().SpectreMoveHash;
SpectreAnimator.SetTrigger(“WindowLook”);
}
}
} else if (Physics.Raycast(SeatCamera.transform.position, SeatCamForward, out hitInfo, 10.0f))
if (hitInfo.collider.gameObject.name == “HouseWindows”)
{
if (audio.time > 10)
{
SpectreAnimator = GameObject.Find(“spectre_prefab(Clone)”).GetComponent();
int SpectreMoveHash = GameObject.Find(“spectre_prefab(Clone)”).GetComponent().SpectreMoveHash;
SpectreAnimator.SetTrigger(“WindowLook”);
}
}
}*/
}
//Set Stage Visibility
if (IsSitting == false)
{
Renderer[ ] renderers = Stage.GetComponentsInChildren();
foreach (Renderer r in renderers)
{
r.enabled = false;
}
Light[ ] lights = Stage.GetComponentsInChildren();
foreach (Light l in lights)
{
l.enabled = false;
}
} else
{
Renderer[ ] renderers = Stage.GetComponentsInChildren();
foreach (Renderer r in renderers)
{
r.enabled = true;
}
Light[ ] lights = Stage.GetComponentsInChildren();
foreach (Light l in lights)
{
l.enabled = true;
}
}
// sit Down
if (Input.GetMouseButtonDown(0))
{
Player = GameObject.Find(“Player”);
Fireplace = GameObject.Find(“fireplace”);
if (IsSitting == false)
{
if (Physics.Raycast(transform.position, forward, out hitInfo, 2.0f))
{
if (hitInfo.collider.gameObject.name == “SofaChair”)
{
IsSitting = true;
//Debug.Log(“You’ve Pressed ‘e’”);
Player.gameObject.GetComponent().isKinematic = true;
//GetComponent().enabled = false;
Player.gameObject.transform.position = new Vector3(123.21f, 1.638f, 270.57f);
Player.transform.LookAt(Vector3.zero);
//WalkingCamera.enabled = false;
//SeatCamera.enabled = true;
}
}
}
else
{
IsSitting = false;
Player.gameObject.GetComponent().isKinematic = false;
//GetComponent().enabled = false;
Player.gameObject.transform.position = new Vector3(123.95f, 2.06f, 270.17f);
//WalkingCamera.enabled = true;
//SeatCamera.enabled = false;
}
}
}
}