如果b1被触发,我正在尝试更改我的文本。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class Player_Start : MonoBehaviour
{
[SerializeField] public TextMeshProUGUI textTest;
public void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("b1"))
{
textTest.text = "Now let's move the right leg up!";
transform.GetChild(0).gameObject.SetActive(false);
transform.GetChild(1).gameObject.SetActive(true);
}
if (collision.gameObject.CompareTag("b2"))
{
transform.GetChild(1).gameObject.SetActive(false);
transform.GetChild(3).gameObject.SetActive(true);
}
}
}我说错了
NullReferenceException:对象引用未设置为对象Player_Start.OnTriggerEnter2D的实例(UnityEngine.Collider2D冲突)(在资产/Player_Start.cs:16处)
第16行说:
textTest.text = "Now let's move the right leg up!"; 发布于 2020-08-12 04:27:44
如果您改变了,它是否有效:
TextMeshProUGUI textTest
至
TMP_Text textTest
(然后将tmp游戏对象重新分配给脚本上的textTest变量)
否则,该错误通常只是意味着您忘记在检查器中为该变量赋值。
https://stackoverflow.com/questions/63368631
复制相似问题