简体   繁体   English

此 Unity 场景未加载

[英]This Unity Scene is not loading

I don't know why my scene is not loading, can I get help?我不知道为什么我的场景没有加载,我能得到帮助吗? When I press the button nothing happens.当我按下按钮时,什么也没有发生。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class gamecontroller : MonoBehaviour
{
    public Text points;
    public void Start() {
        points.text = Score.scoreval + " POINTS";
    }
    
    public void Restart() {
        SceneManager.LoadScene("SampleScene");
        Score.scoreval = 0;
    }
    public void Menu() 
    {
        SceneManager.LoadScene("Menu");
        Score.scoreval = 0;
    }
}

Reason might be that you did not assign the scene in your build.原因可能是您没有在构建中分配场景。 This is an easy fix if this is the case.如果是这种情况,这很容易解决。 To check if it is, you can go to the Build Settings... under the File tab.要检查它是否是,您可以 go 到File选项卡下的Build Settings... Once in there, you should see the Scenes In Build category, in there you should also see your scene(s).进入后,您应该会看到Scenes In Build类别,在那里您还应该会看到您的场景。 If not, you will need to assign them by going to each scene and pressing Add Open Scenes .如果没有,您将需要通过转到每个场景并按Add Open Scenes来分配它们。 Once done, it should work properly from there.完成后,它应该可以从那里正常工作。

Not sure if this is an issue, it has been a while since I have coded in C#. But, in my scene manager, I wrote the scenes name as such:不确定这是否是一个问题,自从我在 C# 中编码以来已经有一段时间了。但是,在我的场景管理器中,我这样写场景名称:

    public void StartButton()
{
    SceneManager.LoadScene(labScene);
}

Not sure if that matters, but I thought I might as well put that out there.不确定这是否重要,但我想我不妨把它放在那里。

There seems to be a bug from Unity side as it has happened with me sometimes that whenever I'm trying to load the scene using the LoadScene method by passing the SceneName as the parameter, Unity throws up an error even when those scenes have been added in the Build Settings. Unity 方面似乎存在一个错误,因为我有时会遇到这种情况,每当我尝试通过将 SceneName 作为参数传递来使用 LoadScene 方法加载场景时,即使添加了这些场景,Unity 也会抛出错误在构建设置中。

Removing the scenes from the build settings and adding them again is what worked for me.从构建设置中删除场景并再次添加它们对我有用。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM