Hi,
I have 2 scenes: AR and VR.
In the AR scene there are 2 teleporter gameobjects that start the transition to VR. Depending on which teleporter I have selected, I would like to set the camera in VR to a specific position.
public class VRGaze : MonoBehaviour
{
public Image imgGaze;
public float totalTime = 2;
bool gvrStatus;
float gvrTimer;
public LevelChanger m_LevelChanger;
public GameObject Teleporter;
Camera cam;
...
Ray ray = cam.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
{
if(imgGaze.fillAmount == 1 && hit.transform.CompareTag("TeleportZuVR"))
{
Debug.Log(hit.transform.name);
Teleporter = hit.transform.gameObject;
m_LevelChanger.FadeToScene(m_LevelChanger.sceneToLoad);
}
else if (imgGaze.fillAmount == 1 && hit.transform.CompareTag("TeleportZuAR"))
{
m_LevelChanger.FadeToScene(m_LevelChanger.sceneToLoad);
}
}
}
In the following script the teleporter is selected with gauze and after 2 seconds the transition to the VR scene starts. In line 19, I save the name of the teleporter.
Now I want the camera to be set to a certain position in the AR scene, depending on which teleporter was selected.
Therefore I have a second script, which is attached to the VR-Camera.
public class CameraPositioning : MonoBehaviour
{
public VRGaze m_VRGaze;
public GameObject teleportZelt;
// Update is called once per frame
void Update()
{
if (m_VRGaze.Teleporter.name == "Teleport_Zelt")
{
transform.position = teleportZelt.transform.position;
}
}
}
During the running time in AR I see in the inspector that the right teleporter was selected. When the VR scene is loaded, the name disappears from the inspector and Unity displays the error message:
UnassignedReferenceException: The variable Teleporter of VRGaze has not been assigned.
You probably need to assign the Teleporter variable of the VRGaze script in the inspector.
If I drag the correct teleporter into the field in the inspector during runtime, the camera position is also changed. So that works. Only the assignment is incorrect.
Can you tell me where the error is?