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 Margallo · Nov 25, 2016 at 10:44 AM · c# tutorialunity 5.2

unity c# money system

I want this to program please help me im stock with this logic! example: i have a $10 dollar money and when playing the game i get score of $4 how can i add the $4 in the $10 money. How can i code that in unity c#

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Margallo · Nov 25, 2016 at 12:54 PM

I'm sorry for my bad english @ dacarrera! that's why its not working the totalMoney and the money is reverse thanks :) but one more thing how can i save the totalMoney using playerprefs?

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 dacarrera · Nov 25, 2016 at 12:58 PM 2
Share

You'll want to use the SetInt() method as seen in the docs here. Glad I was able to help answer your question! :)

avatar image
3

Answer by dacarrera · Nov 25, 2016 at 11:01 AM

Hey Margallo,

An exact implementation for a money system will depend on the nature of your game. A simple way of doing this is to store your "money" as an int and to increase/decrease it as needed.

For example:

 // Simple money system
 
 public int playerMoney = 0; // Start with $0
 
 // Function to increase money
 // This should change based on the way you want to
 // have the player make money
 
 void addPlayerMoney(addAmount){
     playerMoney += addAmount;
 }

So now whenever addPlayerMoney() is called, it'll increased your money variable by addAmount. From here, it'll be up to you! For example, calling addPlayerMoney(5) will increase your money by 5, and playerMoney will now = 5.

I hope this helps!

Comment
Add comment · Show 2 · 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 Margallo · Nov 25, 2016 at 12:05 PM 0
Share

Hi! thank you for helping i just did what you said but in my game i just want to make like for example

whenever it collide to the coins it score of +2 and when in game over i want it to have a total coin and the total text have save not in the coins text. i need a function to increase the save money by in total coins.the
coin.text + total.text something like that?

here is my code in money$$anonymous$$anager!


 public static int money =  0;
 public Text moneytxt;
 public Text totalTxt;
 public static int total$$anonymous$$oney;

    void Update () {
     moneytxt.text = "" + money;
 }
 void Total$$anonymous$$oney (){
     money += total$$anonymous$$oney;
     totalTxt.text = "" + total$$anonymous$$oney;
 }


and in the coin Collision!

    public int moneyToadd = 2;

     void OnCollisionEnter(Collision col){
     if(col.gameObject.tag == "Player"){
         Destroy (gameObject);
         sm.coinSound.Play ();
         scoreCOin.money += moneyToadd;
     }
 }
avatar image dacarrera Margallo · Nov 25, 2016 at 12:17 PM 2
Share

Glad to be of some help. I'm slightly confused with the wording of your question, so please let me know if I'm going off track here. Right now I see that on collision, you'll add 2 to your money from money$$anonymous$$anager. However, in your Total$$anonymous$$oney() function, you're increasing the value of money rather than total$$anonymous$$oney. You should switch it around so that total$$anonymous$$oney is being increased --> total$$anonymous$$oney += money. Is there anything else you're trying to add/implement?

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

80 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

Related Questions

Vector3.distance not working with UNET 0 Answers

Enemy destroys player if scale is bigger 1 Answer

Saving data in a txt file from Input Field button? 0 Answers

Cursor missing in Unity 5 editor 1 Answer

I m getting error please solve my errors I m beginner in unity,Getting error of : 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