attaching custom script objects

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

1. Attaching scripts to objects

1.1. create a new object

1.1.1. GameObject->Create Other->Cube

1.2. 2 methods

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

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

1.3. Inspector

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

1.4. Press Play to test your creation.

1.4.1. beside the Play/Pause/Step buttons

2. Manipulating the GameObject

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

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

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

2.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

2.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

3. The Power of Variables

3.1. variable can now be modified directly in the Inspector

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

4. Accessing Other Components

4.1. Using the GameObject members

4.1.1. transform == gameObject.transform

4.1.2. gameObject == this.gameObject

4.1.3. transform.Translate() == gameObject.transform.Translate()

4.2. Using GetComponent()

4.2.1. scriptA = GetComponent(“ScriptA”);

5. Using Scripts

5.1. writing simple behaviour scripts

5.1.1. JavaScript

5.1.2. C#

5.1.3. Boo

6. Creating New Scripts

6.1. create

6.1.1. main menu Assets->Create->JavaScript

6.1.2. Project View NewBehaviourScript

6.2. edit

6.2.1. double-clicking on it in the Project View

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

6.2.3. before function Update () { }

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

6.3. Execute

6.3.1. nothing that causes the code to be executed yet