2014-11-08 5 views
0

새로운 스크립트로 최종/최고 점수를 이월하려고하지만 웬일인지 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; 



    } 


} 

답변

0

setScore() 내부, 당신은 예를 들어, bestfinal를 재 선언 ..하지 않는다 int best = PlayerPrefs.GetInt(key);. 두 번째 선언은 상단에있는 것들을 섀도 잉합니다. 기본값은 0입니다. 과제 전에 int을 삭제하십시오.

+0

전에 int를 제거 하시겠습니까 ?? 최고 = PlayerPrefs.GetInt (key) ;; –

+0

예. 'public int best;가 최상위에 이미 선언되어 있기 때문에'int '를'setScore()'안에 넣으면 기본적으로'setScore()'안에서만 유효하고 같은 이름의 다른 변수가 생성됩니다. –

+0

나는 그것을 변경하고 여전히 실패 :( –