How to grab a players playerobject, grab the mesh, and modify it..

Trying to apply a random color to a players character when they join the game.
Current code:
using UnityEngine; using System.Collections; using System.Collections.Generic; public class NetworkManager : Photon.MonoBehaviour { public string status; public string roomName; public string playerPrefabName = "StarterBall"; public Transform spawnPoint; public List<Material> Mats = new List<Material>(); public GameObject playerGO; private int playerGOID; private int counter = 1; void Start () { Connect(); InvokeRepeating("UpdateStatus", 2, 1); } void Connect() { PhotonNetwork.ConnectUsingSettings("v001"); } void UpdateStatus() { status = PhotonNetwork.connectionStateDetailed.ToString(); if(status == "JoinedLobby") { RoomOptions roomOptions = new RoomOptions(); PhotonNetwork.JoinOrCreateRoom(roomName, roomOptions, TypedLobby.Default); } if(status == "Joined" && counter == 1) { counter = 2; onJoinedRoom(); } } void onJoinedRoom() { PhotonView.Find(PhotonNetwork.Instantiate(playerPrefabName, spawnPoint.position, spawnPoint.rotation, 0).GetInstanceID()).transform.GetComponentInChildren<MeshRenderer>().material = Mats[Random.Range(0, Mats.Count)]; } }

1. Player joins server, then joins room.
2. On room join I spawn it then grab the players gameobject then the meshrenderer which is under a gameobject mesh which is a child of PlayerObject.
3. Modify it.

Appreciate all and any help, have been stuck on this for the last two days.
P.S this script is applied to my networkmanager which is just a blank gameobject in my game.


  • Dapkin
    Can't really edit it now, but it does spawn my player correctly, just won't let me apply the material.