I am developing a racing game project in which i want to do something as simple as when any one of the client hit the finishing point display a message on all other clients showing the name of that specific player say 'John;
This is the message that I want to display on all the clients connected when John hits finishing point.
‘John has won’
After that there is a driving script attached to all the clients which i want to disable.
I’ve been trying to do this for 2 days now and can’t seem to handle this scenario. I came to know that client can only update it’s instance on other clients and cannot change their’s.
This is what I’ve done so far
[SyncVar] string winner = "";
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag.ToLower().Equals("finish"))
{
winner = pname;
CmdServerNotify(winner);
}
}
[Command] public void CmdServerNotify(string name)
{
winner = name;
}
[ClientRpc] public void RpcUpdateWinner(string name)
{
winner = name;
}
void Update()
{
if (winner == "")
{
GetComponentInChildren<TextMesh>().text = pname;
if (isLocalPlayer)
{
Camera.main.transform.position = cameraplace.transform.position;
Camera.main.transform.rotation = cameraplace.transform.rotation;
}
}
else
{
RpcUpdateWinner(winner);
GetComponent<drive>().enabled = false;
GetComponentInChildren<TextMesh>().text = winner + " has won.";
}
}
This just works for own instance of ‘John’ on other clients but not their’s
What is the most appropriate way to do this? Any help will be appreciated