我在一个名为Player.cs的脚本中有一个无法调用的静态方法。当通过GameManager.cs调用时,它应该让我使用它并刷新播放器
我尝试更改引用的名称本身,但这只会产生更多错误。
GameManager.CS
public class GameManager : MonoBehaviourPunCallbacks
{
public Player PlayerPrefab;
[HideInInspector]
public Player LocalPlayer;
private void Awake()
{
if (!PhotonNetwork.IsConnected)
{
SceneManager.LoadScene("Menu");
return;
}
}
// Use this for initialization
void Start()
{
player.RefreshInstance(ref LocalPlayer, PlayerPrefab);
}
// Update is called once per frame
void Update()
{
}
public override void OnPlayerEnteredRoom(Photon.Realtime.Player newPlayer)
{
base.OnPlayerEnteredRoom(newPlayer);
player.RefreshInstance(ref LocalPlayer, PlayerPrefab);
}
}
Player.cs
public class Player : MonoBehaviourPun
{
public static void RefreshInstance(ref Player player, Player Prefab)
{
var position = Vector3.zero;
var rotation = Quaternion.identity;
if (player != null)
{
position = player.transform.position;
rotation = player.transform.rotation;
PhotonNetwork.Destroy(player.gameObject);
}
player = PhotonNetwork.Instantiate(Prefab.gameObject.name, position, rotation).GetComponent<PlayerController>();
}
}
我得到的错误是CS0117: `Photon.Realtime.Player' does not contain a definition for `RefreshInstance'
对不起,如果它缺乏质量,这是我的第一篇帖子。