- Home /
How to sync non-player objects with uNet?
I have spawned in my player and I can easily sync them as I can check for "isLocalPlayer", but each player has a gun being controlled with OVR Touch controllers and therefore need to sync'd separately.
Basically all I need to do is be able to tell if that gun belongs to a specific player so I can check that in the same way I check "isLocalPlayer" but I have become completely stuck.
Is there anyway to identify an object as being owned by a player?
Thanks!
Answer by Norfinity · Aug 10, 2016 at 10:40 AM
Yes, you have to add a NetworkIdentity and a NetworkTransform component on your gun. With the NetworkServer.SpawnWithClientAuthority you spawn your gun on each player. The gun which belongs to the local player should have authority (hasAuthority flag) on the NetworkIdentity component.
That was it, I just needed to check the hasAuthority Flag, I misunderstood how hasLocalAuthority works and didn't realise it sets that for everyone so I was checking that and triggering on all clients.
Thanks!
Your answer
Follow this Question
Related Questions
Unity hlapi networktransform rigidbody rotation and interpolation issue 1 Answer
SyncListStruct Unity Error 0 Answers
Synchronizing Item Crates 0 Answers
UNET SyncVar on a NetworkInstanceId SyncList structure not updating across network 1 Answer
Unity 5.2 SyncVar hook only gets called on host. VS debugger dosent debug it fully. 0 Answers