0
我試圖把我的最終/最好成績帶進一個新的腳本,但由於某種原因,它採取0值..調試。登錄屏幕底部註冊我的最後/最好成績,但我的公衆注意到頂端不承認他們?我不明白怎麼回事..高分問題
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;
}
}
在最好之前刪除int?如best = PlayerPrefs.GetInt(key);? – 2014-11-08 06:20:31
是的。由於它已經被聲明爲'public int best;'在頂部,在setScore()內部擁有'int'基本上創建了一個具有相同名稱的不同變量,僅在'setScore()'內有效。 – 2014-11-08 06:26:46
我改變了它,仍然失敗:( – 2014-11-08 06:30:04