简体   繁体   English

使用脚本 (Unity) 将网格分配给粒子系统

[英]Assign a Mesh to a Particle System using Script (Unity)

so I have a custom mesh that I have generated using script and I want to assign it in a particle system but nothing will work.所以我有一个使用脚本生成的自定义网格,我想在粒子系统中分配它,但没有任何效果。 The first part of my code is where I delcare a public Mesh in my script just so I can assign the mesh there when I generate it and then take it from there to assign it to the particle system.我的代码的第一部分是我在我的脚本中 delcare 一个公共网格,这样我就可以在生成网格时在那里分配网格,然后从那里获取它以将其分配给粒子系统。

public Mesh Mesh;
[...]
Mesh = generated_mesh;
[...]
var shape = ps.shape;
shape.enabled = true;
shape.shapeType = ParticleSystemShapeType.MeshRenderer;
shape.mesh = Mesh;

The type changed to Mesh Renderer but the Mesh itself doesn't change.类型更改为 Mesh Renderer,但 Mesh 本身没有更改。

Okay so it seems I was doing it the wrong way all along.好吧,看来我一直都在以错误的方式做这件事。 I changed the shape type from mesh renderer to mesh and it's all good now.我将形状类型从网格渲染器更改为网格,现在一切都很好。 The confusing part is that when I was testing the particle system the only way I could assign the mesh to it manually was through the shape called mesh renderer and not the simple mesh.令人困惑的部分是,当我测试粒子系统时,我可以手动为其分配网格的唯一方法是通过称为网格渲染器的形状而不是简单的网格。 Anyway, it's all good now.不管怎样,现在一切都很好。

var shape = ps.shape;
shape.enabled = true;
shape.shapeType = ParticleSystemShapeType.Mesh;
shape.mesh = Mesh;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM