Я делаю многопользовательскую игру и нахожусь на сцене меню, где я делаю комнату выбора - на одной панели и создаю комнату - другую панель. Это работает, чтобы создать комнату, но когда я нажимаю, чтобы показать панель с «ChooseRoom», она ничего не появляется. Вот сценарий, который я использую. Так что он не выглядит как сборник, который я сделал с помощью RoomListing1 (текст) ![enter image description here](https://i.stack.imgur.com/tfGDN.png)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SingletonReferences : MonoBehaviour
{
[SerializeField]
private MasterManager _masterManager;
}
using Photon.Pun;
using Photon.Realtime;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RoomListingsMenu : MonoBehaviourPunCallbacks
{
[SerializeField]
private Transform _content;
[SerializeField]
private RoomListing _roomListing;
private List<RoomListing> _listings = new List<RoomListing>();
private RoomsCanvases _roomsCanvases;
public void FirstInitialize(RoomsCanvases canvases)
{
_roomsCanvases = canvases;
}
public override void OnJoinedRoom()
{
_roomsCanvases.CurrentRoomCanvas.Show();
// _content.DestroyChildren();
_listings.Clear();
}
public override void OnRoomListUpdate(List<RoomInfo> roomList)
{
foreach (RoomInfo info in roomList)
{
//Removed from rooms list.
if (info.RemovedFromList)
{
int index = _listings.FindIndex(x => x.RoomInfo.Name == info.Name);
if (index != -1)
{
Destroy(_listings[index].gameObject);
_listings.RemoveAt(index);
}
}
//Added to rooms list.
else
{
int index = _listings.FindIndex(x => x.RoomInfo.Name == info.Name);
if (index == -1)
{
RoomListing listing = Instantiate(_roomListing, _content);
if (listing != null)
{
listing.SetRoomInfo(info);
_listings.Add(listing);
}
}
else
{
//Modify listing here.
//_listings[index].dowhatever.
}
}
}
}
}
using Photon.Pun;
using Photon.Realtime;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class RoomListing : MonoBehaviour
{
[SerializeField]
private Text _text;
public RoomInfo RoomInfo { get; private set; }
public void SetRoomInfo(RoomInfo roomInfo)
{
RoomInfo = roomInfo;
_text.text = roomInfo.MaxPlayers + ", " + roomInfo.Name;
}
public void OnClick_Button()
{
PhotonNetwork.JoinRoom(RoomInfo.Name);
}
}
using Photon.Pun;
using Photon.Realtime;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestConnect : MonoBehaviourPunCallbacks
{
private void Start()
{
Debug.Log("Connecting to Photon...", this);
AuthenticationValues authValues = new AuthenticationValues("0");
PhotonNetwork.AuthValues = authValues;
PhotonNetwork.SendRate = 20; //20.
PhotonNetwork.SerializationRate = 5; //10.
PhotonNetwork.AutomaticallySyncScene = true;
PhotonNetwork.NickName = MasterManager.GameSettings.NickName;
PhotonNetwork.GameVersion = MasterManager.GameSettings.GameVersion;
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
Debug.Log("Connected to Photon.", this);
Debug.Log("My nickname is " + PhotonNetwork.LocalPlayer.NickName, this);
if (!PhotonNetwork.InLobby)
PhotonNetwork.JoinLobby();
}
public override void OnDisconnected(DisconnectCause cause)
{
Debug.Log("Failed to connect to Photon: " + cause.ToString(), this);
}
public override void OnJoinedLobby()
{
print("Joined lobby");
PhotonNetwork.FindFriends(new string[] { "1" });
}
public override void OnFriendListUpdate(List<FriendInfo> friendList)
{
base.OnFriendListUpdate(friendList);
foreach (FriendInfo info in friendList)
{
Debug.Log("Friend info received " + info.UserId + " is online? " + info.IsOnline);
}
}
}