So on my player I have the standard third person controller. I have a script attached to a building that’s supposed to switch the main camera with one that’s inside the building:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(BoxCollider))]
public class SwitchCamera : MonoBehaviour {
public Camera MainCamera, RoomCamera;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
MainCamera.enabled = false;
RoomCamera.enabled = true;
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Player")
{
RoomCamera.enabled = false;
MainCamera.enabled = true;
}
}
}
And both cameras have the tag “MainCamera.”
My problem is, once I enter the room, the screen turns grey and I am given this error:
NullReferenceException: Object reference not set to an instance of an object
ThirdPersonController.UpdateSmoothedMovementDirection () (at Assets/Standard Assets/Character Controllers/Sources/Scripts/ThirdPersonController.js:129)
ThirdPersonController.Update () (at Assets/Standard Assets/Character Controllers/Sources/Scripts/ThirdPersonController.js:302)
What is going on here and how can I fix it?