tutorial 3 - scottylabs...tutorial 3 calling scripts from other scripts. public fields are used as...

9
TUTORIAL 3 Calling scripts from other scripts

Upload: others

Post on 27-Sep-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: TUTORIAL 3 - ScottyLabs...TUTORIAL 3 Calling scripts from other scripts. Public fields are used as script parameters. 200 is the default value. We will make the speed adjustable

TUTORIAL 3Calling scripts from other scripts

Page 2: TUTORIAL 3 - ScottyLabs...TUTORIAL 3 Calling scripts from other scripts. Public fields are used as script parameters. 200 is the default value. We will make the speed adjustable

Public fields are used as script parameters.

200 is the default value.

We will make the speed adjustable by making it a parameter

Multiply by Speed

Page 3: TUTORIAL 3 - ScottyLabs...TUTORIAL 3 Calling scripts from other scripts. Public fields are used as script parameters. 200 is the default value. We will make the speed adjustable

Script parameter is set for each object the script is applied to

Select the correct GameObject

You can test the script now and try different values for Speed

Page 4: TUTORIAL 3 - ScottyLabs...TUTORIAL 3 Calling scripts from other scripts. Public fields are used as script parameters. 200 is the default value. We will make the speed adjustable

Now we will make the SpinningObject only start spinning

when a function is run

This private field keeps track of if the object is

spinning

It only updates if it is spinning

This public function starts the spinning and

can be called from other scripts

Page 5: TUTORIAL 3 - ScottyLabs...TUTORIAL 3 Calling scripts from other scripts. Public fields are used as script parameters. 200 is the default value. We will make the speed adjustable

Make a new script called Helicopter

Page 6: TUTORIAL 3 - ScottyLabs...TUTORIAL 3 Calling scripts from other scripts. Public fields are used as script parameters. 200 is the default value. We will make the speed adjustable

Open the new script

Reload All if you see this

Page 7: TUTORIAL 3 - ScottyLabs...TUTORIAL 3 Calling scripts from other scripts. Public fields are used as script parameters. 200 is the default value. We will make the speed adjustable

On left mouse down, the rotor will start spinning

Add a parameter for the Rotor. This will let us call

the other script

We now edit the Helicopter script

Page 8: TUTORIAL 3 - ScottyLabs...TUTORIAL 3 Calling scripts from other scripts. Public fields are used as script parameters. 200 is the default value. We will make the speed adjustable

Apply the script to the Helicopter GameObject

Page 9: TUTORIAL 3 - ScottyLabs...TUTORIAL 3 Calling scripts from other scripts. Public fields are used as script parameters. 200 is the default value. We will make the speed adjustable

Select the Helicopter

To assign the Rotor, drag the rotor GameObject to the

Helicopter's script

Test you scene now. The rotor will start moving when you click. This is how scripts communicate in Unity.