6
\$\begingroup\$

I'm using Mirror as UNet is deprecated. How can I get the local player GameObject in my code?

\$\endgroup\$

1 Answer 1

6
\$\begingroup\$

Currently, the best method is using NetworkClient from Mirror:

using Mirror;
GameObject localPlayer = NetworkClient.localPlayer.gameObject;

Note that the following is deprecated and shouldn't be used.
The ClientScene class has a static property called localPlayer of type NetworkIdentity. All Components in Unity have gameObject as property which refers to the GameObject they're attached to. So in order to get the localPlayer object you would do:

using Mirror;
GameObject localPlayer = ClientScene.localPlayer.gameObject;
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .