When entering the room, I want to know when all the objects have been read.

Options

This question has been posted on other sites as well, making it a multi-post question.

As soon as we receive an answer, we will post the answer on both sites, and if it is resolved, we will promptly close the call for answers and post the resolution on all sites.


Is there a variable to indicate that a non-master client has finished reading another player's object after entering a room?

I'm studying PUN2 for an online game, and I was hoping that the master client of the room would create an object that all participants would use in common, and players who enter the room later would get that object and use it together... I was hoping to do it like this

However, there is a little lag between the time you enter the room and the time when the other players' objects are reflected, so even if you tried to get an object immediately after entering the room, you wouldn't be able to.

Now, I use a coroutine to wait a little while after entering the room to get the object, but depending on the situation, it may take longer to connect, and it would be nice to have a variable to indicate that it has finished loading...

Translated with www.DeepL.com/Translator (free version)


Class to be executed by each player when the game starts.

Only the Master creates the "Avater" when he enters the room, and all players get the "Avater" object after entering the room.

using Photon.Pun;
using Photon.Realtime;
using System.Collections;
using UnityEngine;

public class SampleScene : MonoBehaviourPunCallbacks
{
    public GameObject obj;

    private void Start()
    {
        PhotonNetwork.ConnectUsingSettings();
        if(PhotonNetwork.LocalPlayer.IsMasterClient == false)
        {
            StartCoroutine(DelayLoad());
        }
    }

    public override void OnConnectedToMaster()
    {
        PhotonNetwork.JoinOrCreateRoom("Room", null, null);
    }

    public override void OnJoinedRoom()
    {
        if(PhotonNetwork.LocalPlayer.IsMasterClient)
        {
            obj = PhotonNetwork.Instantiate("Avater", Vector3.zero, Quaternion.identity, 0);
        }
    }

    public IEnumerator DelayLoad()
    {
        yield return new WaitForSeconds(5f);
        obj = GameObject.Find("Avater(Clone)");
    }
}

Best Answer

  • mushipan0929
    Answer ✓
    Options
    void Start()
    {
        FindObjectOfType<SampleScene>().obj = this.gameObject
    }
    

    I received an answer on another site.

    The solution was for the master client to give everyone a "SampleScene" when all players entered the room.

Answers

  • mushipan0929
    Answer ✓
    Options
    void Start()
    {
        FindObjectOfType<SampleScene>().obj = this.gameObject
    }
    

    I received an answer on another site.

    The solution was for the master client to give everyone a "SampleScene" when all players entered the room.