Search Unity

Button color in client RPC

Discussion in 'Multiplayer' started by reiconrooc, Apr 8, 2023.

  1. reiconrooc

    reiconrooc

    Joined:
    Aug 11, 2018
    Posts:
    16
    I am working for a simple turn multiplayer game.
    What I need is that when a player click on a button, this is sent by a server RPC that check the selection and call a client RPC. In this client RPC I need to change the color of that button.
    My problem is that the button doesn't change the color.
    Here the code:

    Code (CSharp):
    1.  
    2. [ClientRpc]
    3.     public void SetActivePlayerClientRPC(ulong id,Matrix m)
    4.     {
    5.         table = m;
    6.         for (int i = 0; i < 4; i++)
    7.             for (int j = 0; j < 4; j++)
    8.                 if (m.matrix[i, j] != -1)
    9.                     MatrixObject.Find(string.Format("{0}-{1}", i, j)).GetComponent<Image>().color = mapColors[ulong.Parse(m.matrix[i, j].ToString())];
    10.     }
    11.  
    The MatrixObject is a gameobject is found this way (in every client is the only tagged "Matrix"):
    Code (CSharp):
    1. _matrixObject = GameObject.FindGameObjectsWithTag("Matrix")[0].transform;
    I tryed to color the button in other points of the code and it works. I can't understand why in this part of the code it doesn't work.

    Any ideas?
    Thanks
     
  2. reiconrooc

    reiconrooc

    Joined:
    Aug 11, 2018
    Posts:
    16
    Thanks, but same result. What I can't understand is that the MatrixObject is not null and the Find(string.Format("{0}-{1}", i, j)).GetComponent<Image>().color take the value I provided. So I can't figure why the button don't change color.