统一在运行时粒子系统中的终身梯度改变颜色;

发布于 2025-01-25 23:25:25 字数 913 浏览 2 评论 0原文

我正在开发一个需要在运行时控制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 ColorKeys and AlphaKeys .

I'm sure that the gradient is setted correctly but somehow the particle system isn't updating.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦过后 2025-02-01 23:25:25

我认为您的最后两行是问题所在。不应该像

col.color = gradient;

doc

I think your last two lines are the issue. Shouldn't it be

col.color = gradient;

instead like in the doc?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文