2017-04-07 83 views
0

我正在製作一個多人躲避球遊戲,每次我啓動一個主機和一個客戶端時,只有一個玩家可以移動。 enter image description hereif(!localplayer)不做任何事情

我希望玩家能夠獨立移動。這裏是我的(更新)代碼:

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 
using UnityEngine.Networking; 
public class Script4Network : NetworkBehaviour 
{ 

// Use this for initialization 
void Start() { 
if (!isLocalPlayer) 
    { 

     gameObject.GetComponent<FirstPersonController>().enabled = false; 
     gameObject.GetComponent<throwing>().enabled = false; 
     gameObject.GetComponent<HeadBob>().enabled = false; 
     // gameObject.GetComponent<Camera>().enabled = false; 
    } 
} 

void Update() 
{ 

} 
} 

回答

0

這不是一個答案,因爲我已經出統一的太久,只是讓你知道:

void Update() 
{ 
    if (!isLocalPlayer) 
    { 
     return; 
    } 
} 

根本不做任何事。它是一樣的:

void Update() 
{ 
    if (!isLocalPlayer) 
    { 
     return; 
    } 
    return; 
} 

因爲每個函數在最後返回。所以如果我們不是本地的,那就馬上回來。否則,立即返回。您需要某種方法來禁用輸入控件 - 可能在Start()中找到輸入控件組件,並在!isLocalPlayer時禁用。

+0

我會嘗試.. –

+0

我剛剛嘗試了上面的代碼,我禁用了控制輸入的腳本以及播放器上的其他腳本。結果是他們是獨立的,但其中只有一個可以移動。 –