Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 legion_44 · May 26, 2013 at 02:16 AM · c#guieditorbuild

Script work in editor but not in build

Hi, i have problem with my script. It's working in Editor but when i restart Unity or build game it stops working (like it's doesn't exist).

Here's my script:

 using UnityEngine;
 using System.Collections;
 
 public class Leveling : MonoBehaviour {
 
     public Texture2D Exp;
     public Texture2D Background;
 
     public int actLevel = 0;
 
     public int actExp = 0;
     public int[] expToNextLevel;
 
     public string[] addons;
 
     public GUIStyle style;
 
     public void gainExp(int exp)
     {
         actExp += exp;
     }
 
     IEnumerator Wait(float time)
     {
         yield return new WaitForSeconds(time);
     }
 
     void Update()
     {
         if (actLevel >= expToNextLevel.Length - 2)
         {
             actLevel = expToNextLevel.Length - 2;
         }
         if (actLevel >= expToNextLevel.Length - 1)
         {
             actExp = 0;
         }
 
         if (actExp >= expToNextLevel[actLevel + 1])
         {
             actLevel += 1;
             actExp = 0;
             
         }
     }
 
     void OnGUI()
     {
         float exPerc = 0;
         exPerc = (float.Parse("" + actExp) / float.Parse("" + expToNextLevel[actLevel + 1])) * 100;
         GUI.DrawTexture(new Rect(5, Screen.height - 25, 100, 10), Background);
 
         GUI.BeginGroup(new Rect(5, Screen.height - 25, exPerc, 10));
         GUI.DrawTexture(new Rect(0, 0, 200, 10), Exp);
         GUI.EndGroup();
 
         GUI.Label(new Rect(105, Screen.height - 30, 1000, 1000), "" + actLevel, style);
     }
 }
 
Comment
Add comment · Show 9
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 $$anonymous$$ · May 26, 2013 at 04:04 AM 2
Share

What do you mean by "not working" do you mean showing no effect or failing to build or crashing, the only thing I can think that could be going wrong is a null reference exception with the Texture2D's

avatar image $$anonymous$$ · May 26, 2013 at 04:06 AM 0
Share

On second thought, where is gainExp(int exp) being called, it isn't public so it isn't being called by another script

avatar image pixelsyntax · May 26, 2013 at 07:22 AM 0
Share

A more general comment on debugging code that doesn't work outside the editor, you can attach monodevelop to the running unity process and use step-through debugging, breakpoints etc, which makes it very easy to see why your code is 'not working'.

http://answers.unity3d.com/questions/7572/how-can-i-attach-a-debugger-to-the-code-running-on.html

avatar image numberkruncher · May 26, 2013 at 02:24 PM 0
Share

In what way is your script "not working". Please be more specific and reword question title to a) help people answer more effectively, and b) make this question of greater use for future readers :)

avatar image jerobinson · May 27, 2013 at 01:11 AM 0
Share

I am having a similar problem with key inputs not being recognized outside the editor. Please post an answer if you figure this out...

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

18 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

Related Questions

Distribute terrain in zones 3 Answers

Create Multiple Foldouts. 1 Answer

Handling Undo/REdo in EditorWindow when editing DB record. 0 Answers

GUI Score Overlapping 1 Answer

How to fix ArgumentException? 3 Answers


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