How do I make a renderer switch on or off for ALL players in a multiplayer game

if (this.isLocalPlayer & Input.GetKeyDown (“1”) & pistolInHand == true) {
Pistol.gameObject.GetComponent ().enabled = false;
Invoke (“PistolInHandFalse”, 0.5f);
}

if (this.isLocalPlayer & Input.GetKeyDown (“1”) & pistolInHand == false) {
Pistol.gameObject.GetComponent ().enabled = true;
Invoke (“PistolInHandTrue”, 0.5f);
}
It only makes it true or false for the local player.
How do I make it true or false for everybody?
Thanks In Advance!

Have you tried using an event/action? I’m not familiar with multiplayer stuff, but it sounds like you need a way to broadcast the state of a single players game object to other players/clients. Just guessing here but I think its possible that while your instanced object is the same to each client in code, it is its own unique instance in terms of mesh/appearance, ie. each player is rendering different geometry/sprites that all represent the same thing (your gun) in logic… so what you do to the rendering on your side, you will have to do to each instance of your gun on each clients side for them to see the change.

Not sure if its good practice or efficient for multiplayer, but in theory you could invoke an event that each client is subscribed to, to let them know the state of your weapon.

Depending on which network library you’re using, you need to use an RPC, CustomProperty or network RaiseEvent to signal the other clients to update their copy of the object you want to change.

1 Like