实例化的预制件会丢失组件

时间:2015-07-01 06:54:11

标签: unity3d

我在脚本中实例化了一个预制件。创建的GameObject在项目视图中没有来自我的预制件的任何组件。我的预制件假设有一个脚本组件,但是当我实例化它时它没有。它怎么可能发生?

IEnumerator StartDownload()
{
  WWW www = new WWW(Application.StreamingAssetsPath() + "/shadow.unity3d");

  yield return www;

  AssetBundle ab = www.assetBundle;
  AssetBundleRequest abr = ab.LoadAsync("shadow", typeof(GameObject));

  yield return abr;

  GameObject tmp = abr.asset as GameObject;
  LoadShaderAgain myScriptComponent = tmp.GetComponent<LoadShaderAgain>();

  if (myScriptComponent == null)
  {
      Debug.LogError("losing the script compoent");
  }

  GameObject obj = GameObject.Instantiate(tmp);
}

0 个答案:

没有答案