Last active
August 4, 2018 14:31
-
-
Save haydenjameslee/19646fef2563ede60d2b5d57d93e35cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class PhotonNetworkManager : Photon.PunBehaviour | |
{ | |
void Awake() | |
{ | |
PhotonNetwork.autoJoinLobby = false; | |
} | |
void Start() | |
{ | |
Connect(); | |
} | |
/// Start the connection process. | |
/// - If already connected, we attempt joining a random room | |
/// - if not yet connected, Connect this application instance to Photon Cloud Network | |
public void Connect() | |
{ | |
// we check if we are connected or not, we join if we are , else we initiate the connection to the server. | |
if (PhotonNetwork.connected) | |
{ | |
// #Critical we need at this point to attempt joining a Random Room. If it fails, we'll get notified in OnPhotonRandomJoinFailed() and we'll create one. | |
PhotonNetwork.JoinRandomRoom(); | |
} | |
else | |
{ | |
// #Critical, we must first and foremost connect to Photon Online Server. | |
PhotonNetwork.ConnectUsingSettings("1"); | |
} | |
} | |
// Gets called when another player joins the game | |
public override void OnPhotonPlayerConnected(PhotonPlayer other) { | |
PhotonNetwork.Instantiate("NetworkedPlayer", Vector3.zero, Quaternion.identity, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment