c# - Photon Pun 2(找不到合适的方法来覆盖)
问题描述
没有找到合适的方法来覆盖你好,我是 C# 中的初学者,我无法覆盖 void 以下代码有人可以帮助我这是我的错误
Assets\GameData\Script\PhotonLauncherScript.cs(15,26): 错误 CS0115: 'PhotonLauncherScript.OnConnectedToMaster()': 找不到合适的方法来覆盖
Assets\GameData\Script\PhotonLauncherScript.cs(20,27): 错误 CS0115: 'PhotonLauncherScript.OnJoinedLobby()': 找不到合适的方法来覆盖
这是代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class PhotonLauncherScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Debug.Log("Connecting to Master");
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
Debug.Log("Connected to Master");
PhotonNetwork.JoinLobby();
}
public override void OnJoinedLobby()
{
Debug.Log("Joined Lobby succesfully");
}
// Update is called once per frame
void Update()
{
}
}
解决方案
所以我可以识别出 2 个错误,这可能会导致您的问题。
1.) 您需要在脚本中使用 Photon.Realtime 和 Photon.Pun。所以添加“使用 Photon.Realtime;” 在上面。
2.) OnConnectedToMaster 是 MonoBehaviourPunCallbacks.OnConnectedToMaster() 的替代,而 MonoBehaviour 中没有类似的功能。这就是控制台错误日志向您显示的内容 - 因此将您的类定义编辑为: public class PhotonLauncherScript : MonoBehaviourPunCallbacks
祝你好运!
PS:有关更多信息,您可以查看官方的 Pun2 教程:https ://doc.photonengine.com/en-us/pun/v2/demos-and-tutorials/pun-basics-tutorial/lobby - 它在类似的主题上对我自己很有帮助,因为它涵盖了使用 C# 和 Unity 设置 PUN 或 PUN2 多人游戏应用程序的基础知识。