c# - TextMeshPro 文本没有变化,控制台出现快速错误
问题描述
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class Num : MonoBehaviour
{
private int score;
public TextMeshPro TMP;
void Start()
{
TMP = GetComponent<TextMeshPro>();
score = 0;
}
void Update()
{
TMP.text = score.ToString();
score++;
}
}
文字没有改变,我不知道为什么。控制台中的错误是“NullReferenceException:对象引用未设置为对象 Num.Update () 的实例(在 Assets/Scripts/Num.cs:19)”
解决方案
错误是您的脚本没有找到TextMeshPro
同级组件。如果您使用的是 UI 版本,那么您真正想要的是找到一个TextMeshProUGUI
推荐阅读
- php - Wordpress,如何自定义原始传记信息字段的描述行
- c# - 使用 Import-Module 时如何指定程序集的路径
- php - ArrayObject::offsetUnset 以意想不到的方式推进内部指针
- java - @Transactional(isolation = Isolation.SERIALIZABLE) 如何只锁定几行
- json - 将 Scala 类对象(具有集合)转换为 Json 字符串
- r - R的do.call函数的意外行为与平均值
- redis - 关于带有 TTL 的键的 redis EVAL 原子性怎么样?
- opencl - clGetPlatformIDs(): CL_PLATFORM_NOT_FOUND_KHR Hashcat
- vue.js - 创建组件后如何在 Vuejs 中运行函数?
- javascript - 如何在 Firebase 中更新用户个人资料?