The Component-Script Relationship 组件和脚本之间的关系

优质
小牛编辑
133浏览
2023-12-01

When you create a script and and attach it to a GameObject, the script appears in the GameObject's Inspector just like a Component. This is because scripts become Components when they are saved - a script is just a specific type of Component. In technical terms, a script compiles as a type of Component, and is treated like any other Component by the Unity engine. So basically, a script is a Component that you are creating yourself. You will define its members to be exposed in the Inspector, and it will execute whatever functionality you've written.

当您创建一个脚本,并将其附加到一个游戏对象上,脚本将出现在游戏对象的检视视图中,看起来就像一个组件。这是因为在它们保存时,脚本将变成组件,——脚本只是一种特定类型的组件。在技术层面,脚本编译为一种组件类型,Unity引擎将象其他组件一样对待它。所以基本上,脚本是一个你自己创建的组件,你将定义其元素并陈列在检视视图中,它会执行任何你写的功能。

Read more about creating and using scripts on the Scripting page.

关于创建和使用脚本的更多内容,请阅读Scripting