【发布时间】:2017-01-02 11:56:22
【问题描述】:
我正在制作一个 VR 游戏,其中只有一个关卡在主场景上,另一个场景是“结束”,在该场景上,游戏 Over text Score 可以通过重新启动(重新加载主场景)和退出按钮。
我的问题是,M 使用这个脚本作为我下面给出的ScoreManager 脚本。我也想要这个分数在结尾场景中,这是使用 PlayerPrefs 的 m
但主要问题是,当在结束场景点击重启时,游戏重新加载主场景但该分数仍然与前一游戏相同。我希望它设置为零。
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
namespace CompleteProject
{
public class ScoreManager : MonoBehaviour
{
public static int score ; // The player's score.
Text text; // Reference to the Text component.
void Awake()
{
// Set up the reference.
text = GetComponent<Text>();
score = 0;
score = PlayerPrefs.GetInt("Score");
}
void Update ()
{
// Set the displayed text to be the word "Score" followed by the score value.
text.text = "Score: " + score;
PlayerPrefs.SetInt("Score", score);
}
}
}
我也用DeleteKey(string)删除了分数,但是什么也没发生。
【问题讨论】:
-
如果你想在下一个级别重置分数,为什么要使用
PlayerPrefs?