zoukankan      html  css  js  c++  java
  • 有关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.... esourcesprefabName.prefab

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

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

  • 相关阅读:
    Disharmony Trees HDU
    Xenia and Bit Operations CodeForces
    Gym
    背包入门
    搜索入门
    Farm Tour POJ
    Flow Problem HDU
    Hie with the Pie POJ
    Building a Space Station POJ
    kuangbin 最短路集合
  • 原文地址:https://www.cnblogs.com/sevenmoons/p/3991352.html
Copyright © 2011-2022 走看看