Setting GameObject's color? (Color successfully stored per player.ID in CustomProperties)
Options
krx
✭
I'm halfway there. I can see each object's color in CustomProperties, but how do I go about accessing each GameObject's Renderer so I can change the color there?
Picture:
https://imgur.com/a/0MKAc4W
.
Picture:
https://imgur.com/a/0MKAc4W
.
public class PlayerColorRandomizer : MonoBehaviour { public Vector3 colorRGB; private ExitGames.Client.Photon.Hashtable playerCustomProperties = new ExitGames.Client.Photon.Hashtable(); public void SetPlayerColor () { colorRGB = new Vector3(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f)); gameObject.GetComponent<Renderer>().material.SetColor("_Color", new Color(colorRGB.x, colorRGB.y, colorRGB.z)); playerCustomProperties["colorRGB"] = colorRGB; PhotonNetwork.player.SetCustomProperties(playerCustomProperties); foreach(PhotonPlayer pl in PhotonNetwork.playerList) { Vector3 plColor = (Vector3)pl.CustomProperties["colorRGB"]; print("Player " + pl.ID + "'s colorRGB is: " + plColor); } } }
0
Comments
-
You just want to know how toaccsess the Render.Material ?
https://docs.unity3d.com/Manual/class-MeshRenderer.html
Basically you have to get the Renderer from the Object and accsess the Material to change colormeshrenderer.material.color = Color.Green;
Thats an Example i made for someone, it changes the Color based on the Player Score.
https://hastebin.com/avuvovuvak.cs
1 -
@S_Oliver: I feel like your code has me pointed in the right direction. To be clear, I know how to access local renderers, but I didn't know how to access them on other networked objects. Your (m_photonPlayer.ID == m_pView.OwnerActorNr) code is key.
What's working now: Player 1 is already in a room and Player 2 joins, Player 1 sees and applies the correct color to Player 2 (since Player 1 can see OnPhotonPlayerPropertiesChanged).
I still need to figure out: how Player 2 can apply Player 1's color when Player 1 is already in the room... Player 2 can see Player 1's color, but Player 2 needs to access Player 1's renderer when Player 2 joins the room...
I'm working on it, but help is appreciated!0