问题
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
回答1:
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
来源:https://stackoverflow.com/questions/26934920/how-do-i-restart-my-score-reset-static-score-in-reloading-scene-in-unity