【问题标题】:High score Unity C# [closed]高分 Unity C# [关闭]
【发布时间】:2016-05-05 07:11:03
【问题描述】:

我正在制作一个涂鸦跳跃游戏,现在我被卡住了。玩家一碰硬币就得到分数,我想打个高分,这样当它重新启动时,或者当你点击主菜单时,会有一个文字说高分和你的分数。我已经写好了文字。请帮助我!

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class GameManager : MonoBehaviour 
{
    public static GameManager instance = null;
    public GameObject textscoreobject;
    int score;
    Text scoretext;

    void Awake()
    {
        scoretext = textscoreobject.GetComponent<Text>();
        scoretext.text = "Score: " + score.ToString ();
        if (instance == null)

            instance = this;

        else if(instance != null)

            Destroy(gameObject);

    }
    public void Collect(int passedvalue, GameObject passedobject)
    {
        Destroy (passedobject);
        score = score + passedvalue;
        scoretext.text = "Score: " + score.ToString ();
    }
}


using UnityEngine;
using System.Collections;

public class Score : MonoBehaviour {

    public int value;
    public float rotatespeed;

    void Update () 
    {
        gameObject.transform.Rotate (Vector3.up * Time.deltaTime * rotatespeed);
    }
    void OnTriggerEnter()
    {
        GameManager.instance.Collect (value, gameObject);
    }
}

这里是现在一些屏幕的代码! https://www.dropbox.com/s/90mf2esf4tqe7xh/Capture.PNG?dl=0 这里是高分需要显示的地方! 请帮帮我!

【问题讨论】:

  • 什么不起作用?您在此处显示的代码的哪一部分与您的实际问题相关?
  • 其实我展示的东西有效,我希望你帮我写代码来保存高分!
  • 有太多可能的答案,而好的答案对于这种格式来说太长了。请添加详细信息以隔离可以在几段中回答的问题。

标签: c# unity3d


【解决方案1】:

在此处提问之前请先尝试谷歌...

(StackExchange 规则:不要询问您没有尝试找到答案的问题) - 例如http://answers.unity3d.com/questions/672869/player-prefs-to-store-high-scores.html

如果您的实际问题是如何保存高分,请使用@987654322@

例如,为了以后保存一个高分(每次你达到一个新的分数,例如在游戏结束时):

if(score > PlayerPrefs.GetInt("HighScore", 0)) {
    PlayerPrefs.SetInt("HighScore", score);
    PlayerPrefs.Save();
}

要阅读它(在主菜单中的 Start()Awake() 方法中),输入

SomeHighScoreUIText.text = PlayerPrefs.GetInt("HighScore", 0);

【讨论】:

  • 好的,谢谢,我现在试试
  • 等等,我需要添加所有这些代码吗?还是曾经?
  • 我不明白,我尝试了更多的东西,但它不起作用!\
  • 实际上可以,但是分数不是显示在主菜单中而是在游戏中,所以当我重新启动游戏时它会继续添加,这很好,这几乎是我需要的,但我还需要在主菜单中显示那个分数,怎么做?
  • 感谢您的帮助,它运行良好,我已将您的代码和我的代码合并,现在可以运行了!
猜你喜欢
  • 2013-05-10
  • 1970-01-01
  • 2021-03-15
  • 1970-01-01
  • 2012-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-03
相关资源
最近更新 更多