统一在运行时粒子系统中的终身梯度改变颜色;
我正在开发一个需要在运行时控制PRAINTELLESYSTEM
的游戏。 但是问题在于,我无法在运行时和脚本中更改promantystem / coloroverlifetime /渐变< / code < / code>。这是我的代码无法使用的代码:
ParticleSystem.ColorOverLifetimeModule col = backgroundParticleSystem.colorOverLifetime;
Gradient gradient = new Gradient();
GradientColorKey[] colorKeys = new GradientColorKey[2];
GradientAlphaKey[] alphaKeys = new GradientAlphaKey[1];
colorKeys[0].color = backgroundParticleStartColor;
colorKeys[0].time = 0f;
colorKeys[1].color = backgroundColor;
colorKeys[1].time = 1f;
alphaKeys[0].alpha = 1f;
alphaKeys[0].time = 0f;
gradient.SetKeys(colorKeys, alphaKeys);
ParticleSystem.MinMaxGradient gr = col.color;
gr.gradient = gradient;
在此代码中,我只是尝试通过每次重新重置新梯度来更改梯度并重置其colorKey
s和alphakey
> s。
我敢肯定,梯度已正确设置,但粒子系统没有更新。
I'm working on a game that needs to control ParticleSystem
in runtime.
But the problem is that I can't change the ParticleSystem / ColorOverLifetime / Gradient
in runtime and with scripts. Here is my code to do that which didn't worked :
ParticleSystem.ColorOverLifetimeModule col = backgroundParticleSystem.colorOverLifetime;
Gradient gradient = new Gradient();
GradientColorKey[] colorKeys = new GradientColorKey[2];
GradientAlphaKey[] alphaKeys = new GradientAlphaKey[1];
colorKeys[0].color = backgroundParticleStartColor;
colorKeys[0].time = 0f;
colorKeys[1].color = backgroundColor;
colorKeys[1].time = 1f;
alphaKeys[0].alpha = 1f;
alphaKeys[0].time = 0f;
gradient.SetKeys(colorKeys, alphaKeys);
ParticleSystem.MinMaxGradient gr = col.color;
gr.gradient = gradient;
In this code I just tried to change the gradient by remaking a new one each time and resetting its ColorKey
s and AlphaKey
s .
I'm sure that the gradient is setted correctly but somehow the particle system isn't updating.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您的最后两行是问题所在。不应该像
doc ?
I think your last two lines are the issue. Shouldn't it be
instead like in the doc?