Hi, noob needs help! I have a player character with Camera following him. And immediately after my character dies, Unity goes to Pause mode giving the following error:
MissingReferenceException: The object of type ‘Transform’ has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.
This is my Player Health script:
```csharp
*[/I]
public class playerHealth : MonoBehaviour {
public float fullHealth;
float currentHealth;
public GameObject playerDeathFX;
// Use this for initialization
void Start () {
currentHealth = fullHealth;
}
// Update is called once per frame
void Update () {
}
public void addDamage(float damage){
currentHealth -= damage;
if (currentHealth <= 0){
makedDead();
}
}
public void makedDead(){
Instantiate(playerDeathFX, transform.position, Quaternion.Euler(new Vector3(-90,0,0)));
Destroy (gameObject);
}
}
_*_ <em>_**This is my Camera's follow script:**_</em> _*csharp*_
*public class CameraFollow : MonoBehaviour {
public Transform target;
public float smoothing = 5f;
Vector3 offset;
// Use this for initialization
void Start () {
offset = transform.position - target.position;
}
// Update is called once per frame
void FixedUpdate () {
Vector3 targetCamPos = target.position + offset;
transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);
}
}
_```*_
Ok, character is being destroyed and camera is still referencing no longer existing transform of my character. Ideally I would like camera to stay at least at the same position when destruction of character occured. Please help and thanks in advance!