- Home /
GUI Counter
Hi!
I am making a game like the game Cookie Clicker and when I get the powerups, they give me score each second. But my problem is. If I want it to give 5 points per second, it goes like 0, 5. I want it to count those numbers like 0, 1, 2, 3, 4, 5 but it still takes on second.
Here is the powerup code:
var cookieGenerateAmount : float = 1;
var timer : float = 1;
function Start () {
Generate();
}
function Generate () {
while(true){
yield WaitForSeconds(timer);
Score.score += cookieGenerateAmount;
}
}
Like @$$anonymous$$arkD - I don't completely understand your question. If you want the code to run 5 times per second and increase some variable by 1 each time, then set the 'timer' to 0.2.
Answer by MarkD · Jan 18, 2014 at 12:53 AM
I'm not really clear about your variables in your script as it is a class execution only in start.
If you run it in start then it won't update very frame so it will be impossible to increase by +1 until 5. You need to run it in an update.
What I would do is create a checkup with a sub counter for instance if your main subcounter is not equal to the main counter subcounter +1;
Then add the subcounter to the score.score. simply use the main counter as an ifstatment limitation so the subcounter does not go out of bounds when adding up to the score.score.
Basically what @robertbu said, you need to increase your variable by 1 each frame, to prevent it from raising simply put a limit on it for instance.
//this will increase your counter value +1 untill 5 is reached
if (counter <5){
counter ++;
}
//now if you want it to match your score simply replace 5 with //your Score.score
Your answer

Follow this Question
Related Questions
Count objects with a certain tag and display number on GUI 1 Answer
How to create a Event??? 1 Answer
adding ammo count 2 Answers
How to increase score on hit 0 Answers
Collect and through 1 Answer