如何统一重新加载场景中的分数(重置静态分数)? [英] How do I restart my score (reset static score) in reloading scene in unity?

查看:122
本文介绍了如何统一重新加载场景中的分数(重置静态分数)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重新加载屏幕时如何重新启动比分

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();

我还有一个计时器,当我没有时间的时候,场景会切换到级别选择菜单,在这里我再次单击级别(即级别1),但是我仍然可以看到自己的得分如何.我知道它是静态的,因此它仍然是一样的,是否有任何方法可以在每次重新加载级别时将值重置为零.谢谢

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

推荐答案

您可以实现MonoBehaviour.OnLevelWasLoaded(int)函数.
每次加载关卡时都会调用它.

You can implement the MonoBehaviour.OnLevelWasLoaded(int) function.
It called every time that a level is loaded.

示例

void OnLevelWasLoaded(int level) {
    KeepingScore.score = 0;
}

查看文档: http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnLevelWasLoaded.html

这篇关于如何统一重新加载场景中的分数(重置静态分数)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆