I am attempting to use Detonator for explosions in my game. I started off by testing that the explosion will work. In testing I used:
using UnityEngine;
using System.Collections;
public class LifeTime : MonoBehaviour {
public float LifeSpan;
public Transform boom;
void Awake () {
Invoke("DelayedDestroy", LifeSpan);
}
void DelayedDestroy() {
Instantiate(boom, new Vector3(0, 0, 0), Quaternion.identity);
}
}
Works flawlessly. This is attached to a game object that has a rigidbody and nothing else.
Now in the game I have attached to a missile (game object) that has other items attached to it . The code I am using there is smaller but in scope is not much different. However I then made this a prefab. And there is where it breaks.
using UnityEngine;
using System.Collections;
public class HitTarget : MonoBehaviour {
public Transform boom;
void OnCollisionEnter(){
Instantiate(boom, new Vector3(0, 0, 0), Quaternion.identity);
}
}
Instead of waiting (lifespan =5) 5 seconds it waits till it hits.
Should be straight forward right? The error I am getting is kind of odd:
NullReferenceException
UnityEngine.Component.get_transform () (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/UnityEngineComponent.cs:21)
DetonatorFireball.UpdateFireShadow () (at Assets/Detonator/System/DetonatorFireball.cs:159)
DetonatorFireball.Explode () (at Assets/Detonator/System/DetonatorFireball.cs:195)
Detonator.Explode () (at Assets/Detonator/System/Detonator.cs:335)
Detonator.Start () (at Assets/Detonator/System/Detonator.cs:278)
I have asked about this in the past and no one was able to help.
Any help is appreciated.
Richard