最佳答案
由于您创建粒子的方式,问题是缺少 Material 。
创建粒子系统有两种方法:
1.创建空的游戏对象,选择它然后转到组件 --> 效果并添加粒子系统 组件到那个空的游戏对象。这就是您创建当前粒子系统的方式。
如果您使用方法#1 创建您的粒子系统,Unity 将不会将 Material 附加到粒子系统,因此使其变成粉红色。您必须创建一个新 Material ,将着色器更改为“Particles/Alpha Blended Premultiply”,并使用“Default-Particle”作为纹理以使粒子看起来像默认 Material 。
您也可以只为粒子系统使用“默认 Material ”,但您不能修改它。
2。通过转到 GameObject ---> Effects ---> Particle System 创建粒子.
如果您使用方法#2 创建粒子系统,Unity 将 创建新的游戏对象,附加一个粒子系统和还有一个 Material 。
总是通过转到 GameObject ---> Effects ---> Particle System 来创建你的 Material 。这将为您节省一些时间。
简单的解决方案是删除当前的粒子游戏对象,通过转到游戏对象 ---> 效果 ---> 粒子系统 而不是 #1 中描述的方法。
如果您需要从代码创建粒子系统,那么按照我在方法#1 中所说的操作,但是通过脚本。以下是如何做到这一点:
void Start()
{
createParticleSys();
}
void createParticleSys()
{
//Create GameObject to hold the Particle System
GameObject psObj = new GameObject("Particle System");
//Add Particle System to it
ParticleSystem ps = psObj.AddComponent<ParticleSystem>();
//Assign material to the particle renderer
ps.GetComponent<Renderer>().material = createParticleMaterial();
}
Material createParticleMaterial()
{
//Create Particle Shader
Shader particleShder = Shader.Find("Particles/Alpha Blended Premultiply");
//Create new Particle Material
Material particleMat = new Material(particleShder);
Texture particleTexture = null;
//Find the default "Default-Particle" Texture
foreach (Texture pText in Resources.FindObjectsOfTypeAll<Texture>())
if (pText.name == "Default-Particle")
particleTexture = pText;
//Add the particle "Default-Particle" Texture to the material
particleMat.mainTexture = particleTexture;
return particleMat;
}
关于c# - 粒子系统附加到游戏对象时为粉红色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50236252/