GameObject changes to None in inspector after pressing Play
I have a script which controls my MainCamera attached to the Camera. The script uses a referance from the GameObject Player: Here is the script:
public GameObject player;
public float sens;
void Start()
{
player = GetComponent<GameObject>();
Debug.Log("Component found! " + player.transform.position);
}
void Update()
{
this.transform.position = player.transform.position;
this.transform.Rotate(0, Input.GetAxis("Mouse X") * sens, 0);
}
However if I press Play the "Player" variable changes from Player to None:
And then I get the error: MissingComponentException: There is no 'GameObject' attached to the "Main Camera" game object, but a script is trying to access it. You probably need to add a GameObject to the game object "Main Camera". Or your script needs to check if the component is attached before using it. CameraHandler.Update () (at Assets/Scripts/CameraHandler.cs:18)
What's the problem here?
Your answer
Follow this Question
Related Questions
Can't add Orbital script - "The script needs to derive from MonoBehaviour!" 0 Answers
One script with multiple Gameobject only one Works 0 Answers
Scripted GameObjects vs Prefabs 0 Answers
NullReferenceException: Object reference not set to an instance of an object error? 0 Answers
Instantiated bullet wont destroy 1 Answer