Public 脚本中的变量名称与 inspector/editor 中的字段显示不匹配

Public variable name in script does not match field display in inspector/editor

S0 我正在关注 YouTube 上的 Unity 教程。它是一只飞扬的鸟类克隆体。一切进展顺利,但我 运行 进入了一段我无法理解的代码。我附上了图片(其中一个是统一检查器,另一个是脚本)。

我的问题是,在 GameControl 脚本的第 8 行中,创建了一个类型为 GameObject 的变量 gameOverText。然后在第 27 行调用 gameOverText.SetActive("true")。我没有看到统一如何将 gameOverText 变量与统一检查器中的 GameOverText 联系起来。
我知道我将 GameOverText 从 Hierarchy 拖到 Game Control。正如您在图片中看到的,检查器中的 GameOverText 与脚本中的“gameOverVariable”拼写不同。

我只是不明白它是如何工作的。

Unity检查器中显示的public GameObject gameOverText和字段"Game Over Text"都指的是同一个变量。当 Unity 在检查器中显示变量时,它会按大写字母拆分变量名称,然后根据需要将第一个单词的首字母大写。 (估计这是为了让变量多human-readable。)

这样,我们可以看到"gameOverText" => "Game Over Text";当您将引用拖到 "Game Over Text" 字段时,您实际上是在设置 gameOverText 变量的值。