Local Player instantiation issues
Options
ahaupa
✭
Hello,
I created two different scenes : my Photon setup scene (create/join a room) and my Game scene.
I would like to be able to join at multiple times my Game scene after returning to the setup scene (I have a menu in the game scene in which I can load the initial scene).
However, when I come back to my Game Scene my Local Player is instantiated twice.
I am using the scripts coming from the PUN2 Tutorial :
I created two different scenes : my Photon setup scene (create/join a room) and my Game scene.
I would like to be able to join at multiple times my Game scene after returning to the setup scene (I have a menu in the game scene in which I can load the initial scene).
However, when I come back to my Game Scene my Local Player is instantiated twice.
I am using the scripts coming from the PUN2 Tutorial :
public class PlayerManager : MonoBehaviourPunCallbacks, IPunObservable { public static GameObject LocalPlayerInstance; void Awake() { if (photonView.IsMine) { LocalPlayerInstance = this.gameObject; } DontDestroyOnLoad(this.gameObject); } void Update() { UnityEngine.SceneManagement.SceneManager.sceneLoaded += OnSceneLoaded; } void OnSceneLoaded(UnityEngine.SceneManagement.Scene scene, UnityEngine.SceneManagement.LoadSceneMode loadingMode) { this.CalledOnLevelWasLoaded(scene.buildIndex); } void CalledOnLevelWasLoaded(int level) { if ((LocalPlayerInstance != null) && (!Physics.Raycast(transform.position, -Vector3.up, 5f))) { Debug.Log("Entered"); transform.position = new Vector3(0f, 5f, 0f); } } public override void OnDisable() { base.OnDisable(); UnityEngine.SceneManagement.SceneManager.sceneLoaded -= OnSceneLoaded; }and a GameManager Script :
public class GameManager : MonoBehaviourPunCallbacks { public static GameManager Instance; void Start() { Instance = this; if (ProxyManager.LocalPlayerInstance == null) { Debug.LogFormat("We are Instantiating LocalPlayer from {0}", SceneManagerHelper.ActiveSceneName); PhotonNetwork.Instantiate("Player", new Vector3(0f, 5f, 0f), Quaternion.identity, 0); } else { Debug.LogFormat("Ignoring scene load for {0}", SceneManagerHelper.ActiveSceneName); } }Could you help me ? Thanks for the answers
0
Comments
-
Hi, @ahaupa ,
take a look at this tutorial: https://doc.photonengine.com/en-us/pun/v2/demos-and-tutorials/pun-basics-tutorial/intro
It's all done exactly the way you want.
In your scripts, there is some code which purpose I can't understand. Who can guess what is ProxyManager for example?
0 -
Hi @develax ,
I followed exactly this tutorial and this issue has not been taken care of !
You will have an error when you reload the scene a second time.
My ProxyManager is my PlayerManager (I just rename it so everyone can understand in the forum what script I am talking about in the tutorial).0