From the course: Unity 5: 2D Level Design

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Wire up the air meter

Wire up the air meter - Unity Tutorial

From the course: Unity 5: 2D Level Design

Start my 1-month free trial

Wire up the air meter

- [Instructor] Now all that's left is to wire up our air meter. Inside of our jetroidLevelDesign Scripts folder, let's create a new C# script, and we're going to call this AirMeter. Then, let's open this up inside of MonoDevelop. We're going to need a few fields at the top of our class. Let's create a public float, and we're going to call this air, and we'll set this value equal to 10. Next, we'll create a public float called maxAir. We'll also set this value to 10, as well. Next, we'll need a public float called airBurnRate. This is how quickly the player will lose air. Let's set this to 0.5f. Next, we'll create two private fields. We'll start with one with a type of Player, and we'll call this player. Next, we'll set a private field to Slider, and at this point, we haven't imported the Slider classes, so simply hit Escape to get out of the auto-complete. We'll call this field Slider. At the top of our class, let's type in using UnityEngine.UI, which will import the Slider class…

Contents