You can see that the character rotates.
It moves to one of the waypoints, waits for a second, turns around,
moves back and so this is our patrolling behavior.
Now, there are some patrolling waypoint behaviors built into standard assets.
I wanted to go ahead and make this ourselves because it allows us to have
a little bit more control of what's happening.
And allows you to get more in-depth into the NAVMesh system in Unity,
which is what we're using here.
Okay, so looking at that I just want to take
a little bit of a look at more of what's going on here.
You can see I have a series of waypoints.
I only have three of them and I'm reusing waypoint 1 as both the first and
third waypoint, they're 0, 1, 2, 3, right.
And the waypoints have a facing and a wait time, as you can see here.
So you can see that the waypoint 1 here is facing along the positive axis.
Other things to note are that if I click on the enemy and
then select Draw Gizmos here I get this really cool thing where I
can see which waypoints I've assigned to that enemy.
And the order in which it will walk them, zero, one, two,
three, zero, one, two, three.
And you can see its given me this nice red line here as well.
So that I think is pretty cool and that's part of your challenge,
is to implement that.
You can find those icons for the numbers here in the Gizmos folder,
they are 128 by 128 pixels.
But that's not actually necessary, it, kind of, scales them the same regardless,
it seems, of what size they are.
Another thing to note here is that I built this little hallway using ProBuilder,
which is now free from Unity, you can get it on the Asset Store.
And it is a great tool for mocking up spaces like this,
I had a lot of fun working with it.
Note, of course, that the waypoints do disappear whenever we're playing.
And I told the gizmos for the preview to disappear as well,
that's up to you whether you want to do that.
And then the very last thing to show you is I created this little script.
This is your bonus challenge here, this enemy NAV waypoint editor preview script.
When I check this and then check that, you'll see that I get this little,
sort of, green thing that walks along the path.
Now, it does not maintain a constant speed.
Instead, it just kind of animates, regardless of the distance,
it takes the same amount of time to go between points.
But that kind of shows me the path that my character will be walking.
If the navigation has to go around corners or something,
this just does a straight line, it doesn't go around corners.
But that's totally fine for our purposes here.
If you decide to implement this bonus challenge, I do encourage you to look into
editor application.update as a way to get things to animate smoothly in the editor.
If you just try and use OnDrawGizmos it doesn't animate smoothly because
OnDrawGizmos only gets called when it needs to redraw.
Instead of every frame like editor application.update does.
So now let's hop back and
look at what I'm going to give you in your starter project for this challenge.
So here we are in the starter project for this challenge.
You can see that you've got the same hallway that I gave you,
you've got the enemy there with the ACS 17 model underneath it.
You've got all the waypoints already set up, they're in a hierarchy here.
And so all of this is ready for you to do your programming challenge here.
Another thing that I will point out, if you're on any kind of a slower machine,
like a laptop or something like that, I do recommend going into Lighting.
And turning off Auto Generate and
just clicking Generate Lighting once in the scene.
That way you don't have to wait for it to, kind of,
regenerate the lighting all the time whenever you do things.
This will, of course, add this folder full of the, sort of,
baked information for the lighting there.
And that just makes it a little bit faster to deal with when you're adding new
objects to the scene.
You get to choose when it bakes the lighting.
And so I think that's it.
I hope you enjoy this challenge and I look forward to seeing you in the next video,
take care.
>> [MUSIC]