2017-04-05 50 views
0

我正在为我的躲避球游戏制作一个多人游戏场景,一旦我有一台主机和一个客户端运行,它就会出现一阵混乱并迫使我在一个窗口中同时控制主机和客户端。这里是我的意思是:enter image description here网络运行不起作用

这是我的代码管理网络:

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

// Use this for initialization 
void Start() { 

} 

void Update() 
{ 
    if (!isLocalPlayer) 
    { 

     return; 

    } 
} 
} 

它可能有一些与我缺乏了解LocalAuthority。

+0

我无法理解你的问题?你的角色/玩家是不是通过网络移动?要不然? –

+0

@MohammadFaizanKhan当我启动主机和客户端时,我控制两个球员,他们不会独立移动 –

+0

所以你想控制两个球员? –

回答

1

您应该使用isLocalPlayer在更新

// Update is called once per frame 
void Update() 
{ 
    if (!isLocalPlayer) 
    { 
     return; 
    } 

    if(lives == 0) 
    { 
     SceneManager.LoadScene("Lose"); 

    } 



    livesText.text = "Lives: " + lives; 
} 
+0

刚刚尝试过,仍然无法正常工作。 –

+0

什么不起作用?我无法理解您控制(移动)您的播放器的代码。分享该代码 –