Created
April 7, 2017 04:29
-
-
Save sam-keene/d0f44cd6c00d68c27f5b278057dbf847 to your computer and use it in GitHub Desktop.
Part of a Medium tutorial on building a multiplayer game in Daydream VR and Unity
This file contains hidden or 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 System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| using UnityEngine.UI; | |
| using Photon; | |
| public class PhotonCommsManager : Photon.PunBehaviour { | |
| private GameObject currentPlayer; | |
| void Start () { | |
| PhotonNetwork.logLevel = PhotonLogLevel.Full; | |
| PhotonNetwork.ConnectUsingSettings ("0.1"); | |
| } | |
| /////////////////////// Photon Methods /////////////////////// | |
| public override void OnJoinedLobby () { | |
| PhotonNetwork.JoinRandomRoom (); | |
| } | |
| public override void OnJoinedRoom () { | |
| // instantiate user avatar locally and spawns in remote instances | |
| currentPlayer = PhotonNetwork.Instantiate("Player", new Vector3(0,1.6f,0), Quaternion.identity, 0); | |
| currentPlayer.GetComponent<PlayerController>().isControllable = true; | |
| } | |
| // This is called if there is no one playing or if all rooms are full, so create a new room | |
| void OnPhotonRandomJoinFailed() | |
| { | |
| Debug.Log("Can't join random room!"); | |
| PhotonNetwork.CreateRoom(null); | |
| } | |
| void OnGUI() | |
| { | |
| GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment