- Home /
Time passes / if time is at certain point
Hi guys, so i am trying to do the following, i searched unity3d forums and also here for an answer but couldnt find any, so i hope someone can help me.
So, I want to do the following;
the time keeps passing ingame ( for example tycoon games, where weeks/months/years pass ) and at certain points i want to be able to activate another script ( for example, every 4 weeks the player should receive 10 points )
I hope someone knows how i can do this the right way, thank you.
ps: i use c#
Answer by Paparakas · Sep 12, 2013 at 10:52 PM
You could use Time.time http://docs.unity3d.com/Documentation/ScriptReference/Time-time.html
Let's say in your game, every second counts as a day. You could use Time.time to check how many seconds have gone by, and use that to see if the time was at a certain point.
An extremely simple example would be:
private float weeksSinceLastPayUp = 0;
private float daysSinceLastPayUp = 0;
private float TimePassed = 0;
void Update()
{
daysSinceLastPayUp = Time.time - TimePassed
weeksSinceLastPayUp = days / 7;
if(weeksSinceLastPayUp >= 4)
{
this.points += 10;
TimePassed += daysSinceLastPayUp;
daysSinceLastPayUp = 0;
weeksSinceLastPayUp = 0;
}
thank you very much. i will try this out once i get home from work :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613114036im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I stop 'timeSinceLevelLoad' without pausing entire game? 2 Answers
How to manipulate time in unity? 1 Answer
Timer manipulation with timescale not working correctly 2 Answers
timeScale doesn't work 0 Answers
Accelerating Time Dramatically 1 Answer