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 /
avatar image
0
Question by NextVertex · Sep 26, 2016 at 05:45 PM · scripting problemscript.scripting beginner

Scripting - need help to make my script shorter

Hi, I'm not very good in scripting, i've never made c# before using Unity. So i try to do my best but sometimes, it's not very compact and light.

So i'm here to ask your help about this code, that i would like to make shorter / more compact.

using UnityEngine; using System.Collections;

 public class Coins : MonoBehaviour
 {
       public float cash;
 
 voidUpdate(){
       if(TileManager.score==1)
       {
             if(TileManager.score==3)
             {
                   if(TileManager.score==7)
                   {
                         if(TileManager.score==10)
                         {
                               something like cash = cash + 100
                         }
 
 ETC ... ... ... ...
 
                         else
                         {
                               something like cash = cash + 150
                         }
                   }
                   else
                   {
                        something like cash = cash + 50
                   }
             }
             else
             {
                  something like cash = cash + 30
              }
       }
       else
       {
             something like cash = cash + 10
       }
 

Maybe my code is wrong, i have not test it yet because i don't want to have this huge code if another way, more compact, to make it exist.

Thank you in advance for your help, have a nice day :)

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

· Add your reply
  • Sort: 
avatar image
1

Answer by Erwin23p · Sep 27, 2016 at 04:12 AM

Hello, I'm learning too, but I'll try to maybe help you. I created the other script too simulating your other script. Well, In the other script I have this:

TileManager.cs

and in the script you're trying to do, I have this:

Cash.cs

I tried, and worked pretty damn well.

I hope I helped you. :D

Comment
Add comment · Show 3 · 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 NextVertex · Sep 27, 2016 at 06:21 PM 0
Share

Hi, thank you for your answer The problem is that the Tile$$anonymous$$anager script that you have done isn't very similar to what i have. $$anonymous$$y script Tile$$anonymous$$anager, add 1 to SCORE when a tile spawn because the player reach the limit of the screen. So in this script, i have just one float which is incremented by 1 when the score grow up.

avatar image NextVertex · Sep 27, 2016 at 06:24 PM 0
Share

But thank you for the script you've done, because it realy helped me in my project :)

avatar image Erwin23p NextVertex · Sep 27, 2016 at 10:37 PM 0
Share

Hi, I'm glad that It helped you. I need a lot of practice to learn C# and Unity program$$anonymous$$g/scripting so I'm always glad to try to help.

And sorry, I forgot to add some serious explanations: The Tile$$anonymous$$anager is to simulate a way of getting points... so, the important stuff are the boolean, the floats and the GetScore method. all in the update method is to test if it's working. But do you understand what I've done? Or at least, now?

If you want, you can show me your Tile manager script to see if I can help.

So, I'm gonna try to help you a bit more. The cash should grow with every tile spawned, so the cash should go 10 for 1 of score right? I did some modifications, what about now? You just have to call the GetScore method on every tile spawned, and It will add 1 of score and 10 of cash.

Tile$$anonymous$$anager.cs

Cash.cs

I tried, and worked fine.

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

88 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

Related Questions

Unity {[(2D)]} RotateAround while jumping 0 Answers

vehicle transmission script problem 0 Answers

Make enemy patrol without Nav Points? 0 Answers

Rigidbody2D movement is lagging 0 Answers

CAMERAS ERROR , I NEED HELP 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