Hello. I’m new to unity (I’m creating one of my first games
). And i have a “problem”.
My code is:
MenuGlowne (MainMenu)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MenuGlowne : MonoBehaviour
{
MenadzerPolaczen mp;
public InputField ifNick;
void Start()
{
DontDestroyOnLoad(gameObject);
mp = GetComponent<MenadzerPolaczen>();
}
// Odpala mape gdy BtnGraj
public void BtnGraj ()
{
if (ifNick.text.Length >= 4)
{
PhotonNetwork.playerName = ifNick.text;
mp.Polacz();
}
}
}
Menadzer Polaczen (ConnectingMenager)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MenadzerPolaczen : Photon.MonoBehaviour {
void Update ()
{
if (Input.GetKeyDown(KeyCode.L))
{
Gracz.Debuguj();
}
}
public void Polacz ()
{
PhotonNetwork.ConnectUsingSettings("EarlyAcces_June2019_ClosedAlpha_0.0.1");
}
void OnGUI ()
{
GUI.Label(new Rect(50, 30, 200, 20), PhotonNetwork.connectionStateDetailed.ToString());
}
void OnJoinedLobby()
{
SceneManager.LoadScene(1);
}
void OnPhotonRandomJoinFailed()
{
PhotonNetwork.CreateRoom(null);
}
void OnLevelWasLoaded(int level)
{
if (level != 0)
{
PhotonNetwork.JoinRandomRoom();
}
}
void OnPhotonPlayerConnected(PhotonPlayer pp)
{
if (PhotonNetwork.isMasterClient)
{
photonView.RPC("GraczWszedl", PhotonTargets.AllBuffered, pp);
}
}
void OnPhotonPlayerDisconnected (PhotonPlayer pp)
{
}
[PunRPC]
void GraczWszedl(PhotonPlayer pp)
{
Gracz gracz = new Gracz();
Gracz.gracze.Add(gracz);
gracz.nick = pp.NickName;
gracz.pp = pp;
}
[PunRPC]
void GraczWyszedl (PhotonPlayer pp)
{
}
void OnCreatedRoom()
{
photonView.RPC("GraczWszedl", PhotonTargets.AllBuffered, PhotonNetwork.player);
}
}
Gracz (Player)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Gracz {
public string nick = "";
public PhotonPlayer pp;
public static List<Gracz> gracze = new List<Gracz>();
public static void Debuguj()
{
Debug.Log("Game list debug! Player count: " + gracze.Count + "all players:: ");
foreach (var gracz in gracze)
{
Debug.Log(gracz.nick + ", ");
}
}
}
All is nice, but when i get down BtnGraj (Button play) I see this in consle
PS: Sorry for my English
Grasz = Player
Wszedl = Connected
Wyszedl = Disconnected
BtnGraj = Button Play