- Home /
Getting Gameobjects in Unet
I am building a multiplayer game where i need the Transform of the object i want to attack so that i can use the LERP function now my problem is getting to those objects beacuse they all share the same script and the only way to defferinciat them from me is through IslocalPlayer ,the objects i want to get consists of players and a spawnable object.
there must be something that distinguishes even the other players com one another. how are you attacking? all of them at once? I mean you could just create a static list where each of them subscribes on Start and unsubscribes on Destroy. access it, skip the one that is local player and there you go. but usually you would get them by just using physics or something.
Answer by Ricna · Jul 17, 2018 at 04:52 AM
Considering your GameObjects already have a script with NetworkBehaviour you can use their netId attribute to identify "yourself" or any other instance. https://docs.unity3d.com/ScriptReference/Networking.NetworkIdentity-netId.html
The isLocalPlayer flag is like a shortcut to do the same thing, but will just verify if the current instance has the same netId. With the netId you can compare any other as you want.
Note that when you send a command to your playerobject you can pass a GameObject referemce as parameter, but only when that gameobject has a NetworkBehaviour attached. When the command is send to the server Unity will automatically send the netId of that object to the server and when the command method is executed on the server it will receive the local instance of that gameobject you originally passed in.
So it's all happening transparently. $$anonymous$$eep in $$anonymous$$d that a client can only send commands to object he has control over. This usually is only the one player object each client has. It's the main communication channel. A client can not send a command to other player objects or objects owned by the server. You need to send the command to your own player object and pass a reference to the object you want to manipulate. When finally executed on the server, the server can decide what to do. The server is allowed to send client RPCs to any objects.
Your answer
![](https://koobas.hobune.stream/wayback/20220612170637im_/https://answers.unity.com/themes/thub/images/avi.jpg)