0
\$\begingroup\$

So I am trying to change a variable on a player object by clicking a button using Unet. However, I am having trouble getting the instance of the player object. Is there a way to get the instance of a player from the Network Manager component? I can change the variable before the player connects but once they are connected I can no longer modify it.

Is there a way to do this?

I have a PlayerController script and all I basically want to do is change an integer on my player object based on a button press. I have tried referencing the gameObject attached to the script with gameObject and this. That doesn't seem to work and I have also tried player.GetComponent<PlayerController>().myInt and that doesn't seem to change it either.

All of these methods work until I connect as a Host or client and then it just doesn't do anything once I am connected.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

I finally figured this out in the very depths of the terrible documentation that I could find.

GameObject player = FindObjectOfType<NetworkManager>().client.connection.playerControllers[0].gameObject;

\$\endgroup\$

You must log in to answer this question.

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