1. 程式人生 > >Unity5.x 專案升級過程中常見問題解決方案總結

Unity5.x 專案升級過程中常見問題解決方案總結

最近整理Unity4.x專案升級Unity5.0過程中出現的各種常見問題,與大家共享。1:Unity4.x專案中3D模型其材質丟失,成為“白模”?解決方案:手工重新賦值材質貼圖.
 1:Unity4.x 專案中3D模型其材質丟失,成為“白模”?
      解決方案:手工重新賦值材質貼圖。

  2:Unity4.x 專案中的NavMesh 升級報錯?
     “NavMesh asset format has changed. Please rebake the NavMesh data.” ?
     解決方案:按照字面含義,重新對靜態物體進行烘焙即可。

  3:Unity4.x 天空盒子升級後顯示混亂?
     解決方案: 找到專案中“標準資源”(Standard Assets),點選天空盒子的材質,出現提示資訊“This texture contains alpha, but is not RGBM(Incompatible with HDR[高動態光照渲染])”點選“Fix Now”進行自動修復即可。
     
  4:Unity4.x 在升級後出現某些3D模型不顯示的“嚴重”問題?
     解決方案: 由於Unity5.0 與Unity4.x版本的底層編碼變化較大,Unity5.0已經不能正確識別部分老“預設”,從而造成不顯示問題。此時我們找到對應模型的“原型”3D模型,重新建立“預設”在場景中的原位置進行重新載入即可。(注意與原來的方位需要一致才可以)。


  5:Unity4.x 專案升級後部分Animation動畫失效(不動沒有反應)?
     解決方案:基本原理同上題,我們把Animation動畫在Unity5.0中重新編輯與測試即可。
     
  6: 由於指令碼升級過程中造成的各種異常現象?
      例如:跑酷、射擊、RPG等遊戲中的英雄對輸入資訊沒有反應,射擊與攻擊無效等。
      解決方案: 造成以上問題的直接或者間接原因多數是指令碼的升級造成的問題,詳細整理如下:
    6.1>:螢幕滑鼠鎖定://Screen.lockCursor = true; //被Unity5 新指令碼代替
    Cursor.lockState = CursorLockMode.Locked;  
而螢幕滑鼠解鎖:Cursor.lockState = CursorLockMode.None;
    
    6.2>://GoNeedAddScriptsObj.AddComponent("類名稱");//被Unity5 新指令碼代替
    GoNeedAddScriptsObj.AddComponent<DynamicAddScripts>();//必須用泛型代替。 
     
    6.3> //goCreatObj.Renderer.Material.color=Color.red;//老寫法已經作廢。
       goCreatObj.GetComponent<Renderer>().material.color = Color.red

    6.4> //this.animation.Play(); //寫法禁用了
       this.GetComponent<Animation>().Play("Walking"); //Unity5自動更正。 
    
    6.5> //con.gameObject.collider.xx;//否決
       con.gameObject.GetComponent<Collider>().xxx;

     7:關於AssetBounds錯誤資訊:
     “UnityEngine.AssetBundle.Load(string)' is obsolete: `Method Load has been deprecated. Script updater cannot update it as the loading behaviour has changed. Please use LoadAsset instead and check the documentation for details.”


    解決方案:

    WWW downloadAsset = new WWW(path);

    //等待下載完成
    yield return downloadAsset;

    //載入複合物件,且通過名稱把他們讀取出來  
    //GameObject goPrefabs1= (GameObject)downloadAsset.assetBundle.Load("Prefabs_SelfRotationCube");   GameObject goPrefabs1 = (GameObject)downloadAsset.assetBundle.LoadAsset("Prefabs_SelfRotationCube");//Unity5方式。

     8:讀取當前關卡Application.LoadLevel(Application.loadLevelName)//老化
     //Unity5.x中讀取當前關卡:首先在類上載入名稱空間:Using UnityEngine.SceneManagement;
          SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);

     9.播放音訊
兩種屬性定義:方法各有不同,其實原理一樣,都是先找到音效源AudioSource,然後再找片段AudioClip 
1. 屬性定義為public AudioClip m_shootClip;時
Unity4.x版本中的this.audio.PlayOneShot(m_shootClip)語句
在Unity5.x版本中應該為this.GetComponent<AudioSource>().PlayOnShot(m_shootClip);

2. 屬性定義為
protected AudioSource m_audio;
   public AudioClip m_shootClip;時
可以直接使用m_audio.PlayOneShot(m_shootClip);