Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Shazrock · Dec 30, 2012 at 09:18 PM · errorvariableclear

Variables defined in editor, but clear on runtime

OK, so I have a GUI script, which gets a variable called BarkyStatus, which is a script name. The GameObject that has that script is the player, which I define. But, whenever I hit Play, the variable clears and halts the entire script.

Here is the basic formula:

• Script needs the BarkyStatus variable, which contains score data, pickup data and health data.

 var scoreTexture : Texture;
 var timeTexture : Texture;
 var checkmarksTexture : Texture;
 var gemsTexture : Texture;
 var healthBase : Texture;
 var healthBar : Texture;
 
 var nativeVerticalResolution = 600.0;
 
 var barky : BarkyStatus;
 barky = GetComponent("BarkyStatus");
 
 function OnGUI () {
     var timeText = Time.timeSinceLevelLoad;
     GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (Screen.height / nativeVerticalResolution, Screen.height / nativeVerticalResolution, 1)); 
 GUI.DrawTexture(Rect(5,5,80,20),scoreTexture,ScaleMode.ScaleAndCrop,true,0);
 GUI.Label (Rect(85,6,100,23), barky.score.ToString());
 GUI.Label (Rect(65,27,100,23), timeText.ToString());
 }

Well, that's the incomplete version, anyway.

• Plug in the variable in the editor.

• Press Play, and the variable clears itself.

Any tips on how to prevent this? Not that this affects the core gameplay, but I kinda want to see what my score is during gameplay. Help?

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Shazrock · Dec 31, 2012 at 02:38 AM

OK, here's what worked:

 var player : GameObject; // Just this part in the beginning

Then, I modified the GUI.Label command...

 GUI.Label (Rect(85,6,100,23), player.GetComponent(BarkyStatus).score.ToString());

This solved the problem. Thanks!

Comment
Add comment · 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
0

Answer by TomPendergrass · Dec 30, 2012 at 09:56 PM

I believe you're searching for BarkyStatus script only on the object this script is attached to. Try searching the owner object for the compenent.

 player : GameObject; //Your player goes here!
 
 barky = player.GetComponent(BarkyStatus);
Comment
Add comment · 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

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

9 People are following this question.

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

Related Questions

error modifying a var 1 Answer

Script not working, help please 1 Answer

UnassignedReferenceException when its already assigned 1 Answer

Scripting error! 1 Answer

C# - variable is assigned but its value is never used 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