Well I have a script that when the player touch a coin it will play a sound, an animation and then it will be destroyed.
I have a playermodel and two coins on a row, i grab the first coin and get 1 score, the animation plays and is then destroyd, then i grab the second coin but it gives me:
“MissingReferenceException: The object of type ‘Animation’ has been destroyed but you are still trying to access it.”
Script:
#pragma strict
var score = 0;
var coinSound: AudioClip;
var coinPickAnimation: Animation;
function Start () {
}
function Update () {
}
function OnTriggerEnter (other:Collider) {
if(other.gameObject.tag == "coin"){
score++;
audio.PlayOneShot(coinSound);
coinPickAnimation.animation.Play("coinpicker");
yield WaitForSeconds (0.5);
Destroy (other.gameObject);
}
}
function OnGUI () {
GUI.Label(Rect(10,10,200,200),"score : " + score);
}
What to do?