简体   繁体   English

如何修复“无法将类型'void'隐式转换为'UnityEngine.AsyncOperation”?

[英]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.

相关问题 如何修复“无法将转换类型‘float’隐式转换为‘UnityEngine.Quaternion’”? - How do I fix " Cannot implicitly convert convert type 'float' to 'UnityEngine.Quaternion' "? 我如何解决“错误 CS0029 无法将类型 'UnityEngine.Quaternion' 隐式转换为 'UnityEngine.Vector3” - How do i fix "error CS0029 Cannot implicitly convert type 'UnityEngine.Quaternion' to 'UnityEngine.Vector3" 我如何在统一中修复此错误:无法将类型浮点隐式转换为 UnityEngine.transform - How do I fix this error on unity: Cannot implicitly convert type float to UnityEngine.transform 无法将类型“UnityEngine.AudioClip”隐式转换为“UnityEngine.AudioSource” - Cannot implicitly convert type 'UnityEngine.AudioClip' to 'UnityEngine.AudioSource' 无法隐式转换类型'UnityEngine.Vector2?'到'UnityEngine.Vector2' - Cannot implicitly convert type 'UnityEngine.Vector2?' to 'UnityEngine.Vector2' 无法将类型'UnityEngine.ScriptableObject'隐式转换为'T' - Cannot implicitly convert type `UnityEngine.ScriptableObject' to `T' 无法将类型字符串隐式转换为“UnityEngine.UI.Text” - Cannot implicitly convert type string to `UnityEngine.UI.Text' 无法将类型`string'隐式转换为`UnityEngine.GUIText' - Cannot implicitly convert type `string' to `UnityEngine.GUIText' 无法将类型int'隐式转换为unityengine.vector3' - cannot implicitly convert type int' to unityengine.vector3' 无法将类型“UnityEngine.GameObject”隐式转换为“GameObject” - Cannot implicitly convert type 'UnityEngine.GameObject' to 'GameObject'
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM