Get Player Component

Hi.

I'm trying to get an instantiate player's component from a script that isn't attached to the
prefab. How would i do that?
i was trying something like this:
ThirdPersonController myC = PhotonNetwork.player.GetComponent<ThirdPersonController>();
myC.isControllable = false;
but that isn't how you do it, Can anybody help?

Comments

  • The player does not have the components. It's just an instance of some Player.
    You need to find the GameObject you associate with that player and then do something on that.
  • Tobias wrote:
    The player does not have the components. It's just an instance of some Player.
    You need to find the GameObject you associate with that player and then do something on that.

    When i Instantiate the prefab "player" i set the gameobject to public static and i then use:
    ThirdPersonController controller = ScriptName.playerprefab.GetComponent<ThirdPersonController>();
    			    controller.isControllable = false;
    

    It seems to be working correctly. But is this the best way to go?.
    I mean could this mess it up so maybe other players get isControllable = false or is this a fine method?
  • The snippet you show does not include how you select which playerprefabs you deactivate.
    Aside from that, this is fine.
Sign In or Register to comment.