Please help spawning players in my case

Hello!

I am a Newbie with Unity and even a worst newbie with Photon PUN. I have a situation like this. I want two players challanging each other. Lets say CAT vs. DOG.

In the Lobby players connecting the network will chose to be a CAT or a DOG.

The player who chose CAT creates a room and wait for a DOG to join.

The player who chose DOG receive in his screen a list of the available rooms (created by CATS). When the DOG enters a room, the room is == 2 and the game begins.

Now I am asking: How to spawn players? Player A is CAT, Player B is DOG but how to spawn player A as a CAT and PLAYER B as a DOG?

I need to have TWO prefabs (A cat and a dog) but I can't understand how to give the right character to the right player.

How would you script a "SpawnManager" in a case like this?


Thanks!

Comments

  • Dibbie
    Dibbie ✭✭

    If the host is always a "cat", then you can have your manager check if the PhotonPlayer is the MasterClient, if so spawn your "cat" prefab with PhotonNetwork.Instantiate, if not then spawn your "dog" prefab with the same function - if you then need to, you can use IPunInstantiateMagicCallback for each spawned player to either update their local version of the spawn manager, or send out an RPC to the other player

  • Thanks for your Reply! :-)

    Yes. I thought that having just the CAT opening rooms it would be better for my (poor) matchmaking, at the moment! May be later I can experiment and improove!

    If I get your suggestion well, I should NOT use PhotonNetwork.automaticallySyncScene = true

    and then, if I am the master spawn cat, otherwise, spawn dog. This because "spawnManager" script will run on both devices, knowing which one is master. Right?

  • Dibbie
    Dibbie ✭✭

    I think you SHOULD be using automaticallySyncScene, since usually the host should handle transitioning players to the next scene, unless in your specific setup, the cat player is able to run around in essentially a empty room until a dog joins, in which case syncing the scene wouldnt make a lot of sense in that context - But yes, once a player connects to a room, they get the info of that room, including the master client and other players so each client will always know who the master client is, or at least they can always check if a certain player (or themselves) isMasterClient

  • Funesto
    Funesto
    edited June 19

    Thank you for helping me!

    I tried also "Automatically...." but the MasterClient get stuck in an error!

    On the "Server Script" I have

    private void Start()

      {

        PhotonNetwork.ConnectUsingSettings();

        PhotonNetwork.AutomaticallySyncScene = true;

      }

    Once the CAT (who creates the room), he is alone in the room he created. So I have "WAITING ROOM" scripted just for the CAT with this code:

    private void Update()

      {

        if (PhotonNetwork.CurrentRoom.PlayerCount == 2) { PhotonNetwork.LoadLevel("Game_Scene"); }

      }

    I guess, ... when the dog picks the room, the romm has TWO players and the Game Scene can be loaded!

    At this point ... while te DOG (notMaster) goes in the scene, the CAT who created the room (master) get this error:

    PUN cancels an ongoing async level load, as another scene should be loaded. Next scene to load: Game_Scene

    UnityEngine.Debug:LogWarning (object)

    and does not go into the scene!

  • Dibbie
    Dibbie ✭✭

    In general, you really dont want to be doing level loading like that in Update, it can be called multiple times, and I think that is where your error is coming from, level loading is handled async and pauses messages until the level is loaded for that client - you could instead try moving that logic from Update into the OnPlayerJoinedRoom event or onto a button press for the host/master client

  • Funesto
    Funesto
    edited June 22

    Eheheheheh!!!! <3

    thanks again!!!! Now It works :-)

    ... I can't wait to get in the next trouble! :-)