加入房间和产卵玩家

时间:2020-03-31 16:49:15

标签: c# unity3d photon

我正在用光子做一个多人游戏,它是2d。每次尝试按启动按钮(启动正在加入或创建另一个房间)时,都会出现此错误,即“ JoinRandomRoom失败。客户端在NameServer上(必须是对接服务器,并且是Master Server)并且已经准备就绪。”这就是我用于此按钮启动的脚本-选择CreateOrJoin() 我也尝试生成我的播放器,但是我不知道我在OnJoinRoom上写的是否正确

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon;
using Photon.Pun;
using UnityEngine.UI;
using Photon.Realtime;

public class MPManager : MonoBehaviourPunCallbacks
{
    public PlayFabAuth auth;



    public string GameVersion;
    public Text connectState;

    public GameObject[] DisableOnConnected;
    public GameObject[] DisableOnJoinRoom;
    public GameObject[] EnableOnConnected;
    public GameObject[] EnableOnJoinRoom;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    private void FixedUpdate()
    {
        connectState.text = "Is Connected: " + PhotonNetwork.IsConnected;
    }
    public void ConnectToMaster()
    {
      //  PhotonNetwork.connectionStateDetailed
        PhotonNetwork.ConnectUsingSettings();
    }

    public virtual void onConnectedToMaster()
    {
       foreach(GameObject disable in DisableOnConnected)
        {
            disable.SetActive(false);
        }
       foreach(GameObject enable in EnableOnConnected)
        {
            enable.SetActive(true);
        }
    }

    public void CreateOrJoin()
    {
        PhotonNetwork.JoinRandomRoom();
    }
    public virtual void OnPhotonRandomJoinFailed()
    {
        RoomOptions rm = new RoomOptions
        {
            MaxPlayers = 3,
            IsVisible = true

        };
        int rndID = Random.Range(0, 3000);
        PhotonNetwork.CreateRoom("Default: "+rndID, rm, TypedLobby.Default);
    }
    public virtual void OnJoinRoom()
    {
        foreach (GameObject disable in DisableOnJoinRoom)
        {
            disable.SetActive(false);
        }
        foreach (GameObject enable in EnableOnJoinRoom)
        {
            enable.SetActive(true);
        }
        GameObject player =  PhotonNetwork.Instantiate("Player", Vector3.zero, Quaternion.identity, 0);

        
}

}

enter image description here

0 个答案:

没有答案