[Unity] ハイスコアの実装 & アプリを終了しても記録を残す方法
上記のサイトを参考にハイスコアの機能を作成したのですが、ハイスコアではなく、毎回スコアの点数と同じ記録が表示されてしまいます。
[例]7点を取る→3点を取る,この場合3点の方がハイスコアに入ってしまいます。
ご教授願います。
c#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.SceneManagement; 5using UnityEngine.UI; 6 7public class CubeController : MonoBehaviour { 8 private Rigidbody2D rb2D; 9 public GameObject Score; 10 public Text RScoreText; 11 public GameObject EndPanel; 12 public ScoreScript scorescript; 13 public GameObject RButton; 14 public Text highScoreText; //ハイスコアを表示するText 15 private int highScore; //ハイスコア用変数 16 private string key = "HIGH SCORE"; //ハイスコアの保存先キー 17 18 private void Start () { 19 RButton.gameObject.SetActive(false); 20 } 21 22 void OnCollisionEnter2D (Collision2D collision) { 23 EndPanel.gameObject.SetActive(true); 24 int Rscore; 25 Rscore = scorescript.score; 26 RScoreText.text = "Score:" + Rscore.ToString(); 27 if (Rscore > highScore) { 28 highScore = Rscore; 29 //ハイスコア更新 30 PlayerPrefs.SetInt(key, highScore); 31 //ハイスコアを保存 32 highScoreText.text = "HighScore:" + highScore.ToString(); 33 //ハイスコアを表示 34 } 35 RButton.gameObject.SetActive(true); 36 } 37 38 void OnTriggerEnter2D (Collider2D col) { 39 //Score(GUIText)のScoreUpメソッドを呼び出す 40 Score.SendMessage ("ScoreUp", 1); 41 Destroy (col.gameObject); 42 } 43}
c#
1using UnityEngine; 2using UnityEngine.UI; 3using System.Collections; 4 5public class ScoreScript : MonoBehaviour { 6 public int score = 0; 7 8 void Start () { 9 GetComponent<Text>().text = score.ToString(); 10 } 11 12 public void ScoreUp (int point) { 13 score += point; 14 GetComponent<Text>().text = score.ToString(); 15 } 16}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/07/26 08:32
2018/07/26 10:34
退会済みユーザー
2018/07/26 12:03