简体   繁体   English

评分系统收集项目不更新文本 UI - Unity C#

[英]Scoring system collect item not updating Text UI - Unity C#

I have created 2 scripts one which handles the collection of the item and another which handles the score being displayed to the screen.我创建了 2 个脚本,一个处理项目的集合,另一个处理显示在屏幕上的分数。 Currently the sound plays and the item is destroyed onTriggerEnter but the score's UI-Text does not update.目前,声音播放并且项目在触发输入时被销毁,但分数的 UI-Text 不会更新。 I have tried to add the score inside ScoringSystem and CollectGem both scripts are below.我试图在 ScoringSystem 和 CollectGem 中添加分数,这两个脚本都在下面。

ScoringSystem is attached to a GameObject with TextScore assigned to the slot. ScoringSystem 附加到一个游戏对象,TextScore 分配给插槽。

Can anybody see why the text would not be adding 1 on collection?有人能明白为什么文本不会在集合上加 1 吗?

CollectGem收藏宝石

public class CollectGem : MonoBehaviour
{
    public AudioSource collectNoise;

    public void OnTriggerEnter(Collider collider)
    {
        collectNoise.Play();
        ScoringSystem.theScore += 1;
        Destroy(gameObject);
    }
}

Scoring System评分系统

public class ScoringSystem : MonoBehaviour
{
    public GameObject score;
    public static int theScore;

    void update()
    {
        score.GetComponent<Text>().text = "Gems: " + theScore;
    }
}

Careful, spelling matters very much in our code.小心,拼写在我们的代码中非常重要。

void update() != void Update() void update() != void Update()

Seems like you just forgot to capitalize the name of "Update" .好像您只是忘记将"Update"的名称大写。

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

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