I want the camera to freeze after the player/gameobject is destroyed. However, when the player is destroyed, the game just freezes and it gives me this error “System.NullReference Exception has been thrown. Object reference not set to an instance of an object.” I don’t know what to change. This is what I have right now:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyContact : MonoBehaviour {
PlayerController playerMovement;
CameraController cameraMovement;
public GameObject player;
public Camera camera;
public ParticleSystem particleSystemPlayer;
public Vector3 PosofDeadPlayer;
void Awake()
{
playerMovement = GetComponent <PlayerController> ();
cameraMovement = GetComponent<CameraController>();
}
void OnTriggerEnter (Collider other)
{
if (other.gameObject.tag == "Floor") {
return;
}
if (other.gameObject.tag != "Floor") {
Destroy (gameObject);
PlayerisDead ();
}
}
void PlayerisDead()
{
playerMovement.enabled = false;
cameraMovement.enabled = false; //this is where the error message is
PosofDeadPlayer = player.transform.position;
particleSystemPlayer.transform.position = PosofDeadPlayer;
particleSystemPlayer.Play (true);
}
}