Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by conesco3 · Feb 18, 2016 at 09:23 PM · c#editorbuild-error

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Zeronev · Feb 19, 2016 at 02:09 AM 0
Share

Please, use Scene$$anonymous$$anager.LoadScene("Startup scene") to load it.

EditorScene$$anonymous$$anager is used ONLY inside the editor.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image conesco3 · Feb 19, 2016 at 07:24 AM 0
Share

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.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

100 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

My android app build has more bugs on it than the editor/deveploment version 0 Answers

Why using UnityEditor.SceneManagement; is gray like not in use and give error when building my game ? 2 Answers

Initialising List array for use in a custom Editor 1 Answer

Multiple Cars not working 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges