评分在 Unity 引擎上的游戏中不起作用
Scoring does not work in the game on the Unity engine
我为 android 调制 3d 游戏。和评分剂量工作。其本质是在去除地图外的汽车后,钉住积分,最高成绩和硬币。 unity不报错的编译器是什么
using UnityEngine;
using UnityEngine.UI;
public class ScoreShow : MonoBehaviour
{
[SerializeField]
private Text topRecord;
void onEnable()
{
GetComponent<Text>().text = "Score: " + deletecar.countCars.ToString();
if (PlayerPrefs.GetInt("Score") < deletecar.countCars)
{
PlayerPrefs.SetInt("Score", deletecar.countCars);
topRecord.text = "Top:" + deletecar.countCars.ToString();
}
else
topRecord.text = "Top:" + PlayerPrefs.GetInt("Score").ToString();
}
}
代码的第 2 部分
using UnityEngine;
public class deletecar : MonoBehaviour
{
public static int countCars;
void Start()
{
countCars = 0;
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
if (!Collisoinscars.lose)
{
countCars++;
PlayerPrefs.SetInt("Coins", PlayerPrefs.GetInt("Coins") + 1);
Destroy(other.gameObject);
}
}
}
}
应该是 OnEnable() 打错了。
实际上,问题出在您启用游戏对象的这段代码中。
void onEnable()
{
GetComponent<Text>().text = "Score: " + deletecar.countCars.ToString();
if (PlayerPrefs.GetInt("Score") < deletecar.countCars)
{
PlayerPrefs.SetInt("Score", deletecar.countCars);
topRecord.text = "Top:" + deletecar.countCars.ToString();
}
else
topRecord.text = "Top:" + PlayerPrefs.GetInt("Score").ToString();
}
打错了,void onEnable
应该是OnEnable
我为 android 调制 3d 游戏。和评分剂量工作。其本质是在去除地图外的汽车后,钉住积分,最高成绩和硬币。 unity不报错的编译器是什么
using UnityEngine;
using UnityEngine.UI;
public class ScoreShow : MonoBehaviour
{
[SerializeField]
private Text topRecord;
void onEnable()
{
GetComponent<Text>().text = "Score: " + deletecar.countCars.ToString();
if (PlayerPrefs.GetInt("Score") < deletecar.countCars)
{
PlayerPrefs.SetInt("Score", deletecar.countCars);
topRecord.text = "Top:" + deletecar.countCars.ToString();
}
else
topRecord.text = "Top:" + PlayerPrefs.GetInt("Score").ToString();
}
}
代码的第 2 部分
using UnityEngine;
public class deletecar : MonoBehaviour
{
public static int countCars;
void Start()
{
countCars = 0;
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
if (!Collisoinscars.lose)
{
countCars++;
PlayerPrefs.SetInt("Coins", PlayerPrefs.GetInt("Coins") + 1);
Destroy(other.gameObject);
}
}
}
}
应该是 OnEnable() 打错了。
实际上,问题出在您启用游戏对象的这段代码中。
void onEnable()
{
GetComponent<Text>().text = "Score: " + deletecar.countCars.ToString();
if (PlayerPrefs.GetInt("Score") < deletecar.countCars)
{
PlayerPrefs.SetInt("Score", deletecar.countCars);
topRecord.text = "Top:" + deletecar.countCars.ToString();
}
else
topRecord.text = "Top:" + PlayerPrefs.GetInt("Score").ToString();
}
打错了,void onEnable
应该是OnEnable