利用脚本组件的public变量
把prefabs拖入到对象相应脚本组件的public变量中,如下图
然后在脚本中写如下代码:
public class explosionScript : MonoBehaviour {
// our ParticleExamples class being turned into an array of things that can be referenced
public ParticleExamples[] particleSystems;
// the gun GameObject
public GameObject gunGameObject;
// a private integer to store the current position in the array
private

本文介绍了在Unity3D中引用和实例化对象的三种方法:通过脚本组件的public变量,直接加载Resource文件夹中的prefabs,以及引用已有对象。详细讲解了如何操作并提供了代码示例。
最低0.47元/天 解锁文章
671

被折叠的 条评论
为什么被折叠?



