Get GameObject in OnPlayerEnteredRoom()

Options
I am trying to get the newest gameObject that has joined the room.

So I want to add a canvas above the character that joins. It will be a name canvas that hovers above the player.
I am trying something like:
GameObject joinedPlayer = PhotonView.Find(newPlayer.ActorNumber).gameObject;
but obviosuly not correct. Does the player variable have any view of the object I need to get a hold of?

Thanks

Here are the two main functions
public void InstantiatePlayer() {

            GameObject[] spawns = GameObject.FindGameObjectsWithTag("Spawn");
            int spawnIndex = Random.Range(0, spawns.Length);

            Debug.LogFormat("We are Instantiating LocalPlayer from {0}", SceneManagerHelper.ActiveSceneName);
            // we're in a room. spawn a character for the local player. it gets synced by using PhotonNetwork.Instantiate
            GameObject MyPlayer = PhotonNetwork.Instantiate("Car"+PlayerPrefs.GetInt("playerCar"), new Vector3(spawns[spawnIndex].transform.position.x, spawns[spawnIndex].transform.position.y, spawns[spawnIndex].transform.position.z), Quaternion.identity, 0);

        }

        public override void OnPlayerEnteredRoom(Player newPlayer) {
            //Add name to car
            Debug.Log(newPlayer.ActorNumber);
            GameObject joinedPlayer = PhotonView.Find(newPlayer.ActorNumber).gameObject;
            GameObject go = Instantiate(myName, new Vector3(joinedPlayer.gameObject.transform.position.x, joinedPlayer.gameObject.transform.position.y+5.0f, joinedPlayer.gameObject.transform.position.z), Quaternion.identity) as GameObject;
            go.gameObject.transform.parent = joinedPlayer.transform;
        }

Comments

  • MomasVII
    Options
    Ok for anyone wondering I actually was thinking about this all wrong.
    I instead added some code to the car ono Start() so it builds on instantiate....
    GameObject go = Instantiate(myName, new Vector3(this.gameObject.transform.position.x, this.gameObject.transform.position.y+1.5f, this.gameObject.transform.position.z), Quaternion.identity) as GameObject;
                go.gameObject.transform.parent = this.transform;
                go.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = photonView.Owner.NickName;