进入房间的最少玩家数量 PHOTON
Posted
技术标签:
【中文标题】进入房间的最少玩家数量 PHOTON【英文标题】:Minimum players to enter in a room PHOTON 【发布时间】:2020-04-27 12:26:04 【问题描述】:我正在做一个多人游戏,我想知道如何添加最少数量的玩家让用户进入房间。喜欢在至少连接一名玩家之前不要孤单。我应该在我的脚本中添加什么?我有这个房间选项功能,但它不能像 Min 播放器或其他东西一样工作。 (我预计 MaxPlayers 是否也存在 MinPlayers)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon;
using Photon.Pun;
using UnityEngine.UI;
using Photon.Realtime;
public class MPManager : MonoBehaviourPunCallbacks, IPunObservable
public PlayFabAuth auth;
public string GameVersion;
public Text connectState;
public GameObject[] DisableOnConnected;
public GameObject[] DisableOnJoinRoom;
public GameObject[] EnableOnConnected;
public GameObject[] EnableOnJoinRoom;
public LoadedPlayer loadPlayer;
// Start is called before the first frame update
void Start()
// Update is called once per frame
void Update()
private void FixedUpdate()
connectState.text = "Connection: " + PhotonNetwork.NetworkClientState;
public void ConnectToMaster()
// PhotonNetwork.connectionStateDetailed
PhotonNetwork.ConnectUsingSettings();
public override void OnConnectedToMaster()
PhotonNetwork.JoinLobby();
public override void OnJoinedLobby()
foreach(GameObject disable in DisableOnConnected)
disable.SetActive(false);
foreach (GameObject enable in EnableOnConnected)
enable.SetActive(true);
public void CreateOrJoin()
PhotonNetwork.LeaveLobby();
PhotonNetwork.JoinRandomRoom();
public override void OnJoinRandomFailed(short returnCode, string message)
RoomOptions rm = new RoomOptions
MaxPlayers = 3,
IsVisible = true
;
int rndID = Random.Range(0, 3000);
PhotonNetwork.CreateRoom("Default: " + rndID, rm, TypedLobby.Default);
public override void OnJoinedRoom()
foreach (GameObject disable in DisableOnJoinRoom)
disable.SetActive(false);
foreach (GameObject enable in EnableOnJoinRoom)
enable.SetActive(true);
Debug.Log(loadPlayer.currentPlayer.name);
GameObject player = PhotonNetwork.Instantiate(loadPlayer.currentPlayer.name , Vector3.zero, Quaternion.identity, 0);
public override void OnLeftRoom()
PhotonNetwork.LeaveRoom();
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
throw new System.NotImplementedException();
【问题讨论】:
【参考方案1】:感谢您选择 Photon!
当您加入房间 (OnJoinedRoom
) 或其他玩家加入房间 (OnPlayerEnteredRoom
) 时,您需要获取演员数量 (PhotonNetwork.CurrentRoom.PlayerCount
)。当加入的演员数量足够你时,启动游戏逻辑,例如加载场景、发送自定义事件等。
【讨论】:
以上是关于进入房间的最少玩家数量 PHOTON的主要内容,如果未能解决你的问题,请参考以下文章