Scoring based on count up timer
can anyone help .. im try to make a countup timer, that when the play finish the level the time stop and base on that time the player finishes the a score of (1,2 or 3) stars ..
Answer by Cepheid · Jan 24, 2016 at 01:02 AM
@KCG00 Well, you would start by simply deciding what times the player should receive certain stars and then evaluate your timer at the end to decide if they have met the condition to recieve a star. So for a quick example let's say:
20 seconds - they get a gold star.
40 seconds - they get a silver star.
60 seconds - they get a bronze star.
Now that we know what time's make up a star we simply check our timer in our code after the level is finished and evaluate it against those conditions. So, a really rough setup would look something like this:
// Our initial timer variable which will store our time.
float timer = 0;
void Update ()
{
// Timer begins counting up from 0.
timer += Time.deltaTime;
}
void LevelFinished ()
{
// Is the time less than or equal to 20 seconds?
if(timer <= 20f)
{
print("Player get's a gold star!");
}
// Is the time less than or equal to 40 seconds,
//but greater than 20 seconds?
else if(timer <= 40f && timer > 20f)
{
print("Player get's a silver star!");
}
// Is the time less than or equal to 60 seconds,
//but greater than 40 seconds?
else if(timer <= 60f && timer > 40f)
{
print("Player get's a bronze star!");
}
// The timer has counted too far for the player to get a star.
else
{
print("Player get's nothing!");
}
}
Now, all going well it should print the appropriate message after the correct times have been met. Now, there are more elegant and cleaner solutions to doing this, but this should hopefully give you a good rough idea of how to implement the mechanic.
thanks really appreciate it , but i was try to incorporate into this code that shows the time on the camera screen. how would i go about that or do i even need these codes.
this the Timer Script
startTimer = Time.time;
PlayerPrefs.SetInt("Level_2", 1);
PlayerPrefs.SetInt("Level_1_Score", TimeScore);
}
// Update is called once per frame
void Update() {
float t = Time.time - startTimer;
string $$anonymous$$utes = ((int)t / 60).ToString();
string seconds = (t % 60).ToString("f2");
timerText.text = $$anonymous$$utes + ":" + seconds;
}
which it gets the score settings from the my Level $$anonymous$$anager
void FillList()
{
foreach (var level in LevelList)
{
GameObject newbutton = Instantiate(levelButton) as GameObject;
LevelButtons button = newbutton.GetComponent<LevelButtons>();
button.LevelText.text = level.LevelText;
//Level_1, Level_2,Level_3,Level_4,Level_5
if(PlayerPrefs.GetInt("level_" + button.LevelText.text) == 1)
{
level.Unlocked = 1;
level.IsInteractable = true;
}
button.unlocked = level.Unlocked;
button.GetComponent<Button>().interactable = level.IsInteractable;
button.GetComponent<Button>().onClick.AddListener(() => loadLevels("Level_" + button.LevelText.text));
if (PlayerPrefs.GetInt("Level_1_Score" + button.LevelText.text + "_score") > 20)
{
button.Star1.SetActive(true);
}
if (PlayerPrefs.GetInt("Level_1_Score" + button.LevelText.text + "_score") >= 20)
{
button.Star2.SetActive(true);
}
if (PlayerPrefs.GetInt("Level_1_Score" + button.LevelText.text + "_score") >= 20)
{
button.Star3.SetActive(true);
}