我已经尝试了一切来实现这一点。我有两个球员,他们都吃食物。主机播放器工作正常,但是当客户端吃的时候主机没有更新。我正在使用命令属性在服务器上更新。
请帮忙。
以下是我的代码
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);
}
}
}