Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 TargonStudios · Dec 27, 2012 at 04:37 PM · money

Earning Money

So i have created a script where every 10 seconds you should earn 1$. But there is a problem with the script and i don't know what it is. any solutions?

Money Earning Script-------------------------------------------------------------

pragma strict

ar Earn = true;

function Start () {

}

function Update () {

if (Earn == true);

{

Player_Money.players_money += 1;

print(Player_Money.players_money);

Earn = false;

yield WaitForSeconds (10);

Earn = false; }

}

Player Money Script-----------------------------------------------------------------

static var players_money = 100;

function Start () {

}

function Update () {

}

Comment
Add comment · Show 5
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 gardian06 · Dec 27, 2012 at 04:44 PM 0
Share

please format your code as code. placing 4 spaces at the beginning of each line (remove all indents, and replace with 4 spaces)

avatar image Golan2781 · Dec 27, 2012 at 04:46 PM 0
Share

What do you mean by 'there is a problem with the script'? Does it not work? Does Unity throw an error upon compilation?

avatar image Next Beat Games · Dec 27, 2012 at 04:52 PM 1
Share

you cant have yield WaitForSeconds in your Update function. also, you are setting earn to false before and after the yield call.. should probably be true after the yield

avatar image whydoidoit · Dec 29, 2012 at 04:40 PM 0
Share

You only want money to be earned while the game is actually active right (not when it is paused, not running etc)?

avatar image Fattie · Dec 29, 2012 at 09:38 PM 1
Share

you could make it Euros and earn 25% more

2 Replies

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

Answer by Eric5h5 · Dec 27, 2012 at 05:41 PM

Use InvokeRepeating:

 function Start () {
     InvokeRepeating ("YoGimmeMoney", 10.0, 10.0);
 }
 
 function YoGimmeMoney () {
     Player_Money.players_money++;
 }
Comment
Add comment · Show 6 · 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 TargonStudios · Dec 27, 2012 at 06:31 PM 0
Share

do i just paste this into the java script?

avatar image Golan2781 · Dec 27, 2012 at 06:39 PM 1
Share

It should replace the current code of what you called $$anonymous$$oney Earning Script in your initial post.

avatar image TargonStudios · Dec 29, 2012 at 01:57 AM 0
Share

Worked Great! Thanks :D

avatar image TargonStudios · Dec 29, 2012 at 04:21 PM 0
Share

Hmmm, I have just encountered a problem. somtimes is gives 2$ ins$$anonymous$$d of 1$. any solution?

avatar image Eric5h5 · Dec 29, 2012 at 08:01 PM 0
Share

Presumably you have it running on more than one object.

Show more comments
avatar image
0

Answer by KoningStoma · Dec 27, 2012 at 08:50 PM

I don't know why you use two separate scripts for this. I don't know exactly what you want to achieve, but I would do it something like this:

 #pragma strict
 
 var Earn = true;
 var money = 0;
 
 function Start () {
     InvokeRepeating("GiveMoney",0,10);
 }
 
 function GiveMoney()
 {
     if(Earn == true) money+=1;
 }
 
 function Update () {
 
 }
Comment
Add comment · 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

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

14 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

Related Questions

C# Saving data to the player's computer 1 Answer

Player Money not working 1 Answer

Saving changes while playing... 1 Answer

a one time script 1 Answer

default script editor now working anymore 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