Search Unity

Help Wanted [PUN] Sending specific player property to an instantiated player controller. How do you do it?

Discussion in 'Multiplayer' started by ghegi, Nov 17, 2020.

  1. ghegi

    ghegi

    Joined:
    Jun 3, 2018
    Posts:
    28
    Anyone here who knows photon PUN that can help? Basically this is my problem.

    So in the room just before the start of a game, you are able to choose a color of your own, and I've put them in a custom player properties so it can travel through scenes. Now when the game starts, I can set my own characters color that I chose except those who are not my player.

    ```cs
    Code (CSharp):
    1. void Start()
    2.     {
    3.         if(!PV.IsMine)
    4.         {
    5.             Destroy(GetComponentInChildren<Camera>().gameObject);
    6.         }
    7.         else
    8.         {
    9.             playerModel.layer = 9;
    10.             Material mat = myPlayer.material;
    11.             mat = (Material)Resources.Load((string)PhotonNetwork.LocalPlayer.CustomProperties["Color"], typeof(Material));
    12.             myPlayer.material = mat;
    13.         }
    14.     }`
    ```
    This code only applies to the local player. I want to be able to do this with other players as well and then I tried this:
    ```cs
    Code (CSharp):
    1. `void Start()
    2.     {
    3.         if(!PV.IsMine)
    4.         {
    5.             Destroy(GetComponentInChildren<Camera>().gameObject);
    6.             Material mat = myPlayer.material;
    7.             mat = (Material)Resources.Load((string)PhotonNetwork.LocalPlayer.CustomProperties["Color"], typeof(Material));
    8.             myPlayer.material = mat;
    9.         }
    10.         else
    11.         {
    12.             playerModel.layer = 9;
    13.             Material mat = myPlayer.material;
    14.             mat = (Material)Resources.Load((string)PhotonNetwork.LocalPlayer.CustomProperties["Color"], typeof(Material));
    15.             myPlayer.material = mat;
    16.         }
    17.     }`
    ```
    But this just uses the same property as yours for everyone else so basically, they all got the same colors. Maybe there is a way for the local player to know that that exact player controller should have this exact color. I just don't know how to do it.
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,688
    I think I replied to this exact question on Discord, right?
    If that helped and you found a solution, maybe you could update this thread. Or let us know where you're stuck.
     
  3. ghegi

    ghegi

    Joined:
    Jun 3, 2018
    Posts:
    28
    You did reply but it's on the forum of photon. Do you have a discord server?? Can I join?

    and yes ofcourse
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,688
unityunity