2016-05-27 51 views
-2

我製作了一個統一的多人遊戲,並有一個c#腳本。它包含一個方法public void UpdatePlane來更新對手飛機。
在此方法中,我想一個值更改(private bool oppdeadtrue或者只是布爾變量不以任何理由int opponentisdead1工作),或者如果我不能在那裏更改值在所有甚至只是調用該方法makeoppdead()更改數值那裏。但確切地說,這些東西在他們應該時不會改變。我知道當方法UpdatePlane,死亡成爲真實,我收到日誌("oppplayer dead is true")但價值並沒有改變和方法makeoppdead()不beeing執行,我沒有得到日誌("method was called")。另一方面,令我意外的是,它可以毫無問題地改變opponentPrefab。下面的代碼:當其他腳本訪問時,Unity方法不起作用?

 public GameObject opponentPrefab; 
     public Rigidbody2D oppPlane; 

     private bool _multiplayerReady; 
     private string _myParticipantId; 


     private bool oppdead; 
     int opponentisdead = 0; 
    bool boolopponentisdead; 

     float opponentdistance; 
     float distancex; 
     float distancey; 
     float distance; 

     public void UpdatePlane(string senderId, float x, float y, float z, bool death, float oppdistance) 
     { 

      MultiplayerController.Instance.GetMyParticipantId(); 

      opponentdistance = oppdistance; 
       if (death) 
      { 

      //this stuff is NOT being executed: 

       makeoppdead(); 
      opponentisdead = 1; 
    boolopponentisdead = true; 

    //but I do receive this message: 
      Debug.Log("oppplayer dead is true"); 


      } 
      //this stuff is being executed: 

       opponentPrefab = GameObject.Find("Opponent"); 

       opponentPrefab.transform.position = new Vector3(x, y, 0); 
        opponentPrefab.transform.rotation = Quaternion.Euler(0, 0, z); 




     } 
     void makeoppdead() 
     { 
Debug.Log("method was called"); 
    //do some stuff to provide he is really dead 
     } 
+0

@sstan請給我一個更好的,我會立即編輯 –

+0

請更詳細地解釋它是如何失敗。描述當你嘗試執行另一個方法,或者設置一個bool或一個int爲另一個值時發生的情況的行爲。另外,Unity允許你使用帶有腳本的調試器。在函數中放入一個斷點並逐步執行,查看邏輯出錯的位置。 –

+0

@ScottChamberlain android studio'attach to proces'識別我的wifi連接設備,但monoDevelop沒有。只有'統一編輯'才能選擇。根據http://docs.unity3d.com/Manual/AttachingMonoDevelopDebuggerToAnAndroidDevice.html –

回答

0

感謝您的支持,我才能夠解決這個問題,在我自己的,有一點點不同的方式:它工作得很好,如果我在劇本2改變腳本1的任何值與(script1).instanceMP.opponentisdead = 1;

相關問題