如何改变粒子效果的颜色?

3
我该如何将粒子系统的颜色改为与我的玩家颜色相同?
我尝试在一些教程中找到如何做到这一点,我得到了以下解决方案:
GameObject effectBlow = Instantiate(blowOut, transform.position, Quaternion.identity) as GameObject;
effectBlow.gameObject.GetComponent<ParticleSystem>().startColor = material.material.color;

但是现在我的Unity抱怨那段代码已经过时了,当然游戏中的颜色也没有改变。

我不知道如何更改它,有人可以帮助我吗?


你是否将这个脚本附加到了Player游戏对象上? - undefined
1个回答

3

startColor属性已经被弃用,因此不能像那样使用它,请尝试使用以下代码

        GameObject effectBlow = Instantiate(blowOut, transform.position, Quaternion.identity) as GameObject;
        var main = effectBlow.gameObject.GetComponent<ParticleSystem>().main;
        main.startColor = player.GetComponent<Renderer>().material.color;

所以它的基本作用是创建一个变量main,并将实例化的游戏对象的particleSystem主模块引用到该变量中,我们使用startColor属性来修改玩家游戏对象的颜色。
更多信息请查看: https://docs.unity3d.com/ScriptReference/ParticleSystem-main.html

2
补充一下你的回答,如果你想要应用颜色,那么粒子系统中使用的精灵材质必须是完全白色的,否则颜色会与精灵的颜色混合(我猜在Unity3D中也是如此,这里主要指的是Unity2D)。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接