attaching custom script objects

Get Started. It's Free
or sign up with your email address
attaching custom script objects by Mind Map: attaching custom script objects

1. Using Scripts

1.1. writing simple behaviour scripts

1.1.1. JavaScript

1.1.2. C#

1.1.3. Boo

2. Creating New Scripts

2.1. create

2.1.1. main menu Assets->Create->JavaScript

2.1.2. Project View NewBehaviourScript

2.2. edit

2.2.1. double-clicking on it in the Project View

2.2.2. default script editor Unity->Preferences->External Script editor

2.2.3. before function Update () { }

2.2.4. After function Update () { print("Hello World"); }

2.3. Execute

2.3.1. nothing that causes the code to be executed yet

3. Attaching scripts to objects

3.1. create a new object

3.1.1. GameObject->Create Other->Cube

3.2. 2 methods

3.2.1. drag the script from the Project View to the Cube

3.2.2. select the Cube choose Component->Scripts->New Behaviour Script. Every script you create will appear in the Component->Scripts menu

3.3. Inspector

3.3.1. you will see that the script is now visible. This means it has been attached.

3.4. Press Play to test your creation.

3.4.1. beside the Play/Pause/Step buttons

4. Manipulating the GameObject

4.1. function Update () { transform.Rotate(0, 5*Time.deltaTime, 0); }

4.1.1. Update () {} a container for code that Unity executes multiple times per second (once per frame)

4.1.2. transform a reference to the GameObject’s Transform Component.

4.1.3. Rotate() a function contained in the Transform Component The numbers in-between the commas represent the degrees of rotation around each axis of 3D space: X, Y, and Z

4.1.4. Time.deltaTime a member of the Time class that evens out movement over one second cube will rotate at the same speed no matter how many frames per second your machine is rendering

5. The Power of Variables

5.1. variable can now be modified directly in the Inspector

5.2. you can re-use one script on many objects, each with a different variable value.

6. Accessing Other Components

6.1. Using the GameObject members

6.1.1. transform == gameObject.transform

6.1.2. gameObject == this.gameObject

6.1.3. transform.Translate() == gameObject.transform.Translate()

6.2. Using GetComponent()

6.2.1. scriptA = GetComponent(“ScriptA”);