[36013-nan+error.png|36013]
So here’s some background information, I am trying to create this explosion effect of “cubie’s”. I have one object called enemy that when he collides with a bullet it destroys itself and instantiates another object called EnemyDeathAnimation which is not really an animation but a gameObject that replicates an explosion effect based on this tutorial: How to Make an Object Shatter Into Smaller Fragments in Unity
when I play the game and shoot the enemies occasionally I get the NaN error. I think it may be caused by the sphere used in the explosion effect instantiating and interfering with other objects. If anyone could shed some light on how to avoid/fix the error that would be great. If there is any better way of creating the explosion effect I would be more than happy to scratch this method and do it that way.
Enemy Script:
using UnityEngine;
using System.Collections;
public class EnemyCubeScript : MonoBehaviour
{
public GameObject deathAnimation;
private float fadeTimer = 1.9f;
private Transform player;
private NavMeshAgent nav;
void OnTriggerEnter (Collider col)
{
if(col.tag == "Bullet")
{
GameObject deathAnimationClone = Instantiate(deathAnimation, transform.position, transform.rotation) as GameObject; //instantiates deathAnimation gameObject
Destroy (gameObject); //destroy self
Destroy (deathAnimationClone, fadeTimer);
Destroy (col.gameObject); //destroy bullet
}
}
void Awake () {
player = GameObject.FindGameObjectWithTag ("Player").transform;
nav = GetComponent <NavMeshAgent> ();
}
void Update () {
nav.SetDestination (player.position);
}
}