高分问题

时间:2014-11-08 05:56:00

标签: int save

我试图将我的最终/最佳分数转移到一个新的脚本中但由于某种原因它取0值.. debug.Log向下屏幕底部注册我的最终/最佳分数但我的公众注册顶部不承认他们?我不知道怎么回事......

using UnityEngine;
using System.Collections;

public class ScoreBoard : MonoBehaviour 
{

    public GameObject m_new;
    public Score m_score;
    public Score m_best;
    public int best;
    public int final;


    public GameObject m_spriteBronze;
    public GameObject m_spriteSilver;
    public GameObject m_spriteGold;

    public int m_bronze = 10;
    public int m_silver = 20;
    public int m_gold = 30;


    // Use this for initialization
    void Start () 
    {

    }

    // Update is called once per frame
    void Update () 
    {

    }

    public int setScore(int score)
    {

        if(m_gold <= score)
        {
            m_spriteGold.SetActive(true);
        }
        else if(m_silver <= score)
        {
            m_spriteSilver.SetActive(true);
        }
        else if(m_bronze <= score)
        {
            m_spriteBronze.SetActive(true);
        }

        string key = "best";
        int best = PlayerPrefs.GetInt(key);
        if(best < score)
        {
            PlayerPrefs.SetInt(key, score);
            best = score;
            m_new.SetActive(true);
        }
        m_score.setScore (score);
        m_best.setScore (best);

        int final = (score);

        Debug.Log(final);

        return final;



    }


}

1 个答案:

答案 0 :(得分:0)

setScore()内,您重新声明bestfinal,例如int best = PlayerPrefs.GetInt(key);。第二个声明是遮蔽顶部的声明,它们保持默认值0。在转让之前删除int