如果(!localplayer)没有做任何事情

时间:2017-04-07 02:21:41

标签: c# unity3d

我正在进行多人躲避式游戏,每当我启动主持人和客户时,只有其中一个玩家可以移动。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() {
if (!isLocalPlayer)
    {

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

void Update()
{

}
}

1 个答案:

答案 0 :(得分:0)

这不是一个答案,因为我已经失去了很长时间的团结,但只是你知道:

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

什么都不做。它与以下内容相同:

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

因为每个函数都在最后返回。因此,如果我们不是本地人,那么立即返回。否则,立即返回。您需要一些方法来禁用输入控件 - 可能在Start()找到输入控件组件并禁用!isLocalPlayer