Teleporting MainCamera and GameController
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
Answer by Statement · Dec 20, 2015 at 11:42 PM
Static member `UnityEngine.Camera.main' cannot be accessed with an instance reference
GetComponent<Camera>().main // Eek! Error. 'main' is a static member, not an instance member.
qualify it with a type name instead
Camera.main.transform.position = new Vector3 (300, 100, 0);
Your answer
Follow this Question
Related Questions
How to move a character along the Y axis x amount of units using the G key? 1 Answer
need help teleporting an object 0 Answers
How to teleport an object to 1 of 8 possible locations on collision? 1 Answer
How to teleport player in unity using X, Y, Z axis,How to teleport a player using X,Y,Z. 0 Answers