3
\$\begingroup\$

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

\$\endgroup\$
3
\$\begingroup\$

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;

Note that in more recent development, one should use NetworkClient from Mirror instead:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.