I am trying to do a pretty simple thing, and I finally thought I some what understood Networking, but guess not hehe.
I have a fully functioning FPS multiplayer game thanks to Unity Fragmas 3.0 tutorial series!
I was trying to implement a simple weapon pick up. So basically i added a gameobject and disabled it, and wanted to enable it for that player once you collided with that object on the level and disable the other weapon.
I made it even simpler for testing that if you press “r” it would just swap between the 2 weapons regardless of pickup. But that doesn’t seem to work either.
Add Debug.Log() to various sections of your code and see where it’s breaking down.
-Is the button R being detected on the client?
-Is the command being received on the server
-Is the RPC being received on the client
-Is the gunSyncScript.ChangeToRifle script being called?
I suggest you send over the networkinstanceid (netId) when sending commands and trying to disable and enable other objects with rpc call, it may not return the correct gameobject or even return null in some cases, so basically send the netId to the server and to the rpc aswell, define the target with ClientScene.FindLocalGameObject(input_netid) and define a path to the weapon slot and enable it.
Do not mix up the usual GameObject.Find, FindGameobjects, etc. functions (relatively slow, not ideal choices in some cases) with NetworkServer/ClientScene.FindLocalObject. These work differently and the latter is quite as fast as fetching a value from a dictionary. It is the usual way to identify networked objects across server and clients. So, there should not be any discourage for using.