2.通过进入GameObject ---> Effects ---> Particle System创建粒子。
如果你使用方法#2创建粒子系统,Unity将会创建新的GameObject,附加一个粒子系统和材质。
始终通过进入GameObject ---> Effects ---> Particle System来创建你的材质。这将节省你一些时间。
简单的解决方案是删除当前的粒子GameObject,通过进入GameObject ---> Effects ---> Particle System创建新的粒子系统,而不是使用#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;
}