- Home /
Projectiles with animated light, are all animating in sync, how can i fix that ?
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);
}
}
Answer by AlucardJay · Oct 03, 2012 at 07:23 PM
Your problem is with :
curveValue = curve.Evaluate(Time.deltaTime);
Change this to :
curveValue = curve.Evaluate(duration);
You want to evaluate the duration, this is already modified over time to give a value between duration(2.0f) and zero. Time.deltaTime will always evaluate around the same point of the curve (approx 0.016 secs). This should be confirmed by the value returned by Debug.Log(curveValue);
Your answer
![](https://koobas.hobune.stream/wayback/20220613081829im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Generic root motion jitter? 0 Answers
Curves going past keyframes 0 Answers
Can I make animations snap to a frame? 1 Answer
Forcing curves to update in animation editor window 1 Answer
Editing animation curves. 0 Answers