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 /
  • Help Room /
This question was closed Dec 16, 2015 at 11:09 PM by shotofop for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by shotofop · Dec 14, 2015 at 08:38 PM · c#unity 5script.programming

Need help with c#

How to make this shorter.I m a beginner so i dont know much yet but i think i might an array but i dont know how to set it up. Here is the code

void HpUpgradelvl()

 {
     if (PlayerControl.coins >= 30)
     {
         healthPoints = healthPoints + 10;
         PlayerPrefs.SetFloat("HealthUP", healthPoints);
         if (PlayerControl.coins >= 60)
         {
             txt.SetActive(false);
             txt1.SetActive(true);
             txt2_0.SetActive(false);
             txt2_1.SetActive(true);
             healthPoints = healthPoints + 10;
             PlayerPrefs.SetFloat("HealthUP", healthPoints);
             if (PlayerControl.coins >= 100)
             {
                 txt1.SetActive(false);
                 txt2.SetActive(true);
                 txt2_1.SetActive(false);
                 txt2_2.SetActive(true);
                 healthPoints = healthPoints + 10;
                 PlayerPrefs.SetFloat("HealthUP", healthPoints);
                 if (PlayerControl.coins >= 150)
                 {
                     txt2.SetActive(false);
                     txt3.SetActive(true);
                     txt2_2.SetActive(false);
                     txt2_3.SetActive(true);
                     healthPoints = healthPoints + 10;
                     PlayerPrefs.SetFloat("HealthUP", healthPoints);
                     if (PlayerControl.coins >= 210)
                     {
                         txt3.SetActive(false);
                         txt4.SetActive(true);
                         txt2_3.SetActive(false);
                         txt2_4.SetActive(true);
                         healthPoints = healthPoints + 10;
                         PlayerPrefs.SetFloat("HealthUP", healthPoints);
                         if (PlayerControl.coins >= 280)
                         {
                             txt4.SetActive(false);
                             txt5.SetActive(true);
                             txt2_4.SetActive(false);
                             txt2_5.SetActive(true);
                             healthPoints = healthPoints + 10;
                             PlayerPrefs.SetFloat("HealthUP", healthPoints);
                             if (PlayerControl.coins >= 360)
                             {
                                 txt5.SetActive(false);
                                 txt6.SetActive(true);
                                 txt2_5.SetActive(false);
                                 txt2_6.SetActive(true);
                                 healthPoints = healthPoints + 10;
                                 PlayerPrefs.SetFloat("HealthUP", healthPoints);
                                 if (PlayerControl.coins >= 450)
                                 {
                                     txt6.SetActive(false);
                                     txt7.SetActive(true);
                                     txt2_6.SetActive(false);
                                     txt2_7.SetActive(true);
                                     healthPoints = healthPoints + 10;
                                     PlayerPrefs.SetFloat("HealthUP", healthPoints);
                                     if (PlayerControl.coins >= 500)
                                     {
                                         txt7.SetActive(false);
                                         txt8.SetActive(true);
                                         txt2_7.SetActive(false);
                                         txt2_8.SetActive(true);
                                         healthPoints = healthPoints + 10;
                                         PlayerPrefs.SetFloat("HealthUP", healthPoints);
                                         if (PlayerControl.coins >= 610)
                                         {
                                             txt8.SetActive(false);
                                             txt9.SetActive(true);
                                             txt2_8.SetActive(false);
                                             txt2_9.SetActive(true);
                                             healthPoints = healthPoints + 10;
                                             PlayerPrefs.SetFloat("HealthUP", healthPoints);
                                             if (PlayerControl.coins >= 730)
                                             {
                                                 txt9.SetActive(false);
                                                 txt10.SetActive(true);
                                                 txt2_9.SetActive(false);
                                                 txt2_10.SetActive(true);
                                                 healthPoints = healthPoints + 10;
                                                 PlayerPrefs.SetFloat("HealthUP", healthPoints);
                                                 if (PlayerControl.coins >= 860)
                                                 {
                                                     txt10.SetActive(false);
                                                     txt11.SetActive(true);
                                                     txt2_10.SetActive(false);
                                                     txt2_11.SetActive(true);
                                                     healthPoints = healthPoints + 10;
                                                     PlayerPrefs.SetFloat("HealthUP", healthPoints);
                                                     if (PlayerControl.coins >= 1000)
                                                     {
                                                         txt11.SetActive(false);
                                                         txtmax.SetActive(true);
                                                         imgmax.SetActive(false);
                                                         txt2_11.SetActive(false);
                                                         txtmax2.SetActive(true);
                                                         imgmax2.SetActive(false);
                                                         healthPoints = healthPoints + 10;
                                                         PlayerPrefs.SetFloat("HealthUP", healthPoints);
                                                     }
                                                 }
                                             }

                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     else healthPoints = 100;
 }  
Comment
Add comment · Show 2
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 ZefanS · Dec 15, 2015 at 08:56 AM 0
Share

This isn't the most reader-friendly piece of code. Could you explain what it's supposed to do?

avatar image shotofop ZefanS · Dec 15, 2015 at 06:47 PM 0
Share

when you get certain amount coins it increses the health by 10 and it changes the text that displays how much coins you need for next upgrade

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by hexagonius · Dec 15, 2015 at 07:23 PM

I think you'd get the help you need on like stackoverflow. This is more a Unity specific Answers site.

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 shotofop · Dec 16, 2015 at 11:09 PM 0
Share

thank you for the suggestion they helped me.

Follow this Question

Answers Answers and Comments

50 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

Related Questions

Basic Code Problem 1 Answer

transform.localscale to specific size 1 Answer

Tempreture drop script "spirit ontriggerstay" problems. 0 Answers

Hiding part of mesh 0 Answers

Game working in pc but not in Android While Testing 0 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