I made projectile that, when they hit a collider, spawn prefab.
That prefab contain a particle system, a light and a script i made, to animate the light.range.
Problem is every light that are spawned retain the light.range of the first spawned one.
Any way i could make it so that everytime the prefab spawned, the animation plays and kill the object ?
note: the curve variable is not set in script, i created it by hand in the inspector on the prefab.
using UnityEngine;
using System.Collections;
public class DestroySelfOverTime : MonoBehaviour {
public AnimationCurve curve;
public float curveValue;
public float duration;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
duration-=Time.deltaTime;
curveValue = curve.Evaluate(Time.deltaTime);
Debug.Log(curveValue);
light.range = curveValue;
if(duration <=0){
KillMyself();
}
}
void KillMyself(){
Debug.Log("BOOM");
Destroy(gameObject);
}
}