- Home /
Question by
JakeOfSpades · Feb 01, 2016 at 06:35 PM ·
unity 5networkingclienthostcommands
Object not updating on host
Basically what I'm doing is when the player clicks a line, it will display (enable the Renderer and slap a material on it) and show on all clients. When the host performs this operation, it shows on all clients perfectly. However, when a client performs this operation it does not show on the host. Why is this?
Code:
//Player Click
void OnMouseDown() {
//Place line
if (!GetComponent<PlayerClick>().linePlaced) {
GetComponent<PlayerClick>().linePlaced = true;
GetComponent<Renderer> ().enabled = true;
GetComponent<Renderer> ().material = lineMat;
if (isLocalPlayer) {
string id = gameObject.name;
CmdPlaceLine (id);
}
}
//On click place a line at the mouse location
[Command]
void CmdPlaceLine(string id)
{
linePlaced = true;
GameObject go = GameObject.Find (id);
go.GetComponent<Renderer> ().enabled = true;
go.GetComponent<Renderer> ().material = lineMat;
}
//Check if a player placed a line and update on clients if so
[ClientRpc]
void RpcChangeLineAppearance()
{
StartCoroutine(CheckIfPlayerPlacedLine());
}
IEnumerator CheckIfPlayerPlacedLine()
{
if (linePlaced) {
yield return new WaitForSeconds (0.2f);
GetComponent<Renderer> ().enabled = true;
GetComponent<Renderer> ().material = lineMat;
}
}
// Update is called once per frame
void Update () {
StartCoroutine(CheckIfPlayerPlacedLine());
if(isServer)
RpcChangeLineAppearance();
}
}
Comment
Your answer
Follow this Question
Related Questions
Starting a client on standalone.exe not working but i works on editor play 2 Answers
How can a client connect more players to a network game? 1 Answer
NETWORKING: Start as Host if no Host; Otherwise Start as Client 0 Answers
unity netcode object doesnt get declared on client when instantiated 0 Answers
[Command] not being called by clients 0 Answers