有关Unity 的一些 笔记之prefab

        unity动态创建对象,需要使用预设prefab,以下方法可以动态创建。

        首先需要在Hierarchy视图里创建GameObject,然后创建Prefab。

        方法一:

                   public   GameObject instantiate;

                   GameObject go=Instantiate(instantiate,transform.position,transform.rotation) as GameObject;

                    将做好的prefab拖到Inspector界面中的 instantiate 字段中,获得原型对象。

         方法二:

                    在Assets目录下的任意位置创建一个名为resources的文件夹,将做好的prefab放到这个文件夹下,path形式如下:

                     Assets\....\resources\prefabName.prefab

                     在代码里使用Resource.Load 或 LoadAll 函数,获得原型对象。

                    GameObject go= Resource.Load("prefabName") as GameObject;

 

posted @ 2014-09-24 18:57  sevenmoons  阅读(4282)  评论(0编辑  收藏  举报