- Home /
Game won't build unless 2 vital scripts are in editor folder
Hello everyone. I have a game ready for some testing to see if some aspects that don't work in the editor do outwith as they involve file writing. The two scripts that are being pulled up and cause an error are my movement script and a GUI script for the end of my game that isn't complete yet but does what I want it to currently.
Movement script:
using UnityEngine;
using System.Collections;
public class moveAround : MonoBehaviour {
public float speed = 5f;
public float rotationSpeed = 3f;
public CharacterController cc;
private float curSpeed;
// Use this for initialization
void Awake () {
cc = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update ()
{
transform.Rotate (0, Input.GetAxis ("Horizontal") * rotationSpeed, 0);
float h = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
float v = Time.deltaTime * speed;
transform.Translate(h,0,v);
}
}
GUI script:
using UnityEngine;
using System.Collections;
using UnityEditor.SceneManagement;
public class GUIfinishscene : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI () {
GUI.Box(new Rect(30, 30, Screen.width - 70, Screen.height - 70), "Highscores");
if (GUI.Button (new Rect (Screen.width - 700, Screen.height - 70, 80, 20), "Try Again")) {
EditorSceneManager.LoadScene ("Startup scene");
}
}
}
I know the editor folder means that any scripts in there wont be added to any builds which I obviously need to actually run the game. Any help would be appreciated. Thanks in advance.
Please, use Scene$$anonymous$$anager.LoadScene("Startup scene") to load it.
EditorScene$$anonymous$$anager is used ONLY inside the editor.
Answer by Cherno · Feb 18, 2016 at 09:37 PM
You can't create a Build if one of your scripts is using UnityEditor. You have to encapsulate all code that uses the Editor.
using UnityEngine;
using System.Collections;
#if UNITY_EDITOR
using UnityEditor.SceneManagement;
#endif
public class GUIfinishscene : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI () {
GUI.Box(new Rect(30, 30, Screen.width - 70, Screen.height - 70), "Highscores");
if (GUI.Button (new Rect (Screen.width - 700, Screen.height - 70, 80, 20), "Try Again")) {
#if UNITY_EDITOR
EditorSceneManager.LoadScene ("Startup scene");
#endif
}
}
}
Why aren't you using UnityEngine.SceneManagement with SceneManager.LoadScene?
What about the movement script. Why is that needing to be in the Editor folder? The scripts aren't linked and I can't see any reason for that one causing errors.