[MUSIC] In this lecture, we'll start to walk through the enemy code. Our objectives will be to explore the public and private variables of the script and modify the script to be more designer and editor friendly through the use of a number of Unity editor attributes. So let's go ahead and open our enemy script. I'll go ahead and select one of the enemies. Scroll down to the script component and double-click on the script. And of course, at the top of our class are all the public and private variables of the class. We already outlined what most of these public variables are doing when we looked through the enemy script component in the editor. Now we wanna modify the script to be a bit more designer friendly in the Unity Editor. So let's start by putting a range on the Move Speed. We can do this by adding the Range Attribute above the Move Speed variable. We actually saw this on the Character Controller 2D script. So the way that we do this is we type a bracket, then type range, and then within parentheses define the minimum and maximum values. So the move speed for the enemy will be between zero, and I'll do F for floating point value. And 10 in an effort for loading point value, we'll do the InParen and then the InBracket. Now if I save this and then go back to the Unity Editor, you'll see the component will update here, and now rather than just the value, we actually have the value and the slider. So I can drag this to down to 0 or drag it up to 10. So maybe it just makes a little more designer friendly so they can just tweak the slider as they're designing the game. And let me go to my script, moving down a bit you can see this isStunned public bool, which we saw there in the editor. Now isStunned is basically a public variable that indicates if the enemy is stunned or not. It's a public variable so that other scrips have the ability to check on the status of the enemy. But since it's a public variable, you can also see and modify it in the editor. But it really doesn't make sense to do so, since the code really has to do multiple things to actually make the enemy be stunned. You know, that is if I actually check this. It's not gonna stun the enemy. It's just gonna basically be an incorrect value of isStunned, because the enemy will still be moving but not actually be stunned. So we need this to be a public variable, for a script to script sort of mitigation. But we don't really want it to be exposed in the editor, because it's confusing for the designer. They might accidentally check this thinking that it's gonna make the enemy initially stunned. So let me uncheck that once again and let's go back to the script. So there is a way to hide it from the inspector using another attribute. So above the variable, I'll go ahead and type a bracket and then type HideInInspector and then end bracket. So once again if I save this and then go back to Unity. You can see that after the script compiles, that is done variable one away. Now one other thing that we can do to make a script a little more friendly to designers is to add tooltips that show up in the editor. And the way that we do this is through yet another attribute, so for example, up here it says stunnedCheck, let me go ahead and add a bracket and then type Tooltip. And then once again this is sort of like a function so we do a paren and then we provide a string that defines the message that we want to communicate in the editor. So let me just type child gameObject for detecting stun. And then end quote and then end paren and then end bracket. Notice we don't actually put semi colons on these attribute lines because it's not really C# code. And let me go ahead and add another one. So down here where it says waitAtWaypointTime, let's go ahead and, another Tooltip. And this one will be how much time in seconds to wait at each waypoint. Of course we have code comments, but some designers and artists really don't want to get into the code at all. They'd rather just have these in the editor. So let me go ahead and save this and go back to the editor. And if I go ahead and roll over, for example, Stunned check, you'll see that my little tool tip pops up and if I roll over Wait at Waypoint Time, I get my other tool tip. So let's go back to the script. So moving down a little bit you can see we've got various private variable down here below. All the movement tracking variables are all private variables to the class since they don't really need to be seen or modified from other scripts. However, there are times when you may wanna make a private variable visible for the unity editor to see and possible even modify. So for example _myWavePointIndex is a variable that tracks which wave point the enemy is currently moving towards. This information may be useful to expose to the editor while not outright making this a public variable. So the way that we can make private variables appear in the editor is through yet another attribute. So this one is called SerializeField. So let me go ahead and type SerializeField, and end bracket, right above the _myWaypointIndex and save this. And if I come back to the editor here after the script recompiles you can see that my waypoint index shows up at the bottom. Now currently I'm on the non moving enemies so I actually don't have any waypoints. But let me go to the enemy on the right side. And notice that if I zoom in on this, the waypoints currently, you know it's gonna move to the right first, and then to the left. Let me move it over a little bit just so he doesn't fall off the platform. And if I go ahead and select the Enemy Game Object and then Play, you'll see that my waypoint index so it's going to zero, now it's going to one, now it's going to zero, now it's going to one. You know based on, you know these weight points up above here. So you can see that in the editor as things are playing out. And you can actually even modify this. So if I stop this, I could change this now even though it's a private variable, I could set the default to one, for example. So in this case, for this enemy, it's going to move first to waypoint one and then waypoint zero. And of course, I'm just modifying this game object so the other one is moving to zero and then one, and so forth. That's a good example of why you would want to expose a private variable in the editor using that serialized field. I'm gonna go ahead and leave this as one for this enemy. [MUSIC]