1
00:00:00,000 --> 00:00:00,000
Hello, guys.

2
00:00:00,000 --> 00:00:06,000
In this video, I want to take care of the last element of the canvas, and that is end game UI.

3
00:00:06,000 --> 00:00:12,000
So what we need to do here is to switch on end game UI when player dies instead of restarting game instantly.

4
00:00:12,000 --> 00:00:13,000
So we're going to switch it on.

5
00:00:13,000 --> 00:00:20,000
We're going to update values inside and at the same point we switch in on this UI, we save in the info

6
00:00:20,000 --> 00:00:26,000
and then player just need to restart the button, but all of the info will be saved by that moment just

7
00:00:26,000 --> 00:00:26,000
in case.

8
00:00:26,000 --> 00:00:32,000
If he, for example, switched off the application before he clicked, go to main menu for example.

9
00:00:32,000 --> 00:00:33,000
Right.

10
00:00:33,000 --> 00:00:34,000
This what we're going to do.

11
00:00:34,000 --> 00:00:38,000
First, let's just modify and screen by a bit.

12
00:00:38,000 --> 00:00:44,000
I want to take this score with below just like this, and then I want to take coins, move it above.

13
00:00:45,000 --> 00:00:47,000
I want to reduce font size to 60.

14
00:00:49,000 --> 00:00:56,000
And I want to duplicate this text of the coins, move it above, change it to the instance.

15
00:00:56,000 --> 00:00:58,000
And this is a.

16
00:00:59,000 --> 00:01:00,000
Distance here.

17
00:01:02,000 --> 00:01:04,000
So it's going to be like this.

18
00:01:05,000 --> 00:01:06,000
Very good.

19
00:01:06,000 --> 00:01:08,000
Let's make all of the fonts bold.

20
00:01:08,000 --> 00:01:09,000
I think it's going to look better.

21
00:01:10,000 --> 00:01:13,000
And now we need to add the script here.

22
00:01:13,000 --> 00:01:15,000
New script, UI and game.

23
00:01:15,000 --> 00:01:16,000
Yeah.

24
00:01:17,000 --> 00:01:22,000
We're going to get access to three types of we're going to get access to that text we have.

25
00:01:22,000 --> 00:01:29,000
So it's going to be serialized field, private text, match pro we distance, then we need coins, coins

26
00:01:29,000 --> 00:01:31,000
and we need score.

27
00:01:33,000 --> 00:01:33,000
All right.

28
00:01:33,000 --> 00:01:39,000
We have distance and the coins in the game manager at the moment, but score is not available because

29
00:01:39,000 --> 00:01:41,000
score is a temp value.

30
00:01:41,000 --> 00:01:47,000
But what we can do is to delete, float from here and create score public value over here.

31
00:01:47,000 --> 00:01:49,000
Public float score.

32
00:01:52,000 --> 00:01:54,000
Now it's going to be accessible from anywhere.

33
00:01:56,000 --> 00:02:01,000
We can go back to end Game UI and in the start we can get access to game manager and I want to make

34
00:02:01,000 --> 00:02:03,000
it a bit easier to write.

35
00:02:03,000 --> 00:02:04,000
So I'll do this.

36
00:02:04,000 --> 00:02:05,000
Game manager.

37
00:02:05,000 --> 00:02:16,000
Manager equals to game manager instance and now distance not text equals to manager, distance to string

38
00:02:16,000 --> 00:02:18,000
with the format and key.

39
00:02:19,000 --> 00:02:27,000
I'm going to copy this to string so it's easier for me then coins text manager or you see in the sense

40
00:02:27,000 --> 00:02:28,000
helps me.

41
00:02:31,000 --> 00:02:32,000
Another one.

42
00:02:32,000 --> 00:02:34,000
Score text to string.

43
00:02:38,000 --> 00:02:39,000
Yeah, that's good.

44
00:02:39,000 --> 00:02:40,000
We don't need update.

45
00:02:40,000 --> 00:02:44,000
And what I also want to do here is to set timescale to zero time.

46
00:02:44,000 --> 00:02:46,000
The time scale equals to zero.

47
00:02:46,000 --> 00:02:51,000
If you remember, we set timescale to one by default in the UI, and I want to take this line of code

48
00:02:51,000 --> 00:02:56,000
from here and transfer it to game manager that has more logic in it.

49
00:02:56,000 --> 00:02:58,000
Let's put it here.

50
00:03:00,000 --> 00:03:01,000
Good enough.

51
00:03:01,000 --> 00:03:06,000
And the next thing we need to do, we need to make a function that will switch on end game UI.

52
00:03:06,000 --> 00:03:11,000
And at the same time we'll save information about coins we collected and so on.

53
00:03:11,000 --> 00:03:13,000
So let's go to game manager.

54
00:03:14,000 --> 00:03:16,000
And create public void.

55
00:03:18,000 --> 00:03:20,000
Game ended.

56
00:03:21,000 --> 00:03:22,000
Inside.

57
00:03:22,000 --> 00:03:27,000
We're going to do save info and if we have it here, we can remove it from restart level now.

58
00:03:29,000 --> 00:03:35,000
After we save that info, we need to open in-game UI and we don't have access to UI yet, but we can

59
00:03:35,000 --> 00:03:39,000
get it public UI main.

60
00:03:39,000 --> 00:03:40,000
Then I call it just UI.

61
00:03:45,000 --> 00:03:50,000
Then I want to go to UI Main create a function that will open this and game UI for me.

62
00:03:51,000 --> 00:03:55,000
So public void open end game UI.

63
00:03:55,000 --> 00:03:57,000
Now we need that end game UI.

64
00:03:57,000 --> 00:04:04,000
So let's go here and create serialize field, private game, object and game.

65
00:04:05,000 --> 00:04:06,000
And I want to put a space here.

66
00:04:08,000 --> 00:04:08,000
Cool.

67
00:04:08,000 --> 00:04:13,000
Now, here we're going to do switch menu to end game.

68
00:04:13,000 --> 00:04:15,000
This is good in the endgame UI.

69
00:04:16,000 --> 00:04:17,000
This is good.

70
00:04:17,000 --> 00:04:18,000
This is good.

71
00:04:18,000 --> 00:04:19,000
Let's check on game UI.

72
00:04:19,000 --> 00:04:20,000
This is okay.

73
00:04:20,000 --> 00:04:22,000
Now let's go to game manager.

74
00:04:23,000 --> 00:04:27,000
After we save that info, we go UI, open and game UI.

75
00:04:28,000 --> 00:04:29,000
Cool.

76
00:04:29,000 --> 00:04:30,000
Now what we need to do next.

77
00:04:30,000 --> 00:04:32,000
We need to call this function first.

78
00:04:32,000 --> 00:04:38,000
Let's call it from trigger dead zone over here Instead of restart level, we're going to call.

79
00:04:41,000 --> 00:04:43,000
What was that game ended.

80
00:04:46,000 --> 00:04:47,000
Let's copy this line.

81
00:04:47,000 --> 00:04:48,000
Go to player.

82
00:04:49,000 --> 00:04:53,000
And instead of free start level again, we're going to do this.

83
00:04:53,000 --> 00:04:55,000
Now, we don't need a delay here.

84
00:04:55,000 --> 00:05:02,000
And what I want to do is to change the time scale to something like point six or so, to make effect

85
00:05:02,000 --> 00:05:03,000
of the slow motion.

86
00:05:03,000 --> 00:05:05,000
When you get in hit, Let's do this time.

87
00:05:05,000 --> 00:05:08,000
The time scale equals 2.6 F.

88
00:05:16,000 --> 00:05:23,000
I'm going to drag it score wins distance, then switch it off.

89
00:05:23,000 --> 00:05:24,000
Switch on main menu.

90
00:05:25,000 --> 00:05:26,000
Let's go.

91
00:05:29,000 --> 00:05:30,000
Boom.

92
00:05:32,000 --> 00:05:33,000
I forgot something.

93
00:05:33,000 --> 00:05:35,000
And that is a sign.

94
00:05:35,000 --> 00:05:36,000
Canvas to game manager.

95
00:05:36,000 --> 00:05:37,000
Yeah.

96
00:05:38,000 --> 00:05:40,000
UI over here.

97
00:05:43,000 --> 00:05:44,000
Tom.

98
00:05:46,000 --> 00:05:47,000
What again?

99
00:05:48,000 --> 00:05:48,000
Oh.

100
00:05:49,000 --> 00:05:50,000
I'm sorry.

101
00:05:50,000 --> 00:05:51,000
Yeah.

102
00:05:51,000 --> 00:05:53,000
We need to sign in the game as well.

103
00:05:54,000 --> 00:05:55,000
And the game.

104
00:05:56,000 --> 00:05:57,000
Okay, Now it's going to work.

105
00:06:00,000 --> 00:06:01,000
I hope.

106
00:06:02,000 --> 00:06:03,000
Oh, no, it won't.

107
00:06:03,000 --> 00:06:04,000
There is something else to update.

108
00:06:05,000 --> 00:06:07,000
The text of the final score.

109
00:06:07,000 --> 00:06:09,000
And let's go and fix that.

110
00:06:14,000 --> 00:06:15,000
In the endgame UI.

111
00:06:16,000 --> 00:06:18,000
You're going to type here.

112
00:06:19,000 --> 00:06:20,000
Distance.

113
00:06:22,000 --> 00:06:24,000
And plus then.

114
00:06:25,000 --> 00:06:27,000
Plus again am.

115
00:06:28,000 --> 00:06:28,000
And we're here.

116
00:06:28,000 --> 00:06:30,000
We're going to type.

117
00:06:30,000 --> 00:06:31,000
Points.

118
00:06:33,000 --> 00:06:33,000
Plus.

119
00:06:33,000 --> 00:06:35,000
And this one is.

120
00:06:36,000 --> 00:06:37,000
Score.

121
00:06:38,000 --> 00:06:39,000
Plus.

122
00:06:45,000 --> 00:06:46,000
That is good.

123
00:06:51,000 --> 00:06:52,000
Okay, This is good.

124
00:06:56,000 --> 00:06:57,000
Now let's assign the button.

125
00:06:57,000 --> 00:06:59,000
Main menu.

126
00:06:59,000 --> 00:07:01,000
Let's drag the canvas.

127
00:07:02,000 --> 00:07:05,000
UI restart game button.

128
00:07:14,000 --> 00:07:14,000
All right.

129
00:07:14,000 --> 00:07:15,000
It's working.

130
00:07:15,000 --> 00:07:17,000
Now, let me hit the truck.

131
00:07:18,000 --> 00:07:19,000
And if I hit the trap.

132
00:07:21,000 --> 00:07:23,000
It's working perfect.

133
00:07:27,000 --> 00:07:28,000
All right.

134
00:07:28,000 --> 00:07:29,000
I'll see you in the next video.

135
00:07:30,000 --> 00:07:31,000
Oh.

136
00:07:32,000 --> 00:07:35,000
That this is empty because I had zero coins.

137
00:07:35,000 --> 00:07:40,000
Okay, let's modify just by bit, just in case this happens with somebody else.

138
00:07:40,000 --> 00:07:45,000
So what I want to do, I want to make sure one of these numbers has some value.

139
00:07:45,000 --> 00:07:48,000
And if there is no value, we're not going to type anything at all.

140
00:07:48,000 --> 00:07:51,000
This is what it looks like if manager.

141
00:07:54,000 --> 00:08:03,000
Manager that distance less or equals to null then return if manager dot coins equals less or equals

142
00:08:03,000 --> 00:08:05,000
to null, then return.

143
00:08:05,000 --> 00:08:11,000
And we don't need to type anything about score because score cannot be zero unless one of those two

144
00:08:11,000 --> 00:08:11,000
is zero.

145
00:08:12,000 --> 00:08:13,000
Yeah.

146
00:08:16,000 --> 00:08:18,000
Lets just select distance remove text.

147
00:08:19,000 --> 00:08:22,000
Same for coins and fourscore.

148
00:08:22,000 --> 00:08:24,000
Now, if I'll die with zero coins.

149
00:08:25,000 --> 00:08:27,000
This field is going to be empty.

150
00:08:27,000 --> 00:08:27,000
Good.

151
00:08:27,000 --> 00:08:28,000
Let's go to next video now.

