如何在Unity3d的多人游戏中向一个客户端的所有客户端发送更新?

时间:2016-03-05 20:16:26

标签: networking unity3d unity-networking

我已经尝试了一切来实现这一点。我有两个球员,他们都吃食物。主机播放器工作正常,但是当客户端吃的时候主机没有更新。我正在使用命令属性在服务器上更新。

请帮忙。

以下是我的代码

private void CmdCheckForFood(Vector3 snakePartPosToBeInitialize,Vector3 headPos)
{

    if(_food != null)
    {
        if (_food.transform.position == headPos)
        {


            UiControllerCS.UI.showScore();
            _food.transform.position = GenerateRandomPosForFood(); // I am changing here position of food
            _food.GetComponent<NetworkTransform>().SetDirtyBit(1);
         //Following code will create another part of player if player eat the food.
            GameObject obj = Instantiate(snakePart, snakePartPosToBeInitialize, Quaternion.identity) as GameObject;
            currPartOfSnake += 1;
            obj.name = "" + currPartOfSnake;
            obj.transform.parent = gameObject.transform;
            tail.Add(obj);
            if(isLocalPlayer)
            NetworkServer.SpawnWithClientAuthority(obj , connectionToServer);


        }
    }
}

0 个答案:

没有答案