进入房间的最少玩家数量 PHOTON [英] Minimum players to enter in a room PHOTON

查看:27
本文介绍了进入房间的最少玩家数量 PHOTON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个多人游戏,我想知道如何为用户添加最少数量的玩家进入房间.喜欢在至少连接一名玩家之前不孤单.我应该在我的脚本中添加什么?我有这个房间选项功能,但它不起作用太像 Min 玩家或其他东西.(我预计 MaxPlayers 是否也存在 MinPlayers)

I am doing a multiplayer game and I want to know how I can add a minimum number of players for a user to enter a room . Like to not be alone till one player is connected at least. What I should add to my script? I have this Room Options function but It doesn't work too add like Min players or something to it. (I expected if is MaxPlayers to exist MinPlayers too)

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();
    }
}

推荐答案

感谢您选择 Photon!

Thank you for choosing Photon!

您需要在您加入房间时 (OnJoinedRoom) 或其他玩家加入房间时 (PhotonNetwork.CurrentRoom.PlayerCount) 获取演员的数量>OnPlayerEnteredRoom).当加入的演员数量足够你时,开始游戏逻辑,例如加载场景,发送自定义事件等

You need to get the count of actors (PhotonNetwork.CurrentRoom.PlayerCount) when you join the room (OnJoinedRoom) or when another player joins the room (OnPlayerEnteredRoom). When the number of actors joined is enough for you, start the game logic, e.g. load scene, send a custom event etc.

这篇关于进入房间的最少玩家数量 PHOTON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆