How do I restart my score when I reload a screen
public class KeepingScore: Monobehaviour;
public static int Score;
I also have score set as whenever I click on an object, the object is destroyed and gives me a point.
void OnMouseDown()
KeepingScore.score += 1;
Destroy();
I also have a timer where when I run out of time, scene switches to level select menu, where I click on the level again (ie level 1), but then I still see my score back how it was. I know it's static therefore It's still the same, are there any method to reset the value to zero every time I reload the level. Thank you
You can implement the MonoBehaviour.OnLevelWasLoaded(int)
function.
It called every time that a level is loaded.
Example
void OnLevelWasLoaded(int level) {
KeepingScore.score = 0;
}
Check at the docs: http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnLevelWasLoaded.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.