- Home /
How to give a bonus every 1000 points?
I've been trying to set up a bonus system such that at every 1000 points it'll print "Bonus Awarded!".
My idea was to have a bonusCounter count to 1000, give the bonus and reset back to 0 (or whatever is leftover. ie: Player get's score of 1200, bonus is awarded and the counter would start at 200 instead of zero.)
I'm sure the problem is how I'm incrementing the bonusCounter variable...
Thanks in advance!
CODE BELOW:
using UnityEngine;
using System.Collections;
public class BonusBasedOfScoreTest : MonoBehaviour
{
public int scoreToGiveBonus;
private int bonusCounter = 0;
private int playerScore = 1000;
void OnGUI()
{
GUI.Label(new Rect(10, 10, 200, 30), "Score: " + playerScore);
GUI.Label(new Rect(10, 60, 200, 30), "Bonus Every: " + scoreToGiveBonus);
GUI.Label(new Rect(10, 110, 200, 30), "Score Counter: " + bonusCounter);
if (GUI.Button(new Rect(Screen.width * 0.5f, Screen.height * 0.5f, 200, 30), "Increment Score"))
{
playerScore += Random.Range(50, 500) + 400;
bonusCounter += (playerScore % scoreToGiveBonus);
}
if (playerScore < scoreToGiveBonus)
{
bonusCounter = playerScore;
}
else
{
if (bonusCounter >= scoreToGiveBonus)
{
Debug.Log("BONUS AWARDED!!!");
// now reset score counter
bonusCounter = (playerScore % scoreToGiveBonus);
}
}
}
}
Answer by Dreamblur · Jul 06, 2011 at 11:07 PM
if(whatever)
{
score += x;
bonusCheck += x;
if(bonusCheck >= scoreToGiveBonus)
{
// perform bonus function (bonusCheck / scoreToGiveBonus) times
bonusCheck %= scoreToGiveBonus;
}
}
Answer by DavidC02 · Oct 29, 2012 at 11:15 PM
Hello, I did this
if (Common.score >= 5000 * Common.lifesGiven) {
lives++;
Common.lifesGiven++;
}
That gives me a life every 5000 points
Your answer
Follow this Question
Related Questions
Trying to get score counter... 2 Answers
Scoring (i'm stuck) 3 Answers
Make a custom score counter in unity with c# 1 Answer
how to keep track of bricks broken 1 Answer
On Trigger Enter just triggers once for same object 1 Answer