Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BtnMap.cs (odpalanie map)
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- public class BtnMap : MonoBehaviour {
- JoinMenager JM;
- void Start()
- {
- DontDestroyOnLoad(gameObject);
- JM = GetComponent<JoinMenager>();
- }
- public void BtnMap1 ()
- {
- JM.Connect();
- SceneManager.LoadScene(4);
- }
- public void BtnMap2 ()
- {
- JM.Connect();
- SceneManager.LoadScene(5);
- }
- public void BtnMap3 ()
- {
- JM.Connect();
- SceneManager.LoadScene(6);
- }
- }
- JoinMenager (menadżer połączeń, odpowiada za łączenie z serwerem, odłączeniem itd)
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class JoinMenager : Photon.MonoBehaviour
- {
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Tab))
- Player.Debug2();
- }
- public void Connect()
- {
- PhotonNetwork.ConnectUsingSettings("Alpha_EarlyAcces_June2019_0.0.1");
- }
- void OnGUI()
- {
- GUI.Label(new Rect(0, 0, 200, 20), PhotonNetwork.connectionStateDetailed.ToString());
- }
- void OnJoinedLobby()
- {
- PhotonNetwork.JoinRandomRoom();
- }
- void OnJoinedRandomJoinFailed()
- {
- PhotonNetwork.CreateRoom(null);
- }
- void OnPlayerConnected(PhotonPlayer pp)
- {
- if (PhotonNetwork.isMasterClient)
- {
- photonView.RPC("PlayerJoined", PhotonTargets.AllBuffered, pp);
- }
- }
- [PunRPC]
- void PlayerJoined(PhotonPlayer pp)
- {
- Player player = new Player();
- player.nick = pp.NickName;
- player.pp = pp;
- Player.players.Add(player);
- }
- [PunRPC]
- void PlayerDisconnected(PhotonPlayer pp)
- {
- }
- void OnCreatedRoom()
- {
- photonView.RPC("PlayerJoined", PhotonTargets.AllBuffered, PhotonNetwork.player);
- }
- }
- Player.cs (Lista graczy)
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Player
- {
- public string nick = "NicknameNULL";
- public PhotonPlayer pp;
- public static List<Player> players = new List<Player>();
- public static void Debug2()
- {
- Debug.Log("Debug playerlist! Count of player: " + players.Count + " all players: ");
- foreach (var player in players)
- {
- Debug.Log(player.nick + ", ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement