Translation: script _ Tree
This was 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 is called on certain events. The most used ones being the following:
This is a brief overview of how the script works in Untiy.
Scripts in unity consist of attaching custom script objects to game objects. Different functions are called within a script object in a particular event. The following are most commonly used:
Update:
This function is called before rendering a frame. This is where the most game behaviour code goes, except physics code.
This function is called before running a frame, which is where most of the game behavior code executes, except for the physical code.
Fixedupdate:
This function is called once every physics time step. This was the place to do physics-based game behaviour.
This function is called once per fixed physical time step. This is where the basic physical behavior Code of the game is placed.
Code outside any functionfunction External Code:
Code outside functions is a run when the object is loaded. This can is used to initialise the state of the script.
The code outside the function runs when the object is loaded. This can be used to initialize the state of the script.
Note:sections of this document assume you is using Javascript, but see Writing scripts in C # for information on how T o use C # or Boo scripts.
Note: This document assumes that you are using JavaScript, otherwise see Writing scripts in C # (scripting in C #) to get a script using C # or Boo.
You can also define event handlers. These all has names starting with on, (i.e. oncollisionenter). To see the full list of predefined events, see the documentation formonobehaviour.
You can also use event handlers, whose names begin with on (similar to oncollisionenter), looking at all the predefined list of events and reviewing the document Monobehaviour.
Subsections chapters
- Common Operations Common operation
- Keeping track of time record times
- Accessing other component access to additional components
- Accessing other game Objects access other gaming objects
- Vectors Vector
- Member Variables & Globals Variables member variables & global Variables
- Instantiate instances
- Coroutines & Yield co-Program & interrupts
- Writing Scripts in C # writing scripts with C #
- The most important classes important class
- Performance Optimization Performance optimization
- Script compilation (Advanced) scripting
Unity3d Script Manual