May 2018
Beginner
492 pages
11h 53m
English
Using events, BalloonController does not need to check for input actions each frame Update. All that conditional logic can be bypassed. Instead, we'll drag and drop the components to subscribe them to events. The Update function now only needs to grow the balloon if it's already instantiated.
The entire BalloonController.cs now looks like this. Aside from being less code, please note that we changed the NewBalloon and ReleaseBalloon functions from private to public so we can reference them in the Inspector:
public class BalloonController : MonoBehaviour{ public GameObject balloonPrefab; public float floatStrength = 20f; public float growRate = 1.5f; private GameObject balloon; void Update() { if (balloon != null) ...Read now
Unlock full access