网。多人载具
Unet. Multiplayer Vehicles
我目前正在开发多人 fps 射击游戏,我被卡在了车辆上。
我尝试了这些 "ClientRpc" 东西,"Command" 等等。所以 Player 有 Controll 脚本,这个脚本有 OnControllerColliderHit 函数,所以如果发生这种情况我调用 void Disable();
在这种方法中,我禁用了所有碰撞器和一些我不需要的组件,例如:射击、移动、相机等...
basically all i need is: Disable some player components when he gets
in car. script works perfectly in singleplayer, but in multiplayer it
looks really weird.
我也在 Unity 上问过这个答案,但没有得到任何答案: http://answers.unity3d.com/questions/1235436/ (有脚本)
ps(如果您需要我提供更多信息或脚本 post,请发表评论。)
我认为问题在于您只是服务器中的 enabling/disabling 个组件。命令仅在服务器上调用,因此您可能希望使用 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;
}
}
我目前正在开发多人 fps 射击游戏,我被卡在了车辆上。
我尝试了这些 "ClientRpc" 东西,"Command" 等等。所以 Player 有 Controll 脚本,这个脚本有 OnControllerColliderHit 函数,所以如果发生这种情况我调用 void Disable();
在这种方法中,我禁用了所有碰撞器和一些我不需要的组件,例如:射击、移动、相机等...
basically all i need is: Disable some player components when he gets in car. script works perfectly in singleplayer, but in multiplayer it looks really weird.
我也在 Unity 上问过这个答案,但没有得到任何答案: http://answers.unity3d.com/questions/1235436/ (有脚本)
ps(如果您需要我提供更多信息或脚本 post,请发表评论。)
我认为问题在于您只是服务器中的 enabling/disabling 个组件。命令仅在服务器上调用,因此您可能希望使用 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;
}
}