翻译:脚本_树
This is a short overview of how scripting inside Unity works.
Scripting inside Unity consists of attaching custom script objects called behaviours to game objects. Different functions inside the
script objects are called on certain events. The most used ones being the following:
这是一本关于脚本在Untiy中如何工作的简短概述。
脚本在Unity由附加自定义脚本对象到游戏对象构成。不同的函数在脚本对象内在特定事件被调用。以下最常用的:
Update:
This function is called before rendering a frame. This is where most game behaviour code goes, except physics code.
这个函数在运行一帧之前被调用,这是大部分的游戏行为代码在这里执行,除了物理代码。
FixedUpdate:
This function is called once every physics time step. This is the place to do physics-based game behaviour.
这个函数会在每个固定的物理时间步被调用一次。这是放置游戏基本物理行为代码的地方。
Code outside any function 函数外部代码 :
Code outside functions is run when the object is loaded. This can be used to initialise the state of the script.
函数外部的代码在物体被加载时运行。这可以用来初始化脚本状态。
Note: Sections of this document assume you are using Javascript, but see Writing scripts in C# for information
about how to use C# or Boo scripts.
注意:这个文档假设你使用的是Javascript,否则请查看 Writing scripts in C# (用C#编写脚本)来获取如何使用C#或Boo编写脚本。
You can also define event handlers. These all have names starting with On, (i.e. OnCollisionEnter). To see the full list of predefined events, see the documentation forMonoBehaviour.
也可以使用事件处理程序,这些函数的名字都开始于On(类似的OnCollisionEnter),看所有的预定义事件列表,查阅文档 MonoBehaviour .
Subsections 章节
- Common Operations 常用操作
- Keeping Track of Time 记录时间
- Accessing Other Components 访问其他组件
- Accessing Other Game Objects 访问其他游戏物体
- Vectors 向量
- Member Variables & Global Variables 成员变量 & 全局变量
- Instantiate 实例
- Coroutines & Yield 协同程序 & 中断
- Writing Scripts in C# 使用C#书写脚本
- The most important classes 重要的类
- Performance Optimization 性能优化
- Script compilation (Advanced) 脚本编译(高级)