简体   繁体   中英

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. Once in there, you should see the Scenes In Build category, in there you should also see your scene(s). If not, you will need to assign them by going to each scene and pressing 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:

    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.

Removing the scenes from the build settings and adding them again is what worked for me. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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