【问题标题】:I'm trying to use a code to display score in the UI text but it didn't show up/change the text object我正在尝试使用代码在 UI 文本中显示分数,但它没有显示/更改文本对象
【发布时间】:2022-08-05 13:18:59
【问题描述】:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class wastafel : MonoBehaviour
    {
        public Text ctText;
        public static int iscucitangan;//scoring
        public int handwash;
    
        void update()
        {
            handwash = iscucitangan;
            ctText.text = \"Sudah cuci tangan :\" + handwash;
        }

 }

我尝试了这个脚本来显示我统一制作的评分系统(我使用这个视频作为参考:https://www.youtube.com/watch?v=YKeXyaB41EA)。我将此代码应用于程序like this 中的文本UI 对象。 This is the CT text object。但是当我按下播放键时,它出现了like this, no change at allThis is my text setting。有什么我想念的吗?

    标签: c# unity3d


    【解决方案1】:

    这是由于拼写错误引起的,它应该是Update(),大写U,而不是update()

    【讨论】:

      【解决方案2】:

      首先,您是否在检查员中分配了 ctText ? 那么......您的评分变量是如何更新的?

      【讨论】:

        猜你喜欢
        • 2022-11-19
        • 2023-01-28
        • 2021-02-03
        • 2021-02-10
        • 1970-01-01
        • 2012-01-06
        • 2014-08-14
        • 2020-10-08
        • 2021-11-28
        相关资源
        最近更新 更多