- Home /
Object name not changing correctly (photon)
Hi,
i'm trying to, when connected to a room, instantiate the correct object and rename it.
However, when two people connect to the room, the right objects are instantiated. But the names are:
Character01(Clone) Character02
(Depending which player joins first, otherwise it'll be Character01, Character02(Clone)
Which is problematic because my playercontroller is looking for that object, so I can move them independently.
I'm using Photon
This in my network script: void spawnMyPlayer () {
GameObject _gospawnpoint = GameObject.Find ("Player_0" + PhotonNetwork.player.ID + "_SpawnPoint");
GameObject player = PhotonNetwork.Instantiate ("Character0" + PhotonNetwork.player.ID.ToString (), _gospawnpoint.transform.position, Quaternion.identity, 0);
player.name = "Character0" + PhotonNetwork.player.ID.ToString ();
}
void OnJoinedRoom ()
{
spawnMyPlayer ();
}
and this in my playercontroller script: This is attached to the characters which are loaded in the network script above
public GameObject player;
void Start () {
if (player == null) {
player = GameObject.Find ("Character0" + (PhotonNetwork.player.ID).ToString ()).gameObject;
}
}
@RyanPaterson if you set the GameObject in player via code, then you won't have to do the GameObject.Find. Either store the reference to the game object in player, or store the generated name of the player. Either way, then you will be able to operate on the object even with an unexpected name.
Your answer