我目前正在开发多人fps射击游戏,我被卡在车上。
我尝试了这些“ClientRpc”的东西,“Command”等等。所以Player有Controll脚本,这个脚本有OnControllerColliderHit函数,所以如果发生这种情况我调用void Disable();
在这个方法中,我禁用所有碰撞器和一些我不需要的组件:射击,移动,相机等......
基本上我只需要:当他得到时禁用一些播放器组件 在车里。脚本在单人游戏中完美运行,但在多人游戏中 看起来很奇怪。
我也在Unity答案上问了这个问题,但没有得到任何答案: http://answers.unity3d.com/questions/1235436/ (脚本在那里)
ps(如果您需要更多信息或脚本供我发帖,请发表评论。)
答案 0 :(得分:0)
我认为问题在于您只是启用/禁用服务器中的组件。命令仅在服务器上调用,因此您可能希望使用RPC在客户端中执行相同的操作。
void Update()
{
//if there is driver in car then we can controll it. (it's a paradox for me, if there is driver and i am passanger i also can controll it lol.)
if(hasDriver)
{
GetComponent<carController>().enabled = true;
}
else
{
GetComponent<carController>().enabled = false;
}
}
//command function for sitting. in car.
[Command]
public void CmdSit(string _player)
{
//i increase how many people are in car
sitPlayers++;
cam.enabled = true;
//find player who sat there.
GameObject player = GameObject.Find(_player);
//i think you will get it >>
if (hasDriver)
{
player.transform.parent = Sitter.transform;
player.transform.position = Sitter.transform.position;
cam.GetComponent<AudioListener>().enabled = true;
}
else
{
player.transform.parent = Driver.transform;
hasDriver = true;
cam.GetComponent<AudioListener>().enabled = true;
player.transform.position = Driver.transform.position;
}
RpcSit(_player, hasDriver);
}
[ClientRpc]
public void RpcSit(string _player, bool _driver)
{
cam.enabled = true;
//find player who sat there.
GameObject player = GameObject.Find(_player);
//i think you will get it >>
if (_driver)
{
player.transform.parent = Sitter.transform;
player.transform.position = Sitter.transform.position;
cam.GetComponent<AudioListener>().enabled = true;
}
else
{
player.transform.parent = Driver.transform;
cam.GetComponent<AudioListener>().enabled = true;
player.transform.position = Driver.transform.position;
}
}