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 wgrene80 · Apr 11, 2017 at 01:11 AM · playmodeintegeradding

Int doesn't add until after I exit playmode.

In general, what happens is when a button is pressed, it spawns a new gameobject with an assigned number. The new gameobject has a button, and when their button is pressed I want their assigned number to add to the total number. This works, but the number won't add to the total until I exit playmode. (The "total number" in this case represents the total amount of money, and the gameobject's value is represented as more money to add to the total.)

     //Shared Scripts
     public itemManager itm;
     public MoneyManager callMoney;
     
     public int value;
     
     void Start () {
 
         value = callMoney.sellValue;
     }
 
     public void childQuicksell () {
     
         callMoney.money = callMoney.money + value; //<<<----THIS IS THE ISSUE.
         
         callMoney.sold = true;
     
             Debug.Log ("Sold");
     
     }
     
     
     void Update () {
     
     
     }
 }
 

I've used this line of code in many other scripts before and I've never had this issue. I've tried moving that line to the update function but the number just keeps adding up infinitely, again, only after I've exited playmode. It seems like a simple fix but I've been stuck on this for days. Anyone know what's going on here?

P.S. If you don't understand my question let me know and I'll try my best to clarify.

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 EdwinChua · Apr 11, 2017 at 01:53 AM 0
Share

Reply awaiting moderation.

Assu$$anonymous$$g that you are calling childQuicksell() on button press, it looks like it should work.

How are you displaying/updating the value after the calculation appears? Is "Sold" appearing in your console log?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by EdwinChua · Apr 11, 2017 at 04:26 PM

Assuming that you are calling childQuicksell() on button press, it looks like it should work.

How are you displaying/updating the value after the calculation appears? Is "Sold" appearing in your console log?

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 wgrene80 · Apr 11, 2017 at 06:31 PM 0
Share

I can see the "total money" integer in my hierarchy and once I exit playmode, the money adds up to its correct value. Yes. Everything else in the function works on button press, even the money adds up correctly but not until I exit playmode. During play it stays at zero.

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

66 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

Related Questions

How do you add an integer to a random.range? 1 Answer

How do I use an enum value as a variable? 3 Answers

Input.GetKeyDown(KeyCode.Alpha) as an integer? 1 Answer

Adding a box collider to an object in csharp script 3 Answers

Animation plays on one script but not another 2 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