ViewID for character selec?

Options
Hi,

I'm trying to figure out how to select a player, store that info while I'm entering the lobby and chat in my multiplayer game, and then spawn that particular player I selected when I press the start match button.

I read that the pthoton view ID is unique to gameobjects in a game so: Can I allocate a photon view ID for each of my characters in my game, so that when a gamer selects that player, the ID can be what determines which character spawns?

How do I store the ID ?

This is my spawn code for when I press start match, and it only works for one character in the resources folder called: "PlayerController" (There is no ID info called now):
[PunRPC]
private void RPC_CreatePlayer()
{
float randomValue = Random.Range(20f, 50f);
GameObject myPlayerGO = PhotonNetwork.Instantiate(Path.Combine("Prefabs", "PlayerController"), Vector3.up * randomValue, Quaternion.identity, 0);
}

I also need to be able to spawn characters at random spawn points and not somewhere inbetween Random.Range(20f, 50f);

I really appreciate the help.

Comments

  • Tobias
    Options
    The viewID is unique for objects that are network instantiated (with a PhotonView). So this won't help, likely.

    How about you make a "select player" screen and put the selected "prefab" name into a variable. That should then be instantiated with PhotonNetwork.Instantiate, when in-game. The viewID then refers to this instance, not to the prefab (which may or may not be selectable by more than one player).

    PhotonNetwork.Instantiate does instantiate the object for the local client and all remote clients. No need to wrap this in an RPC! Don't. That causes issues.
  • That makes sense. Thank you.

    So from this code: GameObject myPlayerGO = PhotonNetwork.Instantiate(Path.Combine("Prefabs", "PlayerController"), Vector3.up * randomValue, Quaternion.identity, 0);

    I'm instantiating the prefab PlayerController from the prefabs folder. What would an example with a name variable look like instead of the prefab instantiation above?

    Okay I'll remove PUNRPC then :-)

  • Tobias
    Options
    What would an example with a name variable look like instead of the prefab instantiation above?


    More or less as above. I just meant you want to use a variable instead of "PlayerController" :)