【发布时间】:2019-06-10 21:15:52
【问题描述】:
这可能是一个非常简单的解决方案和问题,但我一直在为此绞尽脑汁。每次我统一测试时,如果我得到的分数低于高分,高分无论如何都会改变。这是我的代码。如果您需要更多,请告诉我。
脚本 1:
using UnityEngine;
using UnityEngine.SceneManagement;
public class CheckConeDeath : MonoBehaviour {
public PlayerMovement movement;
void OnCollisionEnter(Collision CollisionInfo){
if(CollisionInfo.collider.tag=="Cone"){
movement.enabled = false;
GetComponent<Rigidbody>().constraints = RigidbodyConstraints.None;
Invoke ("EndGame", 1.5f);
}
}
void EndGame(){
PlayerPrefs.SetFloat ("finalScore", Mathf.RoundToInt(FindObjectOfType<DistanceScore>().plrz));
PlayerPrefs.Save ();
Debug.Log (PlayerPrefs.GetFloat("finalScore"));
SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex + 1);
}
}
脚本 2:
using UnityEngine;
using UnityEngine.UI;
public class finalscore : MonoBehaviour {
public Text text;
public Text highscore;
void Start(){
Debug.Log (Mathf.Round (PlayerPrefs.GetFloat ("finalScore")));
Debug.Log (PlayerPrefs.GetInt ("hs", 0));
Debug.Log (Mathf.Round (PlayerPrefs.GetFloat ("finalScore")) > PlayerPrefs.GetInt ("hs", 0));
// PlayerPrefs.SetFloat ("hs", Mathf.Round(PlayerPrefs.GetFloat("finalScore")));
highscore.text = "All time High Score: "+Mathf.Round (PlayerPrefs.GetFloat ("finalScore")).ToString ();
text.text = "Final Score: " + Mathf.Round(PlayerPrefs.GetFloat("finalScore"));
if(Mathf.Round(PlayerPrefs.GetFloat("finalScore"))<PlayerPrefs.GetInt("hs",0)){
PlayerPrefs.SetFloat ("hs", Mathf.Round (PlayerPrefs.GetFloat ("finalScore")));
highscore.text = "All time High Score: "+Mathf.Round (PlayerPrefs.GetFloat ("finalScore")).ToString ();
}
}
}
这是发生了什么的屏幕截图:
我的高分怎么可能下降!? 非常感谢您的宝贵时间!
【问题讨论】: