- Home /
Animating key on AnimationCurve in real time
Hey. It's my first time working with the Unity particle system and I decided to make some particles to represent the flames behind the jet engine of the player controlled space ship. I'm using Size over Lifetime to edit the size of the flames and want it to grow depending on the speed of the player. In other words, the higher the speed, the bigger the flames. However, it was difficult to find the right documentation on how to animate keys on an Animation Curve. This is my code:
public class EngineFlames : MonoBehaviour
{
private transformForward player;
ParticleSystem ps;
[SerializeField]
private float curveValue;
AnimationCurve curve;
private void Awake()
{
player = FindObjectOfType<transformForward>();
ps = GetComponent<ParticleSystem>();
curveValue = 0.2f;
var sz = ps.sizeOverLifetime;
curve = new AnimationCurve();
curve.AddKey(0.0f, 1);
curve.AddKey(curveValue, 0f);
sz.size = new ParticleSystem.MinMaxCurve(1f, curve);
}
private void Update()
{
curveValue = (player.speed / 100) + 0.1f;
}
}
Just took what I found from [this page][1]. This creates the right curve in the Awake method. I tie the curveValue in Update so that it is connected to the player's speed. Now all I need to do is move the second key in Update, however I have no idea on how to do so. Nor do I know how to talk to the second key created in the Awake method. I know each key has an identity, but I don't know how to get the identity of said key. Also I know that theres a [move key function][2] but this page has very little info and again I need the index of the key I'm moving. Anyone out there that can help me?
Your answer
Follow this Question
Related Questions
Particle Systems wont stop/play 0 Answers
Is their any way to save a particle system when it's not instantiated yet? 2 Answers
Different bullet effect on different physics materals. 1 Answer
Particle Emitting Speed Through Script 1 Answer
Code for destroying object with particle and move to the next object. 1 Answer