我的当前分数和最高分数未显示在 Android 设备中
如图所示,它在DeathGUI中显示分数和高分,但是当我将其构建到android时,它显示0和0
DeathGUI 菜单控制器
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class MenuController : MonoBehaviour {
public Text scoreText;
public void StartGame()
{
SceneManager.LoadScene("Name is Hidden but it is Correct");
}
public void RestartGame()
{
if (GameStateManager.GameState == GameState.Dead)
{
GameStateManager.GameState = GameState.Intro;
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
public void ToggleEndMenu(float score)
{
gameObject.SetActive(true);
scoreText.text = ((int)score).ToString("0");
}
}
玩家得分管理器
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ScoreManager : MonoBehaviour
{
private float score = 0f;
public Text Scoretext;
public MenuController deathmenu;
void Update()
{
score += Time.deltaTime;
Scoretext.text = ((int)score).ToString();
}
public void onDeath()
}
if(PlayerPrefs.GetFloat("Highscore") < score)
PlayerPrefs.SetFloat("Highscore", score);
deathmenu.ToggleEndMenu(score);
}
}
玩家脚本
void Update()
{
//handle back key in Windows Phone
if (Input.GetKeyDown(KeyCode.Escape))
Application.Quit();
if (GameStateManager.GameState == GameState.Intro)
{
MovePlayerOnYAxis();
if (WasTouchedOrClicked())
{
IntroGUI.SetActive(false);
GameStateManager.GameState = GameState.Playing;
}
}
else if (GameStateManager.GameState == GameState.Playing)
{
MovePlayerOnYAxis();
Canvas.SetActive(true);
DeathGUI.SetActive(false);
}
score += Time.deltaTime;
Scoretext.text = ((int)score).ToString();
}
void PlayerDies()
{
GameStateManager.GameState = GameState.Dead;
DeathGUI.SetActive(true);
Canvas.SetActive(false);
GetComponent<AudioSource>().PlayOneShot(DeathAudioClip);
if (PlayerPrefs.GetFloat("Highscore") < score)
PlayerPrefs.SetFloat("Highscore", score);
deathmenu.ToggleEndMenu(score);
}
高分脚本
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class HighScoreText : MonoBehaviour {
public Text HighscoreText;
// Use this for initialization
void Start () {
HighscoreText.text = ((int)PlayerPrefs.GetFloat("Highscore")).ToString();
}
}
如果您在检查器中查看 PlayerSettings,您的写入权限是否设置为外部(SDCard)或仅限内部?
还有安装位置?
我制作了一款具有本地高分的游戏,我看到玩家设置的配置部分具有以下值: 安装位置 = 首选外部 写访问 = 外部(SDCard)
这是我的 LocalScore.js:
#pragma strict
#pragma implicit
var Score1 : int;
var Name1 : String;
var Score2 : int;
var Name2 : String;
var Score3 : int;
var Name3 : String;
var Score4 : int;
var Name4 : String;
var Score5 : int;
var Name5 : String;
var Score6 : int;
var Name6 : String;
var Score7 : int;
var Name7 : String;
var Score8 : int;
var Name8 : String;
var Score9 : int;
var Name9 : String;
var Score10 : int;
var Name10 : String;
function Start () {
}
function Update () {
}
function OnGUI() {
if(GUI.Button(Rect(Screen.width / 2 - 150, Screen.height / 2.5 + 100 , 250 ,50), "Back to Global Scoreboard") ) {
// Application.Quit();
Application.LoadLevel("Highscore");
}
// UpdateHScore();
// GUI.Textfield();
}
function UpdateLocalScores(){
// Score1 = PlayerPrefs.GetInt(HScore0);
// Name1 = PlayerPrefs.GetString(HScoreName0);
//
// Score2 = PlayerPrefs.GetInt(1HScore);
// Name2 = PlayerPrefs.GetString(1HScoreName);
//
// Score3 = PlayerPrefs.GetInt(2HScore);
// Name3 = PlayerPrefs.GetString(2HScoreName);
//
// Score4 = PlayerPrefs.GetInt(3HScore);
// Name4 = PlayerPrefs.GetString(3HScoreName);
//
// Score5 = PlayerPrefs.GetInt(4HScore);
// Name5 = PlayerPrefs.GetString(4HScoreName);
//
// Score6 = PlayerPrefs.GetInt(5HScore);
// Name6 = PlayerPrefs.GetString(5HScoreName);
//
// Score7 = PlayerPrefs.GetInt(6HScore);
// Name7 = PlayerPrefs.GetString(6HScoreName);
//
// Score8 = PlayerPrefs.GetInt(7HScore);
// Name8 = PlayerPrefs.GetString(7HScoreName);
//
// Score9 = PlayerPrefs.GetInt(8HScore);
// Name9 = PlayerPrefs.GetString(8HScoreName);
//
// Score10 = PlayerPrefs.GetInt(9HScore);
// Name10 = PlayerPrefs.GetString(9HScoreName);
}