Advertisement
Munchy2007

PunTutPart3_4

Aug 18th, 2016
11,263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. namespace PUNTutorial
  5. {
  6.     public class GameManager : Photon.PunBehaviour {
  7.         public static GameManager instance;
  8.         public static GameObject localPlayer;
  9.  
  10.         void Awake()
  11.         {
  12.             if(instance != null)
  13.             {
  14.                 DestroyImmediate(gameObject);
  15.                 return;
  16.             }
  17.             DontDestroyOnLoad(gameObject);
  18.             instance = this;
  19.  
  20.             PhotonNetwork.automaticallySyncScene = true;
  21.         }
  22.  
  23.         void Start()
  24.         {
  25.             PhotonNetwork.ConnectUsingSettings("PUNTutorial_Pt1");
  26.         }
  27.  
  28.         public void JoinGame()
  29.         {
  30.             RoomOptions ro = new RoomOptions();
  31.             ro.maxPlayers = 6;
  32.             PhotonNetwork.JoinOrCreateRoom("Default Room",  ro, null);
  33.         }
  34.  
  35.         public override void OnJoinedRoom ()
  36.         {
  37.             Debug.Log("Joined Room");
  38.  
  39.             if(PhotonNetwork.isMasterClient)
  40.             {
  41.                 PhotonNetwork.LoadLevel("Game Scene");
  42.             }
  43.         }
  44.  
  45.         void OnLevelWasLoaded(int levelNumber)
  46.         {
  47.             if (!PhotonNetwork.inRoom) return;
  48.  
  49.             localPlayer = PhotonNetwork.Instantiate(
  50.                 "Player",
  51.                 new Vector3(0,0.5f,0),
  52.                 Quaternion.identity, 0);
  53.         }
  54.  
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement