代码加载 Prefabs
方法1:通过unityeditor提供的方法 从 路径加载(必须带扩展名,由于UnityEditor 所以不能打包)
void Start() { GameObject obj = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/haha.prefab",typeof(GameObject)) as GameObject; Instantiate(obj, Vector3.zero, transform.rotation); }
方法2: 吧资源放在 Assets/Resources 文件夹下 ,通过Resources类提供的方法加载(不能带扩展名)
GameObject obj= Resources.Load("haha", typeof(GameObject)) as GameObject; Instantiate(obj, Vector3.zero, transform.rotation);