我认为问题在于您仅启用/禁用服务器中的组件。命令仅在服务器上调用,因此您可能希望使用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;
}
}