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