我对团结很陌生,我正在尝试制作一个小游戏。我遇到了3个主要问题,我可以使用帮助:
- 我想制作一个显示我健康状况的标签:
我已经拥有的:
private int _healt;
// Start is called before the first frame update
void Start()
{
_healt = 5;
}
public void Hurt(int damage)
{
_healt -= damage;
Debug.Log("Health: " + _healt);
}
我在控制台中显示它,但我需要在标签中显示它?
创建一个分数系统,每增加一秒非死亡分数,并将其显示在标签中。我尝试了什么:没有真的我不知道如何启动
带有重置按钮的GameOver覆盖。我尝试过的:
public bool _PlayerAlive; public void GameOver() { _PlayerAlive = true; if (_healt > 0) { _PlayerAlive = true; } else { _PlayerAlive = false; } } //Button RestartButton = yourObject.GetComponent<RestartButton>(); public void RestartGame() { if (_PlayerAlive = false) { RestartButton.SetActive(true); } else { RestartButton.SetActive(false); } }
所以基本上与问题1中的内容相同,将标签与代码链接起来。
如果您需要更多信息,请询问。
在此脚本中,添加公共文本或[serializedField]私有文本
然后在unity内部,右键点击->UI->text 生成一个新的UI文本
将该文本拖放到检查器中的脚本文本字段
在Update((内的脚本中,写入:text.text=_heal.tostring((
这是实现这一点的最简单方法,但请注意,您需要在谷歌上搜索有关统一UI元素的信息,以了解它是如何工作的。