Missing reference exception
So i'm making a game where if you touch an obstacle, you die(duh) heres my code on the death part
void OnCollisionEnter(Collision collision) { if(collision.gameObject.tag == "o") { Debug.Log("hit"); Destroy(gameObject); return; }
isOnGround = true;
speed = startSpeed;
}
when I destroy the gameobject, it says "the object of type "gameobject" has been destroyed" and it says it for my camera i have a follow player script on my camera
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class FollowPlayer : MonoBehaviour { public GameObject player; private Vector3 offset = new Vector3(0, 5, -7);
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//Offset the camera behind the player by adding to the player’s position
transform.position = player.transform.position + offset;
}
}
how do i fix this?
I added:
if(player == null) { return; } on my camerafollow
but it still doesn't work
Your answer
Follow this Question
Related Questions
Does anyone know the script for a smooth camera follow of the main game object? 8 Answers
Why is my camera shaking when I use my chaser script on something? 0 Answers
Making the camera rotation in line with the ball 1 Answer
When attaching my custom camera script camera shakes when player starts to move fast. 0 Answers
Jittery Camera Follow Lerp 0 Answers