Hello again.
In this lecture, we're starting the process of player death or mortality by saying if you touch the
enemy bump, you can no longer control your player.
We're still doing the animation and stuff.
We don't have a hit reaction yet.
We add some of that in the next video, but for now, we're starting off our process of player death.
Just a quick side note to start us off here.
If you scroll right in, you can see there's these lines on our tiles, which some of you might have
some of you might not.
And I think I've gone back in time and given you a warning, but I'm just going to update this now.
I'm going to click on my Sprite sheet for the background and change from pixel per unit 32 to 31 and
then apply.
And that makes them a tiny bit bigger and those little lines go away.
So it's much more smooth looking and I think we've got some of those on our rule tiles as well.
So I'm going to click on my main tile deck there and change that to 31 as well and then apply.
Sorry.
Oh, yeah.
It all just expands a tiny bit and we don't have those lines.
Yeah, it does look a bit better.
I couldn't put my finger on it, but something wasn't quite right.
Thank you for those in the community who have given me the feedback on that.
Now, for the main bit of our lecture we are having.
So the player dies when they touch the enemy.
And I'm going to give this to as a nice, broad challenge.
So enemies are bad and okay, there's a little bit of a South Park reference there for you.
Hopefully some of you have seen South Park.
When the player collides with an enemy disabled, the player controls.
That's as far as we'll go.
Now, in the next lecture or two, we'll have it.
So the player has some sort of hit reaction and their animation state changes.
But I don't want to do everything in one big long lecture.
That's the mission.
If you choose to take that on.
If that's enough for you, then jump in.
Go ahead.
If you want to make sure you've got things named the same way, I'm going to name them.
I know some of you like that.
My approach is going to be to use an is a live ball and also to create a die method.
So they're the two things I'll be doing.
So pause the video, see if you can figure out how to have the player's controls disabled when they
touch an enemy.
Okay.
Now let's jump into our player movement script in here.
As I mentioned before, we want to create ourselves a ball that is going to say whether we are currently,
currently alive or not.
And if we're alive, do your stuff.
If not, don't do your stuff.
So create a new line.
Ball is alive.
I'm going to call this alive.
It's alive and I'm going to initialize that at true just to be very, very careful.
Ensure that we're starting off as definitely we are alive.
Now what I need to do is to say within update, we don't want to be able to do these things run or flip
sprite or climb ladder if we are not alive.
So the way we're going to write that is if in parentheses we're not.
So exclamation is not is alive.
If we're not is alive, then what do we want to do?
We need our curly braces.
We're going to return.
So get the heck out of this update method and don't do anything else.
If you're not alive, don't do the other stuff.
Now I'm going to copy this one line here.
Copy, and then just pop that also within our on move, that's another place we can have input, pop
it at the top of that as well.
And then also on for our on jump pop that at the top.
Now what we need to do now is to create a method I'm going to call it die.
I know it's a little bit extreme.
I don't really like the word die and death and stuff in games, but, you know, it's video game language,
so we'll use it in here.
Die for the player.
That's a method.
We'll call in.
Update if a right condition is met.
We'll scroll all the way down and create ourselves a new method.
In here we have return type void.
Call it die parentheses.
Squiggly braces, curly braces.
What are we doing in here?
Well, we need to check to see if we've touched the enemy.
Now, I made the mistake just before I recorded this lecture because I did something dumb.
I went to look to see what layer the enemy is on, and I said, Yep, the enemy is on the enemy layout,
but the enemy is actually on the enemies list.
So it's always a good habit to go in here, find it, double click copy.
So you know, you've got it exactly right.
So I've got that in my copy.
Buffer What we're doing here is we'll start off with if my what is it, my body collider.
Yes, my body collider is touching layers.
We've done this before.
He's touching layers.
And then in parentheses, we're going to get ourselves in particular layer mask, dot get mask.
That's a way of saying, Hey, we want to get this thing.
What thing do we want in parentheses?
Quotation marks paste in enemies, not enemy.
Rick Don't waste your time doing that.
And then we want our next line, curly braces.
And what are we doing here?
What are we saying?
If we're touching an enemy, we need to switch something.
We need to switch is alive now equals false.
Simple as that no longer alive is lies false.
And then all of these things up here that we said, if we're not alive, then you can't do these things,
you can't move.
So we'll save back over into Unity.
Click on play.
Move, move, move.
Okay, there we go.
And boom.
Yes.
And we can no longer have input controls.
We're still looping through our run animation.
That's fine.
We're going to change that stuff up in the next lecture.
But for now, we've simulated death by saying You can't actually do anything.
You can't control your player, you just float off the edge of the screen.
So there we go.
Good stuff.
I'll see you in the next lecture.