繁体   English   中英

评分在 Unity 引擎上的游戏中不起作用

[英]Scoring does not work in the game on the Unity engine

我将 3d 游戏调制为 android。并为 dosen 工作打分。 其实质就是把map以外的车去掉后,积分、头名和金币都钉上了。 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM