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 /
avatar image
1
Question by jjvegavideogames · Jun 24, 2011 at 03:17 PM · timescoreaddsecond

Add to score every second

Hey, I'm making a tycoon game and I want to increase the money every second but I can't figure it out.

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

3 Replies

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

Answer by Eric5h5 · Jun 24, 2011 at 04:07 PM

 var money = 500;
 var increase = 25;

 function Start () {
     InvokeRepeating("AddToMoney", 1.0, 1.0);
 }

 function AddToMoney () {
     money += increase;
 }
Comment
Add comment · Show 5 · 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 Joshua · Jun 24, 2011 at 04:12 PM 0
Share

...hate how this new system doesn't warn you when some one posts a new answer. Looks like the answer I edited into $$anonymous$$e is exactly the same as the one you posted.. I guess great $$anonymous$$ds think alike :p but I'll delete $$anonymous$$e since you beat me be a few $$anonymous$$utes. ;)

avatar image Eric5h5 · Jun 24, 2011 at 04:25 PM 1
Share

The system has also stopped sending me notifications for anything.... (I'd rather it had in-site notifications like the old system had anyway.)

avatar image Joshua · Jun 24, 2011 at 04:28 PM 0
Share

Email notifications work 'okay' for me (I'd say I get 80-90%). I meant the notification you'd used to get when you where in the process of answering a question of editing an answer and it said 'a new answer has been added to this question, do you want to load it in?'. And yeah, in-site notifications would be great.

avatar image Eric5h5 · Jun 24, 2011 at 04:42 PM 0
Share

Yes, I know, I was just adding to the complaint. :) Although right after I posted that, I started getting notifications again; figures.

avatar image Nut_Phalloom · Oct 09, 2018 at 03:41 PM 0
Share

i Tried this and its didnt work for me i did do my own changes but i tried the original code and it didn't work for me debug logs say "function" isn't working debug log goes as

"Assets/Scripts/Score.cs(15,3): error CS0246: The type or namespace name function' could not be found. Are you missing an assembly reference?" "Assets/Scripts/Score.cs(7,9): error CS0246: The type or namespace name variable' could not be found. Are you missing an assembly reference?"

"Assets/Scripts/Score.cs(6,9): error CS0246: The type or namespace name variable' could not be found. Are you missing an assembly reference?" Code is below and i am using C# witch might be part of the problem using UnityEngine; using UnityEngine.UI;

public class Score : $$anonymous$$onoBehaviour {

 public variable TotalScore = 0;
 public variable increase = 1;
 public Transform player;
 public Text scoreText;
 
 // Update is called once per frame
 void Update () {
     scoreText.text = InvokeRepeating("AddPoint", 1.0, 1.0);
 }
     function AddPoint () {
      TotalScore += increase;
 }    

} `

avatar image
2

Answer by christo1745 · Jun 24, 2011 at 04:03 PM

That would update the money amount every frame. To do it every second you could do:

 function Update()
 {
   if(Time.time - lastUpdate >= 1f){
     money += increase;
     lastUpdate = Time.time;
 
   }
 }
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 Tasarran · Jun 24, 2011 at 05:40 PM 0
Share

Use the code button at the top (the 101010 button) to format your code, please...

avatar image
-1

Answer by Smorteza · Apr 24, 2013 at 11:57 PM

function Update() { if(Time.time - lastUpdate >= 1f){ money += increase; lastUpdate = Time.time-lastUpdate;

} }

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to increase score by one per second when you are holding an object 2 Answers

Adding time to timer with pickup 1 Answer

Change score based on time remaining. 1 Answer

My score script doesn't seem to work properly, score is not added properly 0 Answers

Add time score to my game 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