[英]How to fix "Cannot implicitly convert type 'void' to 'UnityEngine.AsyncOperation"?
I've tried adapting the usual single-player loading bar code to one that'll work for multiplayer using PHOTON.我已经尝试将通常的单人游戏加载条码调整为适用于使用 PHOTON 的多人游戏的条码。 Below is the code I've tried.
下面是我尝试过的代码。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine.SceneManagement;
public class Launcher : MonoBehaviourPunCallbacks
{
[SerializeField]
public Button CreateNameButton;
[SerializeField]
private Slider LoadingSlider;
void Awake()
{
PhotonNetwork.AutomaticallySyncScene = true;
}
public void loadLevels(int sceneIndex)
{
StartCoroutine(loadSelectedScene(sceneIndex));
}
IEnumerator loadSelectedScene(int sceneIndex)
{
AsyncOperation async = PhotonNetwork.LoadLevel(sceneIndex);
while (!async.isDone){
float progress = Mathf.Clamp01(async.progress / .9f);
LoadingSlider.value = async.progress;
yield return null;
}
}
}
I received the error:我收到错误:
Cannot implicitly convert type 'void' to 'UnityEngine.AsyncOperation'
无法将类型“void”隐式转换为“UnityEngine.AsyncOperation”
You can not assign PhotonNetwork.LoadLevel
to AsyncOperation
.您不能将
PhotonNetwork.LoadLevel
分配给AsyncOperation
。 So, you need to use所以,你需要使用
AsyncOperation asyncOperation = PhotonNetwork.LoadLevelAsync(sceneIndex);
However, in PUN 2 Unity
, the LoadLevelAsync
have been removed so you can use PhotonNetwork.LoadLevel()
但是,在
PUN 2 Unity
中, LoadLevelAsync
已被删除,因此您可以使用PhotonNetwork.LoadLevel()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.