現在unityを使ってゲームを制作しているのですが
どうしてもハイスコアの実装が出来ません。
ゲームをプレイして、リザルト画面にいったときの現スコアは記録できるのですが
ハイスコアが0のままになります。
自分でもどこの変数を参照すれば良いかと考え試してみましたがなかなか上手くいきませんでした
【ハイスコアの処理をしているプログラム】
using UnityEngine; using System.Collections; using UnityEngine.UI; using System.Collections.Generic; public class HighScore : MonoBehaviour { public float score = 0; public Text highScoreText; private float highscore = 0; private string key = "HIGH SCORE"; void Start () { score = Scores.TimeScore; highscore = PlayerPrefs.GetInt (key, 0); highScoreText.text = "HighScore:" + highscore.ToString (); highscore = 0; } void Update () { if(score > highscore) { highscore = score; PlayerPrefs.SetFloat (key, highscore); highScoreText.text = "HighScore: " + highscore.ToString (); } this.GetComponent<Text>().text = "HighScore: " + highscore; } }
【現スコアを記録しているプログラム】
using UnityEngine; using System.Collections; using UnityEngine.UI; public class Scores : MonoBehaviour { //public float score = 0; //public float highscore = 0; public static float TimeScore = 0; // Use this for initialization void Start () { //score = ScoreManager.score_num; TimeScore = GameController.timeCount; } void Update () { this.GetComponent<Text>().text = "Result Score: " + TimeScore * 20; } }
【現スコアを記録する際に参照しているプログラム】
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; public class GameController : MonoBehaviour { public Text timeLabel; public static float timeCount = 0; public static int hp = 100000; public static float Crtime = 0; void Start () { timeLabel.text = "TIME:" + timeCount; hp = HpBarCtrl._hp; Crtime = stageclear1.Ctime; timeCount = 90; } void Update () { timeCount -= Time.deltaTime; timeLabel.text = "TIME:" + timeCount.ToString("0"); if(timeCount < 0){ timeCount = 90; hp = 100000; SceneManager.LoadScene("TimeUp"); } } }
以上がスコアを記録するために使っているスクリプトです。
現スコアを記録する方法は スコアを参照しているプログラムのtimecountの値をとって
その値を*20しています。この値が現スコアになります。
このスコアの表示は出来るのですが、ハイスコアの表示がうまくいきません。
また 一回目のプレイでリザルト画面にいくと0と表示されますが
二回目以降は前のスコアより高くクリアしても0という表記すらされず、低くクリアしても表記されません
何が原因なのでしょうか?
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/14 13:41