C# How to spawn player prefab as unique name

Currently using game manager from demoWorker scene in Photon Cloud example and it is spawning each client as the same playerPrefab name on the server, which results in falling through world and all the extra sadness.

    // Spawn our local player
    PhotonNetwork.Instantiate(this.playerPrefab.name, transform.position, Quaternion.identity, 0);

I would like to try to spawn each new client as a unique prefab name and hope this will fix it.

Any help would be appreciated!

1 Answer

1

Well you can do the following;

PhotonNetwork.Instantiate(this.playerPrefab.name + System.DateTime.Now().ToString("yyMMddHmmffff"), transform.position, Quaternion.identity, 0);

I havent tested the code but this should create a unique name by using system time.(Well almost unique,but i dont think you are planning to spawn more than one players in 1 milisecond :))

To add on @nidre's answer, another alternative is using a static int: player.name = "Name_" + (CertainClass.staticSpawnCounter++);