- Home /
Question by
unity_8ukBSdO7Vys17Q · Mar 01, 2020 at 12:22 AM ·
alphagradientkeys
alphaKeys not being updated
My issue is that alphaKeys isn't being updated after calling colorGradient.SetKeys, there is no change, whatsoever
public class BulletTrail : MonoBehaviour
{
public float Lifespan;
IEnumerator DestroyCoroutine()
{
float StartTime = Time.time;
var TrailRenderer = GetComponent<LineRenderer>();
while (Time.time - StartTime < Lifespan)
{
Debug.Log("Updating alpha to " + (1f - ((Time.time - StartTime) / Lifespan)));
GradientAlphaKey[] alphaKeys = new GradientAlphaKey[TrailRenderer.colorGradient.alphaKeys.Length];
Array.Copy(TrailRenderer.colorGradient.alphaKeys, alphaKeys, TrailRenderer.colorGradient.alphaKeys.Length);
alphaKeys[0].alpha = 1f - ((Time.time - StartTime) / Lifespan);
TrailRenderer.colorGradient.SetKeys(TrailRenderer.colorGradient.colorKeys, alphaKeys);
yield return null;
}
Destroy(gameObject);
}
void Start() => StartCoroutine(DestroyCoroutine());
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612224138im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
dynamic gradient alpha mask 2 Answers
line Renderer alpha keys do not update in runtime,Line Renderer runtime update Alpha Keys 0 Answers
Problem with transparent shader 0 Answers
Stop crossfadealpha 1 Answer
plz let me know how to use sprite mask? 0 Answers