1
00:00:03,100 --> 00:00:03,670
Hello again.

2
00:00:03,670 --> 00:00:08,080
In this lecture, we're starting the process of player death or mortality by saying if you touch the

3
00:00:08,080 --> 00:00:10,840
enemy bump, you can no longer control your player.

4
00:00:10,840 --> 00:00:12,370
We're still doing the animation and stuff.

5
00:00:12,370 --> 00:00:13,750
We don't have a hit reaction yet.

6
00:00:13,750 --> 00:00:18,070
We add some of that in the next video, but for now, we're starting off our process of player death.

7
00:00:18,070 --> 00:00:20,350
Just a quick side note to start us off here.

8
00:00:20,350 --> 00:00:25,090
If you scroll right in, you can see there's these lines on our tiles, which some of you might have

9
00:00:25,090 --> 00:00:25,840
some of you might not.

10
00:00:25,840 --> 00:00:30,250
And I think I've gone back in time and given you a warning, but I'm just going to update this now.

11
00:00:30,250 --> 00:00:35,500
I'm going to click on my Sprite sheet for the background and change from pixel per unit 32 to 31 and

12
00:00:35,500 --> 00:00:36,490
then apply.

13
00:00:36,490 --> 00:00:39,310
And that makes them a tiny bit bigger and those little lines go away.

14
00:00:39,310 --> 00:00:44,950
So it's much more smooth looking and I think we've got some of those on our rule tiles as well.

15
00:00:44,950 --> 00:00:50,890
So I'm going to click on my main tile deck there and change that to 31 as well and then apply.

16
00:00:50,890 --> 00:00:51,340
Sorry.

17
00:00:51,340 --> 00:00:51,670
Oh, yeah.

18
00:00:51,670 --> 00:00:54,730
It all just expands a tiny bit and we don't have those lines.

19
00:00:54,730 --> 00:00:55,690
Yeah, it does look a bit better.

20
00:00:55,690 --> 00:00:58,180
I couldn't put my finger on it, but something wasn't quite right.

21
00:00:58,180 --> 00:01:01,510
Thank you for those in the community who have given me the feedback on that.

22
00:01:01,510 --> 00:01:03,760
Now, for the main bit of our lecture we are having.

23
00:01:03,760 --> 00:01:05,890
So the player dies when they touch the enemy.

24
00:01:05,890 --> 00:01:08,800
And I'm going to give this to as a nice, broad challenge.

25
00:01:08,800 --> 00:01:13,120
So enemies are bad and okay, there's a little bit of a South Park reference there for you.

26
00:01:13,150 --> 00:01:14,980
Hopefully some of you have seen South Park.

27
00:01:14,980 --> 00:01:18,520
When the player collides with an enemy disabled, the player controls.

28
00:01:18,520 --> 00:01:19,600
That's as far as we'll go.

29
00:01:19,600 --> 00:01:21,850
Now, in the next lecture or two, we'll have it.

30
00:01:21,850 --> 00:01:25,420
So the player has some sort of hit reaction and their animation state changes.

31
00:01:25,420 --> 00:01:28,840
But I don't want to do everything in one big long lecture.

32
00:01:28,840 --> 00:01:30,430
That's the mission.

33
00:01:30,430 --> 00:01:31,540
If you choose to take that on.

34
00:01:31,540 --> 00:01:33,250
If that's enough for you, then jump in.

35
00:01:33,280 --> 00:01:33,880
Go ahead.

36
00:01:33,880 --> 00:01:37,810
If you want to make sure you've got things named the same way, I'm going to name them.

37
00:01:37,810 --> 00:01:39,220
I know some of you like that.

38
00:01:39,520 --> 00:01:46,690
My approach is going to be to use an is a live ball and also to create a die method.

39
00:01:46,690 --> 00:01:48,400
So they're the two things I'll be doing.

40
00:01:48,400 --> 00:01:53,860
So pause the video, see if you can figure out how to have the player's controls disabled when they

41
00:01:53,860 --> 00:01:54,970
touch an enemy.

42
00:01:57,950 --> 00:01:58,360
Okay.

43
00:01:58,370 --> 00:02:00,870
Now let's jump into our player movement script in here.

44
00:02:00,890 --> 00:02:05,290
As I mentioned before, we want to create ourselves a ball that is going to say whether we are currently,

45
00:02:05,420 --> 00:02:06,800
currently alive or not.

46
00:02:06,800 --> 00:02:08,240
And if we're alive, do your stuff.

47
00:02:08,240 --> 00:02:09,380
If not, don't do your stuff.

48
00:02:09,410 --> 00:02:10,520
So create a new line.

49
00:02:10,520 --> 00:02:12,200
Ball is alive.

50
00:02:12,230 --> 00:02:13,670
I'm going to call this alive.

51
00:02:13,670 --> 00:02:19,370
It's alive and I'm going to initialize that at true just to be very, very careful.

52
00:02:19,370 --> 00:02:22,760
Ensure that we're starting off as definitely we are alive.

53
00:02:22,760 --> 00:02:27,800
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

54
00:02:27,800 --> 00:02:29,930
sprite or climb ladder if we are not alive.

55
00:02:29,930 --> 00:02:33,680
So the way we're going to write that is if in parentheses we're not.

56
00:02:33,680 --> 00:02:36,590
So exclamation is not is alive.

57
00:02:36,590 --> 00:02:39,560
If we're not is alive, then what do we want to do?

58
00:02:39,590 --> 00:02:41,300
We need our curly braces.

59
00:02:41,300 --> 00:02:42,260
We're going to return.

60
00:02:42,260 --> 00:02:46,430
So get the heck out of this update method and don't do anything else.

61
00:02:46,430 --> 00:02:47,870
If you're not alive, don't do the other stuff.

62
00:02:47,870 --> 00:02:49,910
Now I'm going to copy this one line here.

63
00:02:49,940 --> 00:02:56,090
Copy, and then just pop that also within our on move, that's another place we can have input, pop

64
00:02:56,090 --> 00:02:57,710
it at the top of that as well.

65
00:02:57,710 --> 00:03:01,610
And then also on for our on jump pop that at the top.

66
00:03:01,610 --> 00:03:06,050
Now what we need to do now is to create a method I'm going to call it die.

67
00:03:06,050 --> 00:03:07,220
I know it's a little bit extreme.

68
00:03:07,220 --> 00:03:11,930
I don't really like the word die and death and stuff in games, but, you know, it's video game language,

69
00:03:11,930 --> 00:03:13,220
so we'll use it in here.

70
00:03:13,220 --> 00:03:14,300
Die for the player.

71
00:03:14,300 --> 00:03:14,990
That's a method.

72
00:03:14,990 --> 00:03:15,980
We'll call in.

73
00:03:15,980 --> 00:03:17,990
Update if a right condition is met.

74
00:03:17,990 --> 00:03:21,770
We'll scroll all the way down and create ourselves a new method.

75
00:03:21,770 --> 00:03:23,840
In here we have return type void.

76
00:03:23,840 --> 00:03:26,960
Call it die parentheses.

77
00:03:27,230 --> 00:03:29,600
Squiggly braces, curly braces.

78
00:03:29,600 --> 00:03:30,470
What are we doing in here?

79
00:03:30,470 --> 00:03:33,470
Well, we need to check to see if we've touched the enemy.

80
00:03:33,470 --> 00:03:37,760
Now, I made the mistake just before I recorded this lecture because I did something dumb.

81
00:03:37,760 --> 00:03:42,560
I went to look to see what layer the enemy is on, and I said, Yep, the enemy is on the enemy layout,

82
00:03:42,560 --> 00:03:45,900
but the enemy is actually on the enemies list.

83
00:03:45,920 --> 00:03:50,660
So it's always a good habit to go in here, find it, double click copy.

84
00:03:50,660 --> 00:03:52,190
So you know, you've got it exactly right.

85
00:03:52,190 --> 00:03:53,360
So I've got that in my copy.

86
00:03:53,360 --> 00:03:58,040
Buffer What we're doing here is we'll start off with if my what is it, my body collider.

87
00:03:58,040 --> 00:04:01,010
Yes, my body collider is touching layers.

88
00:04:01,010 --> 00:04:01,730
We've done this before.

89
00:04:01,730 --> 00:04:03,110
He's touching layers.

90
00:04:03,110 --> 00:04:08,840
And then in parentheses, we're going to get ourselves in particular layer mask, dot get mask.

91
00:04:08,840 --> 00:04:10,970
That's a way of saying, Hey, we want to get this thing.

92
00:04:10,970 --> 00:04:13,010
What thing do we want in parentheses?

93
00:04:13,010 --> 00:04:16,190
Quotation marks paste in enemies, not enemy.

94
00:04:16,190 --> 00:04:18,350
Rick Don't waste your time doing that.

95
00:04:18,350 --> 00:04:21,980
And then we want our next line, curly braces.

96
00:04:21,980 --> 00:04:23,240
And what are we doing here?

97
00:04:23,240 --> 00:04:24,290
What are we saying?

98
00:04:24,290 --> 00:04:27,380
If we're touching an enemy, we need to switch something.

99
00:04:27,380 --> 00:04:32,660
We need to switch is alive now equals false.

100
00:04:32,810 --> 00:04:35,810
Simple as that no longer alive is lies false.

101
00:04:35,810 --> 00:04:40,700
And then all of these things up here that we said, if we're not alive, then you can't do these things,

102
00:04:40,700 --> 00:04:41,660
you can't move.

103
00:04:41,660 --> 00:04:43,850
So we'll save back over into Unity.

104
00:04:43,850 --> 00:04:45,590
Click on play.

105
00:04:46,700 --> 00:04:47,580
Move, move, move.

106
00:04:47,600 --> 00:04:48,670
Okay, there we go.

107
00:04:48,680 --> 00:04:49,560
And boom.

108
00:04:49,580 --> 00:04:50,090
Yes.

109
00:04:50,090 --> 00:04:52,510
And we can no longer have input controls.

110
00:04:52,520 --> 00:04:54,500
We're still looping through our run animation.

111
00:04:54,500 --> 00:04:55,010
That's fine.

112
00:04:55,010 --> 00:04:57,140
We're going to change that stuff up in the next lecture.

113
00:04:57,140 --> 00:05:01,190
But for now, we've simulated death by saying You can't actually do anything.

114
00:05:01,190 --> 00:05:04,460
You can't control your player, you just float off the edge of the screen.

115
00:05:04,490 --> 00:05:05,120
So there we go.

116
00:05:05,150 --> 00:05:05,620
Good stuff.

117
00:05:05,630 --> 00:05:06,980
I'll see you in the next lecture.

