attaching custom script objects

Laten we beginnen. Het is Gratis
of registreren met je e-mailadres
attaching custom script objects Door 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

2.1.1.1. Assets->Create->JavaScript

2.1.2. Project View

2.1.2.1. NewBehaviourScript

2.2. edit

2.2.1. double-clicking on it in the Project View

2.2.2. default script editor

2.2.2.1. Unity->Preferences->External Script editor

2.2.3. before

2.2.3.1. function Update () { }

2.2.4. After

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

3.2.2.1. choose Component->Scripts->New Behaviour Script.

3.2.2.2. 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 () {}

4.1.1.1. a container for code that Unity executes multiple times per second (once per frame)

4.1.2. transform

4.1.2.1. a reference to the GameObject’s Transform Component.

4.1.3. Rotate()

4.1.3.1. a function contained in the Transform Component

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

4.1.4.1. a member of the Time class that evens out movement over one second

4.1.4.2. 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”);