Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Photon.Pun;
- using TMPro;
- using Photon.Realtime;
- public class GameLauncher : MonoBehaviourPunCallbacks
- {
- byte maxPlayerPerRoom = 2; //liczba graczy w pokoju
- bool isConnecting; //czy istnieje połączenie
- public TMP_Text networkText; //nasz network text
- string gameVersion = "0.1"; //wersja gry
- void Awake()
- {
- //właczamy synchronizację
- PhotonNetwork.AutomaticallySyncScene = true;
- }
- public override void OnConnectedToMaster()
- {
- if(isConnecting)
- {
- networkText.text += "OnConnectToMaster...\n";
- PhotonNetwork.JoinRandomRoom();
- }
- }
- //Wywołanie przy rozłączeniu
- public override void OnDisconnected(DisconnectCause cause)
- {
- networkText.text += "Disconnected because " + cause + "\n";
- isConnecting = false;
- }
- //Wywołanie przy dołączeniu do pokoju
- public override void OnJoinedRoom()
- {
- networkText.text = "Joined Room with " + PhotonNetwork.CurrentRoom.PlayerCount + "players.\n";
- //Uruchomienie sceny z grą
- PhotonNetwork.LoadLevel("PongOnline");
- }
- //Wywołanie kiedy nie udało się dołączyć do żadnego pokoju
- public override void OnJoinRandomFailed(short returnCode, string message)
- {
- networkText.text += "Failed to join random room. \n";
- //Stworzenie nowego pokoju
- PhotonNetwork.CreateRoom(null, new RoomOptions { MaxPlayers = this.maxPlayerPerRoom });
- }
- //Połączenie z siecią
- public void ConnectNetwork()
- {
- networkText.text = "";
- isConnecting = true;
- if (PhotonNetwork.IsConnected)
- {
- networkText.text += "Joining Room...\n";
- PhotonNetwork.JoinRandomRoom();
- } else
- {
- networkText.text += "Connecting...\n";
- PhotonNetwork.GameVersion = gameVersion;
- PhotonNetwork.ConnectUsingSettings();
- }
- }
- }
Add Comment
Please, Sign In to add comment