Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

load color problem multiplayer

Discussion in 'Multiplayer' started by gagac42, Dec 14, 2019.

  1. gagac42

    gagac42

    Joined:
    Apr 24, 2018
    Posts:
    119
    hello who help my ? my color script work on my player but other players they are black .....my rpc not work pls help my here is my scipt
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class SaveColor : MonoBehaviour
    5. {
    6.     public SkinnedMeshRenderer rend;
    7.     public string[] materials1;
    8.     public string[] materials2;
    9.     public string[] materials3;
    10.     public string ColorName;
    11.     public int Paint;
    12.     public int ColorID;
    13.     public PhotonView photonView;
    14.     public float[] R;
    15.     public float[] G;
    16.     public float[] B;
    17.     public string[] items;
    18.     void Awake()
    19.     {
    20.         Paint = this.gameObject.transform.GetChild(0).GetChild(1).GetComponent<SkinnedMeshRenderer>().materials.Length;
    21.         rend = this.gameObject.transform.GetChild(0).GetChild(1).GetComponent<SkinnedMeshRenderer>();
    22.         materials1 = new string[Paint];
    23.         materials2 = new string[Paint];
    24.         materials3 = new string[Paint];
    25.         R = new float[Paint];
    26.         G = new float[Paint];
    27.         G = new float[Paint];
    28.         B = new float[Paint];
    29.     }
    30.     void Start()
    31.     {
    32.         ColorID = photonView.viewID;
    33.         ColorName = PlayerPrefs.GetString("Player");
    34.     }
    35.     private void Update()
    36.     {
    37.    
    38.         for (int i = 0; i < Paint; i++)
    39.         {
    40.             materials1[i] = rend.materials[i].name + ColorName + 1;
    41.             materials2[i] = rend.materials[i].name + ColorName + 2;
    42.             materials3[i] = rend.materials[i].name + ColorName + 3;
    43.             R[i] = PlayerPrefs.GetFloat(materials1[i]);
    44.             G[i] = PlayerPrefs.GetFloat(materials2[i]);
    45.             B[i] = PlayerPrefs.GetFloat(materials3[i]);
    46.             this.gameObject.transform.GetChild(0).GetChild(1).GetComponent<SkinnedMeshRenderer>().materials[i].color = new Color(R[i], G[i], B[i]);
    47.         }
    48.         if (photonView.isMine)
    49.         {
    50.             photonView.RPC("Name", PhotonTargets.AllBuffered, this.ColorID, this.ColorName);
    51.             photonView.RPC("Color", PhotonTargets.AllBuffered, this.ColorID, (object)R, (object)G, (object)B);
    52.         }
    53.     }
    54.     [PunRPC]
    55.     private void Color( float[]R, float[]G, float[]B)
    56.     {
    57.         for (int i = 0; i < Paint; i++)
    58.         {
    59.          
    60.             PhotonView.Find(ColorID).gameObject.GetComponentInChildren<SaveColor>().R[i] = R[i];
    61.             PhotonView.Find(ColorID).gameObject.GetComponentInChildren<SaveColor>().G[i] = G[i];
    62.             PhotonView.Find(ColorID).gameObject.GetComponentInChildren<SaveColor>().B[i] = B[i];
    63.         }
    64.     }
    65.     [PunRPC]
    66.     private void Name(  int ColorID, string ColorName  )
    67.     {
    68.    
    69.         PhotonView.Find(ColorID).gameObject.GetComponentInChildren<SaveColor>().ColorID = ColorID;
    70.         PhotonView.Find(ColorID).gameObject.GetComponentInChildren<SaveColor>().ColorName = ColorName;
    71.    
    72.     }
    73. }
     
  2. Youdaman

    Youdaman

    Joined:
    Apr 8, 2017
    Posts:
    8
  3. gagac42

    gagac42

    Joined:
    Apr 24, 2018
    Posts:
    119
  4. Youdaman

    Youdaman

    Joined:
    Apr 8, 2017
    Posts:
    8
    I think it's best if you find a tutorial on how to synchronize state with Photon. That page I linked should at least be a good start.
     
    Joe-Censored likes this.
  5. gagac42

    gagac42

    Joined:
    Apr 24, 2018
    Posts:
    119
    I will pay for Help PLS Help me