if(!localplayer)不做任何事情
问题描述:
我正在制作一个多人躲避球游戏,每次我启动一个主机和一个客户端时,只有一个玩家可以移动。 if(!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()
{
}
}
答
这不是一个答案,因为我已经出统一的太久,只是让你知道:
void Update()
{
if (!isLocalPlayer)
{
return;
}
}
根本不做任何事。它是一样的:
void Update()
{
if (!isLocalPlayer)
{
return;
}
return;
}
因为每个函数在最后返回。所以如果我们不是本地的,那就马上回来。否则,立即返回。您需要某种方法来禁用输入控件 - 可能在Start()
中找到输入控件组件,并在!isLocalPlayer
时禁用。
我会尝试.. –
我刚刚尝试了上面的代码,我禁用了控制输入的脚本以及播放器上的其他脚本。结果是他们是独立的,但其中只有一个可以移动。 –