tutorial 3 - scottylabs...tutorial 3 calling scripts from other scripts. public fields are used as...
TRANSCRIPT
TUTORIAL 3Calling scripts from other scripts
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
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
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
Make a new script called Helicopter
Open the new script
Reload All if you see this
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
Apply the script to the Helicopter GameObject
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.