int*_*kho 1 c# 3d game-development unity-game-engine
我正在研究统一粒子系统。
我创建了一个新项目,然后创建了一个空对象,然后向其中添加了粒子系统。由于某种原因,它无法正常工作,您可以看到附件中的图像,以查看发生了什么...
Unity粒子系统粉红色方块:
很可能您没有为粒子选择材质,或者您之前的选择已被擦除(例如通过移动资源)。Unity 通过这种粉红色来指示获取粒子系统的材质时出现问题。您可以通过选择新的粒子纹理或重新选择之前使用的粒子纹理来解决此问题。
在粒子对象检查器的底部周围应该有一个名为renderer 的部分,您可以在其中选择新材质。它是粒子系统中的最后一个选项卡。
现在,您可以通过单击渲染器中的材质字段并找到默认粒子来修复此问题。如果需要,您也可以使用其他材料。
如果您通过脚本创建了粒子系统,您将必须看到@Programmers 的回答,但它仍然会归结为缺少材质。
问题是由于您如何创建粒子而导致缺少材料。
有两种创建粒子系统的方法:
1。创建一个空的GameObject,选择它,然后转到Component- > Effects,然后将粒子系统组件添加到该空的GameObject。这就是您创建当前粒子系统的方式。
如果使用方法#1创建粒子系统,Unity 不会将材质附加到粒子系统,因此将其变为粉红色。您将必须创建新的材质,将着色器更改为“粒子/ Alpha混合预乘”,并使用“默认粒子”作为纹理,以使粒子看起来像默认材质。
您也可以仅对粒子系统使用“默认材料”,但不能对其进行修改。
2通过将.Create粒子游戏物体 ---> 影响 ---> 粒子系统。
如果您使用方法#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;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1580 次 |
最近记录: |