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
1
Question by Pr3Z · Feb 03, 2012 at 01:21 AM · intlevelscount

Finding value of an int?

Hi guys,

I'm trying to read the value of the StuffCollected int so that when it reaches 25 the level will change. Not too sure about it and could use a nudge in the right direction. Here's what I have so far, not sure where to go from here.

Cheers.

 static var StuffCollected : int = 0;
 
 
 function Update () {
 
 guiText.text= "Stuff: " + StuffCollected;
 
 if (StuffCollected == 25){
 
 
 Application.LoadLevel ("Level2");
 
         }
 }

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 Eric5h5 · Feb 03, 2012 at 02:24 AM 0
Share

I would recommend removing that code from Update, since Update runs every frame, and there's no reason to change the guiText.text or check stuffCollected every frame. Just make a function that does that, and call the function when needed.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by aldonaletto · Feb 03, 2012 at 01:45 AM

This code seems ok - are you having any problem? Anyway, be aware that a static variable is created and initialized when the program begins, and survive till the end of the program. Due to this, its value will still be 25 when Level2 is loaded, thus you must zero it at Start or Awake if you plan to use it again.
The script above must be attached to the GUIText object, and you can increment SuffCollected in other scripts using something like this:

 GuiScript.StuffCollected += 1;

where GuiScript is the above script's name.

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 Pr3Z · Feb 09, 2012 at 11:31 PM 0
Share

Bizarre, it works now, but I haven't changed anything. $$anonymous$$aybe I was doing something stupid. Thanks for the help guys :)

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

6 People are following this question.

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

Related Questions

Scoring bug error with 2 int variables 0 Answers

New scene for minigame or not? 1 Answer

Keeping track of time after calling Application.LoadLevel 1 Answer

How come when I restart my level it doesn't work? 2 Answers

CHaracter walking through walls 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