How do I update this SpriteRenderer?

Hello!

I’m encountering a problem and I do not know what to anymore.

[Command]
void CmdStun(GameObject gO) {
	StartCoroutine (getStun (gO));
}
	
public IEnumerator getStun(GameObject gO) {
	SpriteRenderer spR = gO.GetComponent<SpriteRenderer>();
	spR.color = new Color32(0, 160, 255, 255);
	yield return new WaitForSeconds (2);
	spR.color = new Color32(255, 255, 255, 255);
} 
void Update() {
	If(...) CmdStun(gameObject);
}

I don’t get any errors.

This script updates the color of the gameobject only on host (who is also a client). How can I make this to update color for all clients?

Commands are sent from a Client to the Server, so unless the changed values are synced this change will not be automatically replicated on the other clients.

What you can do is when your server recieves the Command send out an RPC calling the method to change the collor. RPCs are sent from Server To Clients connected to it.

https://docs.unity3d.com/ScriptReference/Networking.ClientRpcAttribute.html