Move scene/ change scene in game not working error

Updated on January 8, 2018 in [D] Game Dev. gossip
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on January 6, 2018

I have made a script that when you collide into a block (invisible block) it triggers the game to say ‘level complete’ and load the next level. This was working before but then suddenly it just stopped working and ruined the whole game. When i collide into the block now it does trigger the level complete text but doesn’t actually move onto the next level and gives me an error saying i have to put the scene into build settings (which i have done and is ticking in build settings with all the other scenes). This is the script:

 

[ using System.Collections;
using UnityEngine.SceneManagement;
using UnityEngine;

public class MoveScene : MonoBehaviour
{
    [SerializeField] private string loadlevel;

    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag(Finish))
        {
            SceneManager.LoadScene(loadlevel);
        }
    }

} ]

[/code]

This is the error:

 

Scene ‘3’ couldn’t be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.
To add a scene to the build settings use the menu File->Build Settings…
UnityEngine.SceneManagement.SceneManager:LoadScene(String)
MoveScene:OnTriggerEnter(Collider) (at Assets/MoveScene.cs:13)

 

P.S: I have put it in the build settings and is assigned with a tick next to it but however it says something about AssetBundle with i have no idea of what it is.

  • Liked by
Reply
1 on January 6, 2018

On your last line [SceneManager.LoadScene(loadlevel)], try putting loadlevel into “speech marks”.

But if you constantly jump from the next scene to the next scene, I strongly recommend using:

SceneManager.LoadScene(SceneManager.GetActiveScene().buildindex + 1;

on January 8, 2018

OMG!!!! You won’t believe how happy i feel now thank you so much it works!!!!

Show more replies
  • Liked by
Reply
Cancel