Hello!
I’m in trouble with accessing SteamVR camera via c#. I’am using VRTK, i am trying get refence in Start() using Camera.main. But I’am getting error: NullReferenceException: Object reference not set to an instance of an object.
What do I do wrong?
Thanks
i have found answer by myself. Simple example below, if you use VRTK version 3.2.0
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VRTK;
public class Sample: MonoBehaviour {
public GameObject cameraRig;
public GameObject playerHead;
public GameObject playerBody;
void Awake(){
VRTK_SDKManager.instance.AddBehaviourToToggleOnLoadedSetupChange (this);
}
// Use this for initialization
void Start () {
cameraRig = VRTK_DeviceFinder.PlayAreaTransform ().gameObject;
playerHead = VRTK_DeviceFinder.HeadsetTransform ().gameObject;
playerBody = cameraRig.transform.GetChild (3).gameObject; // Only if you have VRTK Body Physics script attached!
}
}