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 /
This question was closed Jun 16, 2018 at 05:33 PM by Thenosis1 for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by Thenosis1 · Jun 16, 2018 at 01:27 AM · variablefunctionsvalues

Object B doesn't see Variable values that Object A does

In this first picture you can see that Larvae Count and Larvae Currency
each have a value of 5.alt text

In this second picture you can see that Larvae Count and Larvae Currency
have not updated even though both objects are referencing the same script. alt text

I am completely befuddled as to why Object A can see the values but Object B cannot. If it's a code issue then I'm equally as confused. The commented out function at the bottom may be the culprit but I also think I can do things neater instead of using two functions. If I can get object B to see the values of the variables then I can manage the rest.

And frankly, knowing my luck this will be something that I'll face palm right after finding out the answer.

  public Click click;
     public UnityEngine.UI.Text itemInfo;
     public UnityEngine.UI.Text larvae;
     public UnityEngine.UI.Text workers;
     public float cost;
     public int larvaeCount = 0;
     public int workerCount = 0;
     //public string itemName;
     //private float _newCost;
     public float larvaePerClick = 1;
     public float larvaeCurrency = 0.00f;
     public float workerPerClick = 1;
     public float workerCurrency = 0.00f;
 
     private void Update(){
         //itemInfo.text = itemName + "\nCost: " + cost + " Egg";
         
         larvae.text = "Larvae: " + larvaeCurrency;
         workers.text = "Workers: " + workerCurrency;
     }
 
     public void UpgradePurchase(){
 
         if (click.eggCurrency >= cost) {
             click.eggCurrency -= cost;
             larvaeCurrency += larvaePerClick;
             larvaeCount += 1;
         }
     }
 
     /*public void UpgradeWorker(){
 
         if (larvaeCurrency >= cost) {
             larvaeCurrency -= cost;
             workerCurrency += workerPerClick;
             workerCount += 1;
         }
 
     }*/


codehelp1.jpg (46.9 kB)
codehelp2.jpg (45.3 kB)
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

1 Reply

  • Sort: 
avatar image
0

Answer by PedroAK · Jun 16, 2018 at 02:14 AM

How did it get to 5?

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 Thenosis1 · Jun 16, 2018 at 02:49 AM 0
Share

Both of the objects that I'm asking about are buttons. When I click Button A it increases the variables of Larvae Count and Larvae Currency, which is what I want. But as you can see from the second picture the variables do not update according to Button B, this causes Button B to not work correctly when I implement code for it to function.

If I can figure this out then I can work on making Button B work correctly.

Follow this Question

Answers Answers and Comments

91 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

Related Questions

Decreasing a value as another value increases through script 4 Answers

Linking Variable Values 1 Answer

Creating & accessing a function from a diffrent "OnTriggerEnter" Function 1 Answer

Get Value/String From GUIText 3 Answers

How do I add/multiply input field boxes? 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