Unity3d 加载预制物 Resource.Load

//不要加后缀名,和Resources, 
//如:路径"Resources/effect/building/Altar.prefab",
//那么写成"effect/building/Altar"
//把资源加载到内存中  
 GameObject prefab = (GameObject)Resources.Load("effect/building/Altar");
 if (prefab)
 {
     //用加载得到的资源对象,实例化游戏对象,实现游戏物体的动态加载
     GameObject obj = GameObject.Instantiate(prefab) as GameObject;
     if (obj)
     {
         obj.name = "xxxxxxxxxxx";
     }
 }
如果是创建NGUI ui预制物的话:
 GameObject obj =NGUITools.AddChild(NGUIRoot.Instance.gameObject, prefab);


猜你喜欢

转载自blog.csdn.net/u013628121/article/details/80373273
今日推荐