Unity 2018 Cookbook(Third Edition)
上QQ阅读APP看书,第一时间看更新

Accessing the function from other scripts

The AccelerateRocket(...) function was made public so that it can be accessed from other scripts. As an example, we have included the ExternalChangePitch.cs script in the _Scripts folder. To illustrate how the ChangePitch scripted component can be controlled form another script, do the following:

  1. Attach this script to the Main Camera GameObject. Drag the animatedRocket GameObject from the Hierarchy into the public Change Pitch Scripted Component variable.
  2. Run the scene.
  3. Use the UP and DOWN arrow keys to control the animation speed (and sound pitch).