In attempting to teleport GameContoller and MainCamera (MainCamera is a child to GameController) once it touches the object “Door”, I tried to use this script:
using UnityEngine;
using System.Collections;
public class Teleport : MonoBehaviour {
void OnTriggerEnter (Collider other)
{
if (other.name == "Door")
{
other.transform.position = new Vector3(300,100,0);
GetComponent<Camera>().main.transform.position = new Vector3 (300,100,0);
}
}
}
I received the following error message. I’m at a total loss as to what I messed up on, and I just need to know if I’m remotely headed in the right direction, and how to fix this. Thanks in advance for any help.
Error:
Scripts/Teleport.cs(11,48): error CS0176: Static member `UnityEngine.Camera.main’ cannot be accessed with an instance reference, qualify it with a type name instead