C# 为什么我的房间里没有主客户?使用光子制作多人游戏

C# 为什么我的房间里没有主客户?使用光子制作多人游戏,c#,unity3d,photon,C#,Unity3d,Photon,我试图在整个团队中只使用一个人的代码来实现这些事情,我知道“Masterclient”是一种方式,但使用时: if (PhotonNetwork.isMasterClient){ Debug.Log("Im THE MASTERCLIENT for example"); } 它从不进入if,但如果条件为: if (!PhotonNetwork.isMasterClient){ Debug.Log("Im not THE MASTERCLIENT f

我试图在整个团队中只使用一个人的代码来实现这些事情,我知道“Masterclient”是一种方式,但使用时:

if (PhotonNetwork.isMasterClient){
    Debug.Log("Im THE MASTERCLIENT for example");
}
它从不进入if,但如果条件为:

if (!PhotonNetwork.isMasterClient){
    Debug.Log("Im not THE MASTERCLIENT for example");
}
这意味着对我来说根本没有主客户机,我无法在网上找到为什么会发生这种情况,因为每个人都说,主客户机总是用光子创建的,不需要什么


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


public class GameController : MonoBehaviourPunCallbacks
{
    private PhotonView created_PhotonView;

    public object PhotonTargets { get; private set; }

    public int playersTotales;

    void Start()
    {
        playersTotales = PlayerPrefs.GetInt("TotalPlayers");
        
    }

    void Update()
    {
        Debug.Log(PhotonNetwork.countOfPlayers);
        
        created_PhotonView = this.GetComponent<PhotonView>(); // the photon view of player that just spawned
        if (PhotonNetwork.isMasterClient == false)
        {
            Debug.Log("Setting NONmaster to WHITE");
        }
        if (PhotonNetwork.isMasterClient)
        {
            

            if (PhotonNetwork.countOfPlayers == 0)
            {
                Debug.Log(playersTotales);

            }
        }
    }
}

使用光子双关语;
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
使用光子双关语;
使用光子。实时;
使用UnityEngine.UI;
使用TMPro;
公共类GameController:单属性回调
{
创建的私人PhotonView\u PhotonView;
公共对象光目标{get;private set;}
公共整数播放器总数;
void Start()
{
playerTotales=PlayerPrefs.GetInt(“TotalPlayers”);
}
无效更新()
{
Log(PhotonNetwork.countOfPlayers);
创建了_PhotonView=this.GetComponent();//刚刚生成的播放器的光子视图
if(PhotonNetwork.isMasterClient==false)
{
Log(“将NONmaster设置为白色”);
}
if(PhotonNetwork.isMasterClient)
{
if(PhotonNetwork.countOfPlayers==0)
{
Log(playersTotales);
}
}
}
}

实际上,每个房间都应该有一个主客户。。。尝试使用->
var master=PhotonNetwork.MasterClient;Debug.Log($“Master是{Master.NickName}(ID{Master.ActorNumber}”);