Build error ..

So after long time i worked on my project i decided to build it and run it , everytime im trying to build it give’s me this error “Assets/Assest Store/UnityChan/Scripts/SceneLoader.cs(2,7): error CS0246: The type or namespace name `UnityEditor’ could not be found. Are you missing a using directive or an assembly reference?”.

I’ve seen that people telling to fix it with #if UNITY EDITOR and #endif , dident quite understood how to use it.
this is the code :

using UnityEngine;
using UnityEditor.SceneManagement;

public class SceneLoader : MonoBehaviour {

void OnGUI()
{
GUI.Box(new Rect(10 , Screen.height - 100 ,100 ,90), “Change Scene”);
if(GUI.Button( new Rect(20 , Screen.height - 70 ,80, 20), “Next”))
LoadNextScene();
if(GUI.Button(new Rect(20 , Screen.height - 40 ,80, 20), “Back”))
LoadPreScene();
}

void LoadPreScene()
{
int nextLevel = EditorSceneManager.loadedSceneCount + 1;
if( nextLevel <= 1)
nextLevel = EditorSceneManager.sceneCountInBuildSettings;

EditorSceneManager.LoadScene(nextLevel);
}

void LoadNextScene()
{
int nextLevel = EditorSceneManager.loadedSceneCount + 1;
if( nextLevel >= EditorSceneManager.sceneCountInBuildSettings)
nextLevel = 1;

EditorSceneManager.LoadScene (nextLevel);
UnityEngine.SceneManagement.SceneManager.LoadScene (nextLevel);
}
}

it gives the error in :"using UnityEditor.SceneManagement; " , how do i fix this ? any ideas ? and btw sorry for my english.
havnet worked on this project for 2 weeks because this bug , added few scripts here and there but still the idea of me not building it took out my motivation , im a new programmer ( if i can be called one xD ) and realy need help !!)

what version of unity are you using?

and are you sure you didn’t mean

using UnityEngine.SceneManagement;

i.e.

instead of

1 Like

PLEASE insert code properly using the Insert button. Inserting code as text makes it almost impossible to read.

If for whatever reason you can’t get using UnityEngine.SceneManagement; to work, you can always use the older Application.LoadLevel(“YourLevelName”).