1
00:00:00,000 --> 00:00:00,000
Hello, guys.

2
00:00:00,000 --> 00:00:03,000
In this video, I want to make another part of the shop work.

3
00:00:03,000 --> 00:00:06,000
And I mean selling colors to the player, right?

4
00:00:06,000 --> 00:00:07,000
I mean, colors of the player.

5
00:00:07,000 --> 00:00:12,000
And as I said before, it's the best practice to reuse the code that you already have and not to create

6
00:00:12,000 --> 00:00:18,000
same one because another set of buttons basically going to use the same functionality entirely, the

7
00:00:18,000 --> 00:00:18,000
same.

8
00:00:19,000 --> 00:00:26,000
So what we can do here is to just pass another value that says, is it a platform or is it a player

9
00:00:26,000 --> 00:00:27,000
color?

10
00:00:27,000 --> 00:00:29,000
And then we're going to do our actions according to that.

11
00:00:29,000 --> 00:00:30,000
How are we going to do?

12
00:00:30,000 --> 00:00:32,000
We can create an enum.

13
00:00:32,000 --> 00:00:40,000
Enum allows you to define basically a type of something look, public enum, color type.

14
00:00:40,000 --> 00:00:47,000
And inside I'm going to do first one is player player color, another one, platform color.

15
00:00:47,000 --> 00:00:47,000
That's it.

16
00:00:47,000 --> 00:00:48,000
We're going to keep it like this.

17
00:00:49,000 --> 00:00:53,000
And now I can request this type over here, color type, color type.

18
00:00:53,000 --> 00:00:55,000
We need to pass this value as well.

19
00:00:55,000 --> 00:01:00,000
So let's go here and type color, type dot, platform color.

20
00:01:00,000 --> 00:01:01,000
All right.

21
00:01:01,000 --> 00:01:03,000
We have this now.

22
00:01:03,000 --> 00:01:04,000
It's all the same.

23
00:01:04,000 --> 00:01:09,000
But now we know that this function is exactly for platform color.

24
00:01:09,000 --> 00:01:11,000
Next, we can setup buttons for player color.

25
00:01:11,000 --> 00:01:15,000
For that, let's go above and create new bunch of variables.

26
00:01:15,000 --> 00:01:26,000
Serialize field, private game object player color button then serialize field, private transform player,

27
00:01:26,000 --> 00:01:28,000
color parent.

28
00:01:28,000 --> 00:01:33,000
And then we need display serialize field private image player display.

29
00:01:33,000 --> 00:01:40,000
Good enough we can make some headers so it's clear and easy and they're not firm colors.

30
00:01:41,000 --> 00:01:42,000
And there.

31
00:01:43,000 --> 00:01:45,000
Layer colors.

32
00:01:45,000 --> 00:01:48,000
Then let's take this one and drag it here.

33
00:01:49,000 --> 00:01:52,000
So it's all together in one section and over here.

34
00:01:52,000 --> 00:01:54,000
Serialize field.

35
00:01:55,000 --> 00:01:57,000
Prime color to sell.

36
00:01:57,000 --> 00:01:59,000
Layer colors.

37
00:02:00,000 --> 00:02:02,000
Okay, now it's all done here.

38
00:02:02,000 --> 00:02:04,000
We're going to set up this later in the inspector.

39
00:02:04,000 --> 00:02:09,000
Let's just create another for loop, basically the same as we did in the last video.

40
00:02:09,000 --> 00:02:11,000
Just going to change something.

41
00:02:11,000 --> 00:02:14,000
You're going to take this player of colors and paste it in here.

42
00:02:16,000 --> 00:02:17,000
And here.

43
00:02:17,000 --> 00:02:19,000
And in here.

44
00:02:20,000 --> 00:02:22,000
Then we need to change here.

45
00:02:22,000 --> 00:02:25,000
The button player color button.

46
00:02:25,000 --> 00:02:26,000
And.

47
00:02:27,000 --> 00:02:28,000
Oh, sorry.

48
00:02:31,000 --> 00:02:32,000
Layer color.

49
00:02:34,000 --> 00:02:34,000
Parent.

50
00:02:37,000 --> 00:02:37,000
All right.

51
00:02:37,000 --> 00:02:42,000
This can stay the same because we basically get an access to the same button as that one.

52
00:02:43,000 --> 00:02:44,000
And add listener.

53
00:02:44,000 --> 00:02:50,000
We only need to change color type, which is now player color.

54
00:02:51,000 --> 00:02:51,000
Good.

55
00:02:51,000 --> 00:02:59,000
Now we create in two sets of buttons, and the only functionality left is to decide which color we purchasing

56
00:02:59,000 --> 00:03:06,000
according to the color type we use in in the if statement enough money, we're going to make another

57
00:03:06,000 --> 00:03:13,000
if statement that says if color type equals equals to color type of the platform, then we're going

58
00:03:13,000 --> 00:03:16,000
to do this two lines of code, same as we did before.

59
00:03:16,000 --> 00:03:23,000
Nothing much changes here and we need another ls if I make an ls if because there can be more color

60
00:03:23,000 --> 00:03:27,000
types, maybe you want to do something else like change color of the crops.

61
00:03:27,000 --> 00:03:31,000
For example, if color type is equal to color type.

62
00:03:32,000 --> 00:03:34,000
Dot player color.

63
00:03:35,000 --> 00:03:36,000
Then game manager.

64
00:03:36,000 --> 00:03:42,000
That instance dot player color equals to color and we need display.

65
00:03:42,000 --> 00:03:42,000
We already have it.

66
00:03:42,000 --> 00:03:47,000
So player display that color equals to color.

67
00:03:47,000 --> 00:03:54,000
After all of that, after we decide which color we change in, I want to do debug line of successful

68
00:03:54,000 --> 00:04:01,000
purchase, but I don't want to do it in the console because player doesn't have console when he plays

69
00:04:01,000 --> 00:04:01,000
the game.

70
00:04:01,000 --> 00:04:03,000
So we need to do it in a different way.

71
00:04:03,000 --> 00:04:09,000
Luckily for us, if you remember we said text at the top of the shop, click to buy over here and we

72
00:04:09,000 --> 00:04:11,000
can change this for some time.

73
00:04:12,000 --> 00:04:15,000
So I want to create a core routine here.

74
00:04:15,000 --> 00:04:19,000
I enumerator with the name notify.

75
00:04:19,000 --> 00:04:20,000
We're going to pass a text.

76
00:04:20,000 --> 00:04:25,000
We want to send string, text and maybe a delay.

77
00:04:25,000 --> 00:04:27,000
So load seconds.

78
00:04:28,000 --> 00:04:33,000
Then inside we're going to take that text, change it, wait for a couple of seconds, and then change

79
00:04:33,000 --> 00:04:33,000
it back.

80
00:04:33,000 --> 00:04:35,000
But we need access to that text.

81
00:04:36,000 --> 00:04:43,000
Maybe somewhere above zero lies filled private text text match pro.

82
00:04:45,000 --> 00:04:47,000
90 by text.

83
00:04:48,000 --> 00:04:50,000
On to create a space here.

84
00:04:51,000 --> 00:04:52,000
So it's easier to read.

85
00:04:53,000 --> 00:04:58,000
Okay, then let's go back here and we say this 95 text.

86
00:04:58,000 --> 00:05:02,000
That text equals to text we pass here.

87
00:05:02,000 --> 00:05:05,000
Then we do yield.

88
00:05:05,000 --> 00:05:08,000
Yield return.

89
00:05:08,000 --> 00:05:18,000
You wait for seconds inside, we pass seconds to wait, and then we do 95 text 95 Text and text equals

90
00:05:18,000 --> 00:05:22,000
to what was that click to buy.

91
00:05:22,000 --> 00:05:23,000
Yeah.

92
00:05:23,000 --> 00:05:26,000
Now let's go over here and start this core routine.

93
00:05:26,000 --> 00:05:32,000
Start core routine 95 going to pass parameters, the text we want and the delay.

94
00:05:32,000 --> 00:05:35,000
So I want to say purchase successful.

95
00:05:36,000 --> 00:05:37,000
Let me copy it from here.

96
00:05:38,000 --> 00:05:39,000
Purchase successful.

97
00:05:40,000 --> 00:05:42,000
I can delete it from here now.

98
00:05:44,000 --> 00:05:47,000
And I'm going to do it for I don't know.

99
00:05:47,000 --> 00:05:48,000
One second.

100
00:05:49,000 --> 00:05:50,000
This is good.

101
00:05:50,000 --> 00:05:52,000
Now, what happens if there is not enough money?

102
00:05:52,000 --> 00:05:53,000
Very simple.

103
00:05:53,000 --> 00:05:55,000
We just do ls.

104
00:05:56,000 --> 00:05:59,000
You do, you start quarantine that says.

105
00:06:01,000 --> 00:06:02,000
Not enough money.

106
00:06:10,000 --> 00:06:12,000
We can delete this line from here.

107
00:06:12,000 --> 00:06:14,000
Do we need to change something else in the shop?

108
00:06:14,000 --> 00:06:15,000
Yes, we do.

109
00:06:15,000 --> 00:06:18,000
But first, let's go and see how this works.

110
00:06:20,000 --> 00:06:21,000
I'm going to take my shock UI.

111
00:06:22,000 --> 00:06:25,000
I'm going to close platform colors and I need to set up player colors.

112
00:06:25,000 --> 00:06:26,000
Let me click this.

113
00:06:26,000 --> 00:06:27,000
Lock it.

114
00:06:28,000 --> 00:06:35,000
First we drag the button, so project prefab player button, then the parent.

115
00:06:37,000 --> 00:06:40,000
Their parent then display image.

116
00:06:41,000 --> 00:06:42,000
Player.

117
00:06:43,000 --> 00:06:44,000
Then we need to set up colours.

118
00:06:44,000 --> 00:06:45,000
We have.

119
00:06:52,000 --> 00:06:53,000
Okay, I've got my colors.

120
00:06:53,000 --> 00:06:54,000
Now let's rock.

121
00:06:54,000 --> 00:06:56,000
Notify text.

122
00:06:56,000 --> 00:06:58,000
Or is it in for text over here?

123
00:06:58,000 --> 00:07:03,000
I'm going to change the name as well, just in case not to fi modify text.

124
00:07:04,000 --> 00:07:05,000
OC.

125
00:07:07,000 --> 00:07:10,000
We have it here and we can try this.

126
00:07:10,000 --> 00:07:14,000
I have only 100 coins, but I think that should be enough.

127
00:07:15,000 --> 00:07:16,000
Purchase successful.

128
00:07:16,000 --> 00:07:18,000
Let me change the color of the player.

129
00:07:19,000 --> 00:07:20,000
Not enough money.

130
00:07:20,000 --> 00:07:21,000
Okay.

131
00:07:21,000 --> 00:07:22,000
How about this one?

132
00:07:22,000 --> 00:07:23,000
Boom.

133
00:07:23,000 --> 00:07:24,000
Color change in the display.

134
00:07:24,000 --> 00:07:28,000
But maybe you notice that actual color of the player is not changed at all.

135
00:07:28,000 --> 00:07:29,000
So we need to fix that.

136
00:07:29,000 --> 00:07:32,000
And also, we need to update the amount of money over here in the info bar.

137
00:07:33,000 --> 00:07:34,000
It's going to be a pretty easy task.

138
00:07:34,000 --> 00:07:36,000
We could do it in a couple of different ways.

139
00:07:36,000 --> 00:07:41,000
What I want to do here is to delete player color from here, from the game manager.

140
00:07:42,000 --> 00:07:46,000
Before I start, we can create a function here, but actually it's not really needed.

141
00:07:46,000 --> 00:07:51,000
Let's go to UI shop and instead of this line we're going to do game manager dot instance, dot player

142
00:07:51,000 --> 00:07:55,000
and get component of sprite renderer.

143
00:07:55,000 --> 00:07:58,000
Then we're going to do dot color equals to color.

144
00:07:58,000 --> 00:08:00,000
So we actually going to change the color.

145
00:08:00,000 --> 00:08:07,000
And if you want to save the color, you can do game manager dot instance, dot save color and you need

146
00:08:07,000 --> 00:08:09,000
to pass color dot.

147
00:08:10,000 --> 00:08:12,000
Are color dot g colored dot b.

148
00:08:13,000 --> 00:08:15,000
Yeah, this will do.

149
00:08:15,000 --> 00:08:20,000
Also, we need to update the info bar, as I said, so let's go above and create another serialized

150
00:08:20,000 --> 00:08:21,000
field.

151
00:08:22,000 --> 00:08:26,000
Private text message, pro gooey coins.

152
00:08:26,000 --> 00:08:27,000
Text.

153
00:08:27,000 --> 00:08:28,000
We can go.

154
00:08:33,000 --> 00:08:35,000
We can go over here.

155
00:08:35,000 --> 00:08:42,000
Get this line of code and just go to the start and say that code and text.

156
00:08:43,000 --> 00:08:51,000
Don't text equals to get into of the coins and we only need to do two string in the format and let's

157
00:08:51,000 --> 00:08:57,000
copy this line of code and update this info not only on the start, but when our amount of money was

158
00:08:57,000 --> 00:09:02,000
changed and this is happening over here so we can do it here, we're going to update the info every

159
00:09:02,000 --> 00:09:04,000
time we purchase something.

160
00:09:04,000 --> 00:09:06,000
That's basically it.

161
00:09:07,000 --> 00:09:08,000
Yeah, I think so.

162
00:09:08,000 --> 00:09:10,000
Let's go and modify a bit.

163
00:09:14,000 --> 00:09:16,000
Let's go and make sure all of that is working.

164
00:09:16,000 --> 00:09:19,000
I'm going to select my cannabis.

165
00:09:21,000 --> 00:09:22,000
Shop UI.

166
00:09:27,000 --> 00:09:28,000
Find the info bar.

167
00:09:28,000 --> 00:09:33,000
There is a coin text over here and just going to drag it over here.

168
00:09:35,000 --> 00:09:37,000
This is done, and I think we are ready.

169
00:09:38,000 --> 00:09:39,000
I think that's it.

170
00:09:43,000 --> 00:09:45,000
I only have 24 coins.

171
00:09:45,000 --> 00:09:46,000
Wait a second.

172
00:09:49,000 --> 00:09:49,000
Okay.

173
00:09:49,000 --> 00:09:50,000
95 coins.

174
00:09:50,000 --> 00:09:51,000
Let's go.

175
00:09:52,000 --> 00:09:54,000
I'll purchase this color.

176
00:09:54,000 --> 00:09:55,000
That is done.

177
00:09:55,000 --> 00:09:56,000
I'll try this one.

178
00:09:56,000 --> 00:09:58,000
Oh, not enough money.

179
00:09:58,000 --> 00:09:58,000
Hmm.

180
00:09:59,000 --> 00:10:01,000
Okay, let's try to purchase hero color.

181
00:10:01,000 --> 00:10:02,000
We did it.

182
00:10:04,000 --> 00:10:05,000
And it's all fine.

183
00:10:05,000 --> 00:10:11,000
Now, the last one here, just in case you want to play this game on the PC, not the mobile.

184
00:10:11,000 --> 00:10:16,000
We want to change the scroll speed over here, because when I try to do that with my wheel, it's really,

185
00:10:16,000 --> 00:10:18,000
really hard to do.

186
00:10:18,000 --> 00:10:19,000
Luckily, that is very easy.

187
00:10:19,000 --> 00:10:25,000
Fix We need to choose player color, view, find scroll sensitivity and set it to something higher.

188
00:10:25,000 --> 00:10:27,000
And let's do it out of the play mode.

189
00:10:28,000 --> 00:10:31,000
These two scroll sensitivity 50.

190
00:10:37,000 --> 00:10:38,000
And it's okay now.

191
00:10:40,000 --> 00:10:41,000
Very good.

192
00:10:41,000 --> 00:10:44,000
Now, regarding the color, what color should you sell?

193
00:10:44,000 --> 00:10:49,000
You can make a random color or you can choose a bunch of colors, but sell only three at a time.

194
00:10:49,000 --> 00:10:54,000
So every time you update the shop, it's going to be three out of ten or three out of 100.

195
00:10:54,000 --> 00:11:00,000
For example, just make sure your colors are not too dark and not are the same as the background because

196
00:11:00,000 --> 00:11:02,000
it's going to be difficult to see the player.

197
00:11:02,000 --> 00:11:03,000
Yeah.

198
00:11:03,000 --> 00:11:04,000
Let's go to the next video now.

