All language subtitles for Learn Unity Beginner_Intermediate 2023 (FREE COMPLETE Course - Unity Tutorial) (1)

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian Download
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,060 --> 00:00:01,060 hello and welcome I'm your code monkey 2 00:00:02,100 --> 00:00:03,100 and here is a free complete course on 3 00:00:04,620 --> 00:00:05,620 making a game from start to finish if 4 00:00:06,839 --> 00:00:07,839 you've always wanted to learn how to 5 00:00:08,220 --> 00:00:09,220 make a game or if you already know the 6 00:00:10,019 --> 00:00:11,019 basics but want to see how to organize a 7 00:00:11,880 --> 00:00:12,880 more complex project then this video is 8 00:00:13,620 --> 00:00:14,620 for you it's perfect for both beginners 9 00:00:16,020 --> 00:00:17,020 and more intermediate users this is a 10 00:00:18,720 --> 00:00:19,720 completely free course video but it has 11 00:00:20,699 --> 00:00:21,699 the same level of quality as my paid 12 00:00:22,500 --> 00:00:23,500 courses or my Steam games you can 13 00:00:24,600 --> 00:00:25,600 download the project files to follow 14 00:00:26,039 --> 00:00:27,039 along or inspect the funnel game you can 15 00:00:28,260 --> 00:00:29,260 even play the final game directly on 16 00:00:29,820 --> 00:00:30,820 scene we're going to start commonly from 17 00:00:31,679 --> 00:00:32,679 scratch and build a really awesome game 18 00:00:33,420 --> 00:00:34,420 with tons of systems and mechanics 19 00:00:35,160 --> 00:00:36,160 building this design requires working 20 00:00:37,380 --> 00:00:38,380 with lots of unity and c-sharp features 21 00:00:39,300 --> 00:00:40,300 so this is a really awesome project for 22 00:00:40,980 --> 00:00:41,980 you to learn after following this course 23 00:00:42,960 --> 00:00:43,960 and learning all of these techniques you 24 00:00:44,579 --> 00:00:45,579 won't be able to build all kinds of 25 00:00:46,079 --> 00:00:47,079 games in all kinds of genres this is 26 00:00:48,480 --> 00:00:49,480 going to involve learning about the 27 00:00:49,860 --> 00:00:50,860 basics of unity and c-sharp learning how 28 00:00:51,899 --> 00:00:52,899 to make a character controller physics 29 00:00:53,460 --> 00:00:54,460 raycast learn all about c-sharp 30 00:00:55,680 --> 00:00:56,680 interface and events using script more 31 00:00:57,480 --> 00:00:58,480 objects handling UI the new input system 32 00:00:59,520 --> 00:01:00,520 and lots more 33 00:01:00,840 --> 00:01:01,840 very importantly everything that we're 34 00:01:02,579 --> 00:01:03,579 going to do here is going to be focused 35 00:01:04,199 --> 00:01:05,199 on writing good easy to understand clean 36 00:01:06,000 --> 00:01:07,000 code meaning that I will not be teaching 37 00:01:08,580 --> 00:01:09,580 you bad practices that some beginner 38 00:01:10,140 --> 00:01:11,140 tutorials teach the code that we're 39 00:01:12,180 --> 00:01:13,180 going to write here is production 40 00:01:13,439 --> 00:01:14,439 quality code this is not a throwaway 41 00:01:15,659 --> 00:01:16,659 demo the quality of the code and the 42 00:01:17,880 --> 00:01:18,880 structure of the game that we're going 43 00:01:18,960 --> 00:01:19,960 to build is on the same level of quality 44 00:01:20,640 --> 00:01:21,640 as my own Steam games as you can see 45 00:01:22,799 --> 00:01:23,799 from the video link this is indeed a 46 00:01:24,540 --> 00:01:25,540 complete very thorough course so don't 47 00:01:27,119 --> 00:01:28,119 try to watch this whole thing in one 48 00:01:28,619 --> 00:01:29,619 sitting take your time take it slow and 49 00:01:30,900 --> 00:01:31,900 just focus on learning there are 50 00:01:33,000 --> 00:01:34,000 chapters for every single lecture in the 51 00:01:34,740 --> 00:01:35,740 video here's a quick overview of the 52 00:01:36,840 --> 00:01:37,840 entire course all the steps that we're 53 00:01:38,280 --> 00:01:39,280 going to take to reach the final 54 00:01:39,360 --> 00:01:40,360 published game so first of all we're 55 00:01:41,759 --> 00:01:42,759 going to start commonly from scratch by 56 00:01:43,740 --> 00:01:44,740 selecting a Unity version and creating a 57 00:01:46,020 --> 00:01:47,020 brand new project with that new project 58 00:01:48,119 --> 00:01:49,119 we will then learn all about the basics 59 00:01:50,280 --> 00:01:51,280 of the UNT interface and setup plane 60 00:01:52,140 --> 00:01:53,140 layout 61 00:01:53,040 --> 00:01:54,040 then the other important part is Visual 62 00:01:55,079 --> 00:01:56,079 Studio which is where we're going to be 63 00:01:56,460 --> 00:01:57,460 writing all of our code 64 00:01:58,020 --> 00:01:59,020 after that comes an extremely important 65 00:01:59,939 --> 00:02:00,939 lecture all about coding style and 66 00:02:01,619 --> 00:02:02,619 naming rules like I said the code in 67 00:02:03,720 --> 00:02:04,720 this course is on the same level of 68 00:02:05,100 --> 00:02:06,100 quality as my Steam games so having 69 00:02:06,840 --> 00:02:07,840 proper naming rules and good code sound 70 00:02:08,640 --> 00:02:09,640 is Paramount next we're going to 71 00:02:10,679 --> 00:02:11,679 download and import all the assets that 72 00:02:12,660 --> 00:02:13,660 we're going to use in the course 73 00:02:13,560 --> 00:02:14,560 everything is included so you can follow 74 00:02:15,660 --> 00:02:16,660 along with every step of the way 75 00:02:17,580 --> 00:02:18,580 with yes it's important we're going to 76 00:02:19,260 --> 00:02:20,260 set up some quick post processing just 77 00:02:20,940 --> 00:02:21,940 to make the game look good then for our 78 00:02:23,280 --> 00:02:24,280 first piece of logic we're going to make 79 00:02:24,720 --> 00:02:25,720 a simple character controller with that 80 00:02:27,300 --> 00:02:28,300 logic working we will then Implement a 81 00:02:29,340 --> 00:02:30,340 proper character visual with the 82 00:02:30,660 --> 00:02:31,660 included assets 83 00:02:31,980 --> 00:02:32,980 next we're going to learn the basics of 84 00:02:34,080 --> 00:02:35,080 animation and the animator component and 85 00:02:36,300 --> 00:02:37,300 with that we're going to make our player 86 00:02:37,800 --> 00:02:38,800 really Common live with some simple but 87 00:02:39,720 --> 00:02:40,720 really nice animations then we're going 88 00:02:42,000 --> 00:02:43,000 to install the send machine package this 89 00:02:44,280 --> 00:02:45,280 isn't actually used too much in this 90 00:02:45,720 --> 00:02:46,720 course but I still wanted to include it 91 00:02:47,400 --> 00:02:48,400 because it is such a useful tool so I do 92 00:02:49,560 --> 00:02:50,560 want you to know about it after that 93 00:02:51,300 --> 00:02:52,300 comes another extremely extremely 94 00:02:53,099 --> 00:02:54,099 important lecture with regards to 95 00:02:54,480 --> 00:02:55,480 writing some good link code we're going 96 00:02:56,519 --> 00:02:57,519 to do a nice refactor to replace the 97 00:02:58,860 --> 00:02:59,860 Legacy input Venture with the brand new 98 00:03:00,660 --> 00:03:01,660 input system 99 00:03:01,800 --> 00:03:02,800 learning how to refactor is an extremely 100 00:03:04,080 --> 00:03:05,080 important and very valuable skill that 101 00:03:05,879 --> 00:03:06,879 will massively improve the quality of 102 00:03:07,500 --> 00:03:08,500 your code with that then we're going to 103 00:03:09,540 --> 00:03:10,540 implement some nice Collision detection 104 00:03:11,280 --> 00:03:12,280 to make sure our character doesn't want 105 00:03:12,900 --> 00:03:13,900 through walls 106 00:03:14,159 --> 00:03:15,159 next we're going to create the very 107 00:03:16,080 --> 00:03:17,080 first kitchen counter and make a script 108 00:03:18,000 --> 00:03:19,000 to handle how to interact with it then 109 00:03:20,340 --> 00:03:21,340 we're going to learn all about c-sharp 110 00:03:22,260 --> 00:03:23,260 events and create a proper interact 111 00:03:24,180 --> 00:03:25,180 input next we're going to build a 112 00:03:26,580 --> 00:03:27,580 selected counter visual which will 113 00:03:28,140 --> 00:03:29,140 require us to learn about the extremely 114 00:03:30,060 --> 00:03:31,060 useful Singleton pattern with the 115 00:03:32,280 --> 00:03:33,280 counters working we're going to start 116 00:03:33,780 --> 00:03:34,780 working on the kitchen objects 117 00:03:35,099 --> 00:03:36,099 themselves so these are going to be the 118 00:03:37,080 --> 00:03:38,080 ingredients and the plates we're going 119 00:03:38,819 --> 00:03:39,819 to use scriptable objects to Define all 120 00:03:40,739 --> 00:03:41,739 of the types 121 00:03:41,940 --> 00:03:42,940 then a very important part of our design 122 00:03:43,920 --> 00:03:44,920 is each kitchen object will have to be 123 00:03:46,019 --> 00:03:47,019 placed somewhere so we're going to take 124 00:03:48,180 --> 00:03:49,180 some time to really think about the best 125 00:03:49,920 --> 00:03:50,920 way to achieve that all while riding 126 00:03:51,599 --> 00:03:52,599 some good clean code next we're going to 127 00:03:53,580 --> 00:03:54,580 enable the player to pick up an object 128 00:03:55,440 --> 00:03:56,440 in doing so we're going to learn about 129 00:03:57,299 --> 00:03:58,299 c-sharp interfaces then we're going to 130 00:03:59,640 --> 00:04:00,640 make a container counter this is from 131 00:04:01,680 --> 00:04:02,680 where we can spawn new objects 132 00:04:03,780 --> 00:04:04,780 with that we will enable the player to 133 00:04:05,700 --> 00:04:06,700 pick up objects and drop them anywhere 134 00:04:07,560 --> 00:04:08,560 where there's space 135 00:04:09,060 --> 00:04:10,060 then we're going to make the cutting 136 00:04:10,739 --> 00:04:11,739 counter this one enables the player to 137 00:04:12,959 --> 00:04:13,959 cut an ingredient into slices so to do 138 00:04:15,780 --> 00:04:16,780 that we're going to make an alternate 139 00:04:17,459 --> 00:04:18,459 interaction 140 00:04:18,780 --> 00:04:19,780 and for handling the cutting we're going 141 00:04:20,760 --> 00:04:21,760 to once again use script more objects to 142 00:04:22,740 --> 00:04:23,740 define a proper cutting recipe 143 00:04:24,720 --> 00:04:25,720 then we're going to learn about a really 144 00:04:26,400 --> 00:04:27,400 awesome Unity feature we're on canvases 145 00:04:28,440 --> 00:04:29,440 and use that to display a nice progress 146 00:04:30,419 --> 00:04:31,419 Bar for our cutting progress after that 147 00:04:32,699 --> 00:04:33,699 is a quick lecture just going to make a 148 00:04:35,160 --> 00:04:36,160 very useful generic script to make any 149 00:04:36,840 --> 00:04:37,840 object look at the camera 150 00:04:38,580 --> 00:04:39,580 next for another counter we're going to 151 00:04:40,560 --> 00:04:41,560 build a trash bin this is where the 152 00:04:42,419 --> 00:04:43,419 player can drop objects to destroy them 153 00:04:45,000 --> 00:04:46,000 then the stove counter this one is going 154 00:04:47,400 --> 00:04:48,400 to be quite a bit complex we're going to 155 00:04:49,560 --> 00:04:50,560 create recipes for cooking and for 156 00:04:51,660 --> 00:04:52,660 burning we're going to learn how to make 157 00:04:53,580 --> 00:04:54,580 a basic state machine and handle timers 158 00:04:55,680 --> 00:04:56,680 next we're going to make the plates 159 00:04:57,660 --> 00:04:58,660 counter this is a simple encounter that 160 00:04:59,699 --> 00:05:00,699 just spawns a bunch of plates 161 00:05:01,440 --> 00:05:02,440 after that we're going to make some 162 00:05:03,060 --> 00:05:04,060 custom Logic on the plate to be able to 163 00:05:04,740 --> 00:05:05,740 hold other objects 164 00:05:06,479 --> 00:05:07,479 with that logic working we're going to 165 00:05:08,100 --> 00:05:09,100 build a complete visual for all the 166 00:05:09,840 --> 00:05:10,840 objects that can exist on the plate 167 00:05:11,759 --> 00:05:12,759 then make a nice UI element on the plane 168 00:05:14,220 --> 00:05:15,220 itself to showcase the icons of what 169 00:05:16,440 --> 00:05:17,440 exactly is on that plate afterwards 170 00:05:18,900 --> 00:05:19,900 we're going to make the very last 171 00:05:20,160 --> 00:05:21,160 counter the delivery counter this is 172 00:05:22,320 --> 00:05:23,320 where we drop the completed plates and 173 00:05:24,780 --> 00:05:25,780 in this lecture we're also going to 174 00:05:26,100 --> 00:05:27,100 learn about the unity share graph and 175 00:05:27,840 --> 00:05:28,840 make a quick simple custom Shader 176 00:05:30,120 --> 00:05:31,120 then we're going to build the delivering 177 00:05:31,919 --> 00:05:32,919 manager class that generates the recipes 178 00:05:33,600 --> 00:05:34,600 that the customers are requesting next 179 00:05:36,060 --> 00:05:37,060 we're going to build a UI to showcase 180 00:05:38,220 --> 00:05:39,220 the wedding recipes after that comes 181 00:05:40,680 --> 00:05:41,680 something pretty crucial we're going to 182 00:05:42,060 --> 00:05:43,060 add some music and then add some sound 183 00:05:44,460 --> 00:05:45,460 effects for all kinds of game actions 184 00:05:47,100 --> 00:05:48,100 without the game won't be almost done so 185 00:05:49,500 --> 00:05:50,500 next we're going to build a proper game 186 00:05:51,240 --> 00:05:52,240 start and a game end 187 00:05:52,800 --> 00:05:53,800 then make a simple main menu and handle 188 00:05:55,259 --> 00:05:56,259 scene loading after that hand on 189 00:05:57,539 --> 00:05:58,539 creating a basic pause window 190 00:05:59,699 --> 00:06:00,699 then make an options menu enable the 191 00:06:02,039 --> 00:06:03,039 player to modify the audio levels and 192 00:06:03,900 --> 00:06:04,900 rebound keys 193 00:06:05,280 --> 00:06:06,280 after that we're going to enable menu 194 00:06:07,080 --> 00:06:08,080 navigation with a controller and in the 195 00:06:09,539 --> 00:06:10,539 end as usual comes the Polish stage so 196 00:06:11,639 --> 00:06:12,639 we're going to add all kinds of small 197 00:06:13,080 --> 00:06:14,080 tweaks and effects to make the game feel 198 00:06:14,880 --> 00:06:15,880 really great like I've said many times 199 00:06:16,800 --> 00:06:17,800 polish is what separates good games from 200 00:06:18,600 --> 00:06:19,600 great games after all of that we will 201 00:06:20,759 --> 00:06:21,759 have our final completed project so as 202 00:06:22,979 --> 00:06:23,979 you can see you will learn about tons of 203 00:06:24,720 --> 00:06:25,720 Topics by following this course also let 204 00:06:27,180 --> 00:06:28,180 me point out one of the reasons why I 205 00:06:28,979 --> 00:06:29,979 chose this specific design is because my 206 00:06:31,319 --> 00:06:32,319 next free course won't be on taking the 207 00:06:33,000 --> 00:06:34,000 game that we're going to build here and 208 00:06:34,319 --> 00:06:35,319 make it multiplayer so if you've ever 209 00:06:36,300 --> 00:06:37,300 wanted to make multiplayer games then 210 00:06:37,800 --> 00:06:38,800 that course will be excellent for you 211 00:06:39,360 --> 00:06:40,360 definitely take your time following this 212 00:06:41,400 --> 00:06:42,400 course the multiplayer free course 213 00:06:42,840 --> 00:06:43,840 should hopefully be out next month or if 214 00:06:44,940 --> 00:06:45,940 you're watching this in the future check 215 00:06:46,319 --> 00:06:47,319 the links in description although that 216 00:06:48,240 --> 00:06:49,240 multiplayer video won't be starting from 217 00:06:49,800 --> 00:06:50,800 where this course ends so definitely 218 00:06:51,360 --> 00:06:52,360 make sure you watch this one now if you 219 00:06:53,520 --> 00:06:54,520 are new to the channel then welcome and 220 00:06:55,440 --> 00:06:56,440 here's a bit about me and my credentials 221 00:06:57,300 --> 00:06:58,300 or why you shouldn't listen to what I 222 00:06:59,160 --> 00:07:00,160 have to teach 223 00:07:00,180 --> 00:07:01,180 my name is Hugo and I've been running 224 00:07:01,860 --> 00:07:02,860 this Code Monkey YouTube channel for 225 00:07:03,539 --> 00:07:04,539 five years now in total almost 700 226 00:07:06,180 --> 00:07:07,180 videos on all kinds of topics including 227 00:07:08,340 --> 00:07:09,340 tons of tutorials sharing my knowledge 228 00:07:10,080 --> 00:07:11,080 to help you on your Game Dev Journey I'm 229 00:07:12,479 --> 00:07:13,479 also a professional indie game developer 230 00:07:14,100 --> 00:07:15,100 making games for over 10 years with 8 231 00:07:16,139 --> 00:07:17,139 successful Games published on scene so 232 00:07:18,419 --> 00:07:19,419 what I'm teaching here is based on a lot 233 00:07:19,979 --> 00:07:20,979 of years of experience making a lot of 234 00:07:21,599 --> 00:07:22,599 games just like with my paid courses I'm 235 00:07:23,940 --> 00:07:24,940 always going to be in the common 236 00:07:24,840 --> 00:07:25,840 censoring questions so if you get stuck 237 00:07:27,000 --> 00:07:28,000 at a particular point or need extra 238 00:07:28,680 --> 00:07:29,680 clarification on something go ahead post 239 00:07:31,139 --> 00:07:32,139 a comment and I'll do my best to help do 240 00:07:33,000 --> 00:07:34,000 make sure you include a timestamp of 241 00:07:34,740 --> 00:07:35,740 what you're referring to I will also be 242 00:07:36,840 --> 00:07:37,840 updating the pin comment with any 243 00:07:38,580 --> 00:07:39,580 frequently asked questions that I see so 244 00:07:40,800 --> 00:07:41,800 actually right now go ahead pause the 245 00:07:42,240 --> 00:07:43,240 video and scroll down a bit just to look 246 00:07:43,620 --> 00:07:44,620 at that comment since on YouTube I 247 00:07:45,780 --> 00:07:46,780 cannot update the video after it's 248 00:07:47,160 --> 00:07:48,160 published I will be updating that 249 00:07:48,720 --> 00:07:49,720 comment over the next months and years 250 00:07:50,039 --> 00:07:51,039 with anything that comes up also I've 251 00:07:52,259 --> 00:07:53,259 been running this channel for five years 252 00:07:53,880 --> 00:07:54,880 and in that time I've made almost 700 253 00:07:55,860 --> 00:07:56,860 videos so there's lots of topics that 254 00:07:58,259 --> 00:07:59,259 I've covered separately in more detail 255 00:07:59,759 --> 00:08:00,759 all of those videos are linked in the 256 00:08:01,680 --> 00:08:02,680 description throughout this course I 257 00:08:03,599 --> 00:08:04,599 will be focused on building this 258 00:08:04,919 --> 00:08:05,919 specific game using whatever it takes to 259 00:08:06,720 --> 00:08:07,720 build it meaning for example when we get 260 00:08:08,880 --> 00:08:09,880 to using c-sharp events I won't teach 261 00:08:10,620 --> 00:08:11,620 the basics about how they work in order 262 00:08:12,360 --> 00:08:13,360 to achieve what we want to build but if 263 00:08:14,340 --> 00:08:15,340 you then want to learn about c-sharp 264 00:08:15,900 --> 00:08:16,900 events in more detail definitely go 265 00:08:17,520 --> 00:08:18,520 watch a dedicated video and I also made 266 00:08:19,680 --> 00:08:20,680 a page on my website for this course it 267 00:08:22,199 --> 00:08:23,199 contains a link to download all of the 268 00:08:23,819 --> 00:08:24,819 project assets you can also download the 269 00:08:26,160 --> 00:08:27,160 complete project files for every single 270 00:08:27,960 --> 00:08:28,960 lecture so if you get stuck at any point 271 00:08:30,240 --> 00:08:31,240 you can download the code at that 272 00:08:31,860 --> 00:08:32,860 lecture and compare with your own 273 00:08:33,419 --> 00:08:34,419 there's also references to all of the 274 00:08:35,580 --> 00:08:36,580 videos and I will also be including 275 00:08:37,320 --> 00:08:38,320 frequently asked questions for each 276 00:08:38,820 --> 00:08:39,820 lecture so definitely keep that page 277 00:08:41,219 --> 00:08:42,219 open in a second tab as you follow along 278 00:08:43,080 --> 00:08:44,080 this course now this free course Took a 279 00:08:45,600 --> 00:08:46,600 ton of work to make so I really hope you 280 00:08:47,160 --> 00:08:48,160 find this video helpful go ahead and hit 281 00:08:49,140 --> 00:08:50,140 the like button if it helps you it's a 282 00:08:51,300 --> 00:08:52,300 small thing but it generally does help 283 00:08:52,740 --> 00:08:53,740 this video on the YouTube algorithm 284 00:08:54,240 --> 00:08:55,240 making this course was a ton of work and 285 00:08:56,459 --> 00:08:57,459 by making it commonly free it means it 286 00:08:58,320 --> 00:08:59,320 will obviously never make as much money 287 00:08:59,820 --> 00:09:00,820 as if I had just made this a paid course 288 00:09:01,920 --> 00:09:02,920 I'm personally okay with that decision 289 00:09:03,959 --> 00:09:04,959 with the hopes that by making it free it 290 00:09:05,700 --> 00:09:06,700 won't reach and help many more people 291 00:09:07,320 --> 00:09:08,320 I'm also a big believer that education 292 00:09:09,839 --> 00:09:10,839 should be free so if you can't afford 293 00:09:11,820 --> 00:09:12,820 one of my paid courses like if you're 294 00:09:13,680 --> 00:09:14,680 just a kid or going through a rough time 295 00:09:15,300 --> 00:09:16,300 I still want you to have access to high 296 00:09:17,339 --> 00:09:18,339 quality education so you can achieve 297 00:09:19,019 --> 00:09:20,019 your Game Dev dreams one easy way you 298 00:09:21,120 --> 00:09:22,120 can help me for free is simply by liking 299 00:09:23,100 --> 00:09:24,100 this video subscribing to the channel 300 00:09:24,480 --> 00:09:25,480 and just watching this course 301 00:09:26,279 --> 00:09:27,279 that will hopefully help push this video 302 00:09:28,200 --> 00:09:29,200 on the YouTube algorithm and help it 303 00:09:29,880 --> 00:09:30,880 reach many more people another free way 304 00:09:32,220 --> 00:09:33,220 to support what I do is I'm currently 305 00:09:33,959 --> 00:09:34,959 working on my next team game called turn 306 00:09:35,640 --> 00:09:36,640 one Liberation you can wish list the 307 00:09:37,920 --> 00:09:38,920 game on Steam wishlists matter a lot for 308 00:09:40,140 --> 00:09:41,140 steam visibility so just by doing that 309 00:09:42,000 --> 00:09:43,000 you won't be helping me and just in case 310 00:09:44,279 --> 00:09:45,279 you can't afford it and you find this 311 00:09:46,080 --> 00:09:47,080 free course useful you can also support 312 00:09:47,760 --> 00:09:48,760 what I do in a few other ways I spent a 313 00:09:50,220 --> 00:09:51,220 bunch of money making this course I 314 00:09:51,660 --> 00:09:52,660 hired an artist for the 3D assets so 315 00:09:53,640 --> 00:09:54,640 that I had the right to distribute them 316 00:09:55,080 --> 00:09:56,080 so that you can download it and follow 317 00:09:56,580 --> 00:09:57,580 along 318 00:09:57,420 --> 00:09:58,420 same thing for the music and sound 319 00:09:59,040 --> 00:10:00,040 effects the logo and the cost to upload 320 00:10:01,200 --> 00:10:02,200 the game to seem so I would like to at 321 00:10:03,420 --> 00:10:04,420 least not lose money on this project 322 00:10:04,760 --> 00:10:05,760 hopefully there's enough of you who 323 00:10:06,959 --> 00:10:07,959 can't afford to help me so that I can at 324 00:10:08,459 --> 00:10:09,459 least break even 325 00:10:09,660 --> 00:10:10,660 and for one way you can support is I 326 00:10:11,760 --> 00:10:12,760 added this exact same course on my 327 00:10:13,560 --> 00:10:14,560 website as a regular paid course 328 00:10:15,000 --> 00:10:16,000 although I want to be very very clear 329 00:10:17,279 --> 00:10:18,279 there is absolutely no difference 330 00:10:19,200 --> 00:10:20,200 between this free video and the paid 331 00:10:20,940 --> 00:10:21,940 course there is absolutely nothing 332 00:10:22,860 --> 00:10:23,860 behind any kind of payroll all of the 333 00:10:25,320 --> 00:10:26,320 lectures are free all of the apps are 334 00:10:27,000 --> 00:10:28,000 free everything is free you don't have 335 00:10:28,980 --> 00:10:29,980 to pay for anything if you can't afford 336 00:10:30,839 --> 00:10:31,839 it or you just don't want to the paid 337 00:10:32,940 --> 00:10:33,940 version is essentially a donation the 338 00:10:35,160 --> 00:10:36,160 only difference is this free YouTube 339 00:10:36,480 --> 00:10:37,480 video has regular YouTube ads whereas 340 00:10:38,580 --> 00:10:39,580 the paid version on the website doesn't 341 00:10:40,019 --> 00:10:41,019 have any ads that's it that's the only 342 00:10:42,240 --> 00:10:43,240 thing so the only reason why I made that 343 00:10:44,399 --> 00:10:45,399 paid version is just in case some of you 344 00:10:46,500 --> 00:10:47,500 can't afford it and you want to support 345 00:10:48,060 --> 00:10:49,060 what I do and want to help me break even 346 00:10:49,860 --> 00:10:50,860 on this project but again only do that 347 00:10:52,200 --> 00:10:53,200 if you can't afford them if you can't 348 00:10:53,940 --> 00:10:54,940 that's personally fine I hope you'll 349 00:10:55,860 --> 00:10:56,860 learn a ton from watching and following 350 00:10:57,540 --> 00:10:58,540 this free course beyond that if you 351 00:10:59,640 --> 00:11:00,640 follow this course and you enjoy my 352 00:11:01,019 --> 00:11:02,019 teaching sound perhaps look into my 353 00:11:02,700 --> 00:11:03,700 other courses if you like this video 354 00:11:04,560 --> 00:11:05,560 then I think you won't really like my 355 00:11:06,180 --> 00:11:07,180 turn-based strategy course that is the 356 00:11:08,399 --> 00:11:09,399 perfect course to follow up on this one 357 00:11:09,540 --> 00:11:10,540 one it Dives even deeper into some of 358 00:11:12,300 --> 00:11:13,300 the concepts used here and it will help 359 00:11:13,980 --> 00:11:14,980 you make the jump from beginner to 360 00:11:15,300 --> 00:11:16,300 Advanced and since you're interested in 361 00:11:17,459 --> 00:11:18,459 unity I think my ultimate unity overview 362 00:11:19,560 --> 00:11:20,560 course would also be very useful to you 363 00:11:21,839 --> 00:11:22,839 each lecture on that course is focused 364 00:11:23,640 --> 00:11:24,640 on teaching one entitled feature there's 365 00:11:25,980 --> 00:11:26,980 already over 15 lectures including 366 00:11:27,899 --> 00:11:28,899 plenty of small but very important 367 00:11:29,640 --> 00:11:30,640 things that you just wouldn't see in a 368 00:11:31,320 --> 00:11:32,320 regular YouTube video if you're 369 00:11:32,880 --> 00:11:33,880 interested in visual scripting I have 370 00:11:34,260 --> 00:11:35,260 course on making three unique games 371 00:11:35,700 --> 00:11:36,700 internally with visual scripting and no 372 00:11:37,500 --> 00:11:38,500 code at all or if you prefer code you 373 00:11:40,019 --> 00:11:41,019 can learn how to build a nice Builder 374 00:11:41,459 --> 00:11:42,459 Defender game so if you enjoy my 375 00:11:43,200 --> 00:11:44,200 teaching Style on this free course then 376 00:11:44,700 --> 00:11:45,700 check out my other ones then of course 377 00:11:46,620 --> 00:11:47,620 YouTube has Channel memberships and 378 00:11:48,420 --> 00:11:49,420 super thanks so you can use those if you 379 00:11:50,279 --> 00:11:51,279 want I also have my patreon if you 380 00:11:52,500 --> 00:11:53,500 prefer that and in a lot of my videos I 381 00:11:55,079 --> 00:11:56,079 have some affiliate links if you ever 382 00:11:56,640 --> 00:11:57,640 pick up anything through those I get a 383 00:11:58,320 --> 00:11:59,320 nice commission and I also have some of 384 00:12:00,420 --> 00:12:01,420 my own assets on the unity Astor so if 385 00:12:02,820 --> 00:12:03,820 you enjoy this free course and you want 386 00:12:04,320 --> 00:12:05,320 to support what I do there's plenty of 387 00:12:05,760 --> 00:12:06,760 ways but again don't feel obligated if 388 00:12:08,459 --> 00:12:09,459 you can't afford it or you just don't 389 00:12:09,839 --> 00:12:10,839 want to that's perfectly fine I hope 390 00:12:11,940 --> 00:12:12,940 you'll learn a ton from watching and 391 00:12:13,440 --> 00:12:14,440 following this recourse alright so 392 00:12:15,420 --> 00:12:16,420 that's enough talk of that for now 393 00:12:16,800 --> 00:12:17,800 before we begin building the game from 394 00:12:19,019 --> 00:12:20,019 scratch let's inspect the final polish 395 00:12:21,300 --> 00:12:22,300 game that we're going to build so let's 396 00:12:22,860 --> 00:12:23,860 see that in the next lecture 397 00:12:25,019 --> 00:12:26,019 hello and welcome I'm your code monkey 398 00:12:27,019 --> 00:12:28,019 here let's take a look at the final game 399 00:12:29,640 --> 00:12:30,640 that we're going to build so we start 400 00:12:31,380 --> 00:12:32,380 off on a simple but really nice main 401 00:12:33,120 --> 00:12:34,120 menu so we've got a nice visual a nice 402 00:12:35,579 --> 00:12:36,579 logo and a bunch of useful buttons then 403 00:12:37,920 --> 00:12:38,920 of course the game has a nice loading 404 00:12:39,480 --> 00:12:40,480 system so when I click on play it's 405 00:12:40,920 --> 00:12:41,920 going to load into a unloading scene and 406 00:12:42,660 --> 00:12:43,660 then funnel into the final game scene so 407 00:12:44,639 --> 00:12:45,639 let's go ahead and play and if there we 408 00:12:46,500 --> 00:12:47,500 go here we do see the game scene and 409 00:12:48,360 --> 00:12:49,360 right away we see a nice internal window 410 00:12:50,160 --> 00:12:51,160 so it's telling us how to play the game 411 00:12:52,200 --> 00:12:53,200 so the basic interactions and then over 412 00:12:54,120 --> 00:12:55,120 here the controls importantly these are 413 00:12:56,339 --> 00:12:57,339 all rebindable so over here this element 414 00:12:58,139 --> 00:12:59,139 is all Dynamic then we can look at this 415 00:13:00,540 --> 00:13:01,540 tutorial for as long as we want and we 416 00:13:02,100 --> 00:13:03,100 are waiting for the interact to continue 417 00:13:03,480 --> 00:13:04,480 there's also a really nice song playing 418 00:13:05,459 --> 00:13:06,459 in the background so the game has music 419 00:13:07,019 --> 00:13:08,019 now we can look at this tutorial for as 420 00:13:09,000 --> 00:13:10,000 long as we want and when we're ready we 421 00:13:10,620 --> 00:13:11,620 can interact and continue and as soon as 422 00:13:12,660 --> 00:13:13,660 we do if there you go we've got a nice 423 00:13:14,760 --> 00:13:15,760 countdown some nice animations a nice 424 00:13:16,380 --> 00:13:17,380 sound effect and there you go now we are 425 00:13:17,760 --> 00:13:18,760 playing okay so here I am controlling a 426 00:13:19,980 --> 00:13:20,980 nice character I can move in any 427 00:13:21,959 --> 00:13:22,959 direction 428 00:13:23,100 --> 00:13:24,100 there is Collision detection so 429 00:13:24,660 --> 00:13:25,660 obviously I cannot go inside solid 430 00:13:26,399 --> 00:13:27,399 objects so I can walk around and for the 431 00:13:28,560 --> 00:13:29,560 goal of the game over here on the left 432 00:13:29,820 --> 00:13:30,820 side we've got recipes that the 433 00:13:31,200 --> 00:13:32,200 customers are waiting for so for example 434 00:13:33,060 --> 00:13:34,060 One customer wants a simple Burger so 435 00:13:35,399 --> 00:13:36,399 for that we gonna need to pick up a nice 436 00:13:37,620 --> 00:13:38,620 bun so let's pick it up then the burger 437 00:13:39,720 --> 00:13:40,720 obviously requires a meat Patty so let's 438 00:13:41,579 --> 00:13:42,579 go ahead we can pick one up from here 439 00:13:43,139 --> 00:13:44,139 but this one is an uncooked meat padding 440 00:13:45,060 --> 00:13:46,060 so we need to drop it over here on the 441 00:13:46,740 --> 00:13:47,740 stove and there you go it starts cooking 442 00:13:48,540 --> 00:13:49,540 we've got a nice timer we've got a nice 443 00:13:50,339 --> 00:13:51,339 warm bar UI 444 00:13:51,839 --> 00:13:52,839 and there you go it keeps counting and 445 00:13:53,940 --> 00:13:54,940 we've got some nice park on some nice 446 00:13:55,380 --> 00:13:56,380 visuals and over there even a nice 447 00:13:56,820 --> 00:13:57,820 indicator telling us the meat is about 448 00:13:58,260 --> 00:13:59,260 to burn and there you go the meat has 449 00:13:59,940 --> 00:14:00,940 burned so now I can pick this up and I'm 450 00:14:02,339 --> 00:14:03,339 holding some burnt meat so the customer 451 00:14:03,959 --> 00:14:04,959 probably doesn't want to eat this so we 452 00:14:06,060 --> 00:14:07,060 can go over here to the trash or trash 453 00:14:07,740 --> 00:14:08,740 it let's try doing another one and do it 454 00:14:09,779 --> 00:14:10,779 properly so let's wait for it to cook 455 00:14:11,459 --> 00:14:12,459 pick up a plate so we can pick it up 456 00:14:13,380 --> 00:14:14,380 directly onto the plate there you go to 457 00:14:14,940 --> 00:14:15,940 the meat is cooked so let's pick it up 458 00:14:16,139 --> 00:14:17,139 then go pick up some bread and there you 459 00:14:18,360 --> 00:14:19,360 go here we have our camelli recipe so 460 00:14:20,579 --> 00:14:21,579 let's go into the delivery counter 461 00:14:21,839 --> 00:14:22,839 deliver it and there you go a nice 462 00:14:23,519 --> 00:14:24,519 delivery success all right awesome we've 463 00:14:26,040 --> 00:14:27,040 just delivered our first recipe so then 464 00:14:28,560 --> 00:14:29,560 someone else wants a salad so let's go 465 00:14:30,240 --> 00:14:31,240 ahead pick up a tomato here we have a 466 00:14:32,459 --> 00:14:33,459 big uncut tomato so let's drop it onto a 467 00:14:34,860 --> 00:14:35,860 cutting board and now we can interact 468 00:14:37,019 --> 00:14:38,019 with it so we can interact with a 469 00:14:38,700 --> 00:14:39,700 secondary interaction key 470 00:14:40,380 --> 00:14:41,380 and by interacting we cut the tomatoes 471 00:14:42,779 --> 00:14:43,779 so it takes a few cuts and there you go 472 00:14:44,220 --> 00:14:45,220 with slices and it's sliced into tomato 473 00:14:46,019 --> 00:14:47,019 slices so let's do the same thing for 474 00:14:48,000 --> 00:14:49,000 the Cabbage here we are holding a 475 00:14:50,160 --> 00:14:51,160 regular cabbage then slice it and this 476 00:14:52,019 --> 00:14:53,019 one actually takes a bunch more and 477 00:14:53,820 --> 00:14:54,820 there you go got both slices okay great 478 00:14:55,860 --> 00:14:56,860 so now let's pick up the plate pick up 479 00:14:58,019 --> 00:14:59,019 both slices and deliver to the customer 480 00:14:59,639 --> 00:15:00,639 and there you go got a nice success all 481 00:15:01,860 --> 00:15:02,860 right awesome and of course we have a 482 00:15:04,139 --> 00:15:05,139 correct identification of if we have a 483 00:15:06,360 --> 00:15:07,360 crack recipe or not 484 00:15:07,860 --> 00:15:08,860 so if I just pick up an empty plate and 485 00:15:10,079 --> 00:15:11,079 deliver it there you go got a film 486 00:15:11,639 --> 00:15:12,639 delivery because nobody wants just an 487 00:15:13,199 --> 00:15:14,199 empty plate alright so here you can 488 00:15:15,060 --> 00:15:16,060 already see quite a lot of interactions 489 00:15:16,500 --> 00:15:17,500 quite a lot of systems at work so the 490 00:15:18,600 --> 00:15:19,600 character has a nice character 491 00:15:19,920 --> 00:15:20,920 controller it has physics interaction 492 00:15:21,660 --> 00:15:22,660 you can see how it identifies the 493 00:15:23,579 --> 00:15:24,579 counter that is in from the character I 494 00:15:25,440 --> 00:15:26,440 can press a button to interact with the 495 00:15:26,880 --> 00:15:27,880 counter and interacting with different 496 00:15:28,199 --> 00:15:29,199 counters does different things so if I 497 00:15:30,240 --> 00:15:31,240 interact with a clear counter I can pick 498 00:15:31,680 --> 00:15:32,680 up or drop things over here I can pick 499 00:15:33,779 --> 00:15:34,779 up drop it with an alternate interaction 500 00:15:35,820 --> 00:15:36,820 I can do the second action then there's 501 00:15:38,279 --> 00:15:39,279 the stove machine so that one has a nice 502 00:15:40,380 --> 00:15:41,380 State machine so it counts up over here 503 00:15:42,540 --> 00:15:43,540 we've got some nice particles we've got 504 00:15:44,100 --> 00:15:45,100 a nice Bloom so all the Visions look 505 00:15:45,779 --> 00:15:46,779 really great so we've got some post 506 00:15:46,920 --> 00:15:47,920 processing we have a bunch of UI 507 00:15:48,959 --> 00:15:49,959 elements directly on the world and 508 00:15:50,880 --> 00:15:51,880 outside of here we've got some regular 509 00:15:52,320 --> 00:15:53,320 UI elements 510 00:15:53,639 --> 00:15:54,639 so we've got the recipes with Dynamic 511 00:15:55,560 --> 00:15:56,560 icons for all of them we've got a timer 512 00:15:57,839 --> 00:15:58,839 over there on the top right corner 513 00:15:59,279 --> 00:16:00,279 showing how long we have to deliver on 514 00:16:01,019 --> 00:16:02,019 our recipes and on the kitchen counter 515 00:16:03,060 --> 00:16:04,060 we're also using a custom Shader so this 516 00:16:04,740 --> 00:16:05,740 was built using shade wrap so as you can 517 00:16:06,959 --> 00:16:07,959 see lots of internalized systems then 518 00:16:09,120 --> 00:16:10,120 the game also has of course the basics 519 00:16:10,680 --> 00:16:11,680 that any game should have so I can pause 520 00:16:13,019 --> 00:16:14,019 the game and there you go we've got a 521 00:16:14,639 --> 00:16:15,639 nice pause menu so we can resume to go 522 00:16:16,500 --> 00:16:17,500 back or pause it again and of course 523 00:16:18,120 --> 00:16:19,120 while pause everything is possible 524 00:16:19,440 --> 00:16:20,440 that's great we can go back into the 525 00:16:21,660 --> 00:16:22,660 main menu or we can go into options and 526 00:16:24,000 --> 00:16:25,000 over here we can play around the sound 527 00:16:25,560 --> 00:16:26,560 effects volume the Music Volume we've 528 00:16:27,660 --> 00:16:28,660 got all of our controls importantly 529 00:16:29,639 --> 00:16:30,639 these are the controls for the keyboard 530 00:16:31,260 --> 00:16:32,260 and also the GamePad 531 00:16:33,360 --> 00:16:34,360 so the game can be played with any 532 00:16:35,040 --> 00:16:36,040 Gamepad so it can be an Xbox controller 533 00:16:37,139 --> 00:16:38,139 PlayStation switch controller it doesn't 534 00:16:38,820 --> 00:16:39,820 matter all of them work and we can also 535 00:16:41,279 --> 00:16:42,279 rebind all these Keys both the keys as 536 00:16:43,620 --> 00:16:44,620 well as the GamePad inputs so let's go 537 00:16:45,899 --> 00:16:46,899 ahead and deliver a cheeseburger so 538 00:16:47,220 --> 00:16:48,220 here's some burn meat so let's toss this 539 00:16:48,899 --> 00:16:49,899 then pick up some more meat pick up a 540 00:16:51,360 --> 00:16:52,360 plate here we've got some cheese we've 541 00:16:53,639 --> 00:16:54,639 got some bread pick up the meat and 542 00:16:55,920 --> 00:16:56,920 deliver it all right awesome and of 543 00:16:58,380 --> 00:16:59,380 course finally at the end when our 544 00:17:00,000 --> 00:17:01,000 timers left here we have a nice game 545 00:17:01,920 --> 00:17:02,920 over window showing how many recipes we 546 00:17:03,899 --> 00:17:04,899 delivered alright so this is the final 547 00:17:06,179 --> 00:17:07,179 game that we're going to build as you 548 00:17:07,799 --> 00:17:08,799 can see it involves lots of interesting 549 00:17:09,360 --> 00:17:10,360 interactions which require learning lots 550 00:17:11,220 --> 00:17:12,220 of different skills we're going to be 551 00:17:13,020 --> 00:17:14,020 using c-sharp interfaces c-sharp events 552 00:17:15,179 --> 00:17:16,179 the new input system shade graphs 553 00:17:16,919 --> 00:17:17,919 critical objects we're going to learn 554 00:17:18,959 --> 00:17:19,959 about c-sharp events making character 555 00:17:20,400 --> 00:17:21,400 controller handle collisions and so on 556 00:17:22,319 --> 00:17:23,319 like I said one thing that we're going 557 00:17:24,120 --> 00:17:25,120 to focus heavily throughout the making 558 00:17:25,559 --> 00:17:26,559 of this game is on writing good clean 559 00:17:27,179 --> 00:17:28,179 code meaning that the final game that 560 00:17:29,400 --> 00:17:30,400 we're going to build won't be very easy 561 00:17:30,780 --> 00:17:31,780 to expand upon thanks to how long the 562 00:17:33,480 --> 00:17:34,480 code is very clean it will be very easy 563 00:17:35,160 --> 00:17:36,160 to add more recipes maybe more counters 564 00:17:37,200 --> 00:17:38,200 with more actions maybe things like 565 00:17:38,940 --> 00:17:39,940 perhaps washing dishes adding an oven 566 00:17:40,620 --> 00:17:41,620 and so on or really you could make 567 00:17:42,660 --> 00:17:43,660 something completely different 568 00:17:44,220 --> 00:17:45,220 this game is all about character and 569 00:17:46,020 --> 00:17:47,020 interactions 570 00:17:47,220 --> 00:17:48,220 so that could be whatever you want you 571 00:17:49,320 --> 00:17:50,320 could take this as a base and build some 572 00:17:51,120 --> 00:17:52,120 kind of sci-fi game something like Among 573 00:17:53,160 --> 00:17:54,160 Us or FTL you could make a survival 574 00:17:55,559 --> 00:17:56,559 crafting game like rust or Minecraft or 575 00:17:57,960 --> 00:17:58,960 Don't Starve really fun learning how to 576 00:18:00,120 --> 00:18:01,120 build this game by the end you won't 577 00:18:01,559 --> 00:18:02,559 have gained the knowledge required to 578 00:18:03,000 --> 00:18:04,000 build all kinds of unique and 579 00:18:04,260 --> 00:18:05,260 interesting games alright so now that 580 00:18:06,240 --> 00:18:07,240 we've seen the final game Let's actually 581 00:18:07,679 --> 00:18:08,679 build it just before we do let's get a 582 00:18:09,900 --> 00:18:10,900 quick refresher of the absolute Basics 583 00:18:11,520 --> 00:18:12,520 you should know in the next lecture 584 00:18:13,980 --> 00:18:14,980 hello and welcome I'm your code monkey 585 00:18:15,900 --> 00:18:16,900 in this lecture we're going to just get 586 00:18:18,299 --> 00:18:19,299 a quick refresher of the absolute Basics 587 00:18:20,220 --> 00:18:21,220 you should know in order to be able to 588 00:18:21,660 --> 00:18:22,660 follow everything in this course okay so 589 00:18:24,240 --> 00:18:25,240 like I said this free course is targeted 590 00:18:26,160 --> 00:18:27,160 at both beginners and more intermediate 591 00:18:28,080 --> 00:18:29,080 users in order to start following the 592 00:18:30,120 --> 00:18:31,120 course you really only need to know the 593 00:18:31,559 --> 00:18:32,559 absolute Basics I've made three useful 594 00:18:33,900 --> 00:18:34,900 videos with all of the basic knowledge 595 00:18:35,520 --> 00:18:36,520 required to follow this course 596 00:18:37,380 --> 00:18:38,380 watch the video on how to download 597 00:18:39,179 --> 00:18:40,179 install and set up Unity then the quick 598 00:18:41,940 --> 00:18:42,940 Unity Basics and the c-sharp basics 599 00:18:44,000 --> 00:18:45,000 those three Quick videos contain all of 600 00:18:46,620 --> 00:18:47,620 the absolute basic knowledge you need so 601 00:18:48,660 --> 00:18:49,660 if you're a complete beginner go ahead 602 00:18:50,220 --> 00:18:51,220 pause this video and go quickly watch 603 00:18:51,960 --> 00:18:52,960 those and even if you are already 604 00:18:53,880 --> 00:18:54,880 somewhat familiar with unity still go 605 00:18:55,799 --> 00:18:56,799 ahead and give those videos a watch 606 00:18:57,000 --> 00:18:58,000 perhaps in a faster speed just so you 607 00:18:59,160 --> 00:19:00,160 know everything that this course assumes 608 00:19:00,780 --> 00:19:01,780 that you know here I will assume that 609 00:19:02,940 --> 00:19:03,940 you know the basics covered in those 610 00:19:04,380 --> 00:19:05,380 videos like what is a game object what 611 00:19:06,419 --> 00:19:07,419 is a transform what is a mono Behavior 612 00:19:08,220 --> 00:19:09,220 how scripts have a start and update and 613 00:19:10,740 --> 00:19:11,740 some c-sharp Basics as long as you know 614 00:19:12,840 --> 00:19:13,840 those absolute Basics you should be able 615 00:19:14,580 --> 00:19:15,580 to follow everything in this course I 616 00:19:16,440 --> 00:19:17,440 won't teach everything above the 617 00:19:17,940 --> 00:19:18,940 absolute Basics and if you are a more 618 00:19:20,160 --> 00:19:21,160 advanced users definitely keep watching 619 00:19:21,840 --> 00:19:22,840 the beginning of this course might not 620 00:19:23,760 --> 00:19:24,760 have much that is new to you but as we 621 00:19:25,860 --> 00:19:26,860 build the game and start using more 622 00:19:27,299 --> 00:19:28,299 advanced tools like script of objects 623 00:19:29,160 --> 00:19:30,160 c-sharp events and interfaces 624 00:19:30,679 --> 00:19:31,679 refactoring code and focusing on Project 625 00:19:32,880 --> 00:19:33,880 architecture and writing some good clean 626 00:19:34,679 --> 00:19:35,679 code 627 00:19:35,580 --> 00:19:36,580 if you are not a complete beginner you 628 00:19:37,440 --> 00:19:38,440 will still learn quite a lot from seeing 629 00:19:38,940 --> 00:19:39,940 how this project is built and again like 630 00:19:41,220 --> 00:19:42,220 I said I answer comments every single 631 00:19:42,900 --> 00:19:43,900 day so any questions you have just post 632 00:19:45,179 --> 00:19:46,179 them there and I'll do my best to help 633 00:19:46,740 --> 00:19:47,740 this course is split into lectures they 634 00:19:49,140 --> 00:19:50,140 are all as chapters on videos so you can 635 00:19:51,000 --> 00:19:52,000 navigate around let me also take this 636 00:19:53,340 --> 00:19:54,340 time to point out that you are not 637 00:19:54,840 --> 00:19:55,840 expected to follow this course in one 638 00:19:56,340 --> 00:19:57,340 sitting go ahead and take your time 639 00:19:58,380 --> 00:19:59,380 focus on actually learning remember 640 00:20:00,539 --> 00:20:01,539 that's the only goal you're not 641 00:20:02,760 --> 00:20:03,760 competing with anyone you're gaining 642 00:20:04,380 --> 00:20:05,380 knowledge just for yourself 643 00:20:05,940 --> 00:20:06,940 so take as much time as you need 644 00:20:07,740 --> 00:20:08,740 re-watch some lectures if you feel you 645 00:20:09,720 --> 00:20:10,720 didn't fully get it or just ask some 646 00:20:11,340 --> 00:20:12,340 questions whatever you do take your time 647 00:20:13,559 --> 00:20:14,559 and just focus on actually learning so 648 00:20:15,960 --> 00:20:16,960 again if you haven't done so go ahead 649 00:20:17,580 --> 00:20:18,580 pause this video and go watch those 650 00:20:19,200 --> 00:20:20,200 three Basics videos with that we're 651 00:20:21,419 --> 00:20:22,419 going to have everything we need to get 652 00:20:22,860 --> 00:20:23,860 started we're going to start only from 653 00:20:25,020 --> 00:20:26,020 scratch so let's begin creating a brand 654 00:20:26,880 --> 00:20:27,880 new project in the next lecture 655 00:20:29,340 --> 00:20:30,340 hello and welcome I'm your code monkey 656 00:20:31,140 --> 00:20:32,140 in this lecture we're going to begin 657 00:20:32,880 --> 00:20:33,880 actually building our game so let's 658 00:20:34,740 --> 00:20:35,740 create a chameleon 2 project and start 659 00:20:36,660 --> 00:20:37,660 building it on from scratch okay so the 660 00:20:38,820 --> 00:20:39,820 first thing that we need is to install 661 00:20:39,900 --> 00:20:40,900 Unity now I cover this in detail on that 662 00:20:41,940 --> 00:20:42,940 other Basics video so here I will assume 663 00:20:44,160 --> 00:20:45,160 that you already have Unity Hub 664 00:20:45,480 --> 00:20:46,480 installed the first decision we really 665 00:20:47,220 --> 00:20:48,220 need to make is choosing a Unity version 666 00:20:48,780 --> 00:20:49,780 Sony Hub you go into installs and 667 00:20:51,059 --> 00:20:52,059 install an editor and now Unity 668 00:20:53,039 --> 00:20:54,039 recommends that you use the LTS version 669 00:20:54,780 --> 00:20:55,780 or long term sport you should be using 670 00:20:56,940 --> 00:20:57,940 that one in most cases it's what it 671 00:20:58,740 --> 00:20:59,740 installs by default which as the time of 672 00:21:00,780 --> 00:21:01,780 this recording the latest one the latest 673 00:21:02,520 --> 00:21:03,520 LTS one is 2021.3 however I want this 674 00:21:05,820 --> 00:21:06,820 video to stay up to date for as long as 675 00:21:07,320 --> 00:21:08,320 possible so for making this game I will 676 00:21:09,120 --> 00:21:10,120 actually be using version 2022.2 if 677 00:21:11,520 --> 00:21:12,520 you're watching this video where it is 678 00:21:12,960 --> 00:21:13,960 came out then download this version and 679 00:21:15,000 --> 00:21:16,000 if you're watching this months in the 680 00:21:16,260 --> 00:21:17,260 future after version 22 on TS is out 681 00:21:18,419 --> 00:21:19,419 then you can use that one it won't 682 00:21:19,740 --> 00:21:20,740 probably be the exact same thing as 683 00:21:21,240 --> 00:21:22,240 version 22.2 so you should be able to 684 00:21:23,340 --> 00:21:24,340 follow everything exactly for any 685 00:21:24,780 --> 00:21:25,780 changes I will Point them out in the 686 00:21:26,520 --> 00:21:27,520 updated pin comment and if you're 687 00:21:28,260 --> 00:21:29,260 watching this years in the future and 688 00:21:29,640 --> 00:21:30,640 there's an even newer LTS version I 689 00:21:31,500 --> 00:21:32,500 would still recommend you follow using 690 00:21:32,880 --> 00:21:33,880 the 22 LTS don't worry about using a 691 00:21:35,220 --> 00:21:36,220 quote unquote older version everything 692 00:21:36,780 --> 00:21:37,780 you'll learn here in this version will 693 00:21:38,400 --> 00:21:39,400 still be applicable even 10 years from 694 00:21:40,080 --> 00:21:41,080 now so I said I'm going to be installing 695 00:21:41,580 --> 00:21:42,580 this one in terms of modulus doesn't 696 00:21:43,380 --> 00:21:44,380 really need anything I already have 697 00:21:45,059 --> 00:21:46,059 Visual Studio Community installed and 698 00:21:46,799 --> 00:21:47,799 all the other ones are unticked so 699 00:21:48,360 --> 00:21:49,360 install 700 00:21:52,620 --> 00:21:53,620 okay so the version is installed now 701 00:21:54,600 --> 00:21:55,600 let's create a new project let's go into 702 00:21:56,039 --> 00:21:57,039 the projects tab then create a new 703 00:21:57,960 --> 00:21:58,960 project and now first up up here make 704 00:22:00,179 --> 00:22:01,179 sure to select the right version so 705 00:22:01,799 --> 00:22:02,799 again I'm going to be using 22.2 then 706 00:22:04,620 --> 00:22:05,620 for the templates this has mainly to do 707 00:22:06,659 --> 00:22:07,659 with the UNT render pipelines now if 708 00:22:08,640 --> 00:22:09,640 you're a beginner don't worry about that 709 00:22:09,960 --> 00:22:10,960 too much just go ahead and select the 3D 710 00:22:12,299 --> 00:22:13,299 urp template so scroll down this one 711 00:22:14,460 --> 00:22:15,460 right here 3D urp make sure to select 712 00:22:16,980 --> 00:22:17,980 this one and not the one that says just 713 00:22:18,299 --> 00:22:19,299 reading the urp here stands for the 714 00:22:20,520 --> 00:22:21,520 universal render pipeline which means 715 00:22:22,200 --> 00:22:23,200 our game will be playable on literally 716 00:22:23,760 --> 00:22:24,760 any platform so we can make the funnel 717 00:22:25,980 --> 00:22:26,980 game and put it on steam or consoles are 718 00:22:27,900 --> 00:22:28,900 mobile it won't run on everything then 719 00:22:30,059 --> 00:22:31,059 over here on the right side let's 720 00:22:31,140 --> 00:22:32,140 quickly just download the template there 721 00:22:33,000 --> 00:22:34,000 it is it's done 722 00:22:34,320 --> 00:22:35,320 now select the name for your project so 723 00:22:36,960 --> 00:22:37,960 I'm going to call this kitchen chaos and 724 00:22:39,539 --> 00:22:40,539 then select the founder for it all right 725 00:22:41,400 --> 00:22:42,400 so that's it again make sure you're 726 00:22:42,960 --> 00:22:43,960 using the exact right version make sure 727 00:22:44,700 --> 00:22:45,700 you're using the 3D urp template give it 728 00:22:46,799 --> 00:22:47,799 a name a folder and let's head on create 729 00:22:53,640 --> 00:22:54,640 all right so it's open and right away 730 00:22:55,559 --> 00:22:56,559 you might or might not see a window 731 00:22:57,179 --> 00:22:58,179 talking about urp material upgrades I 732 00:22:59,400 --> 00:23:00,400 think this has to do with the template 733 00:23:00,659 --> 00:23:01,659 not having the default materials updated 734 00:23:02,460 --> 00:23:03,460 to the latest Erp version so if you're 735 00:23:04,320 --> 00:23:05,320 watching this in the future chances are 736 00:23:05,700 --> 00:23:06,700 you might not see this one at all but if 737 00:23:07,440 --> 00:23:08,440 you do then just go ahead click on OK 738 00:23:09,120 --> 00:23:10,120 and it will automatically upgrade all of 739 00:23:10,860 --> 00:23:11,860 the default materials alright so here we 740 00:23:13,260 --> 00:23:14,260 have our basic unity window now since we 741 00:23:15,840 --> 00:23:16,840 started a project starting from the RP 742 00:23:17,520 --> 00:23:18,520 template we have down here A bunch of 743 00:23:19,320 --> 00:23:20,320 Erp helper files so you can click to 744 00:23:21,240 --> 00:23:22,240 select the readme file and you can see 745 00:23:22,740 --> 00:23:23,740 it over here on the right side on the 746 00:23:24,299 --> 00:23:25,299 inspector if you want you can browse 747 00:23:25,799 --> 00:23:26,799 around these links in order to learn 748 00:23:27,299 --> 00:23:28,299 more about urp but in our case we're 749 00:23:28,919 --> 00:23:29,919 building the our game we really don't 750 00:23:30,240 --> 00:23:31,240 need this so we're here on the 751 00:23:31,740 --> 00:23:32,740 inspection let's just click this button 752 00:23:33,120 --> 00:23:34,120 to clean up these readme files just go 753 00:23:35,159 --> 00:23:36,159 ahead click on yes and okay that's it so 754 00:23:37,919 --> 00:23:38,919 basically you should only have these 755 00:23:39,419 --> 00:23:40,419 files in your project window so there's 756 00:23:41,159 --> 00:23:42,159 a scene folder and inside we've got the 757 00:23:43,020 --> 00:23:44,020 simple scene then we've got the settings 758 00:23:44,580 --> 00:23:45,580 and inside a bunch of urp assets while 759 00:23:47,220 --> 00:23:48,220 this should have been set up 760 00:23:48,179 --> 00:23:49,179 automatically since we use the 3D 761 00:23:49,620 --> 00:23:50,620 template and then finally we just have 762 00:23:51,360 --> 00:23:52,360 the urp equivalent settings asset now 763 00:23:53,159 --> 00:23:54,159 let's just verify find everything worked 764 00:23:54,600 --> 00:23:55,600 correctly so let's go to the top left go 765 00:23:56,640 --> 00:23:57,640 into edit then go down into project 766 00:23:58,440 --> 00:23:59,440 settings then over here let's go into 767 00:24:00,539 --> 00:24:01,539 the graphics Tab and you should see the 768 00:24:02,520 --> 00:24:03,520 urp High Fidelity asset assigned by 769 00:24:04,440 --> 00:24:05,440 default if not you can click on the 770 00:24:06,000 --> 00:24:07,000 circle icon and assign it then the other 771 00:24:07,860 --> 00:24:08,860 menus over here the urp mobile settings 772 00:24:09,659 --> 00:24:10,659 again this one should be set by default 773 00:24:11,520 --> 00:24:12,520 then down here on the quality tab on 774 00:24:13,740 --> 00:24:14,740 this one make sure High Fidelity is 775 00:24:15,299 --> 00:24:16,299 selected basically whatever you select 776 00:24:16,980 --> 00:24:17,980 here is the quality that we'll be using 777 00:24:18,480 --> 00:24:19,480 in the editor and in turn the selected 778 00:24:20,280 --> 00:24:21,280 quality over here also has a render 779 00:24:21,780 --> 00:24:22,780 pipeline Ascent now in order to avoid 780 00:24:23,640 --> 00:24:24,640 any confusion let's actually get rid of 781 00:24:25,200 --> 00:24:26,200 the other ones so let's just click on 782 00:24:26,760 --> 00:24:27,760 the trash icon to get rid of the 783 00:24:28,080 --> 00:24:29,080 performance and the bounce quality so 784 00:24:29,520 --> 00:24:30,520 just click and click okay so we only 785 00:24:31,260 --> 00:24:32,260 have this one then let's close the 786 00:24:33,120 --> 00:24:34,120 project settings and let's go into the 787 00:24:34,860 --> 00:24:35,860 settings folder and over here let's 788 00:24:36,299 --> 00:24:37,299 select the urp balance there are two 789 00:24:38,159 --> 00:24:39,159 assets for each quality so select those 790 00:24:39,960 --> 00:24:40,960 leave the High Fidelity and the 791 00:24:41,460 --> 00:24:42,460 performance and let's delete these 792 00:24:42,900 --> 00:24:43,900 alright that's it by the way if you made 793 00:24:44,640 --> 00:24:45,640 a mistake and accidentally deleted 794 00:24:46,020 --> 00:24:47,020 something don't worry you can always 795 00:24:47,280 --> 00:24:48,280 just click over here on the plus icon on 796 00:24:48,960 --> 00:24:49,960 the project window and then go over here 797 00:24:50,580 --> 00:24:51,580 under rendering and you can create a new 798 00:24:52,440 --> 00:24:53,440 urp asset with the universe personal 799 00:24:53,820 --> 00:24:54,820 render okay so just like this so we only 800 00:24:56,220 --> 00:24:57,220 have one quality setting we have high 801 00:24:58,140 --> 00:24:59,140 fidelity the quality setting is using 802 00:25:00,000 --> 00:25:01,000 this random pipeline asset which is also 803 00:25:01,679 --> 00:25:02,679 using this renderer so that's really it 804 00:25:03,539 --> 00:25:04,539 with this we have the absolute bare 805 00:25:05,039 --> 00:25:06,039 minimum we need if in the end after 806 00:25:06,780 --> 00:25:07,780 building the whole game you want to 807 00:25:08,100 --> 00:25:09,100 provide multiple quality settings then 808 00:25:09,659 --> 00:25:10,659 you can come back to this menu and 809 00:25:11,100 --> 00:25:12,100 recreate them but in order to avoid 810 00:25:12,539 --> 00:25:13,539 confusion while building the game let's 811 00:25:13,799 --> 00:25:14,799 keep things like this as simple as 812 00:25:15,240 --> 00:25:16,240 possible okay so that's the basic setup 813 00:25:17,159 --> 00:25:18,159 done next we want to prepare our layout 814 00:25:19,200 --> 00:25:20,200 so let's continue on to the next lecture 815 00:25:22,380 --> 00:25:23,380 hello and welcome I'm your code monkey 816 00:25:24,299 --> 00:25:25,299 in this lecture we're going to learn 817 00:25:26,039 --> 00:25:27,039 about the union layout and set it up so 818 00:25:28,200 --> 00:25:29,200 first things first let's familiarize 819 00:25:30,000 --> 00:25:31,000 ourselves with the various NT Windows to 820 00:25:31,980 --> 00:25:32,980 create our own layout it's very 821 00:25:33,360 --> 00:25:34,360 important that you feel uncomfortable 822 00:25:34,440 --> 00:25:35,440 with your layout that you have easy 823 00:25:36,059 --> 00:25:37,059 access to all the things that you need 824 00:25:37,380 --> 00:25:38,380 then you know where everything is you 825 00:25:38,940 --> 00:25:39,940 can see that there's lots of tabs 826 00:25:40,260 --> 00:25:41,260 everywhere over here on the NT window 827 00:25:41,640 --> 00:25:42,640 all of them can be dragged and dropped 828 00:25:43,200 --> 00:25:44,200 in any different position so you can 829 00:25:45,240 --> 00:25:46,240 customize your layout to get it looking 830 00:25:46,740 --> 00:25:47,740 exactly as you want you can set it up in 831 00:25:48,840 --> 00:25:49,840 any way but it will be easier to follow 832 00:25:50,460 --> 00:25:51,460 this course if you're following the same 833 00:25:51,960 --> 00:25:52,960 layout as me I'm assuming you've seen my 834 00:25:53,880 --> 00:25:54,880 quick Basics video so I'm assuming you 835 00:25:55,679 --> 00:25:56,679 know what is the inspector what is a 836 00:25:57,299 --> 00:25:58,299 game object what is a transform what is 837 00:25:59,159 --> 00:26:00,159 the console where is the hierarchy and 838 00:26:00,600 --> 00:26:01,600 so on if this is the very first time 839 00:26:02,220 --> 00:26:03,220 you're seeing the UNT interface go watch 840 00:26:03,720 --> 00:26:04,720 that other quick video first just learn 841 00:26:05,400 --> 00:26:06,400 the absolute Basics now for me I've been 842 00:26:07,380 --> 00:26:08,380 using Unity for over 10 years now so 843 00:26:09,240 --> 00:26:10,240 let's see the layout that I've developed 844 00:26:10,620 --> 00:26:11,620 over the years first the inspector on 845 00:26:12,419 --> 00:26:13,419 the right side just like default that 846 00:26:14,220 --> 00:26:15,220 way we always have a nice view of the 847 00:26:15,840 --> 00:26:16,840 selected object and whatever scripts and 848 00:26:17,520 --> 00:26:18,520 components it has then for the hierarchy 849 00:26:19,320 --> 00:26:20,320 I like to put it down here only on left 850 00:26:21,240 --> 00:26:22,240 side we're going to make sure that in 851 00:26:22,679 --> 00:26:23,679 our scene is always organized so we 852 00:26:24,120 --> 00:26:25,120 don't need the hierarchy to take up tons 853 00:26:25,679 --> 00:26:26,679 of space then with the project files 854 00:26:27,659 --> 00:26:28,659 next to it this corner is enough to 855 00:26:29,279 --> 00:26:30,279 really browse all of the files we want 856 00:26:31,080 --> 00:26:32,080 the console to be on the tab right next 857 00:26:32,880 --> 00:26:33,880 to it usually I find that when making 858 00:26:34,500 --> 00:26:35,500 the game I want to look at the project 859 00:26:36,000 --> 00:26:37,000 window but when playing the game I just 860 00:26:37,860 --> 00:26:38,860 want to look at the console so keeping 861 00:26:39,539 --> 00:26:40,539 them in the same place but on different 862 00:26:40,860 --> 00:26:41,860 tabs works great then over here on the 863 00:26:42,659 --> 00:26:43,659 center of the scene View and again with 864 00:26:44,279 --> 00:26:45,279 the game view right next to it okay so 865 00:26:46,020 --> 00:26:47,020 this is the basic layout that I normally 866 00:26:47,820 --> 00:26:48,820 use now for a couple more options let's 867 00:26:50,159 --> 00:26:51,159 go into the project window and on the 868 00:26:52,679 --> 00:26:53,679 top right corner you can see over here 869 00:26:53,880 --> 00:26:54,880 these little three dots by default it 870 00:26:55,980 --> 00:26:56,980 shows you a two column layout so there's 871 00:26:57,419 --> 00:26:58,419 a column here and a column here but 872 00:26:59,039 --> 00:27:00,039 personally I prefer the one column 873 00:27:00,419 --> 00:27:01,419 layout this shock is one of the project 874 00:27:02,340 --> 00:27:03,340 files in a nice compact list view the 875 00:27:04,440 --> 00:27:05,440 one thing where I prefer the other one 876 00:27:05,760 --> 00:27:06,760 is if you're browsing for some visual 877 00:27:07,260 --> 00:27:08,260 assets over here you can increase the 878 00:27:08,760 --> 00:27:09,760 thumbnail size but for most times I 879 00:27:10,740 --> 00:27:11,740 really like to use the one com layout 880 00:27:12,240 --> 00:27:13,240 much more compact also since we're 881 00:27:14,159 --> 00:27:15,159 talking about the project window just in 882 00:27:15,840 --> 00:27:16,840 case you don't know there's over here 883 00:27:17,159 --> 00:27:18,159 this little button with the eye this one 884 00:27:19,200 --> 00:27:20,200 has to do with package visibility if you 885 00:27:21,120 --> 00:27:22,120 toggle it then some of the inside 886 00:27:22,260 --> 00:27:23,260 compacts are hidden whereas if you 887 00:27:24,059 --> 00:27:25,059 untangle it then you can see all the 888 00:27:25,980 --> 00:27:26,980 various packages with all the source 889 00:27:27,539 --> 00:27:28,539 code and so on you can expand over here 890 00:27:29,159 --> 00:27:30,159 the packages and right now it is showing 891 00:27:30,960 --> 00:27:31,960 all of them all of them with source code 892 00:27:32,940 --> 00:27:33,940 the things everything in there and if 893 00:27:34,620 --> 00:27:35,620 you click on this then it hides it only 894 00:27:36,000 --> 00:27:37,000 shows a bunch of core ones but for most 895 00:27:37,919 --> 00:27:38,919 part you really want to leave this text 896 00:27:39,299 --> 00:27:40,299 and leave this one collapse nice and 897 00:27:41,100 --> 00:27:42,100 clean okay so then on the console over 898 00:27:43,500 --> 00:27:44,500 here once again let's go into the three 899 00:27:44,940 --> 00:27:45,940 dots and for the unlock entry for this 900 00:27:47,400 --> 00:27:48,400 one I like to select one line this makes 901 00:27:49,380 --> 00:27:50,380 the console nice and compact which I 902 00:27:51,120 --> 00:27:52,120 personally prefer you can see more logs 903 00:27:53,460 --> 00:27:54,460 without taking up more space and if you 904 00:27:55,140 --> 00:27:56,140 want to read the home log you can always 905 00:27:56,520 --> 00:27:57,520 just click on it to see the home stack 906 00:27:58,320 --> 00:27:59,320 Trace now there are also some more 907 00:27:59,580 --> 00:28:00,580 options over here if you want for 908 00:28:01,080 --> 00:28:02,080 example show the timestamp this will 909 00:28:02,880 --> 00:28:03,880 show the timestamp when each message 910 00:28:04,140 --> 00:28:05,140 were sent you can use a mono space font 911 00:28:06,240 --> 00:28:07,240 meaning a font where every character has 912 00:28:08,460 --> 00:28:09,460 the exact same width so a bunch of 913 00:28:09,960 --> 00:28:10,960 options but for me leaving it just like 914 00:28:11,520 --> 00:28:12,520 this works perfectly fine then also 915 00:28:13,559 --> 00:28:14,559 importantly over here these three 916 00:28:14,760 --> 00:28:15,760 buttons these toggle the visibility for 917 00:28:17,100 --> 00:28:18,100 the type of messages that appear in the 918 00:28:18,480 --> 00:28:19,480 console the unlocked one this one is for 919 00:28:20,340 --> 00:28:21,340 regular messages we're going to use this 920 00:28:21,840 --> 00:28:22,840 a lot then we've got warnings and 921 00:28:23,760 --> 00:28:24,760 finally errors if you untangle them then 922 00:28:25,980 --> 00:28:26,980 the messages of that type will not show 923 00:28:27,659 --> 00:28:28,659 up on the console so if you ever come 924 00:28:29,100 --> 00:28:30,100 across an issue where nothing is showing 925 00:28:30,779 --> 00:28:31,779 up on the console make sure all three of 926 00:28:32,400 --> 00:28:33,400 these buttons are ticked then on left 927 00:28:33,900 --> 00:28:34,900 side on clear you can click on the Arrow 928 00:28:35,520 --> 00:28:36,520 to see more options I like to set it to 929 00:28:37,140 --> 00:28:38,140 clear on play then collapse this one 930 00:28:39,360 --> 00:28:40,360 basically collapses messages that are 931 00:28:40,980 --> 00:28:41,980 the same all of them into one entry 932 00:28:42,960 --> 00:28:43,960 personally I do nothing like this I want 933 00:28:45,059 --> 00:28:46,059 to see every single message as it comes 934 00:28:46,740 --> 00:28:47,740 out even if it's repeated I've also seen 935 00:28:48,600 --> 00:28:49,600 this lead to a lot of confusion for some 936 00:28:50,279 --> 00:28:51,279 people they think their code is firing 937 00:28:52,140 --> 00:28:53,140 just one message when it's actually 938 00:28:53,279 --> 00:28:54,279 firing hundreds So to avoid any 939 00:28:54,960 --> 00:28:55,960 confusion make sure you leave this 940 00:28:56,340 --> 00:28:57,340 Untitled then for airpods this will 941 00:28:58,500 --> 00:28:59,500 automatically pause the game when there 942 00:28:59,880 --> 00:29:00,880 occurs you should definitely have this 943 00:29:01,440 --> 00:29:02,440 one toggled if there is an area you 944 00:29:03,120 --> 00:29:04,120 definitely want to know about it you 945 00:29:04,500 --> 00:29:05,500 want to know when it happens so you can 946 00:29:05,880 --> 00:29:06,880 fix it whereas if you untuckle this you 947 00:29:07,799 --> 00:29:08,799 might get some errors and the game might 948 00:29:09,360 --> 00:29:10,360 keep playing which will then lead to 949 00:29:10,860 --> 00:29:11,860 lots of confusion when something starts 950 00:29:12,539 --> 00:29:13,539 behaving weirdly so always leave this 951 00:29:14,400 --> 00:29:15,400 one toggled and then the editor button 952 00:29:16,080 --> 00:29:17,080 this one is for more advanced use case 953 00:29:17,520 --> 00:29:18,520 so don't worry about it okay so that's 954 00:29:19,380 --> 00:29:20,380 the console then over here for the game 955 00:29:21,240 --> 00:29:22,240 view we've got a button here to select 956 00:29:23,520 --> 00:29:24,520 the aspect ratio let's go ahead and 957 00:29:25,380 --> 00:29:26,380 select fully Gene this one is a 16x9 958 00:29:27,899 --> 00:29:28,899 aspect ratio so everything is pretty 959 00:29:29,460 --> 00:29:30,460 normal this will really only matter when 960 00:29:31,380 --> 00:29:32,380 we start working on the UI but so I like 961 00:29:33,299 --> 00:29:34,299 to keep it at 16x9 always then on this 962 00:29:35,580 --> 00:29:36,580 button that says play Focus we can 963 00:29:37,200 --> 00:29:38,200 modify some options basically Focus 964 00:29:39,059 --> 00:29:40,059 won't play exam like this on this small 965 00:29:40,919 --> 00:29:41,919 window if you choose maximize then it 966 00:29:42,720 --> 00:29:43,720 will maximize this one when playing the 967 00:29:44,279 --> 00:29:45,279 game and play in Focus won't play the 968 00:29:46,140 --> 00:29:47,140 game even when the window is not in 969 00:29:47,760 --> 00:29:48,760 Focus then another important one is 970 00:29:49,320 --> 00:29:50,320 actually on the same one as the aspect 971 00:29:50,880 --> 00:29:51,880 ratio here we've got a button to turn on 972 00:29:52,500 --> 00:29:53,500 vsync usually When developing the game 973 00:29:54,299 --> 00:29:55,299 you really want to toggle this that's 974 00:29:55,679 --> 00:29:56,679 because right in the beginning when the 975 00:29:57,000 --> 00:29:58,000 game doesn't really have anything you 976 00:29:58,380 --> 00:29:59,380 can leave it on Talent then this might 977 00:29:59,820 --> 00:30:00,820 run at like a thousand frames per second 978 00:30:01,500 --> 00:30:02,500 and that will pretty much drive your GPU 979 00:30:03,480 --> 00:30:04,480 crazy finally if your game view is 980 00:30:05,159 --> 00:30:06,159 looking a bit too pixelated make sure 981 00:30:06,779 --> 00:30:07,779 over here on the scale slider make sure 982 00:30:08,580 --> 00:30:09,580 this one is not zoomed in this one 983 00:30:10,320 --> 00:30:11,320 should always be pushed straight to the 984 00:30:11,880 --> 00:30:12,880 left as much as possible okay so that's 985 00:30:13,440 --> 00:30:14,440 the game view then over here on the 986 00:30:15,179 --> 00:30:16,179 scene view for this one default should 987 00:30:16,860 --> 00:30:17,860 be good these two buttons are extremely 988 00:30:18,840 --> 00:30:19,840 important pretty much all the time you 989 00:30:20,520 --> 00:30:21,520 want to keep the tone handles on the 990 00:30:21,899 --> 00:30:22,899 pivot it and not on the center if you 991 00:30:23,700 --> 00:30:24,700 ever see your handles on weird places 992 00:30:25,140 --> 00:30:26,140 always come back to this you want to 993 00:30:26,760 --> 00:30:27,760 sound pivot pretty much all the time 994 00:30:28,080 --> 00:30:29,080 then for rotation sometimes local is 995 00:30:30,299 --> 00:30:31,299 useful but for the most part you should 996 00:30:31,919 --> 00:30:32,919 probably be keeping in and Global then 997 00:30:33,539 --> 00:30:34,539 for the great showing the reason why yep 998 00:30:35,279 --> 00:30:36,279 down looks pretty good a nice little 999 00:30:36,480 --> 00:30:37,480 visual grid then you've got a bunch more 1000 00:30:38,039 --> 00:30:39,039 options if you want then next to it 1001 00:30:39,840 --> 00:30:40,840 we've got snapping this one we also 1002 00:30:42,299 --> 00:30:43,299 don't need this for now and finally same 1003 00:30:44,220 --> 00:30:45,220 thing for increment also don't need this 1004 00:30:45,899 --> 00:30:46,899 okay then on the right for the drum mode 1005 00:30:47,580 --> 00:30:48,580 let's leave it on Shaden for two then 1006 00:30:49,320 --> 00:30:50,320 let's leave this disabled since we're 1007 00:30:50,700 --> 00:30:51,700 working on a 3D game for lights let's 1008 00:30:52,620 --> 00:30:53,620 make sure this one is enabled for sound 1009 00:30:54,480 --> 00:30:55,480 we're only going to add this in the end 1010 00:30:55,799 --> 00:30:56,799 so it doesn't really matter for now then 1011 00:30:57,299 --> 00:30:58,299 for special effects usually you want 1012 00:30:59,220 --> 00:31:00,220 this one to be enabled so it shows 1013 00:31:00,779 --> 00:31:01,779 everything you can click on the arrow 1014 00:31:02,279 --> 00:31:03,279 and make sure all of them are toggled 1015 00:31:03,600 --> 00:31:04,600 the only exception is always refresh you 1016 00:31:05,700 --> 00:31:06,700 probably don't need this little scene 1017 00:31:07,260 --> 00:31:08,260 window to be refreshing at 60 frames per 1018 00:31:09,299 --> 00:31:10,299 second so you can leave that one 1019 00:31:10,500 --> 00:31:11,500 unticked and take on the others then 1020 00:31:12,179 --> 00:31:13,179 these are for the hidden objects so 1021 00:31:13,980 --> 00:31:14,980 let's leave them toggled for the camera 1022 00:31:15,480 --> 00:31:16,480 here are the defaults and finally gizmos 1023 00:31:17,820 --> 00:31:18,820 leave them all enabled as the defaults 1024 00:31:19,799 --> 00:31:20,799 alright so down that's end here is in 1025 00:31:21,659 --> 00:31:22,659 layout and going to be using throughout 1026 00:31:23,159 --> 00:31:24,159 the course it will be easier to follow 1027 00:31:24,840 --> 00:31:25,840 the course if you're using the exact 1028 00:31:26,100 --> 00:31:27,100 same layout as me so ideally you should 1029 00:31:27,899 --> 00:31:28,899 be using this but again like I mentioned 1030 00:31:29,580 --> 00:31:30,580 all the windows are customizable so if 1031 00:31:31,380 --> 00:31:32,380 there's something that you absolutely 1032 00:31:32,580 --> 00:31:33,580 prefer differently then go ahead you can 1033 00:31:34,559 --> 00:31:35,559 drag and drop and place any Windows 1034 00:31:36,000 --> 00:31:37,000 anywhere you want so once you have 1035 00:31:37,380 --> 00:31:38,380 layout your happy win you can go up here 1036 00:31:39,299 --> 00:31:40,299 to the top right corner where it says 1037 00:31:40,860 --> 00:31:41,860 default you can click on it and here 1038 00:31:42,480 --> 00:31:43,480 you've got a bunch of layouts so you can 1039 00:31:43,860 --> 00:31:44,860 save your new layout so I'm going to 1040 00:31:45,480 --> 00:31:46,480 save this one as kitchen chaos and then 1041 00:31:47,640 --> 00:31:48,640 over here you can select anyone you want 1042 00:31:49,200 --> 00:31:50,200 for example if you ever have some issues 1043 00:31:51,000 --> 00:31:52,000 with any kind of weird editor Windows 1044 00:31:52,860 --> 00:31:53,860 you can load back the default layout and 1045 00:31:54,840 --> 00:31:55,840 then go back and load your own layout 1046 00:31:56,340 --> 00:31:57,340 okay so with that our layout is set up 1047 00:31:58,260 --> 00:31:59,260 the next important thing is setting up 1048 00:32:00,000 --> 00:32:01,000 visual studio so let's do that in the 1049 00:32:01,679 --> 00:32:02,679 next lecture 1050 00:32:03,179 --> 00:32:04,179 hello and welcome I'm your code monkey 1051 00:32:05,159 --> 00:32:06,159 in this lecture we're going to set up 1052 00:32:07,140 --> 00:32:08,140 our Visual Studio alright so with the 1053 00:32:09,539 --> 00:32:10,539 Intel layout setup let's make sure 1054 00:32:11,100 --> 00:32:12,100 Visual Studio is also set up correctly 1055 00:32:12,840 --> 00:32:13,840 I'm going to be using version 22 1056 00:32:14,940 --> 00:32:15,940 Community this one is the free version 1057 00:32:16,679 --> 00:32:17,679 you don't absolutely have to use the 1058 00:32:18,659 --> 00:32:19,659 same code ID that I'm using you can use 1059 00:32:20,520 --> 00:32:21,520 writer or vs code or whatever you want 1060 00:32:22,620 --> 00:32:23,620 so let's see my setup for visual studio 1061 00:32:24,419 --> 00:32:25,419 but first let's actually set up 1062 00:32:25,980 --> 00:32:26,980 something over here in unity so let's go 1063 00:32:28,200 --> 00:32:29,200 up top into window and then let's open 1064 00:32:30,480 --> 00:32:31,480 up the package manager then over here on 1065 00:32:32,760 --> 00:32:33,760 the drop down menu let's select the 1066 00:32:34,620 --> 00:32:35,620 packages and select the ones from DNT 1067 00:32:36,600 --> 00:32:37,600 registry then let's scroll down to find 1068 00:32:38,760 --> 00:32:39,760 the visual studio editor package so here 1069 00:32:41,039 --> 00:32:42,039 it is this one this package basically 1070 00:32:42,659 --> 00:32:43,659 handles the integration with visual 1071 00:32:44,159 --> 00:32:45,159 studio so you can use the debugger and a 1072 00:32:46,080 --> 00:32:47,080 bunch of things alternatively there's 1073 00:32:47,640 --> 00:32:48,640 also a package over here for visual 1074 00:32:49,140 --> 00:32:50,140 studio code and there's also one over 1075 00:32:50,940 --> 00:32:51,940 here for jetbrains Rider so if you're 1076 00:32:52,799 --> 00:32:53,799 using a different IDE go ahead and 1077 00:32:54,539 --> 00:32:55,539 install the package for me I'm going to 1078 00:32:56,039 --> 00:32:57,039 install the visual City one so this one 1079 00:32:57,899 --> 00:32:58,899 just go ahead and install okay it's done 1080 00:32:59,880 --> 00:33:00,880 so next let's go up into edit and let's 1081 00:33:02,640 --> 00:33:03,640 open up the print preferences then over 1082 00:33:04,320 --> 00:33:05,320 here let's go down into external tools 1083 00:33:06,240 --> 00:33:07,240 and on the external script editor make 1084 00:33:08,100 --> 00:33:09,100 sure you select the one you're using so 1085 00:33:09,539 --> 00:33:10,539 again for me I'm using visual studio 22 1086 00:33:11,520 --> 00:33:12,520 and also over here you've got a bunch of 1087 00:33:13,200 --> 00:33:14,200 extra options now if you want to play 1088 00:33:14,940 --> 00:33:15,940 around with reading the source code for 1089 00:33:16,500 --> 00:33:17,500 the very CNT packages then you can tick 1090 00:33:18,240 --> 00:33:19,240 on these boxes but in our case for this 1091 00:33:19,980 --> 00:33:20,980 simple game we don't need that so go 1092 00:33:21,840 --> 00:33:22,840 ahead and leave everything just like 1093 00:33:23,100 --> 00:33:24,100 this with defaults okay so with this 1094 00:33:24,840 --> 00:33:25,840 setup now we can go over here into 1095 00:33:26,399 --> 00:33:27,399 assets and open up the c-sharp project 1096 00:33:28,080 --> 00:33:29,080 and this should open up visual studio 1097 00:33:29,760 --> 00:33:30,760 and alright so here it is now for some 1098 00:33:32,220 --> 00:33:33,220 more settings inside of here in my 1099 00:33:33,960 --> 00:33:34,960 visual studio I have a really nice 1100 00:33:35,519 --> 00:33:36,519 extension that adds a bit more colors to 1101 00:33:37,440 --> 00:33:38,440 my code which makes it easier to read 1102 00:33:39,000 --> 00:33:40,000 and write so up top let's go into the 1103 00:33:40,980 --> 00:33:41,980 extensions menu and manage extensions 1104 00:33:42,779 --> 00:33:43,779 and the important one that I've 1105 00:33:44,100 --> 00:33:45,100 installed is this one vs4 if you want 1106 00:33:45,960 --> 00:33:46,960 you can go into the online Tab and over 1107 00:33:47,820 --> 00:33:48,820 here search for it any Apple that show 1108 00:33:49,559 --> 00:33:50,559 up in here then for the settings on that 1109 00:33:51,539 --> 00:33:52,539 extension let's go up here into tools 1110 00:33:53,580 --> 00:33:54,580 and let's open up the options then over 1111 00:33:55,440 --> 00:33:56,440 here let's scroll down and find vs4 Yep 1112 00:33:57,779 --> 00:33:58,779 this one and here are all the settings 1113 00:33:59,159 --> 00:34:00,159 and expand this and a bunch more 1114 00:34:00,600 --> 00:34:01,600 settings now for me I think these are on 1115 00:34:02,399 --> 00:34:03,399 the defaults I don't remember if I 1116 00:34:04,019 --> 00:34:05,019 changed anything the important one is 1117 00:34:05,940 --> 00:34:06,940 over here the rainbow braces so these 1118 00:34:08,820 --> 00:34:09,820 have a bunch of Commerce which make it a 1119 00:34:10,260 --> 00:34:11,260 bit easier to read the code so let's 1120 00:34:12,060 --> 00:34:13,060 create a simple script just to see this 1121 00:34:13,800 --> 00:34:14,800 so back in until let's go into the 1122 00:34:15,839 --> 00:34:16,839 project window let's click the plus icon 1123 00:34:17,760 --> 00:34:18,760 and let's create the brand new c-sharp 1124 00:34:19,320 --> 00:34:20,320 script let's call it just testing wait 1125 00:34:21,060 --> 00:34:22,060 for it to compile and now let's open now 1126 00:34:23,280 --> 00:34:24,280 over here I'm just going to write a 1127 00:34:24,780 --> 00:34:25,780 bunch of simple code just to test it out 1128 00:34:26,520 --> 00:34:27,520 you don't have to follow this alright so 1129 00:34:28,440 --> 00:34:29,440 here's a bunch of sample code these are 1130 00:34:30,540 --> 00:34:31,540 the colors you can see it makes 1131 00:34:31,800 --> 00:34:32,800 everything a bit easier to read although 1132 00:34:33,659 --> 00:34:34,659 again this is not a requirement you 1133 00:34:35,099 --> 00:34:36,099 don't absolutely need this extension but 1134 00:34:36,720 --> 00:34:37,720 personally I do find it quite useful I 1135 00:34:38,520 --> 00:34:39,520 find that it helps make the code more 1136 00:34:39,780 --> 00:34:40,780 readable than having everything be gray 1137 00:34:41,460 --> 00:34:42,460 okay so that's the setup for this 1138 00:34:43,320 --> 00:34:44,320 extension next for the text formatting 1139 00:34:45,480 --> 00:34:46,480 options so once again let's go into two 1140 00:34:47,220 --> 00:34:48,220 holes go into options and then over here 1141 00:34:49,139 --> 00:34:50,139 let's go into the text editor then over 1142 00:34:51,179 --> 00:34:52,179 here I think I've got pretty much all 1143 00:34:52,800 --> 00:34:53,800 the same defaults then we can go into 1144 00:34:54,839 --> 00:34:55,839 the c-sharp rules so here are all the 1145 00:34:57,359 --> 00:34:58,359 settings if you notice something 1146 00:34:58,560 --> 00:34:59,560 different on your end go ahead and pause 1147 00:35:00,119 --> 00:35:01,119 the video and compare the settings but 1148 00:35:01,619 --> 00:35:02,619 again I think everything here is pretty 1149 00:35:03,000 --> 00:35:04,000 much defaults I believe the only 1150 00:35:04,859 --> 00:35:05,859 difference that I did was over here on 1151 00:35:06,480 --> 00:35:07,480 the code style over here for new lines 1152 00:35:08,640 --> 00:35:09,640 personally I like to have the currently 1153 00:35:10,619 --> 00:35:11,619 brackets on the same line but if you 1154 00:35:12,599 --> 00:35:13,599 want you can also change it and put it 1155 00:35:13,920 --> 00:35:14,920 on the second leg I think that's pretty 1156 00:35:15,420 --> 00:35:16,420 much the only difference that I did 1157 00:35:16,500 --> 00:35:17,500 everything else should be exactly the 1158 00:35:17,940 --> 00:35:18,940 same as defaults so that's the code 1159 00:35:19,500 --> 00:35:20,500 sound settings and speaking of that the 1160 00:35:21,420 --> 00:35:22,420 next lecture is very important we're 1161 00:35:22,980 --> 00:35:23,980 going to talk a bit about naming rules 1162 00:35:24,900 --> 00:35:25,900 although just before we go let's just 1163 00:35:26,700 --> 00:35:27,700 clean up our testing script so let's 1164 00:35:28,380 --> 00:35:29,380 close this one click on the X then back 1165 00:35:30,300 --> 00:35:31,300 into Unity we don't need the script so 1166 00:35:32,040 --> 00:35:33,040 let's just delete it okay so with that 1167 00:35:33,720 --> 00:35:34,720 we have Visual Studio setup and ready to 1168 00:35:35,700 --> 00:35:36,700 go now let's continue in the next 1169 00:35:37,260 --> 00:35:38,260 lecture to learn about some naming rules 1170 00:35:40,020 --> 00:35:41,020 hello and welcome I'm your code monkey 1171 00:35:42,060 --> 00:35:43,060 in this lecture we're going to learn 1172 00:35:43,680 --> 00:35:44,680 something extremely important let's 1173 00:35:45,359 --> 00:35:46,359 learn about naming world this one is a 1174 00:35:47,339 --> 00:35:48,339 very important lecture that you should 1175 00:35:48,720 --> 00:35:49,720 definitely refer back to whenever you 1176 00:35:50,339 --> 00:35:51,339 have some questions so first what 1177 00:35:52,140 --> 00:35:53,140 exactly are naming rules these are 1178 00:35:54,060 --> 00:35:55,060 really just rules you follow when 1179 00:35:55,380 --> 00:35:56,380 writing your code it is extremely 1180 00:35:57,180 --> 00:35:58,180 important that you are consistent in 1181 00:35:58,740 --> 00:35:59,740 applying your own rules you don't want 1182 00:36:00,599 --> 00:36:01,599 one class in your game to be written a 1183 00:36:02,400 --> 00:36:03,400 certain way and then a different class 1184 00:36:04,020 --> 00:36:05,020 using a completely different style that 1185 00:36:06,240 --> 00:36:07,240 would create tons of confusion so naming 1186 00:36:08,640 --> 00:36:09,640 rules and writing the code correctly is 1187 00:36:10,560 --> 00:36:11,560 very very important one mistake that I 1188 00:36:12,660 --> 00:36:13,660 see a lot of beginners do is they send 1189 00:36:14,280 --> 00:36:15,280 me some code and ask why it's not 1190 00:36:15,660 --> 00:36:16,660 working then I take a quick look and I 1191 00:36:17,760 --> 00:36:18,760 see that all of the code is written in a 1192 00:36:19,320 --> 00:36:20,320 very messy way some functions are on 1193 00:36:21,119 --> 00:36:22,119 lowercase others using snake case some 1194 00:36:23,099 --> 00:36:24,099 films are in personal case some in camel 1195 00:36:25,020 --> 00:36:26,020 case and so on remember that code is 1196 00:36:27,180 --> 00:36:28,180 case sensitive so it is extremely 1197 00:36:29,160 --> 00:36:30,160 important that you write the code 1198 00:36:30,420 --> 00:36:31,420 correctly if you change a character from 1199 00:36:32,280 --> 00:36:33,280 lowercase to uppercase then you are 1200 00:36:34,020 --> 00:36:35,020 suddenly referring to something 1201 00:36:35,160 --> 00:36:36,160 completely different if you're a 1202 00:36:36,660 --> 00:36:37,660 beginner keep that always in your mind 1203 00:36:38,220 --> 00:36:39,220 code is case sensitive so don't just 1204 00:36:40,859 --> 00:36:41,859 write code semi-randomly write it 1205 00:36:42,839 --> 00:36:43,839 properly as if you were doing an English 1206 00:36:44,579 --> 00:36:45,579 literature test now with that said when 1207 00:36:46,440 --> 00:36:47,440 it comes to naming roles you can use 1208 00:36:48,240 --> 00:36:49,240 whatever name neurons you want different 1209 00:36:49,859 --> 00:36:50,859 people like different rules for example 1210 00:36:51,720 --> 00:36:52,720 you can use a prefix in your variables 1211 00:36:53,640 --> 00:36:54,640 you can use a postpick you can use 1212 00:36:55,440 --> 00:36:56,440 capitals for consonants chemical case 1213 00:36:57,300 --> 00:36:58,300 for properties snake case for Fields by 1214 00:36:59,220 --> 00:37:00,220 the way here are the definitions of what 1215 00:37:00,780 --> 00:37:01,780 those terms actually mean Pascal K 1216 00:37:02,640 --> 00:37:03,640 starts with a capital and every word is 1217 00:37:04,440 --> 00:37:05,440 capitalized camel case starts lowercase 1218 00:37:06,720 --> 00:37:07,720 and then uppercase for the first 1219 00:37:08,160 --> 00:37:09,160 selector of every other word kind of 1220 00:37:10,260 --> 00:37:11,260 like a camel hump in the middle and 1221 00:37:11,880 --> 00:37:12,880 snake Haze is where you add an 1222 00:37:13,260 --> 00:37:14,260 underscore in between the words I send 1223 00:37:15,119 --> 00:37:16,119 every rule can be valid the important 1224 00:37:17,160 --> 00:37:18,160 thing is that you are consistent in 1225 00:37:18,720 --> 00:37:19,720 always following through with your rules 1226 00:37:20,160 --> 00:37:21,160 as you might know Unity mono behaviors 1227 00:37:21,900 --> 00:37:22,900 have some deformed functions you can 1228 00:37:23,339 --> 00:37:24,339 Implement things like start and update 1229 00:37:25,260 --> 00:37:26,260 which are written using pastel case 1230 00:37:27,000 --> 00:37:28,000 since you can't really change in these 1231 00:37:28,859 --> 00:37:29,859 rules at least on function names I would 1232 00:37:30,660 --> 00:37:31,660 say you should base your rules off of 1233 00:37:32,220 --> 00:37:33,220 theirs so for functions you should 1234 00:37:33,720 --> 00:37:34,720 probably be using Pascal case for the 1235 00:37:35,579 --> 00:37:36,579 rules like I said choose whatever makes 1236 00:37:37,320 --> 00:37:38,320 sense to you here are some of my own 1237 00:37:39,000 --> 00:37:40,000 personal rooms that have developed 1238 00:37:39,900 --> 00:37:40,900 jumped over the last 10 years and the 1239 00:37:41,880 --> 00:37:42,880 code sound that I won't be following in 1240 00:37:43,260 --> 00:37:44,260 this course for functions I use Pascal 1241 00:37:45,540 --> 00:37:46,540 case just like unity and just like the 1242 00:37:47,460 --> 00:37:48,460 c-sharp standard for function parameters 1243 00:37:49,680 --> 00:37:50,680 I use camel case for Fields also camel 1244 00:37:52,560 --> 00:37:53,560 case properties are in personal case 1245 00:37:54,480 --> 00:37:55,480 constants are in uppercase snake case 1246 00:37:56,820 --> 00:37:57,820 then another rule is that I like to add 1247 00:37:58,980 --> 00:37:59,980 the top of the variable as a postfix so 1248 00:38:01,200 --> 00:38:02,200 if it's a list type in the list if it's 1249 00:38:02,880 --> 00:38:03,880 an array open array and now you might be 1250 00:38:04,800 --> 00:38:05,800 thinking with this wouldn't it be an 1251 00:38:06,240 --> 00:38:07,240 issue if we change the type then the 1252 00:38:07,859 --> 00:38:08,859 name is suddenly wrong and the simple 1253 00:38:09,300 --> 00:38:10,300 solution for that is that if I change 1254 00:38:10,980 --> 00:38:11,980 the type then I just use Visual Studio 1255 00:38:12,660 --> 00:38:13,660 to quickly change the name that's it 1256 00:38:14,339 --> 00:38:15,339 then for the currently brackets like I 1257 00:38:16,020 --> 00:38:17,020 mentioned in previous lecture I like 1258 00:38:17,460 --> 00:38:18,460 them on the same line some people have 1259 00:38:19,200 --> 00:38:20,200 some very strong opinions about this 1260 00:38:20,820 --> 00:38:21,820 really it's just a visual style and this 1261 00:38:22,920 --> 00:38:23,920 is the one that I personally prefer if 1262 00:38:24,420 --> 00:38:25,420 you like new online then go ahead and 1263 00:38:25,800 --> 00:38:26,800 use that it doesn't change how the code 1264 00:38:27,359 --> 00:38:28,359 Works in any way in a final rule spend 1265 00:38:29,880 --> 00:38:30,880 some time deciding on a proper name and 1266 00:38:31,619 --> 00:38:32,619 don't be afraid to rename things you 1267 00:38:33,240 --> 00:38:34,240 will note how all the code that we're 1268 00:38:34,619 --> 00:38:35,619 going to write in this course has proper 1269 00:38:36,240 --> 00:38:37,240 names for everything you should never 1270 00:38:37,800 --> 00:38:38,800 use a variable with a single letter like 1271 00:38:39,660 --> 00:38:40,660 X X or k the exception of course would 1272 00:38:41,940 --> 00:38:42,940 be iterated in a for Loop also don't use 1273 00:38:44,339 --> 00:38:45,339 acronyms or abbreviations those might 1274 00:38:46,680 --> 00:38:47,680 seem player right now but in a few weeks 1275 00:38:48,420 --> 00:38:49,420 you might not remember what they mean 1276 00:38:49,740 --> 00:38:50,740 remember you don't get bonus points for 1277 00:38:51,660 --> 00:38:52,660 writing extremely compact code so 1278 00:38:53,579 --> 00:38:54,579 prioritize making your code readable and 1279 00:38:55,619 --> 00:38:56,619 understandable even if it requires 1280 00:38:57,540 --> 00:38:58,540 variables and functions with long names 1281 00:38:59,220 --> 00:39:00,220 so these are my general rules and the 1282 00:39:01,320 --> 00:39:02,320 code style that I personally follow 1283 00:39:02,579 --> 00:39:03,579 figure out what works for you and follow 1284 00:39:04,500 --> 00:39:05,500 your own naming rules but naturally in 1285 00:39:06,240 --> 00:39:07,240 this course I will be using my own code 1286 00:39:07,800 --> 00:39:08,800 cell so if when following the course you 1287 00:39:09,780 --> 00:39:10,780 are not sure how to write some type of 1288 00:39:11,220 --> 00:39:12,220 code you can refer back to this lecture 1289 00:39:13,140 --> 00:39:14,140 and watch it again like I've mentioned 1290 00:39:14,400 --> 00:39:15,400 many times the code that I won't teach 1291 00:39:15,660 --> 00:39:16,660 you how to write in this course is on 1292 00:39:17,220 --> 00:39:18,220 the exact same level of quality as my 1293 00:39:18,839 --> 00:39:19,839 paid courses and my Steam games so as 1294 00:39:20,880 --> 00:39:21,880 such because that this lecture these 1295 00:39:22,800 --> 00:39:23,800 naming rules are all extremely important 1296 00:39:24,480 --> 00:39:25,480 okay so with this very important lecture 1297 00:39:26,400 --> 00:39:27,400 out of the way now let's start playing 1298 00:39:27,839 --> 00:39:28,839 with some visuals by importing some 1299 00:39:29,460 --> 00:39:30,460 Assets in the next lecture hello and 1300 00:39:32,099 --> 00:39:33,099 welcome I'm your code monkey in this 1301 00:39:34,079 --> 00:39:35,079 lecture we're going to import the 1302 00:39:35,280 --> 00:39:36,280 project files with all the assets that 1303 00:39:36,900 --> 00:39:37,900 we're going to use by the way remember 1304 00:39:38,339 --> 00:39:39,339 that if you have any questions go ahead 1305 00:39:39,960 --> 00:39:40,960 and post them in the comments I go 1306 00:39:41,460 --> 00:39:42,460 through those every day and I'll do my 1307 00:39:42,960 --> 00:39:43,960 best to help okay so with the project 1308 00:39:44,640 --> 00:39:45,640 created the next thing we want is to 1309 00:39:46,200 --> 00:39:47,200 import the assets that we're going to 1310 00:39:47,520 --> 00:39:48,520 use to make this game you can download 1311 00:39:49,320 --> 00:39:50,320 all of the assets with the link in the 1312 00:39:50,700 --> 00:39:51,700 description which by the way like I 1313 00:39:52,140 --> 00:39:53,140 mentioned a while ago that link contains 1314 00:39:53,640 --> 00:39:54,640 a Unity package that contains both the 1315 00:39:55,500 --> 00:39:56,500 assets and the final game so when you 1316 00:39:57,599 --> 00:39:58,599 download that you get ENT package just 1317 00:39:59,579 --> 00:40:00,579 go ahead and double click or click and 1318 00:40:01,380 --> 00:40:02,380 drag and drop it on the projects window 1319 00:40:02,940 --> 00:40:03,940 here is the asset import window just 1320 00:40:04,859 --> 00:40:05,859 make sure you select all and let's 1321 00:40:06,359 --> 00:40:07,359 import okay so here it is let's import 1322 00:40:08,400 --> 00:40:09,400 the assets folder and inside comes all 1323 00:40:10,680 --> 00:40:11,680 of the assets meshes textures and so on 1324 00:40:12,660 --> 00:40:13,660 so everything we're going to need and 1325 00:40:14,820 --> 00:40:15,820 then it also imported inside of it 1326 00:40:16,619 --> 00:40:17,619 another ENT package so if you want to 1327 00:40:18,960 --> 00:40:19,960 import the final project with all of the 1328 00:40:20,640 --> 00:40:21,640 code already written it's also here if 1329 00:40:22,619 --> 00:40:23,619 you extract this one you're going to get 1330 00:40:24,060 --> 00:40:25,060 the complete project files now of course 1331 00:40:26,040 --> 00:40:27,040 don't do that if you want to follow 1332 00:40:27,540 --> 00:40:28,540 along with the course and be aware that 1333 00:40:29,520 --> 00:40:30,520 if you're following along and you 1334 00:40:30,780 --> 00:40:31,780 accidentally end unpack this one it will 1335 00:40:32,520 --> 00:40:33,520 override all of your own files so if you 1336 00:40:34,859 --> 00:40:35,859 want to inspect the final project files 1337 00:40:36,240 --> 00:40:37,240 go ahead and do that but do that in a 1338 00:40:37,859 --> 00:40:38,859 separate project in order to make sure 1339 00:40:39,720 --> 00:40:40,720 that we have no accidents I'm going to 1340 00:40:41,640 --> 00:40:42,640 delete this one from the current project 1341 00:40:42,960 --> 00:40:43,960 so just go ahead and delete okay so 1342 00:40:45,119 --> 00:40:46,119 that's it and over here we've got all of 1343 00:40:46,980 --> 00:40:47,980 our really nice visuals we can look in 1344 00:40:49,140 --> 00:40:50,140 the prefabs visuals and over here we've 1345 00:40:50,880 --> 00:40:51,880 got a visual for a container Sergo 1346 00:40:53,400 --> 00:40:54,400 that's a container counter then we have 1347 00:40:55,500 --> 00:40:56,500 a cutting counter we've got a trash bin 1348 00:40:57,660 --> 00:40:58,660 then on the kitchen object visuals we've 1349 00:41:00,000 --> 00:41:01,000 got all the visuals so a block of cheese 1350 00:41:01,800 --> 00:41:02,800 we've got some burned meat we've got a 1351 00:41:03,780 --> 00:41:04,780 plate and so on these are all the nice 1352 00:41:05,700 --> 00:41:06,700 3D models that we're going to use in our 1353 00:41:07,560 --> 00:41:08,560 game and then over here on the textures 1354 00:41:09,420 --> 00:41:10,420 folder we also got a bunch of General 1355 00:41:11,040 --> 00:41:12,040 icons as well as actual icons for all of 1356 00:41:13,680 --> 00:41:14,680 the various parts okay so all of the 1357 00:41:15,960 --> 00:41:16,960 assets have been important now let's 1358 00:41:17,460 --> 00:41:18,460 continue on to the next lecture 1359 00:41:19,740 --> 00:41:20,740 hello and welcome I'm your code monkey 1360 00:41:21,720 --> 00:41:22,720 in this lecture we're going to set up 1361 00:41:23,579 --> 00:41:24,579 post processing now here let me make a 1362 00:41:25,740 --> 00:41:26,740 quick note usually when making your 1363 00:41:27,660 --> 00:41:28,660 games you probably don't want to hand on 1364 00:41:29,220 --> 00:41:30,220 post-processing right way you should 1365 00:41:30,839 --> 00:41:31,839 first get an ugly prototype up and 1366 00:41:32,400 --> 00:41:33,400 working before worrying about any 1367 00:41:34,020 --> 00:41:35,020 visuals so normally I would only add 1368 00:41:36,240 --> 00:41:37,240 post-processing much later on in the dev 1369 00:41:38,040 --> 00:41:39,040 process but since this is a course in 1370 00:41:40,260 --> 00:41:41,260 video format in order for the video to 1371 00:41:42,000 --> 00:41:43,000 look a bit more appealing let's set a 1372 00:41:43,560 --> 00:41:44,560 post processing right away now we 1373 00:41:45,000 --> 00:41:46,000 already have the project set up to use 1374 00:41:46,500 --> 00:41:47,500 urp so adding post-processing is 1375 00:41:48,480 --> 00:41:49,480 actually super simple it's actually 1376 00:41:50,099 --> 00:41:51,099 already added by default first before we 1377 00:41:52,380 --> 00:41:53,380 do that let's rename our scene with a 1378 00:41:54,000 --> 00:41:55,000 proper name so inside the scenes folder 1379 00:41:55,740 --> 00:41:56,740 it starts off with sample scene this 1380 00:41:57,420 --> 00:41:58,420 will be our main game scene so let's 1381 00:41:58,800 --> 00:41:59,800 just rename this to game scene okay and 1382 00:42:01,260 --> 00:42:02,260 now here on the hierarchy we can see by 1383 00:42:03,240 --> 00:42:04,240 default this scene already contains a 1384 00:42:05,220 --> 00:42:06,220 global volume game object this is how 1385 00:42:07,200 --> 00:42:08,200 you actually add post-processing and by 1386 00:42:09,000 --> 00:42:10,000 default you can see that it also already 1387 00:42:10,619 --> 00:42:11,619 has a sample and profile attached this 1388 00:42:13,020 --> 00:42:14,020 is how you add all of the various 1389 00:42:14,099 --> 00:42:15,099 effects you can click on this link and 1390 00:42:16,140 --> 00:42:17,140 it will show it over here on the project 1391 00:42:17,700 --> 00:42:18,700 window now let's film this from scratch 1392 00:42:19,320 --> 00:42:20,320 instead of starting from this one so 1393 00:42:20,820 --> 00:42:21,820 let's go into that file into that asset 1394 00:42:22,800 --> 00:42:23,800 and just delete it okay so now we have 1395 00:42:24,900 --> 00:42:25,900 no value profile now let's go ahead and 1396 00:42:26,640 --> 00:42:27,640 click on new to create a brand new one 1397 00:42:28,200 --> 00:42:29,200 okay so now here we can add overrides 1398 00:42:30,180 --> 00:42:31,180 add all of the effects that we want 1399 00:42:31,680 --> 00:42:32,680 let's drag some visual meshes that we 1400 00:42:33,720 --> 00:42:34,720 imported in the last lecture to get a 1401 00:42:35,160 --> 00:42:36,160 better look at all these effects and 1402 00:42:36,599 --> 00:42:37,599 what they do so first let's make some 1403 00:42:38,640 --> 00:42:39,640 kind of more so let's make a 3D object 1404 00:42:40,440 --> 00:42:41,440 let's make it a plane let's name this D4 1405 00:42:42,839 --> 00:42:43,839 also one extremely important thing 1406 00:42:44,520 --> 00:42:45,520 whenever you create a brand new object 1407 00:42:46,020 --> 00:42:47,020 always check the object's transform 1408 00:42:47,820 --> 00:42:48,820 position by default when you create an 1409 00:42:49,680 --> 00:42:50,680 object it appears in front of the scene 1410 00:42:51,180 --> 00:42:52,180 camera which will probably not be on 1411 00:42:53,280 --> 00:42:54,280 zero zero zero you always want to be 1412 00:42:55,020 --> 00:42:56,020 very careful with the position of your 1413 00:42:56,400 --> 00:42:57,400 actual objects so for a plane we do want 1414 00:42:58,619 --> 00:42:59,619 this to be on the origin so on zero zero 1415 00:43:01,079 --> 00:43:02,079 zero so make sure you always do that 1416 00:43:02,760 --> 00:43:03,760 then let's scale it up a bit so on the 1417 00:43:04,440 --> 00:43:05,440 scale let's put it on 555 which by the 1418 00:43:06,780 --> 00:43:07,780 way you've got this nice little icon 1419 00:43:08,520 --> 00:43:09,520 this was added in a recent Indie version 1420 00:43:10,260 --> 00:43:11,260 basically if you enable this and matches 1421 00:43:12,060 --> 00:43:13,060 all of these values so if you just 1422 00:43:13,500 --> 00:43:14,500 change one of them it changes all of 1423 00:43:14,760 --> 00:43:15,760 them so let's put this on Five okay 1424 00:43:16,079 --> 00:43:17,079 great now for the visual let's go ahead 1425 00:43:18,060 --> 00:43:19,060 into the mesh render on the materials 1426 00:43:19,680 --> 00:43:20,680 and let's select the brand new material 1427 00:43:21,300 --> 00:43:22,300 so let's click on the circle icon and 1428 00:43:23,040 --> 00:43:24,040 over here let's find the floor material 1429 00:43:24,599 --> 00:43:25,599 so here it is it's the one included in 1430 00:43:26,400 --> 00:43:27,400 the assets there you go we've got a nice 1431 00:43:28,319 --> 00:43:29,319 basic form material now let's also drag 1432 00:43:30,300 --> 00:43:31,300 the player visual so let's go inside the 1433 00:43:32,040 --> 00:43:33,040 assets folder and over here let's go 1434 00:43:33,720 --> 00:43:34,720 inside the prefabs visuals and down here 1435 00:43:35,940 --> 00:43:36,940 we find the player visual so let's just 1436 00:43:37,680 --> 00:43:38,680 go ahead and drag this one so there it 1437 00:43:39,180 --> 00:43:40,180 is a nice player visual let's also drag 1438 00:43:41,280 --> 00:43:42,280 a counter so let's find let's say the 1439 00:43:43,440 --> 00:43:44,440 Clear counter let's drag this one let's 1440 00:43:45,780 --> 00:43:46,780 rotate it to face the camera something 1441 00:43:47,280 --> 00:43:48,280 like this and let's also put a cutting 1442 00:43:49,079 --> 00:43:50,079 counter again we're just placing some 1443 00:43:50,640 --> 00:43:51,640 visuals just so we can see what the post 1444 00:43:52,380 --> 00:43:53,380 processing will do and let's also place 1445 00:43:54,240 --> 00:43:55,240 a bunch more things so let's say a 1446 00:43:55,920 --> 00:43:56,920 tomato let's place a tomato over there 1447 00:43:57,660 --> 00:43:58,660 and maybe cabbage all the way over here 1448 00:43:59,640 --> 00:44:00,640 okay so we've got a handful of nice 1449 00:44:01,380 --> 00:44:02,380 visual elements so we can test out our 1450 00:44:03,000 --> 00:44:04,000 post pressing by the way here's a quick 1451 00:44:04,740 --> 00:44:05,740 empty tip on scene controls whenever you 1452 00:44:06,780 --> 00:44:07,780 are on the scene view which make sure 1453 00:44:08,040 --> 00:44:09,040 you're on scene View and not game view 1454 00:44:09,420 --> 00:44:10,420 those are different so on the scene view 1455 00:44:10,980 --> 00:44:11,980 you can move the camera with a mouse you 1456 00:44:12,660 --> 00:44:13,660 can pan with mouse 3 so the middle Mouse 1457 00:44:14,520 --> 00:44:15,520 button so hold that and pan around we 1458 00:44:16,859 --> 00:44:17,859 can rotate with the right Mouse button 1459 00:44:18,660 --> 00:44:19,660 you can rotate around Point by holding 1460 00:44:20,819 --> 00:44:21,819 down left alt and left click and just 1461 00:44:22,800 --> 00:44:23,800 drag it around to rotate around an 1462 00:44:24,540 --> 00:44:25,540 object you can select an object like for 1463 00:44:26,099 --> 00:44:27,099 example player visual then you can press 1464 00:44:27,780 --> 00:44:28,780 on F to select that object and now if 1465 00:44:29,819 --> 00:44:30,819 you hold alt and click it will rotate 1466 00:44:31,560 --> 00:44:32,560 around that object also another method 1467 00:44:33,180 --> 00:44:34,180 is you can hold the right Mouse button 1468 00:44:34,740 --> 00:44:35,740 to move it around and then you can use 1469 00:44:36,180 --> 00:44:37,180 was to move so d a and so on then you 1470 00:44:39,599 --> 00:44:40,599 can even press shift to move in faster 1471 00:44:41,400 --> 00:44:42,400 and you can use the scroll wheel while 1472 00:44:43,200 --> 00:44:44,200 holding down the right Mouse button or 1473 00:44:44,640 --> 00:44:45,640 to modify the speed at which you move so 1474 00:44:46,440 --> 00:44:47,440 there are plenty of camera controls to 1475 00:44:48,240 --> 00:44:49,240 really get you seeing exactly what you 1476 00:44:50,280 --> 00:44:51,280 want to see now for another quick empty 1477 00:44:52,319 --> 00:44:53,319 tip you can move the scene camera to 1478 00:44:53,880 --> 00:44:54,880 where you want the game camera to be so 1479 00:44:55,319 --> 00:44:56,319 let's say I want the game camera to see 1480 00:44:56,700 --> 00:44:57,700 things from about this angle so you just 1481 00:44:58,740 --> 00:44:59,740 position the scene camera then on the 1482 00:45:00,599 --> 00:45:01,599 hierarchy select the camera game object 1483 00:45:02,220 --> 00:45:03,220 so the main camera right here and with 1484 00:45:03,839 --> 00:45:04,839 that object selected you press Ctrl 1485 00:45:05,520 --> 00:45:06,520 shift and F and if there you go you can 1486 00:45:07,560 --> 00:45:08,560 see over here on the camera preview let 1487 00:45:09,180 --> 00:45:10,180 it position the main camera looking on 1488 00:45:10,800 --> 00:45:11,800 the exact same position at the exact 1489 00:45:12,359 --> 00:45:13,359 same direction as the scene camera set 1490 00:45:14,099 --> 00:45:15,099 the shortcut Ctrl shift F or 1491 00:45:15,660 --> 00:45:16,660 alternatively go up into game object and 1492 00:45:17,700 --> 00:45:18,700 over here on line with view now if you 1493 00:45:19,380 --> 00:45:20,380 look here is the scene View and over 1494 00:45:20,940 --> 00:45:21,940 here we've got a nice camera view so 1495 00:45:22,500 --> 00:45:23,500 just position the camera somewhere where 1496 00:45:24,359 --> 00:45:25,359 we can view all of the Assets Now with 1497 00:45:26,160 --> 00:45:27,160 this let's add some post processing 1498 00:45:27,480 --> 00:45:28,480 effects so first let's select the global 1499 00:45:29,520 --> 00:45:30,520 volume game object and over here we can 1500 00:45:31,260 --> 00:45:32,260 add all of our effect overrides first up 1501 00:45:33,540 --> 00:45:34,540 let's begin by adding tone mapping so 1502 00:45:35,700 --> 00:45:36,700 there you go we've got the effect and 1503 00:45:37,079 --> 00:45:38,079 over here we've got a nice little 1504 00:45:38,220 --> 00:45:39,220 checkbox so you can enable it in order 1505 00:45:40,319 --> 00:45:41,319 to enable this effect and set one of the 1506 00:45:42,240 --> 00:45:43,240 options now for this one I'm not too 1507 00:45:43,980 --> 00:45:44,980 familiar with color correction but I 1508 00:45:45,540 --> 00:45:46,540 find that usually adding a neutral tone 1509 00:45:47,099 --> 00:45:48,099 map usually that helps also make sure 1510 00:45:48,900 --> 00:45:49,900 you're looking at the game View and not 1511 00:45:50,579 --> 00:45:51,579 the scene view if you're looking in the 1512 00:45:52,079 --> 00:45:53,079 game View and you enable and disable 1513 00:45:53,460 --> 00:45:54,460 this effect you should see a difference 1514 00:45:54,660 --> 00:45:55,660 whereas on the scene view if you enable 1515 00:45:56,640 --> 00:45:57,640 and disable it doesn't actually show 1516 00:45:57,839 --> 00:45:58,839 that even if you're on the scene view 1517 00:45:59,220 --> 00:46:00,220 over here you have all the effects 1518 00:46:00,720 --> 00:46:01,720 enabled even with that some effects for 1519 00:46:02,579 --> 00:46:03,579 some reason don't show up on the scene 1520 00:46:04,079 --> 00:46:05,079 view so when playing around these 1521 00:46:05,700 --> 00:46:06,700 effects almost make sure you're 1522 00:46:06,660 --> 00:46:07,660 unlocking through the game view so like 1523 00:46:08,099 --> 00:46:09,099 I said you should be able to toggle this 1524 00:46:09,660 --> 00:46:10,660 and see a visual difference on the game 1525 00:46:11,280 --> 00:46:12,280 view if you don't then make sure the 1526 00:46:13,020 --> 00:46:14,020 camera has post processing enabled so 1527 00:46:14,760 --> 00:46:15,760 let's select the main camera game object 1528 00:46:16,319 --> 00:46:17,319 and down here there's a tongue for post 1529 00:46:17,940 --> 00:46:18,940 Crossing make sure this one is enabled 1530 00:46:19,319 --> 00:46:20,319 and then also on the render pipeline 1531 00:46:21,300 --> 00:46:22,300 assets so let's find that one on the 1532 00:46:23,099 --> 00:46:24,099 project window over here we've got the 1533 00:46:24,599 --> 00:46:25,599 settings and we've got the urp High 1534 00:46:26,099 --> 00:46:27,099 Fidelity this one should be using a 1535 00:46:27,960 --> 00:46:28,960 renderer so if you click on the renderer 1536 00:46:29,760 --> 00:46:30,760 over here you should have post-rossing 1537 00:46:31,440 --> 00:46:32,440 enabled again all of this should already 1538 00:46:33,060 --> 00:46:34,060 be correctly set up by default so if 1539 00:46:35,280 --> 00:46:36,280 you're going to take a global volume 1540 00:46:36,240 --> 00:46:37,240 enable our disabled you should see a 1541 00:46:37,920 --> 00:46:38,920 visual difference okay so next Effect 1542 00:46:39,839 --> 00:46:40,839 one that I always like to add is a bit 1543 00:46:41,819 --> 00:46:42,819 of saturation so let's add an override 1544 00:46:43,800 --> 00:46:44,800 post processing and let's add a brand 1545 00:46:45,960 --> 00:46:46,960 new here it is color adjustments then 1546 00:46:48,119 --> 00:46:49,119 over here you've got plenty of things to 1547 00:46:49,500 --> 00:46:50,500 play around with for me I like to add a 1548 00:46:51,420 --> 00:46:52,420 bit of saturation so just lift it up a 1549 00:46:53,220 --> 00:46:54,220 little bit let's say just about 20 and I 1550 00:46:55,740 --> 00:46:56,740 also like to add a little bit of 1551 00:46:56,940 --> 00:46:57,940 contrast over here and let's also add 1552 00:46:58,560 --> 00:46:59,560 20. and there you go it makes the colors 1553 00:47:00,540 --> 00:47:01,540 pop a little bit more so personally I 1554 00:47:02,099 --> 00:47:03,099 don't like this effect then later on 1555 00:47:03,780 --> 00:47:04,780 we're going to have some glowing objects 1556 00:47:05,400 --> 00:47:06,400 for example the stove let's actually try 1557 00:47:07,500 --> 00:47:08,500 dragging that into the scene so let's go 1558 00:47:09,060 --> 00:47:10,060 into scene View and in the assets let's 1559 00:47:11,280 --> 00:47:12,280 find the stove counter so here it is and 1560 00:47:13,920 --> 00:47:14,920 inside the stove counter there are some 1561 00:47:16,319 --> 00:47:17,319 things so here it is the stove on visual 1562 00:47:18,300 --> 00:47:19,300 this one is disabled by default also on 1563 00:47:20,220 --> 00:47:21,220 the inspector let's just enable on this 1564 00:47:21,480 --> 00:47:22,480 game object to make it visible again 1565 00:47:22,920 --> 00:47:23,920 don't worry about the positioning of the 1566 00:47:24,480 --> 00:47:25,480 objects on the scene view right now 1567 00:47:25,619 --> 00:47:26,619 we're only positioning them just to set 1568 00:47:27,180 --> 00:47:28,180 up the post pressing we're going to 1569 00:47:28,440 --> 00:47:29,440 delete them all at the end of this 1570 00:47:29,579 --> 00:47:30,579 lecture okay so now in enable let's go 1571 00:47:31,680 --> 00:47:32,680 into the game View and over here we see 1572 00:47:33,000 --> 00:47:34,000 the stove enabled so now let's go into 1573 00:47:35,040 --> 00:47:36,040 the local volume let's add an override 1574 00:47:36,780 --> 00:47:37,780 go into post pressing let's add a volume 1575 00:47:38,460 --> 00:47:39,460 effect so right now notice how that one 1576 00:47:40,440 --> 00:47:41,440 is not glowing red hot for that work we 1577 00:47:42,660 --> 00:47:43,660 need to have Bloom and we need to enable 1578 00:47:44,220 --> 00:47:45,220 the threshold and the intensity if we 1579 00:47:46,380 --> 00:47:47,380 raise the intensity we do see yep there 1580 00:47:48,180 --> 00:47:49,180 we go a really nice low there by the way 1581 00:47:49,859 --> 00:47:50,859 here's a quick visual attempt if you 1582 00:47:51,540 --> 00:47:52,540 want to make your game feel a bit more 1583 00:47:52,859 --> 00:47:53,859 ethereal and magical one good way is to 1584 00:47:54,780 --> 00:47:55,780 put the threshold that on low value 1585 00:47:56,099 --> 00:47:57,099 below one so something like 0.5 and then 1586 00:47:58,680 --> 00:47:59,680 put the intensity as a little bit and 1587 00:48:00,480 --> 00:48:01,480 with this notice how everything has a 1588 00:48:02,220 --> 00:48:03,220 slight low even colors that don't have 1589 00:48:03,960 --> 00:48:04,960 any extra intensity so the floor is 1590 00:48:05,640 --> 00:48:06,640 glowing the character is going so 1591 00:48:06,839 --> 00:48:07,839 everything looks quite a bit ethereum 1592 00:48:08,280 --> 00:48:09,280 this is a bit extreme but it is an 1593 00:48:09,960 --> 00:48:10,960 interesting effect also another quick 1594 00:48:11,400 --> 00:48:12,400 note here in case you're not seeing 1595 00:48:12,780 --> 00:48:13,780 anything change make sure you go into 1596 00:48:14,520 --> 00:48:15,520 the render prop online assets so the urp 1597 00:48:16,200 --> 00:48:17,200 High Fidelity and over here make sure 1598 00:48:17,760 --> 00:48:18,760 AGR is enabled you can look at so low if 1599 00:48:20,520 --> 00:48:21,520 I disable it yep that one stops glowing 1600 00:48:22,260 --> 00:48:23,260 and with that enabled it does start 1601 00:48:23,579 --> 00:48:24,579 glowing AGR stands for high dynamic 1602 00:48:25,560 --> 00:48:26,560 range so that is how you can have a 1603 00:48:27,300 --> 00:48:28,300 color go with an intensity above one 1604 00:48:29,220 --> 00:48:30,220 which actually makes it low when you 1605 00:48:30,780 --> 00:48:31,780 have the balloon post pressing if even 1606 00:48:32,099 --> 00:48:33,099 with that you're still seeing issues 1607 00:48:33,359 --> 00:48:34,359 then make sure you go into the renderer 1608 00:48:34,740 --> 00:48:35,740 and over here for the post processing 1609 00:48:36,240 --> 00:48:37,240 sometimes Unity has a weird bug and 1610 00:48:38,160 --> 00:48:39,160 doesn't generate this post-process data 1611 00:48:39,960 --> 00:48:40,960 file so if that does happen just go 1612 00:48:41,579 --> 00:48:42,579 ahead untoggle and toggle this and it 1613 00:48:43,440 --> 00:48:44,440 should work and finally like I said on 1614 00:48:45,060 --> 00:48:46,060 the camera make sure you have post 1615 00:48:46,319 --> 00:48:47,319 Crossing in Arrow so with all that you 1616 00:48:48,060 --> 00:48:49,060 should be able to see the game view glow 1617 00:48:49,500 --> 00:48:50,500 okay back into our effects with our 1618 00:48:51,359 --> 00:48:52,359 balloon working like I said you can 1619 00:48:52,920 --> 00:48:53,920 lower this below one to get a nice 1620 00:48:54,480 --> 00:48:55,480 ethereum look but this is a bit too 1621 00:48:56,040 --> 00:48:57,040 intensive on what we want so let's make 1622 00:48:57,780 --> 00:48:58,780 it a bit more subtle so on the threshold 1623 00:48:59,220 --> 00:49:00,220 let's put it at 0.95 so there's a slight 1624 00:49:01,680 --> 00:49:02,680 low on the white Parts but nothing too 1625 00:49:03,240 --> 00:49:04,240 intense and for intensity let's put it 1626 00:49:05,099 --> 00:49:06,099 at a wrong number one okay so I think 1627 00:49:06,839 --> 00:49:07,839 that's a nice amount of Bloom all the 1628 00:49:08,400 --> 00:49:09,400 colors glow a little bit and we can see 1629 00:49:10,319 --> 00:49:11,319 over there the stove it is indeed 1630 00:49:11,700 --> 00:49:12,700 glowing okay great now if you ever 1631 00:49:13,680 --> 00:49:14,680 forget all these steps and you can get 1632 00:49:15,359 --> 00:49:16,359 your project to Glow I made a nice video 1633 00:49:17,220 --> 00:49:18,220 with a nice checklist of everything 1634 00:49:18,660 --> 00:49:19,660 needed for you low definitely go ahead 1635 00:49:20,819 --> 00:49:21,819 and watch that video whenever you have 1636 00:49:22,020 --> 00:49:23,020 issues then for another fun effect we 1637 00:49:24,359 --> 00:49:25,359 have yet so let's go into ad override 1638 00:49:26,280 --> 00:49:27,280 post Crossing and let's find the 1639 00:49:27,839 --> 00:49:28,839 vignette what this one does is adds a 1640 00:49:29,700 --> 00:49:30,700 bit of Darkness to the colors so if we 1641 00:49:31,380 --> 00:49:32,380 enable the intensity and we increase it 1642 00:49:33,119 --> 00:49:34,119 you can see what it does so it adds 1643 00:49:34,740 --> 00:49:35,740 Darkness around the corners there 1644 00:49:35,940 --> 00:49:36,940 personally I find this one looks good 1645 00:49:37,380 --> 00:49:38,380 when it's quite a bit subtle so let's 1646 00:49:38,940 --> 00:49:39,940 put the intensity at some like 0.25 and 1647 00:49:41,700 --> 00:49:42,700 then for the smoothness let's also put 1648 00:49:43,380 --> 00:49:44,380 it on 0.4 so just like that just a 1649 00:49:45,720 --> 00:49:46,720 slight Darkness on the edges so 1650 00:49:46,980 --> 00:49:47,980 personally I think it looks pretty good 1651 00:49:48,300 --> 00:49:49,300 and that's pretty much it for the Post 1652 00:49:50,280 --> 00:49:51,280 Crossing on the volume component I like 1653 00:49:52,260 --> 00:49:53,260 how this looks you can see difference 1654 00:49:53,400 --> 00:49:54,400 with the volume enabled or disabled 1655 00:49:55,319 --> 00:49:56,319 quite a big difference looks pretty nice 1656 00:49:56,880 --> 00:49:57,880 but again these are just visuals so feel 1657 00:49:59,160 --> 00:50:00,160 free to play around maybe add some more 1658 00:50:00,960 --> 00:50:01,960 effects using different settings these 1659 00:50:03,000 --> 00:50:04,000 are just visuals they don't impact the 1660 00:50:04,500 --> 00:50:05,500 game logic at all so feel free to make 1661 00:50:06,119 --> 00:50:07,119 it work exactly as you wanted then yet 1662 00:50:08,520 --> 00:50:09,520 another thing related to post processing 1663 00:50:10,140 --> 00:50:11,140 but not in this component it's some 1664 00:50:11,520 --> 00:50:12,520 anti-aliasing for that one place where 1665 00:50:13,560 --> 00:50:14,560 you can change it is on the main camera 1666 00:50:15,000 --> 00:50:16,000 over here you see a film for post 1667 00:50:16,740 --> 00:50:17,740 Crossing and you have a bunch of types 1668 00:50:18,420 --> 00:50:19,420 so fxa a or smaa or if you want some 1669 00:50:21,960 --> 00:50:22,960 more higher end post processing you can 1670 00:50:23,520 --> 00:50:24,520 go into the render prop online Essence 1671 00:50:24,900 --> 00:50:25,900 so urp and hyphenoly and over here we 1672 00:50:26,880 --> 00:50:27,880 see anti-analyzing msai this one is a 1673 00:50:29,400 --> 00:50:30,400 bit more expensive but looks a bit 1674 00:50:30,780 --> 00:50:31,780 better if you want to see difference you 1675 00:50:32,280 --> 00:50:33,280 can go over here into the aim View and 1676 00:50:34,140 --> 00:50:35,140 on the slider up top on the scale you 1677 00:50:35,880 --> 00:50:36,880 can increase this quite a bit so with 1678 00:50:37,680 --> 00:50:38,680 this we can now see the pixelation and 1679 00:50:39,359 --> 00:50:40,359 you can see over here if I switch at the 1680 00:50:40,980 --> 00:50:41,980 only thing from 4X back into the table 1681 00:50:42,540 --> 00:50:43,540 you can see lots of jagged edges and if 1682 00:50:45,000 --> 00:50:46,000 I put it on 2x Yep looks a bit more 1683 00:50:46,859 --> 00:50:47,859 smooth 4X a bit more smooth and 8x even 1684 00:50:49,140 --> 00:50:50,140 more smooth so with that you can see 1685 00:50:51,000 --> 00:50:52,000 difference on all the edges on the 1686 00:50:52,559 --> 00:50:53,559 things by default this renderer has on 1687 00:50:54,599 --> 00:50:55,599 4X and nothing on the camera this 1688 00:50:56,400 --> 00:50:57,400 already unlocks pretty good but to make 1689 00:50:57,780 --> 00:50:58,780 the video look even better I'm going to 1690 00:50:59,099 --> 00:51:00,099 put it on 8X and on the main camera I'm 1691 00:51:01,619 --> 00:51:02,619 also going to leave it with no 1692 00:51:02,700 --> 00:51:03,700 anti-alency you can combine them but if 1693 00:51:04,319 --> 00:51:05,319 you do then everything looks a bit too 1694 00:51:05,700 --> 00:51:06,700 wiry so I don't quite like that effect 1695 00:51:07,800 --> 00:51:08,800 so put this one on none and the other 1696 00:51:09,540 --> 00:51:10,540 one on 8X although again this is just a 1697 00:51:11,880 --> 00:51:12,880 visual so if you have a low end PC feel 1698 00:51:13,980 --> 00:51:14,980 free to go into the urp and over here 1699 00:51:16,260 --> 00:51:17,260 disable anti-alizing so the game looks a 1700 00:51:18,359 --> 00:51:19,359 bit worse but it won't run much better 1701 00:51:19,920 --> 00:51:20,920 okay let's drag the scale back down okay 1702 00:51:22,260 --> 00:51:23,260 now one final thing we can add is some 1703 00:51:25,079 --> 00:51:26,079 really nice screen space ambient 1704 00:51:26,400 --> 00:51:27,400 conclusion for that let's go into the 1705 00:51:28,140 --> 00:51:29,140 render so not the render pipeline asset 1706 00:51:29,880 --> 00:51:30,880 the renderer and over here by default it 1707 00:51:31,680 --> 00:51:32,680 already added screen space ambient 1708 00:51:33,180 --> 00:51:34,180 Collision if it didn't add you can click 1709 00:51:34,680 --> 00:51:35,680 on ADD render feature and over here you 1710 00:51:36,420 --> 00:51:37,420 won't be able to see it I don't see it 1711 00:51:37,980 --> 00:51:38,980 because I already have it okay so here 1712 00:51:39,480 --> 00:51:40,480 it is basically what this effect does is 1713 00:51:41,520 --> 00:51:42,520 it adds some tiny Shadows where geometry 1714 00:51:43,559 --> 00:51:44,559 intersect if we enable and disable it 1715 00:51:45,599 --> 00:51:46,599 quickly we can see the effect over there 1716 00:51:47,040 --> 00:51:48,040 on the counters so you can see with 1717 00:51:48,780 --> 00:51:49,780 default effects it already Works quite 1718 00:51:50,700 --> 00:51:51,700 nicely for example look there on the 1719 00:51:52,619 --> 00:51:53,619 player we can barely see the difference 1720 00:51:54,059 --> 00:51:55,059 between the head and body but if we 1721 00:51:55,500 --> 00:51:56,500 enable this it has that nice little 1722 00:51:56,760 --> 00:51:57,760 Shadow I think it looks really nice but 1723 00:51:58,680 --> 00:51:59,680 then we've got a bunch of settings we 1724 00:52:00,119 --> 00:52:01,119 can play around increase the intensity 1725 00:52:01,500 --> 00:52:02,500 the radius and so on Now One important 1726 00:52:03,420 --> 00:52:04,420 thing when setting all these effects is 1727 00:52:05,099 --> 00:52:06,099 to remember the point of view of the 1728 00:52:06,720 --> 00:52:07,720 camera in this case we're making a 1729 00:52:08,220 --> 00:52:09,220 top-down game so before we play around 1730 00:52:10,200 --> 00:52:11,200 these settings let's actually position 1731 00:52:11,579 --> 00:52:12,579 the camera in a correct position so 1732 00:52:13,680 --> 00:52:14,680 let's go ahead select the main camera 1733 00:52:15,180 --> 00:52:16,180 and let's position it above pointing 1734 00:52:17,339 --> 00:52:18,339 down so let's put it on an X of 0 on a y 1735 00:52:20,940 --> 00:52:21,940 of 21.5 on his head of minus 21.3 then 1736 00:52:24,900 --> 00:52:25,900 for the rotation on the X 46 then 0 and 1737 00:52:27,660 --> 00:52:28,660 0. and finally on the camera over here 1738 00:52:29,339 --> 00:52:30,339 on the field of view instead of 16 1739 00:52:30,599 --> 00:52:31,599 that's really wine for this game let's 1740 00:52:32,460 --> 00:52:33,460 go with 20. okay so this is the view 1741 00:52:34,079 --> 00:52:35,079 that we're going to use for our game let 1742 00:52:35,700 --> 00:52:36,700 me just rotate the object so they 1743 00:52:37,500 --> 00:52:38,500 actually face the camera so on the 1744 00:52:39,420 --> 00:52:40,420 hierarchy let's just select all the 1745 00:52:41,040 --> 00:52:42,040 objects let's rotate them all around and 1746 00:52:43,619 --> 00:52:44,619 just position them again we're only 1747 00:52:45,359 --> 00:52:46,359 using these just to see what they look 1748 00:52:47,099 --> 00:52:48,099 like we're going to delete all of these 1749 00:52:48,839 --> 00:52:49,839 objects in a bit okay so yep that's the 1750 00:52:50,819 --> 00:52:51,819 game view now that we have the camera 1751 00:52:52,440 --> 00:52:53,440 set up let's work on the settings for 1752 00:52:54,180 --> 00:52:55,180 the eminent conclusion so let's go down 1753 00:52:55,920 --> 00:52:56,920 select the renderer and over here for 1754 00:52:57,540 --> 00:52:58,540 the settings for the intensity and let's 1755 00:52:59,160 --> 00:53:00,160 put it on four for the radiance let's 1756 00:53:01,079 --> 00:53:02,079 put it at 0.3 and direct lighting 1757 00:53:02,940 --> 00:53:03,940 strength let's put it all the way up to 1758 00:53:04,440 --> 00:53:05,440 one okay so you can toggle this enable 1759 00:53:06,480 --> 00:53:07,480 and disable to see difference and yep I 1760 00:53:08,339 --> 00:53:09,339 do think these settings look pretty good 1761 00:53:09,780 --> 00:53:10,780 finally the last thing we need to check 1762 00:53:11,220 --> 00:53:12,220 is in lightning window so let's go into 1763 00:53:13,200 --> 00:53:14,200 window then down into rendering and 1764 00:53:14,819 --> 00:53:15,819 let's go into lighting how it pops up 1765 00:53:16,440 --> 00:53:17,440 the unlighting window personally I like 1766 00:53:18,180 --> 00:53:19,180 to Anchor it over there next thing 1767 00:53:19,200 --> 00:53:20,200 inspector and over here we're really 1768 00:53:20,940 --> 00:53:21,940 going to leave everything on defaults so 1769 00:53:22,980 --> 00:53:23,980 you can leave it as the lighting 1770 00:53:24,119 --> 00:53:25,119 settings assets and nothing assigned and 1771 00:53:26,339 --> 00:53:27,339 then on the environment tab over here 1772 00:53:28,140 --> 00:53:29,140 again all of the defaults I didn't touch 1773 00:53:29,700 --> 00:53:30,700 any of these so we've got environment 1774 00:53:31,319 --> 00:53:32,319 lighting from the Skybox and then some 1775 00:53:32,819 --> 00:53:33,819 multiplier of one so everything pretty 1776 00:53:34,619 --> 00:53:35,619 much on defaults although again like I 1777 00:53:36,480 --> 00:53:37,480 said most of these visual effects are 1778 00:53:37,920 --> 00:53:38,920 very much personal preference so if you 1779 00:53:39,720 --> 00:53:40,720 want to make your game look a bit 1780 00:53:40,859 --> 00:53:41,859 different than mine then go ahead you 1781 00:53:42,540 --> 00:53:43,540 can play around with lighting over here 1782 00:53:44,040 --> 00:53:45,040 you can change Skybox gradient color and 1783 00:53:46,200 --> 00:53:47,200 so on if you want you can use some bake 1784 00:53:48,119 --> 00:53:49,119 lighting then if you want you can add 1785 00:53:49,740 --> 00:53:50,740 all kinds of extra effects and also by 1786 00:53:51,839 --> 00:53:52,839 the way remember that the effects are 1787 00:53:53,280 --> 00:53:54,280 stored on this profile over here so for 1788 00:53:55,380 --> 00:53:56,380 example you can click over here on the 1789 00:53:56,880 --> 00:53:57,880 Clone button and it will include the 1790 00:53:58,619 --> 00:53:59,619 effects and let's click on it to find it 1791 00:53:59,819 --> 00:54:00,819 yep there you go so that's the one that 1792 00:54:01,319 --> 00:54:02,319 I've built and here's a clone one so if 1793 00:54:02,940 --> 00:54:03,940 you want you can make a clone one and 1794 00:54:04,319 --> 00:54:05,319 then make it look very different for 1795 00:54:05,760 --> 00:54:06,760 example let's go into chromatic 1796 00:54:06,900 --> 00:54:07,900 aberration make it really intense and 1797 00:54:09,000 --> 00:54:10,000 for example let's go into the counter 1798 00:54:11,160 --> 00:54:12,160 curves and over here for some reason 1799 00:54:12,960 --> 00:54:13,960 let's drag the green up and so on so 1800 00:54:14,819 --> 00:54:15,819 there you go completely different visual 1801 00:54:16,380 --> 00:54:17,380 so if you want to play around make some 1802 00:54:17,760 --> 00:54:18,760 weird effects and if you want to go back 1803 00:54:19,020 --> 00:54:20,020 to just revert back into the original 1804 00:54:20,520 --> 00:54:21,520 profile personally I'm quite happy with 1805 00:54:22,200 --> 00:54:23,200 how this looks so I'm going to be using 1806 00:54:23,579 --> 00:54:24,579 this one okay again you can enable and 1807 00:54:25,559 --> 00:54:26,559 disable the volume game object to see 1808 00:54:27,359 --> 00:54:28,359 quite the big difference that 1809 00:54:28,500 --> 00:54:29,500 post-processing makes if you ever want 1810 00:54:30,240 --> 00:54:31,240 to make your game look quite a lot 1811 00:54:31,559 --> 00:54:32,559 better always make sure that some post 1812 00:54:33,180 --> 00:54:34,180 processing alright so like I said this 1813 00:54:34,859 --> 00:54:35,859 looks really good I like it now before 1814 00:54:36,839 --> 00:54:37,839 we go to the next lecture let's just 1815 00:54:38,339 --> 00:54:39,339 clean this up so let's get rid of all of 1816 00:54:40,140 --> 00:54:41,140 these objects so the counter cabbage 1817 00:54:41,700 --> 00:54:42,700 tomato and so on let's get rid of all of 1818 00:54:43,319 --> 00:54:44,319 them except the four so let's leave the 1819 00:54:44,700 --> 00:54:45,700 four and get rid of all these alright so 1820 00:54:46,800 --> 00:54:47,800 here we have our nice empty scene let's 1821 00:54:48,540 --> 00:54:49,540 just save our scene and let's get ready 1822 00:54:50,520 --> 00:54:51,520 for the next lecture 1823 00:54:52,740 --> 00:54:53,740 hi there this is a quick intermission so 1824 00:54:55,500 --> 00:54:56,500 how are you doing are you enjoying the 1825 00:54:57,000 --> 00:54:58,000 course so far are you having any trouble 1826 00:54:58,800 --> 00:54:59,800 with anything is there something you 1827 00:55:00,480 --> 00:55:01,480 didn't understand if so remember I'm 1828 00:55:02,579 --> 00:55:03,579 always active in the comments answering 1829 00:55:04,079 --> 00:55:05,079 all the questions so if there's anything 1830 00:55:05,940 --> 00:55:06,940 you need some extra clarification go 1831 00:55:07,920 --> 00:55:08,920 ahead and ask and I'll do my best to 1832 00:55:09,300 --> 00:55:10,300 help also remember to check out the pin 1833 00:55:11,579 --> 00:55:12,579 comment YouTube videos cannot be updated 1834 00:55:14,040 --> 00:55:15,040 so for any notes or comments I'll put 1835 00:55:16,079 --> 00:55:17,079 them in the pin comment and definitely 1836 00:55:18,059 --> 00:55:19,059 check out the website page for this 1837 00:55:19,680 --> 00:55:20,680 course as people ask more and more 1838 00:55:21,780 --> 00:55:22,780 questions I will keep that page updated 1839 00:55:23,339 --> 00:55:24,339 with any frequently asked questions for 1840 00:55:25,140 --> 00:55:26,140 every single lecture so that way you can 1841 00:55:26,940 --> 00:55:27,940 see what others have asked and learn 1842 00:55:28,260 --> 00:55:29,260 from them and you can also download the 1843 00:55:30,420 --> 00:55:31,420 project files for each lecture so keep 1844 00:55:32,700 --> 00:55:33,700 that page open on a second Tab and check 1845 00:55:34,619 --> 00:55:35,619 it every time you start watching a new 1846 00:55:36,119 --> 00:55:37,119 lecture I really hope you're enjoying 1847 00:55:38,280 --> 00:55:39,280 the course and I hope you've already 1848 00:55:39,420 --> 00:55:40,420 learned quite a few things go ahead and 1849 00:55:41,700 --> 00:55:42,700 hit the like button and subscribe to the 1850 00:55:43,140 --> 00:55:44,140 channel if you haven't already 1851 00:55:44,579 --> 00:55:45,579 okay so let's go to the next lecture 1852 00:55:47,940 --> 00:55:48,940 hello and welcome I'm your kudmaki in 1853 00:55:50,400 --> 00:55:51,400 this lecture we're going to begin 1854 00:55:51,420 --> 00:55:52,420 creating our character let's make a nice 1855 00:55:53,579 --> 00:55:54,579 character controller so we can move our 1856 00:55:55,200 --> 00:55:56,200 character in the world 1857 00:55:56,819 --> 00:55:57,819 okay so first let's begin by creating 1858 00:55:58,859 --> 00:55:59,859 the character game object 1859 00:56:00,420 --> 00:56:01,420 and now usually most beginner tutorials 1860 00:56:02,940 --> 00:56:03,940 will tell you to just right click go 1861 00:56:04,800 --> 00:56:05,800 into 3D object and create something like 1862 00:56:06,660 --> 00:56:07,660 a capsule that way you would have the 1863 00:56:09,059 --> 00:56:10,059 game object with the visual included 1864 00:56:11,520 --> 00:56:12,520 however for a good project structure and 1865 00:56:14,040 --> 00:56:15,040 good organization you should only 1866 00:56:15,660 --> 00:56:16,660 separate the visuals from the logic for 1867 00:56:18,119 --> 00:56:19,119 example here in let's say that I don't 1868 00:56:19,619 --> 00:56:20,619 want my capsule exam like this let's say 1869 00:56:21,900 --> 00:56:22,900 that I want my player to be a little bit 1870 00:56:23,460 --> 00:56:24,460 more skinny to do that I would have to 1871 00:56:25,559 --> 00:56:26,559 modify on the scale on this game object 1872 00:56:27,240 --> 00:56:28,240 so put it maybe on 0.7.7 so something 1873 00:56:30,180 --> 00:56:31,180 like this basically by doing that by 1874 00:56:32,040 --> 00:56:33,040 modifying the visual I also modified the 1875 00:56:34,140 --> 00:56:35,140 scale on the actual player game object 1876 00:56:36,000 --> 00:56:37,000 having a non-uniform scale on a logic 1877 00:56:38,880 --> 00:56:39,880 game object that can cause all kind of 1878 00:56:40,680 --> 00:56:41,680 problems with any kind of logic 1879 00:56:42,540 --> 00:56:43,540 component also I would prefer to have my 1880 00:56:44,640 --> 00:56:45,640 character on the floor but if I put it 1881 00:56:46,200 --> 00:56:47,200 on yf0 notice how the character is half 1882 00:56:48,599 --> 00:56:49,599 underneath the floor so if I were to use 1883 00:56:50,760 --> 00:56:51,760 this method I would have to apply some 1884 00:56:52,619 --> 00:56:53,619 kind of offset in order to make the 1885 00:56:53,880 --> 00:56:54,880 visual above the floor so that would 1886 00:56:55,800 --> 00:56:56,800 require rearranging all the logic to 1887 00:56:57,540 --> 00:56:58,540 work with an offset on the Y position so 1888 00:57:00,059 --> 00:57:01,059 because of those reasons and many more 1889 00:57:01,680 --> 00:57:02,680 you should not Place both the logic and 1890 00:57:03,900 --> 00:57:04,900 the visual on the same game object 1891 00:57:05,280 --> 00:57:06,280 instead you should separate them so 1892 00:57:07,800 --> 00:57:08,800 let's get rid of this and instead let's 1893 00:57:09,660 --> 00:57:10,660 create an empty game object let's name 1894 00:57:11,940 --> 00:57:12,940 this the player 1895 00:57:13,319 --> 00:57:14,319 let's put it on zero zero zero okay and 1896 00:57:16,559 --> 00:57:17,559 now inside of it now inside let's create 1897 00:57:19,140 --> 00:57:20,140 let's say a capsule now in this one we 1898 00:57:21,540 --> 00:57:22,540 can easily scale this to get any size 1899 00:57:23,040 --> 00:57:24,040 and shape you want so for example 0.7.7 1900 00:57:25,859 --> 00:57:26,859 then since the visual is a child of the 1901 00:57:28,380 --> 00:57:29,380 game object we can also easily offset 1902 00:57:30,059 --> 00:57:31,059 this so let's say you put it up by about 1903 00:57:31,680 --> 00:57:32,680 one unit so with this we can position 1904 00:57:34,079 --> 00:57:35,079 the visual so that basically the player 1905 00:57:36,059 --> 00:57:37,059 game object is over here on zero zero 1906 00:57:37,740 --> 00:57:38,740 and the character is above the floor so 1907 00:57:39,300 --> 00:57:40,300 we don't have any weird offsets this 1908 00:57:41,700 --> 00:57:42,700 will make all of our logic much more 1909 00:57:43,319 --> 00:57:44,319 simplified 1910 00:57:44,280 --> 00:57:45,280 and on this empty Parent Game object we 1911 00:57:46,740 --> 00:57:47,740 can attach all of the logic components 1912 00:57:48,300 --> 00:57:49,300 we want and then in the child visual we 1913 00:57:51,000 --> 00:57:52,000 can either replace whatever visuals we 1914 00:57:52,859 --> 00:57:53,859 want so as a general rule you should 1915 00:57:55,020 --> 00:57:56,020 always try to do this only separate the 1916 00:57:57,000 --> 00:57:58,000 logic from the Visions in your game 1917 00:57:58,440 --> 00:57:59,440 objects 1918 00:57:59,700 --> 00:58:00,700 okay so with that we have the player 1919 00:58:01,559 --> 00:58:02,559 game object now let's make our character 1920 00:58:03,420 --> 00:58:04,420 controller script 1921 00:58:04,800 --> 00:58:05,800 and before we do let's keep things once 1922 00:58:06,900 --> 00:58:07,900 again organized so before we do let's 1923 00:58:09,359 --> 00:58:10,359 create a brand new folder so let's right 1924 00:58:10,680 --> 00:58:11,680 click on the assets create a brand new 1925 00:58:12,420 --> 00:58:13,420 folder call it scripts and now inside 1926 00:58:15,059 --> 00:58:16,059 let's right click and create new c-sharp 1927 00:58:17,099 --> 00:58:18,099 script called the player wait for the 1928 00:58:19,559 --> 00:58:20,559 code to compound then select the player 1929 00:58:21,480 --> 00:58:22,480 game object and attach the script again 1930 00:58:23,339 --> 00:58:24,339 remember logic components go on the 1931 00:58:25,200 --> 00:58:26,200 parent game object not the channel 1932 00:58:26,640 --> 00:58:27,640 vision so the challenge visual this one 1933 00:58:28,859 --> 00:58:29,859 only has visual components and the 1934 00:58:30,359 --> 00:58:31,359 player this is the one that actually has 1935 00:58:31,859 --> 00:58:32,859 the logic components so let's open up 1936 00:58:33,780 --> 00:58:34,780 this script 1937 00:58:34,859 --> 00:58:35,859 okay so here's our first c-sharp script 1938 00:58:37,079 --> 00:58:38,079 like I said I'm going to assume you know 1939 00:58:39,059 --> 00:58:40,059 the absolute Basics go watch the c-sharp 1940 00:58:41,400 --> 00:58:42,400 basics video If you haven't seen it yet 1941 00:58:43,319 --> 00:58:44,319 so I won't assume that you know what is 1942 00:58:45,240 --> 00:58:46,240 a function what is a variable what is 1943 00:58:47,040 --> 00:58:48,040 start and update so pretty much the 1944 00:58:48,900 --> 00:58:49,900 absolute basics for a character 1945 00:58:50,760 --> 00:58:51,760 controller we first need some input from 1946 00:58:52,799 --> 00:58:53,799 the player and for that EMT actually has 1947 00:58:55,020 --> 00:58:56,020 two methods you have the Legacy input 1948 00:58:57,059 --> 00:58:58,059 manager and the new input system 1949 00:58:58,520 --> 00:58:59,520 basically the Legacy input manager is 1950 00:59:01,020 --> 00:59:02,020 super simple and very easy to use so 1951 00:59:02,819 --> 00:59:03,819 this one is perfect for quickly 1952 00:59:04,200 --> 00:59:05,200 prototyping and the new input system is 1953 00:59:06,720 --> 00:59:07,720 extremely capable with tons of features 1954 00:59:08,339 --> 00:59:09,339 but it's also a bit more complex so what 1955 00:59:10,799 --> 00:59:11,799 I do is while I'm doing a simple demo or 1956 00:59:12,839 --> 00:59:13,839 testing out a new prototype by just 1957 00:59:14,400 --> 00:59:15,400 using Legacy input manager but when 1958 00:59:16,200 --> 00:59:17,200 making a more complex project like for 1959 00:59:18,000 --> 00:59:19,000 example my sim game then at a certain 1960 00:59:19,500 --> 00:59:20,500 point I refactor my code to use the new 1961 00:59:21,299 --> 00:59:22,299 input system so here I'm going to teach 1962 00:59:23,400 --> 00:59:24,400 you both as well as teaching you how to 1963 00:59:25,260 --> 00:59:26,260 refactor code which is an extremely 1964 00:59:26,819 --> 00:59:27,819 useful skill so let's first begin by 1965 00:59:28,920 --> 00:59:29,920 using the Simpson Legacy input manager 1966 00:59:31,440 --> 00:59:32,440 we want some basic was movement to move 1967 00:59:33,660 --> 00:59:34,660 our character and we're going to need to 1968 00:59:35,579 --> 00:59:36,579 run that logic on every single frame so 1969 00:59:37,559 --> 00:59:38,559 let's do it on update and let's actually 1970 00:59:39,720 --> 00:59:40,720 get rid of the code that Unity writes by 1971 00:59:41,700 --> 00:59:42,700 default let's start coming from scratch 1972 00:59:43,440 --> 00:59:44,440 and let's get rid of this just close 1973 00:59:45,059 --> 00:59:46,059 okay so here let's start by writing 1974 00:59:47,460 --> 00:59:48,460 private void update and now here very 1975 00:59:49,980 --> 00:59:50,980 important if you're a beginner make sure 1976 00:59:51,480 --> 00:59:52,480 that update is written exactly like this 1977 00:59:53,339 --> 00:59:54,339 if you write update with lowercase if 1978 00:59:55,799 --> 00:59:56,799 you do this then it won't work the 1979 00:59:57,240 --> 00:59:58,240 function will not be calmed 1980 00:59:58,380 --> 00:59:59,380 automatically I'm pointing this out 1981 01:00:00,240 --> 01:00:01,240 because I have seen a bunch of comments 1982 01:00:01,680 --> 01:00:02,680 from beginners wondering why their code 1983 01:00:03,119 --> 01:00:04,119 doesn't work and it's as simple as this 1984 01:00:04,500 --> 01:00:05,500 with a lowercase Unity will not call 1985 01:00:06,720 --> 01:00:07,720 this automatically it needs to be 1986 01:00:08,040 --> 01:00:09,040 exactly perfect so again if you're a 1987 01:00:10,020 --> 01:00:11,020 beginner make sure you write the code 1988 01:00:11,160 --> 01:00:12,160 exactly the code is case sensitive so 1989 01:00:13,380 --> 01:00:14,380 this is very important 1990 01:00:14,760 --> 01:00:15,760 also another note you saw that the code 1991 01:00:16,980 --> 01:00:17,980 that Unity wrote by default when we made 1992 01:00:18,900 --> 01:00:19,900 a new script it just had void update it 1993 01:00:21,480 --> 01:00:22,480 did not have the private keyword private 1994 01:00:23,700 --> 01:00:24,700 is what is called an accessor you have 1995 01:00:25,859 --> 01:00:26,859 private then you have public and then 1996 01:00:27,599 --> 01:00:28,599 there are some more advanced ones 1997 01:00:29,339 --> 01:00:30,339 secondly you can omit the accessor and 1998 01:00:32,099 --> 01:00:33,099 in most cases it will default to private 1999 01:00:33,960 --> 01:00:34,960 however in writing good clean code you 2000 01:00:36,540 --> 01:00:37,540 should be as explicit as possible there 2001 01:00:38,400 --> 01:00:39,400 should be no room for misunderstandings 2002 01:00:40,140 --> 01:00:41,140 so while technically you could emit the 2003 01:00:42,359 --> 01:00:43,359 private you should always include it to 2004 01:00:44,760 --> 01:00:45,760 make your code easy to read and easy to 2005 01:00:46,619 --> 01:00:47,619 understand 2006 01:00:47,400 --> 01:00:48,400 this one is the first of many clean code 2007 01:00:49,680 --> 01:00:50,680 rules that I will teach you during this 2008 01:00:51,059 --> 01:00:52,059 course like I said all of the code that 2009 01:00:53,040 --> 01:00:54,040 I'm writing here is on the same level of 2010 01:00:54,660 --> 01:00:55,660 quality that I use in my own 2011 01:00:55,859 --> 01:00:56,859 professional games I'm not going to 2012 01:00:57,660 --> 01:00:58,660 teach you bad practices like so many 2013 01:00:59,280 --> 01:01:00,280 beginner tutorials do so always be 2014 01:01:01,619 --> 01:01:02,619 explicit always include the accessor 2015 01:01:03,299 --> 01:01:04,299 okay so we have our update Running code 2016 01:01:05,640 --> 01:01:06,640 on every single frame then to test if a 2017 01:01:08,160 --> 01:01:09,160 key is being pressed we just go inside 2018 01:01:09,839 --> 01:01:10,839 input then over here we've got two 2019 01:01:12,359 --> 01:01:13,359 functions so we have get key and get key 2020 01:01:14,700 --> 01:01:15,700 down 2021 01:01:15,480 --> 01:01:16,480 both these functions were turning Boeing 2022 01:01:17,460 --> 01:01:18,460 so that's how the true or false the 2023 01:01:19,440 --> 01:01:20,440 difference between them is that get key 2024 01:01:21,119 --> 01:01:22,119 down this one only returns true for a 2025 01:01:23,160 --> 01:01:24,160 single frame when the key is pressed 2026 01:01:24,780 --> 01:01:25,780 whereas get key this one stays true for 2027 01:01:27,119 --> 01:01:28,119 as long as the key is held down for 2028 01:01:28,859 --> 01:01:29,859 example for an action like jumping you 2029 01:01:30,839 --> 01:01:31,839 just want to know when the player 2030 01:01:31,920 --> 01:01:32,920 presses the button so for that one you 2031 01:01:34,020 --> 01:01:35,020 would use get key down however in our 2032 01:01:36,359 --> 01:01:37,359 case for a character controller we want 2033 01:01:37,920 --> 01:01:38,920 to know if the key is being held down we 2034 01:01:39,900 --> 01:01:40,900 don't want just one frame but always 2035 01:01:42,180 --> 01:01:43,180 so for movement let's make sure we go 2036 01:01:44,160 --> 01:01:45,160 with get game 2037 01:01:45,480 --> 01:01:46,480 then requires a key so let's write our 2038 01:01:47,520 --> 01:01:48,520 key code and then choose the key let's 2039 01:01:49,140 --> 01:01:50,140 say we want w 2040 01:01:50,640 --> 01:01:51,640 and then let's just put this inside and 2041 01:01:52,859 --> 01:01:53,859 if just like this okay so here we have 2042 01:01:55,559 --> 01:01:56,559 code we want to run while holding down 2043 01:01:57,180 --> 01:01:58,180 the down key let's do a quick test just 2044 01:01:59,400 --> 01:02:00,400 to verify everything is working 2045 01:02:00,480 --> 01:02:01,480 perfectly and for testing we can use a 2046 01:02:02,940 --> 01:02:03,940 super useful debug.log this one lets us 2047 01:02:05,940 --> 01:02:06,940 print a message in the console someone 2048 01:02:07,500 --> 01:02:08,500 said One log here just say something 2049 01:02:09,180 --> 01:02:10,180 like pressing and then let's also do an 2050 01:02:11,640 --> 01:02:12,640 else and if else let's do a debug.log 2051 01:02:14,040 --> 01:02:15,040 and just do a dash okay so here is our 2052 01:02:16,680 --> 01:02:17,680 very basic script let's make sure to 2053 01:02:18,420 --> 01:02:19,420 save it so Ctrl s then back in unity 2054 01:02:21,359 --> 01:02:22,359 over here make sure you have the script 2055 01:02:23,640 --> 01:02:24,640 attached to the player game object and 2056 01:02:25,920 --> 01:02:26,920 now we can test and now down here on the 2057 01:02:28,260 --> 01:02:29,260 console we can already see dashes so I'm 2058 01:02:29,940 --> 01:02:30,940 not pressing anything also like I 2059 01:02:32,040 --> 01:02:33,040 mentioned in the setup lecture if you're 2060 01:02:33,660 --> 01:02:34,660 seeing just one message then maybe that 2061 01:02:35,460 --> 01:02:36,460 means you have over here the collapse 2062 01:02:36,960 --> 01:02:37,960 Target if you talk on it and look how it 2063 01:02:38,880 --> 01:02:39,880 only shows one message but then over 2064 01:02:40,500 --> 01:02:41,500 here on the right side it says the 2065 01:02:41,700 --> 01:02:42,700 number of messages personally I prefer 2066 01:02:43,859 --> 01:02:44,859 to always keep it untoggle so I can see 2067 01:02:45,660 --> 01:02:46,660 every single message also over here on 2068 01:02:47,819 --> 01:02:48,819 the right make sure you have info 2069 01:02:49,260 --> 01:02:50,260 messages visible if you untangle this 2070 01:02:51,720 --> 01:02:52,720 and you don't see it so make sure this 2071 01:02:53,040 --> 01:02:54,040 one and actually both of them make sure 2072 01:02:54,660 --> 01:02:55,660 all of them are enabled okay so we're 2073 01:02:56,579 --> 01:02:57,579 seeing a whole bunch of dashes and one 2074 01:02:58,500 --> 01:02:59,500 more note if over here these chromebars 2075 01:03:00,240 --> 01:03:01,240 stop scrolling so right now you can see 2076 01:03:01,799 --> 01:03:02,799 it's stuck up instead of being down 2077 01:03:03,180 --> 01:03:04,180 there so if that happens one is easy way 2078 01:03:05,520 --> 01:03:06,520 to reset that is just click over here on 2079 01:03:07,200 --> 01:03:08,200 clear and it goes back into AutoZone 2080 01:03:08,520 --> 01:03:09,520 okay so we have the dashes I am not 2081 01:03:11,099 --> 01:03:12,099 pressing anything now as I press yep 2082 01:03:13,440 --> 01:03:14,440 there you go there's a message if you 2083 01:03:15,000 --> 01:03:16,000 don't see it make sure the game window 2084 01:03:16,500 --> 01:03:17,500 is in focus 2085 01:03:17,700 --> 01:03:18,700 so selective game View and click right 2086 01:03:19,740 --> 01:03:20,740 here on the middle to make this one the 2087 01:03:21,059 --> 01:03:22,059 focused window then if you press the 2088 01:03:23,220 --> 01:03:24,220 down key you should see the message and 2089 01:03:24,960 --> 01:03:25,960 if I Let Go yep there it is and I stash 2090 01:03:26,880 --> 01:03:27,880 okay great so all the basic logic is 2091 01:03:28,859 --> 01:03:29,859 working back in the code here now that 2092 01:03:31,140 --> 01:03:32,140 logic is working let's get rid of the 2093 01:03:32,880 --> 01:03:33,880 else here 2094 01:03:34,140 --> 01:03:35,140 and let's set this for all the other 2095 01:03:36,000 --> 01:03:37,000 keys so let's copy paste this so we're 2096 01:03:38,520 --> 01:03:39,520 going to need w a s and D so let's make 2097 01:03:41,940 --> 01:03:42,940 all of these 2098 01:03:44,640 --> 01:03:45,640 okay so we have our inputs let's also 2099 01:03:46,740 --> 01:03:47,740 get rid of the logs we don't need this 2100 01:03:49,079 --> 01:03:50,079 all right so we have all of our key 2101 01:03:50,819 --> 01:03:51,819 presses now let's construct a vector 2102 01:03:52,859 --> 01:03:53,859 with our inputs and since we're just 2103 01:03:55,020 --> 01:03:56,020 going to have two axes 2104 01:03:56,760 --> 01:03:57,760 the double s that is forward and 2105 01:03:58,440 --> 01:03:59,440 backwards and this one is left and right 2106 01:03:59,640 --> 01:04:00,640 so just two axis 2107 01:04:01,260 --> 01:04:02,260 so because we have just two let's use a 2108 01:04:03,359 --> 01:04:04,359 vector two and let's call it the input 2109 01:04:05,400 --> 01:04:06,400 vector 2110 01:04:07,260 --> 01:04:08,260 let's construct it so we'll do a new one 2111 01:04:09,420 --> 01:04:10,420 and start off at zero zero okay 2112 01:04:12,119 --> 01:04:13,119 then over here the logic is pretty 2113 01:04:13,559 --> 01:04:14,559 simple so when we press W then let's go 2114 01:04:15,780 --> 01:04:16,780 into the input vector and set the Y to 2115 01:04:17,579 --> 01:04:18,579 pause one 2116 01:04:19,260 --> 01:04:20,260 then when we have an S we want to go 2117 01:04:21,240 --> 01:04:22,240 backwards so put the Y on -1 for the a 2118 01:04:23,700 --> 01:04:24,700 we want to go left so that's an x on the 2119 01:04:26,280 --> 01:04:27,280 minus one and finally for the D that is 2120 01:04:28,980 --> 01:04:29,980 an x on plus one okay so with this we 2121 01:04:31,500 --> 01:04:32,500 have our correct input Vector let's do a 2122 01:04:33,780 --> 01:04:34,780 quick log just to test so debug down log 2123 01:04:35,819 --> 01:04:36,819 on the input vector 2124 01:04:37,680 --> 01:04:38,680 okay so let's test all right so we can 2125 01:04:39,960 --> 01:04:40,960 see in log zero zero okay makes sense 2126 01:04:41,579 --> 01:04:42,579 now if I press W yep we've got an 1 on 2127 01:04:44,400 --> 01:04:45,400 the Y if I press a we got minus one in 2128 01:04:46,740 --> 01:04:47,740 the X press D plus one press s and minus 2129 01:04:49,260 --> 01:04:50,260 one okay great so everything works 2130 01:04:51,440 --> 01:04:52,440 except we also need to be careful about 2131 01:04:53,819 --> 01:04:54,819 one other thing if I press both W and D 2132 01:04:57,359 --> 01:04:58,359 with this look at that the vector is 1 1 2133 01:04:59,880 --> 01:05:00,880 which is correct that's exactly what it 2134 01:05:01,440 --> 01:05:02,440 is then except the factor one one 2135 01:05:03,240 --> 01:05:04,240 actually has a bigger magnitude than 2136 01:05:05,160 --> 01:05:06,160 just one vector if we leave it like this 2137 01:05:07,200 --> 01:05:08,200 then the character will move faster when 2138 01:05:08,760 --> 01:05:09,760 moving diagonally versus when moving in 2139 01:05:10,619 --> 01:05:11,619 just one direction for our input Vector 2140 01:05:12,839 --> 01:05:13,839 we really want it to be normalized 2141 01:05:14,339 --> 01:05:15,339 meaning we wanted to have the same size 2142 01:05:16,140 --> 01:05:17,140 regardless of the combination of keys 2143 01:05:17,819 --> 01:05:18,819 that we're pressing so back in the code 2144 01:05:19,440 --> 01:05:20,440 here after calculating the input vector 2145 01:05:21,299 --> 01:05:22,299 and let's simply normalize it so we go 2146 01:05:23,819 --> 01:05:24,819 into the input vector and we set it 2147 01:05:25,559 --> 01:05:26,559 equals to input Vector Dot normalized 2148 01:05:28,380 --> 01:05:29,380 so this will normalize our input Vector 2149 01:05:30,420 --> 01:05:31,420 let's see and over here if I press 2150 01:05:32,520 --> 01:05:33,520 doubly you've got one press s minus one 2151 01:05:34,619 --> 01:05:35,619 okay so all those work now if I press 2152 01:05:36,480 --> 01:05:37,480 both W and D if there go now it says 2153 01:05:38,940 --> 01:05:39,940 0.71 when you combine both these I need 2154 01:05:41,280 --> 01:05:42,280 the math these do end up with a 2155 01:05:43,079 --> 01:05:44,079 magnitude of one so with this our 2156 01:05:45,119 --> 01:05:46,119 character will move at the same speed on 2157 01:05:46,740 --> 01:05:47,740 both diagonals and straights okay so we 2158 01:05:49,319 --> 01:05:50,319 have the input Vector on correct now 2159 01:05:51,059 --> 01:05:52,059 let's actually apply some movement for 2160 01:05:53,099 --> 01:05:54,099 that there are many ways of making a 2161 01:05:54,599 --> 01:05:55,599 character controller for example you can 2162 01:05:56,339 --> 01:05:57,339 decide to use physics or not over here I 2163 01:05:58,619 --> 01:05:59,619 want to keep the game simple so let's 2164 01:05:59,940 --> 01:06:00,940 not use physics instead let's just move 2165 01:06:02,040 --> 01:06:03,040 the player transform directly over here 2166 01:06:04,079 --> 01:06:05,079 we have our input Vector okay great now 2167 01:06:06,299 --> 01:06:07,299 we want to apply this to our character 2168 01:06:07,859 --> 01:06:08,859 position so first we access the 2169 01:06:09,780 --> 01:06:10,780 transform 2170 01:06:10,920 --> 01:06:11,920 this one refers to the transform where 2171 01:06:12,900 --> 01:06:13,900 this script is attached to 2172 01:06:14,579 --> 01:06:15,579 this script was attached to the player 2173 01:06:16,440 --> 01:06:17,440 so this is going to refer to the player 2174 01:06:18,180 --> 01:06:19,180 transform then we want to modify the 2175 01:06:20,040 --> 01:06:21,040 position so let's access the position 2176 01:06:21,660 --> 01:06:22,660 and now for moving we don't want to just 2177 01:06:23,940 --> 01:06:24,940 assign it if we do something like this 2178 01:06:28,079 --> 01:06:29,079 like this the player would never leave 2179 01:06:29,819 --> 01:06:30,819 the center of the world he would always 2180 01:06:31,260 --> 01:06:32,260 be near zero zero so instead we don't 2181 01:06:33,780 --> 01:06:34,780 want to just assign it but instead we 2182 01:06:35,819 --> 01:06:36,819 want to add onto it now if you're a 2183 01:06:37,680 --> 01:06:38,680 complete beginner and you don't know 2184 01:06:38,940 --> 01:06:39,940 this syntax then this one is exactly the 2185 01:06:40,980 --> 01:06:41,980 same as this so transform dot position 2186 01:06:43,680 --> 01:06:44,680 equals transform dot position plus input 2187 01:06:46,440 --> 01:06:47,440 vector so both these little lines are 2188 01:06:48,960 --> 01:06:49,960 doing the exact same thing personally I 2189 01:06:50,760 --> 01:06:51,760 prefer to use the shorthand I find that 2190 01:06:53,039 --> 01:06:54,039 equally readable and more compact okay 2191 01:06:55,380 --> 01:06:56,380 so we have this and we add our input 2192 01:06:57,599 --> 01:06:58,599 Vector to the transform position except 2193 01:06:59,520 --> 01:07:00,520 we can also see a really nice error 2194 01:07:01,319 --> 01:07:02,319 basically it's telling us that we are 2195 01:07:03,059 --> 01:07:04,059 mixing two types our input is a vector 2196 01:07:05,640 --> 01:07:06,640 two where we only have an X and Y but 2197 01:07:08,280 --> 01:07:09,280 transform that position is a vector 3 2198 01:07:10,260 --> 01:07:11,260 meaning it has an X Y and Z one simple 2199 01:07:13,319 --> 01:07:14,319 solution is to cast our input Vector 2200 01:07:15,359 --> 01:07:16,359 onto a vector three so we just convert 2201 01:07:18,119 --> 01:07:19,119 this from one type into the other one 2202 01:07:19,859 --> 01:07:20,859 and yep we don't have the error so let's 2203 01:07:21,780 --> 01:07:22,780 test and now if I press W any of the 2204 01:07:24,359 --> 01:07:25,359 character does move Let's ignore the 2205 01:07:26,339 --> 01:07:27,339 massive speed for now so it does move it 2206 01:07:28,740 --> 01:07:29,740 does seem slightly correct except you 2207 01:07:31,200 --> 01:07:32,200 can obviously notice that it's not 2208 01:07:32,640 --> 01:07:33,640 correct we are moving on the x-axis on 2209 01:07:35,099 --> 01:07:36,099 left and right that is correct but then 2210 01:07:36,299 --> 01:07:37,299 we are moving up and down instead of 2211 01:07:37,859 --> 01:07:38,859 fourth and back basically we convert the 2212 01:07:40,260 --> 01:07:41,260 effector 2 directly into a vector three 2213 01:07:41,940 --> 01:07:42,940 so we are moving on the X and Y axes but 2214 01:07:44,460 --> 01:07:45,460 in our 3D game we really don't want the 2215 01:07:46,140 --> 01:07:47,140 characters to fly so instead we want to 2216 01:07:48,059 --> 01:07:49,059 move on the XZ axis so back in code here 2217 01:07:50,880 --> 01:07:51,880 instead of directly casting this down 2218 01:07:52,680 --> 01:07:53,680 into a vector 3. let's construct a move 2219 01:07:55,200 --> 01:07:56,200 to your vector similar to Vector three 2220 01:07:57,740 --> 01:07:58,740 let's call it our move there for our 2221 01:08:00,119 --> 01:08:01,119 move Direction and over here we 2222 01:08:02,280 --> 01:08:03,280 construct a new vector3 2223 01:08:04,260 --> 01:08:05,260 and basically we're just going to assign 2224 01:08:05,819 --> 01:08:06,819 the input y to the Zenon here so first 2225 01:08:08,160 --> 01:08:09,160 of all for the X7 is correct so input 2226 01:08:09,900 --> 01:08:10,900 vector.x then for the Y let's leave this 2227 01:08:12,539 --> 01:08:13,539 one on zero and finally let's use the 2228 01:08:14,880 --> 01:08:15,880 input vector.y as I said on the Move 2229 01:08:16,980 --> 01:08:17,980 direction also now at this point you 2230 01:08:19,080 --> 01:08:20,080 might be questioning if we're using a 2231 01:08:21,179 --> 01:08:22,179 vector 3 here why don't we also use a 2232 01:08:23,580 --> 01:08:24,580 vector 3 appear and then just assign the 2233 01:08:25,560 --> 01:08:26,560 Z directly that's certainly a 2234 01:08:27,420 --> 01:08:28,420 possibility and for making a super quick 2235 01:08:29,100 --> 01:08:30,100 prototype I might even do that myself 2236 01:08:31,440 --> 01:08:32,440 but the proper answer to that is once 2237 01:08:33,600 --> 01:08:34,600 again all about writing good clean code 2238 01:08:35,160 --> 01:08:36,160 the input logically only has two axes 2239 01:08:37,980 --> 01:08:38,980 there's no z-axis on your keyboard so 2240 01:08:40,980 --> 01:08:41,980 logically it makes no sense for the 2241 01:08:42,540 --> 01:08:43,540 input to have three axes and beyond that 2242 01:08:45,000 --> 01:08:46,000 you should keep the logic separate so 2243 01:08:46,920 --> 01:08:47,920 you should first get the input and then 2244 01:08:48,719 --> 01:08:49,719 actually move the object we're going to 2245 01:08:50,699 --> 01:08:51,699 see the benefit of that separation when 2246 01:08:52,199 --> 01:08:53,199 we refactor this code to work with the 2247 01:08:53,940 --> 01:08:54,940 new input system doing that will in turn 2248 01:08:56,339 --> 01:08:57,339 make enabling Gamepad joystick support 2249 01:08:58,199 --> 01:08:59,199 super easy because we have the input 2250 01:09:00,179 --> 01:09:01,179 Vector separated from the actual 2251 01:09:01,799 --> 01:09:02,799 movement some of that to say and let's 2252 01:09:03,719 --> 01:09:04,719 do things properly let's keep the input 2253 01:09:06,120 --> 01:09:07,120 Vector separate from the movement Vector 2254 01:09:07,920 --> 01:09:08,920 so we just translate the X Y onto X end 2255 01:09:10,679 --> 01:09:11,679 and then we just apply this into our 2256 01:09:12,900 --> 01:09:13,900 transform position 2257 01:09:14,400 --> 01:09:15,400 okay so let's test so now if I press the 2258 01:09:17,339 --> 01:09:18,339 right turn left and press W and S and 2259 01:09:19,799 --> 01:09:20,799 there you go okay great so it is indeed 2260 01:09:21,540 --> 01:09:22,540 moving Left Right forward and back okay 2261 01:09:23,160 --> 01:09:24,160 great so it is working but as you can 2262 01:09:25,440 --> 01:09:26,440 see it's moving insanely fast you might 2263 01:09:27,660 --> 01:09:28,660 think the issue here is just applying 2264 01:09:29,279 --> 01:09:30,279 some sort of movement speed multiplier 2265 01:09:30,839 --> 01:09:31,839 except there's actually one sneaky issue 2266 01:09:33,239 --> 01:09:34,239 here on the game view on the top right 2267 01:09:35,520 --> 01:09:36,520 corner we've got a stats button and over 2268 01:09:37,319 --> 01:09:38,319 here we can see a whole bunch of things 2269 01:09:38,839 --> 01:09:39,839 specifically we can look at the frame 2270 01:09:40,920 --> 01:09:41,920 rate we can see that it's running at 144 2271 01:09:43,380 --> 01:09:44,380 frames per second over here on the left 2272 01:09:45,779 --> 01:09:46,779 side on this button I have vsync enabled 2273 01:09:48,420 --> 01:09:49,420 this will cap the frame rate to the 2274 01:09:50,219 --> 01:09:51,219 monitor's refresh rate so that is why 2275 01:09:52,500 --> 01:09:53,500 I'm seeing 144 Hertz I can overhear 2276 01:09:54,900 --> 01:09:55,900 disable vsync and the upload that goes 2277 01:09:56,940 --> 01:09:57,940 all the way up to 700. basically now the 2278 01:09:59,100 --> 01:10:00,100 game is running as fast as my computer 2279 01:10:00,300 --> 01:10:01,300 can run it and if I press the movement 2280 01:10:02,580 --> 01:10:03,580 keys and look at that now it's moving 2281 01:10:04,320 --> 01:10:05,320 even faster 2282 01:10:05,580 --> 01:10:06,580 now I've completely lost track of where 2283 01:10:07,440 --> 01:10:08,440 my player is this is not what we want we 2284 01:10:10,440 --> 01:10:11,440 don't want the player to move at 2285 01:10:11,640 --> 01:10:12,640 different speeds depending on the frame 2286 01:10:12,960 --> 01:10:13,960 rate we want it to always move at the 2287 01:10:15,060 --> 01:10:16,060 same speed regardless of frame rate so 2288 01:10:17,219 --> 01:10:18,219 when you do any kind of movement Logic 2289 01:10:18,900 --> 01:10:19,900 on an update you always need to make 2290 01:10:21,120 --> 01:10:22,120 sure to multiply by time dot Delta time 2291 01:10:23,340 --> 01:10:24,340 what this variable contains is the 2292 01:10:25,440 --> 01:10:26,440 number of seconds in Labs since the last 2293 01:10:27,000 --> 01:10:28,000 frame for example let's unlock to this 2294 01:10:29,280 --> 01:10:30,280 we no longer need the input Vector so 2295 01:10:30,840 --> 01:10:31,840 let's unlock just the time that down to 2296 01:10:32,400 --> 01:10:33,400 time okay so we can see there there's 2297 01:10:35,040 --> 01:10:36,040 basically telling us how many seconds it 2298 01:10:36,960 --> 01:10:37,960 is taking to render a single frame once 2299 01:10:39,420 --> 01:10:40,420 again note how I have vsync enabled so 2300 01:10:41,219 --> 01:10:42,219 I'm running at 144 frames per second and 2301 01:10:43,980 --> 01:10:44,980 now if I disable it let's see what 2302 01:10:45,239 --> 01:10:46,239 happens to that number so if I disable 2303 01:10:46,679 --> 01:10:47,679 and you have a look at that that number 2304 01:10:48,179 --> 01:10:49,179 is now much much smaller and the game is 2305 01:10:49,980 --> 01:10:50,980 now running much much faster so by 2306 01:10:52,080 --> 01:10:53,080 incorporating this value into our 2307 01:10:53,520 --> 01:10:54,520 calculation we are going to be taking 2308 01:10:55,020 --> 01:10:56,020 into account the frame rate 2309 01:10:56,699 --> 01:10:57,699 thus making sure that movement is always 2310 01:10:58,500 --> 01:10:59,500 frame rate independent right now with 2311 01:11:00,719 --> 01:11:01,719 this frame rate if I move you can see 2312 01:11:02,159 --> 01:11:03,159 I'm moving at this speed and now if I 2313 01:11:04,199 --> 01:11:05,199 enable vsync change the frame rate and I 2314 01:11:06,060 --> 01:11:07,060 move and I'm still moving at the exact 2315 01:11:07,500 --> 01:11:08,500 same speed 2316 01:11:08,460 --> 01:11:09,460 okay that's great except obviously it's 2317 01:11:10,800 --> 01:11:11,800 not exactly great it's moving way too 2318 01:11:12,480 --> 01:11:13,480 slow so let's also incorporate a 2319 01:11:14,159 --> 01:11:15,159 movement speed now for this once again 2320 01:11:16,080 --> 01:11:17,080 most beginner tutorials will teach you 2321 01:11:17,640 --> 01:11:18,640 to go all the way up here and find a 2322 01:11:19,500 --> 01:11:20,500 public float move speed 2323 01:11:22,800 --> 01:11:23,800 maybe they found it to some villain like 2324 01:11:24,540 --> 01:11:25,540 7f something like that 2325 01:11:26,580 --> 01:11:27,580 then you have this field and then down 2326 01:11:28,739 --> 01:11:29,739 here you simply use it in the 2327 01:11:30,000 --> 01:11:31,000 calculation so movement here move 2328 01:11:32,040 --> 01:11:33,040 multiply it by move speed and by time 2329 01:11:34,140 --> 01:11:35,140 dot time so this is what most tutorials 2330 01:11:36,719 --> 01:11:37,719 will teach you by making it public up 2331 01:11:39,060 --> 01:11:40,060 here what you're doing is you're 2332 01:11:40,260 --> 01:11:41,260 enabling access from the editor so if 2333 01:11:42,480 --> 01:11:43,480 you go over here in the editor over 2334 01:11:43,800 --> 01:11:44,800 there on the player we can see the move 2335 01:11:45,360 --> 01:11:46,360 speed variable we can see this exposed 2336 01:11:47,280 --> 01:11:48,280 and we can modify it this makes it 2337 01:11:49,380 --> 01:11:50,380 really easy for testing and for 2338 01:11:50,699 --> 01:11:51,699 iterating upon the value even while the 2339 01:11:52,320 --> 01:11:53,320 game is running 2340 01:11:53,460 --> 01:11:54,460 so the game is playing I can move and I 2341 01:11:55,440 --> 01:11:56,440 have this move speed now I can modify 2342 01:11:57,420 --> 01:11:58,420 this and yep now I got a different move 2343 01:11:59,219 --> 01:12:00,219 speed so I can use this to quickly to 2344 01:12:00,900 --> 01:12:01,900 rate and find the perfect value 2345 01:12:02,820 --> 01:12:03,820 so it's great to have this variable 2346 01:12:04,620 --> 01:12:05,620 exposed in the editor and this feature 2347 01:12:06,960 --> 01:12:07,960 is indeed the reason why most beginner 2348 01:12:08,520 --> 01:12:09,520 tutorials will teach you to make it 2349 01:12:09,840 --> 01:12:10,840 public it's so you can see it in the 2350 01:12:11,340 --> 01:12:12,340 editor that is indeed a very valuable 2351 01:12:13,620 --> 01:12:14,620 thing being able to easily iterate upon 2352 01:12:15,719 --> 01:12:16,719 important values is always very useful 2353 01:12:17,540 --> 01:12:18,540 however when you make something public 2354 01:12:19,980 --> 01:12:20,980 when you do that you don't just expose 2355 01:12:22,260 --> 01:12:23,260 the film to the editor you are exposing 2356 01:12:24,179 --> 01:12:25,179 it to every other class in your entire 2357 01:12:25,860 --> 01:12:26,860 code base so some other class could 2358 01:12:28,320 --> 01:12:29,320 access this field and set the player's 2359 01:12:30,000 --> 01:12:31,000 movement speed to something like zero 2360 01:12:31,380 --> 01:12:32,380 and you would have no idea that was 2361 01:12:33,120 --> 01:12:34,120 happening because the issue would not be 2362 01:12:34,620 --> 01:12:35,620 on this code right here I have an entire 2363 01:12:36,960 --> 01:12:37,960 video on this subject why you should not 2364 01:12:39,000 --> 01:12:40,000 make everything public this is an 2365 01:12:41,219 --> 01:12:42,219 extremely important topic to know about 2366 01:12:42,659 --> 01:12:43,659 this one tiny change will massively 2367 01:12:45,120 --> 01:12:46,120 improve the quality of your code 2368 01:12:46,739 --> 01:12:47,739 definitely go ahead and watch that video 2369 01:12:48,600 --> 01:12:49,600 to learn why such a bad thing and make 2370 01:12:50,640 --> 01:12:51,640 sure you don't do it so to avoid all 2371 01:12:52,920 --> 01:12:53,920 kinds of problems you should never make 2372 01:12:54,420 --> 01:12:55,420 films public so very quickly the obvious 2373 01:12:56,880 --> 01:12:57,880 alternative is make it private making it 2374 01:12:59,520 --> 01:13:00,520 private means that only this class only 2375 01:13:01,080 --> 01:13:02,080 the code in here only this can modify 2376 01:13:03,060 --> 01:13:04,060 this film so you know for certain that 2377 01:13:04,920 --> 01:13:05,920 no other class can ever modify this 2378 01:13:06,659 --> 01:13:07,659 however making it private also means the 2379 01:13:08,640 --> 01:13:09,640 editor cannot modify this film so we've 2380 01:13:10,980 --> 01:13:11,980 lost our very useful iteration approach 2381 01:13:13,020 --> 01:13:14,020 so what we can do to expose it just to 2382 01:13:15,420 --> 01:13:16,420 the editor is to keep it private and 2383 01:13:16,980 --> 01:13:17,980 then we add the attribute serialize 2384 01:13:18,900 --> 01:13:19,900 field 2385 01:13:19,860 --> 01:13:20,860 this way this field is still private 2386 01:13:21,900 --> 01:13:22,900 meaning that it can only be modified by 2387 01:13:23,880 --> 01:13:24,880 the code inside the player class but 2388 01:13:26,159 --> 01:13:27,159 with this attribute over here in the 2389 01:13:28,260 --> 01:13:29,260 editor yep we do have an editable field 2390 01:13:30,300 --> 01:13:31,300 so only the code in that class in the 2391 01:13:32,340 --> 01:13:33,340 editor can modify it nothing else can 2392 01:13:34,620 --> 01:13:35,620 touch it nothing else can read or write 2393 01:13:36,540 --> 01:13:37,540 which is exactly what we want one of the 2394 01:13:38,760 --> 01:13:39,760 main rules in writing good clean code is 2395 01:13:40,560 --> 01:13:41,560 minimizing complexity and one of the 2396 01:13:42,360 --> 01:13:43,360 easier ways to minimize complexity is 2397 01:13:43,980 --> 01:13:44,980 simply to minimize axis by making this 2398 01:13:46,620 --> 01:13:47,620 feel private we are minimizing 2399 01:13:48,120 --> 01:13:49,120 complexity because it doesn't matter how 2400 01:13:49,860 --> 01:13:50,860 complex our game is maybe our code base 2401 01:13:52,080 --> 01:13:53,080 is a thousand classes long it doesn't 2402 01:13:53,880 --> 01:13:54,880 really matter because only this class 2403 01:13:55,560 --> 01:13:56,560 can never touch this field so if we have 2404 01:13:57,900 --> 01:13:58,900 a bug related movement speed we know for 2405 01:13:59,880 --> 01:14:00,880 certain it has to be inside this code 2406 01:14:01,620 --> 01:14:02,620 and nothing else so we minimize the 2407 01:14:03,900 --> 01:14:04,900 things we need to keep in our head which 2408 01:14:05,340 --> 01:14:06,340 is always a very good thing okay so with 2409 01:14:07,380 --> 01:14:08,380 all that said we have our movement speed 2410 01:14:08,940 --> 01:14:09,940 and down here we are incorporating it 2411 01:14:10,679 --> 01:14:11,679 into our calculation just with this we 2412 01:14:13,080 --> 01:14:14,080 have our character working with a 2413 01:14:14,340 --> 01:14:15,340 variable movement speed and by using 2414 01:14:16,560 --> 01:14:17,560 Delta time we have our movement 2415 01:14:17,940 --> 01:14:18,940 correctly being frame rate independent 2416 01:14:19,920 --> 01:14:20,920 so here's our character and using the 2417 01:14:21,719 --> 01:14:22,719 keys I can walk around and yep the 2418 01:14:23,340 --> 01:14:24,340 character moves in any direction so we 2419 01:14:24,960 --> 01:14:25,960 have movement only working while using 2420 01:14:26,880 --> 01:14:27,880 the Legacy input manager like I said 2421 01:14:29,159 --> 01:14:30,159 we're going to learn how to refactor our 2422 01:14:30,659 --> 01:14:31,659 code to use the new input system 2423 01:14:31,920 --> 01:14:32,920 learning how to refactor is an extremely 2424 01:14:34,080 --> 01:14:35,080 important skill to improve your own 2425 01:14:35,400 --> 01:14:36,400 programming skills it is something that 2426 01:14:37,679 --> 01:14:38,679 you should always do when necessary it 2427 01:14:39,480 --> 01:14:40,480 will massively help you improve the 2428 01:14:40,800 --> 01:14:41,800 quality of your code 2429 01:14:42,300 --> 01:14:43,300 so we're going to do that but before we 2430 01:14:44,280 --> 01:14:45,280 get to that let's actually do something 2431 01:14:45,659 --> 01:14:46,659 a bit more fun and add some proper 2432 01:14:47,219 --> 01:14:48,219 visuals and animations to our player in 2433 01:14:49,080 --> 01:14:50,080 the next lecture 2434 01:14:51,120 --> 01:14:52,120 hello and welcome I'm your code monkey 2435 01:14:53,100 --> 01:14:54,100 in this lecture we're going to replace 2436 01:14:54,840 --> 01:14:55,840 our boring capsule visual with a nice 2437 01:14:57,060 --> 01:14:58,060 proper character mesh okay so in the 2438 01:14:59,340 --> 01:15:00,340 included assets project files over here 2439 01:15:01,560 --> 01:15:02,560 if we go inside the prefab visuals we 2440 01:15:03,960 --> 01:15:04,960 see a nice player visual let's position 2441 01:15:06,000 --> 01:15:07,000 it inside the player game object so 2442 01:15:08,219 --> 01:15:09,219 let's drag it inside again because we 2443 01:15:10,440 --> 01:15:11,440 separate the logic and visuals this is 2444 01:15:12,060 --> 01:15:13,060 going to be pretty easy we don't need to 2445 01:15:13,860 --> 01:15:14,860 modify the parent game object at all we 2446 01:15:15,780 --> 01:15:16,780 just dropped the visualize this channel 2447 01:15:17,040 --> 01:15:18,040 that's it also again very important make 2448 01:15:19,140 --> 01:15:20,140 sure the visual is over here on low 2449 01:15:20,580 --> 01:15:21,580 composition zero zero zero only the 2450 01:15:22,440 --> 01:15:23,440 parent game object should move the 2451 01:15:24,179 --> 01:15:25,179 visual itself should never move if you 2452 01:15:25,860 --> 01:15:26,860 notice some weird positions as your 2453 01:15:27,360 --> 01:15:28,360 player moves and rotates always check to 2454 01:15:29,340 --> 01:15:30,340 make sure that the channel visual is on 2455 01:15:31,140 --> 01:15:32,140 zero zero zero okay so with this let's 2456 01:15:33,060 --> 01:15:34,060 delete the old capsule delete it okay so 2457 01:15:35,880 --> 01:15:36,880 here we have a pretty simple but really 2458 01:15:37,800 --> 01:15:38,800 nice character visual it's really just 2459 01:15:39,659 --> 01:15:40,659 two spheres stacked on top of one 2460 01:15:41,159 --> 01:15:42,159 another with a bunch of eyes very simple 2461 01:15:42,840 --> 01:15:43,840 for the visual itself the material is 2462 01:15:45,179 --> 01:15:46,179 using just a solid color so here it is 2463 01:15:47,580 --> 01:15:48,580 inside the assets material you can see a 2464 01:15:49,679 --> 01:15:50,679 bunch of player bodies with different 2465 01:15:50,820 --> 01:15:51,820 color these different colors they won't 2466 01:15:52,739 --> 01:15:53,739 be used in the upcoming multiplayer 2467 01:15:54,420 --> 01:15:55,420 video basically each player will have a 2468 01:15:56,040 --> 01:15:57,040 different color also by the way if 2469 01:15:57,420 --> 01:15:58,420 you're a complete beginner here's a 2470 01:15:58,800 --> 01:15:59,800 quick lecture on materials these are 2471 01:16:00,480 --> 01:16:01,480 materials and if we call it select we 2472 01:16:02,040 --> 01:16:03,040 can see a bunch of sets related to that 2473 01:16:03,540 --> 01:16:04,540 material basically the materials have a 2474 01:16:05,400 --> 01:16:06,400 Shader and then a bunch of properties 2475 01:16:06,900 --> 01:16:07,900 now the Shader is the actual code that 2476 01:16:09,300 --> 01:16:10,300 runs on the graphics card that says how 2477 01:16:11,100 --> 01:16:12,100 an object should be rendered by default 2478 01:16:13,080 --> 01:16:14,080 you have a whole bunch of included 2479 01:16:14,640 --> 01:16:15,640 shaders we're using the universal render 2480 01:16:16,560 --> 01:16:17,560 pipeline so you should mostly be using 2481 01:16:18,060 --> 01:16:19,060 the ones inside the urp and by default 2482 01:16:20,340 --> 01:16:21,340 you probably want to be using the 2483 01:16:21,540 --> 01:16:22,540 standard light Shader then of course you 2484 01:16:22,980 --> 01:16:23,980 can also build your own custom shaders 2485 01:16:24,600 --> 01:16:25,600 one excellent tool for doing that is 2486 01:16:26,400 --> 01:16:27,400 shade graph which I have covered in 2487 01:16:27,960 --> 01:16:28,960 detail in a previous video it's a fully 2488 01:16:29,760 --> 01:16:30,760 visual tool that you can use to make 2489 01:16:31,140 --> 01:16:32,140 shaders without having to write any 2490 01:16:32,699 --> 01:16:33,699 shutter code it's a great tool I've also 2491 01:16:34,739 --> 01:16:35,739 made a bunch of tutorials on all kinds 2492 01:16:36,480 --> 01:16:37,480 of effects you can make although right 2493 01:16:37,980 --> 01:16:38,980 now we're not going to be using custom 2494 01:16:39,300 --> 01:16:40,300 shaders we're going to do that later on 2495 01:16:41,100 --> 01:16:42,100 the course but for now we're going to 2496 01:16:42,300 --> 01:16:43,300 stick with default light Shader so 2497 01:16:43,860 --> 01:16:44,860 materials have a combination of shaders 2498 01:16:45,659 --> 01:16:46,659 and the properties on that Shader for 2499 01:16:47,400 --> 01:16:48,400 example over here for the phone light 2500 01:16:48,900 --> 01:16:49,900 sharing you can see that it has over 2501 01:16:50,580 --> 01:16:51,580 here based map that has a counter field 2502 01:16:52,739 --> 01:16:53,739 this is what you can change to apply a 2503 01:16:54,540 --> 01:16:55,540 different color to your player also as 2504 01:16:56,100 --> 01:16:57,100 to how you apply a material to an object 2505 01:16:57,960 --> 01:16:58,960 over here on the player visual you can 2506 01:16:59,699 --> 01:17:00,699 see the objects are made up of a sphere 2507 01:17:01,679 --> 01:17:02,679 so this is the mesh and then the mesh 2508 01:17:03,179 --> 01:17:04,179 render this is the one that has the 2509 01:17:04,860 --> 01:17:05,860 material so both these are what stores 2510 01:17:07,080 --> 01:17:08,080 the shape as well as the visual for the 2511 01:17:09,000 --> 01:17:10,000 object the mesh is just a 3D shape but 2512 01:17:11,100 --> 01:17:12,100 just by some of the mesh filter doesn't 2513 01:17:12,600 --> 01:17:13,600 actually render anything so it needs a 2514 01:17:14,219 --> 01:17:15,219 mesh render which needs a material 2515 01:17:15,780 --> 01:17:16,780 attached to it so for example over here 2516 01:17:17,580 --> 01:17:18,580 on the hierarching let's right click on 2517 01:17:19,080 --> 01:17:20,080 empty space and let's create a brand new 2518 01:17:20,640 --> 01:17:21,640 Cube just to see it so if there you go 2519 01:17:22,500 --> 01:17:23,500 it does create an object and as you can 2520 01:17:24,179 --> 01:17:25,179 see it has a mesh filter and a mesh 2521 01:17:25,920 --> 01:17:26,920 render now to apply a different material 2522 01:17:27,540 --> 01:17:28,540 you can click on this little circle icon 2523 01:17:29,580 --> 01:17:30,580 and it shows you all the materials in 2524 01:17:31,320 --> 01:17:32,320 that project alternatively you can grab 2525 01:17:33,239 --> 01:17:34,239 the material directly from the project 2526 01:17:34,679 --> 01:17:35,679 window so for example the player body 2527 01:17:36,420 --> 01:17:37,420 just grab it and drop it in there or you 2528 01:17:38,640 --> 01:17:39,640 can also drop the material over here on 2529 01:17:40,380 --> 01:17:41,380 scene view as you can see as I Mouse 2530 01:17:41,760 --> 01:17:42,760 over different objects it applies that 2531 01:17:43,560 --> 01:17:44,560 material to a different object although 2532 01:17:45,360 --> 01:17:46,360 note that only works over here on scene 2533 01:17:47,159 --> 01:17:48,159 view it does not work on game view so 2534 01:17:48,900 --> 01:17:49,900 this basically sets the material over 2535 01:17:50,400 --> 01:17:51,400 there on the object right now one more 2536 01:17:52,380 --> 01:17:53,380 very important thing on materials if you 2537 01:17:54,360 --> 01:17:55,360 have multiple meshes only using the 2538 01:17:56,159 --> 01:17:57,159 exact same material and then you modify 2539 01:17:57,960 --> 01:17:58,960 the material it won't change the vision 2540 01:17:59,340 --> 01:18:00,340 while all meshes using that material so 2541 01:18:01,440 --> 01:18:02,440 for example if I modify the color here 2542 01:18:03,360 --> 01:18:04,360 put it on something different there you 2543 01:18:05,159 --> 01:18:06,159 go all three instances all three objects 2544 01:18:07,320 --> 01:18:08,320 that are all using the exact same 2545 01:18:08,699 --> 01:18:09,699 material they all update to the new 2546 01:18:10,380 --> 01:18:11,380 color if for example you wanted the head 2547 01:18:12,300 --> 01:18:13,300 to be a different color from the rest 2548 01:18:13,800 --> 01:18:14,800 then you would just create new material 2549 01:18:15,659 --> 01:18:16,659 so you can right click on the project 2550 01:18:17,159 --> 01:18:18,159 window let's create a new material then 2551 01:18:19,440 --> 01:18:20,440 you can give it a name give it colors 2552 01:18:21,000 --> 01:18:22,000 use a different shade or whatever and 2553 01:18:22,560 --> 01:18:23,560 then use this one for something 2554 01:18:23,580 --> 01:18:24,580 different so that's pretty much the 2555 01:18:24,960 --> 01:18:25,960 basics for materials and by the way if 2556 01:18:26,820 --> 01:18:27,820 you're a complete beginner and you have 2557 01:18:28,080 --> 01:18:29,080 questions remember to post them in the 2558 01:18:29,580 --> 01:18:30,580 comments and I'll do my best to help 2559 01:18:30,900 --> 01:18:31,900 like I said I want to keep this video 2560 01:18:32,280 --> 01:18:33,280 moving I'm trying to teach as much as 2561 01:18:33,960 --> 01:18:34,960 possible while still keeping the video 2562 01:18:35,460 --> 01:18:36,460 reasonable length so if you need any 2563 01:18:37,020 --> 01:18:38,020 further clarification on anything 2564 01:18:38,460 --> 01:18:39,460 specific just go ahead and ask in the 2565 01:18:40,140 --> 01:18:41,140 comments okay so when materials are out 2566 01:18:41,760 --> 01:18:42,760 of the way here we have our player with 2567 01:18:43,020 --> 01:18:44,020 visual let's just get rid of our Cube 2568 01:18:44,880 --> 01:18:45,880 okay and just with this if we test and 2569 01:18:47,100 --> 01:18:48,100 yep over here we already have a nice 2570 01:18:48,840 --> 01:18:49,840 player visual walking around okay great 2571 01:18:51,179 --> 01:18:52,179 except the player isn't actually 2572 01:18:52,860 --> 01:18:53,860 rotating ideally the visual should be 2573 01:18:55,080 --> 01:18:56,080 facing the walking direction so if I 2574 01:18:57,060 --> 01:18:58,060 walk down it should be rotated to face 2575 01:18:58,739 --> 01:18:59,739 down so let's have that doing that is 2576 01:19:00,659 --> 01:19:01,659 actually going to be pretty simple let's 2577 01:19:02,460 --> 01:19:03,460 go into our script here we are on the 2578 01:19:04,140 --> 01:19:05,140 player script and over here we already 2579 01:19:05,820 --> 01:19:06,820 have the movement Direction so we're 2580 01:19:07,980 --> 01:19:08,980 going to use this in order to make sure 2581 01:19:09,300 --> 01:19:10,300 to rotate the game object to face this 2582 01:19:11,580 --> 01:19:12,580 move Direction and for rotating and 2583 01:19:13,440 --> 01:19:14,440 transform there are many many ways to do 2584 01:19:15,120 --> 01:19:16,120 it one obvious one is to modify the 2585 01:19:17,400 --> 01:19:18,400 transform dot rotation however this one 2586 01:19:19,860 --> 01:19:20,860 as you can see works with quaternions 2587 01:19:21,360 --> 01:19:22,360 for me even though I've been doing Game 2588 01:19:22,980 --> 01:19:23,980 Dev for over 10 years I still find 2589 01:19:24,540 --> 01:19:25,540 quaternions quite a bit confusing so I 2590 01:19:26,520 --> 01:19:27,520 normally don't use this method another 2591 01:19:28,440 --> 01:19:29,440 method is to modify the transform dot 2592 01:19:30,659 --> 01:19:31,659 Euler angles this one is much more 2593 01:19:32,640 --> 01:19:33,640 intuitive and makes more sense to me it 2594 01:19:34,560 --> 01:19:35,560 works with regular Euler angles which is 2595 01:19:36,480 --> 01:19:37,480 much easier to understand if you don't 2596 01:19:38,040 --> 01:19:39,040 know that name it really just means the 2597 01:19:39,600 --> 01:19:40,600 angles that go from 0 to 360. then for 2598 01:19:42,120 --> 01:19:43,120 another method you can also use the 2599 01:19:43,380 --> 01:19:44,380 function transform Dot and look at this 2600 01:19:45,719 --> 01:19:46,719 one makes a transform look at a certain 2601 01:19:47,280 --> 01:19:48,280 point so it can be a transform Target 2602 01:19:49,080 --> 01:19:50,080 can be a vector three for one position 2603 01:19:50,820 --> 01:19:51,820 and anything like that so this is a very 2604 01:19:52,800 --> 01:19:53,800 useful function we could calculate a 2605 01:19:54,600 --> 01:19:55,600 point right in front of our move 2606 01:19:55,980 --> 01:19:56,980 Direction and look at it or finally the 2607 01:19:58,260 --> 01:19:59,260 method that I personally like to use for 2608 01:19:59,820 --> 01:20:00,820 this specific purpose which is just 2609 01:20:01,560 --> 01:20:02,560 modify the transform dot forward this 2610 01:20:03,600 --> 01:20:04,600 one has the normalized vector 2611 01:20:05,100 --> 01:20:06,100 representing the foreign axes and 2612 01:20:06,900 --> 01:20:07,900 importantly you can get it and you can 2613 01:20:08,520 --> 01:20:09,520 also set it so you have both read and 2614 01:20:10,440 --> 01:20:11,440 write you can read it to get the current 2615 01:20:12,120 --> 01:20:13,120 transform for it but you can also write 2616 01:20:13,920 --> 01:20:14,920 to it to essentially rotate the 2617 01:20:15,420 --> 01:20:16,420 transform so we can just assign this to 2618 01:20:17,340 --> 01:20:18,340 our forward Vector also by the way you 2619 01:20:19,380 --> 01:20:20,380 also have transform dot up and transform 2620 01:20:21,719 --> 01:20:22,719 dot right both these work exactly the 2621 01:20:23,699 --> 01:20:24,699 same way for example transforms are 2622 01:20:25,320 --> 01:20:26,320 right this one is extremely useful for 2623 01:20:26,940 --> 01:20:27,940 2D games but over here we're working in 2624 01:20:28,739 --> 01:20:29,739 3D so we want to transform that forward 2625 01:20:30,480 --> 01:20:31,480 and all we need is the forward Vector 2626 01:20:32,159 --> 01:20:33,159 which is really just in move Direction 2627 01:20:33,420 --> 01:20:34,420 so let's set this one equal Z move there 2628 01:20:35,280 --> 01:20:36,280 okay so just like this it shouldn't 2629 01:20:37,260 --> 01:20:38,260 really work let's also just clean up the 2630 01:20:38,820 --> 01:20:39,820 log we already need to see the Delta 2631 01:20:40,679 --> 01:20:41,679 time okay so let's see like this okay 2632 01:20:42,420 --> 01:20:43,420 here we are and as I move and you better 2633 01:20:44,219 --> 01:20:45,219 go and look at that the player object 2634 01:20:45,780 --> 01:20:46,780 does indeed rotate to face the move 2635 01:20:47,400 --> 01:20:48,400 Direction okay so it's already looking 2636 01:20:48,960 --> 01:20:49,960 great all right awesome however it also 2637 01:20:51,060 --> 01:20:52,060 looks a bit odd with how it's instant so 2638 01:20:53,280 --> 01:20:54,280 I move left and right look at that it 2639 01:20:54,900 --> 01:20:55,900 instantly rotates so there's no 2640 01:20:56,820 --> 01:20:57,820 smoothing nothing it's way too janky so 2641 01:20:59,159 --> 01:21:00,159 let's add some nice simple smoothing and 2642 01:21:01,020 --> 01:21:02,020 for that let's use a really awesome 2643 01:21:02,460 --> 01:21:03,460 really useful math function called lerp 2644 01:21:04,679 --> 01:21:05,679 it helps you interpolate between two 2645 01:21:06,360 --> 01:21:07,360 values I made a quick video showcasing a 2646 01:21:08,699 --> 01:21:09,699 bunch of uses for it you can alert 2647 01:21:10,380 --> 01:21:11,380 floats Vector 3s quaternions or just 2648 01:21:12,420 --> 01:21:13,420 about anything it's really perfect for 2649 01:21:14,100 --> 01:21:15,100 making some smooth movement or smooth 2650 01:21:15,840 --> 01:21:16,840 rotation so for that we can access the 2651 01:21:18,060 --> 01:21:19,060 function inside the vector 3 class so we 2652 01:21:20,400 --> 01:21:21,400 can find an alert then here we actually 2653 01:21:22,620 --> 01:21:23,620 have two options we've got learn this 2654 01:21:26,100 --> 01:21:27,100 one interpolates and we've got slurp 2655 01:21:28,440 --> 01:21:29,440 this one interpolates but with a 2656 01:21:30,179 --> 01:21:31,179 spherical interpolation basically if 2657 01:21:31,800 --> 01:21:32,800 you're dealing with rotations like what 2658 01:21:33,360 --> 01:21:34,360 we have here then we want to be using 2659 01:21:34,920 --> 01:21:35,920 slurp whereas if you're dealing with 2660 01:21:36,480 --> 01:21:37,480 just positions and you want to use so 2661 01:21:38,340 --> 01:21:39,340 here let's use slurp this one as you can 2662 01:21:41,100 --> 01:21:42,100 see takes an a a b and a t like I said 2663 01:21:43,679 --> 01:21:44,679 this interpolates between A and B based 2664 01:21:45,600 --> 01:21:46,600 on T so for example if T is zero then it 2665 01:21:48,300 --> 01:21:49,300 won't return the value a if T is one 2666 01:21:50,580 --> 01:21:51,580 then it won't return to Value B if C is 2667 01:21:52,860 --> 01:21:53,860 0.5 then it won't return the point in 2668 01:21:54,719 --> 01:21:55,719 between A and B if you want to learn 2669 01:21:56,520 --> 01:21:57,520 some more about interpolation and the 2670 01:21:58,080 --> 01:21:59,080 math behind this then I highly recommend 2671 01:21:59,699 --> 01:22:00,699 you look at my video on splines splines 2672 01:22:01,739 --> 01:22:02,739 are basically just a whole bunch of 2673 01:22:03,179 --> 01:22:04,179 merps put together so anyways over here 2674 01:22:05,040 --> 01:22:06,040 we can add some smoothing to our 2675 01:22:06,239 --> 01:22:07,239 Rotation by just using the current 2676 01:22:07,820 --> 01:22:08,820 transform.ford as our a 2677 01:22:10,679 --> 01:22:11,679 then for the B this one is our Target so 2678 01:22:12,780 --> 01:22:13,780 let's use the move there and finally 14 2679 01:22:15,000 --> 01:22:16,000 let's use time dot Delta time meaning 2680 01:22:17,520 --> 01:22:18,520 that with this over time the character 2681 01:22:19,199 --> 01:22:20,199 won't rotate towards our Target movement 2682 01:22:21,179 --> 01:22:22,179 Direction so just with this let's test 2683 01:22:23,100 --> 01:22:24,100 so here if I move to the right and you 2684 01:22:25,080 --> 01:22:26,080 have a look at that it is indeed 2685 01:22:26,400 --> 01:22:27,400 rotating it's way too slow but yep it is 2686 01:22:28,739 --> 01:22:29,739 rotating smoothly all right so let's 2687 01:22:30,420 --> 01:22:31,420 just add a bit more speed so over here 2688 01:22:32,520 --> 01:22:33,520 let's just find a float for the rotate 2689 01:22:34,500 --> 01:22:35,500 spin let's put it at some like 10f then 2690 01:22:37,320 --> 01:22:38,320 we just multiply it to times that down 2691 01:22:39,000 --> 01:22:40,000 time multiplied by our speed let's see 2692 01:22:40,860 --> 01:22:41,860 and move any up there you go look at 2693 01:22:42,659 --> 01:22:43,659 that much much better okay great so as 2694 01:22:45,420 --> 01:22:46,420 you can see everything works as I move 2695 01:22:47,280 --> 01:22:48,280 the character does rotate to face the 2696 01:22:48,900 --> 01:22:49,900 move Direction all right great so here 2697 01:22:50,760 --> 01:22:51,760 we have our character with a nice visual 2698 01:22:52,500 --> 01:22:53,500 all rotating to face the move Direction 2699 01:22:54,300 --> 01:22:55,300 now next step is we want to add some 2700 01:22:56,460 --> 01:22:57,460 nice animation so let's do that in the 2701 01:22:58,440 --> 01:22:59,440 next lecture 2702 01:23:00,179 --> 01:23:01,179 hello and welcome I'm your code monkey 2703 01:23:02,159 --> 01:23:03,159 in this lecture we're going to add some 2704 01:23:04,199 --> 01:23:05,199 animations to our player character now I 2705 01:23:06,360 --> 01:23:07,360 have already included some pre-made 2706 01:23:07,860 --> 01:23:08,860 animations with a pre-made animator over 2707 01:23:09,900 --> 01:23:10,900 here inside the Asus folder but let's 2708 01:23:11,699 --> 01:23:12,699 first do it from scratch so you'll learn 2709 01:23:13,500 --> 01:23:14,500 how to do it first to animate we're 2710 01:23:15,179 --> 01:23:16,179 going to need the animator component if 2711 01:23:17,100 --> 01:23:18,100 we go inside the player visual game 2712 01:23:18,780 --> 01:23:19,780 object once again remember all the 2713 01:23:20,460 --> 01:23:21,460 visuals go on the visual game object so 2714 01:23:22,320 --> 01:23:23,320 for adding the animator component we 2715 01:23:24,000 --> 01:23:25,000 want it on the visual and not on the 2716 01:23:25,560 --> 01:23:26,560 logic component so anyways over here as 2717 01:23:27,360 --> 01:23:28,360 you can see by default I already attach 2718 01:23:29,280 --> 01:23:30,280 it with the assets included but let's do 2719 01:23:31,560 --> 01:23:32,560 it from scratch so let's remove this by 2720 01:23:33,300 --> 01:23:34,300 default now let's add a new component 2721 01:23:35,159 --> 01:23:36,159 let's go on an animator also one very 2722 01:23:37,800 --> 01:23:38,800 very important thing here it's the 2723 01:23:39,659 --> 01:23:40,659 animator component not the animation 2724 01:23:41,880 --> 01:23:42,880 component these QR can only difference 2725 01:23:44,040 --> 01:23:45,040 the animation component this one is 2726 01:23:46,320 --> 01:23:47,320 actually related to unity's Legacy 2727 01:23:48,120 --> 01:23:49,120 animation system from a very long time 2728 01:23:49,980 --> 01:23:50,980 ago it's only here pretty much for a 2729 01:23:51,719 --> 01:23:52,719 backwards compatibility and for super 2730 01:23:53,340 --> 01:23:54,340 simple use cases so most of the time 2731 01:23:55,080 --> 01:23:56,080 make sure you're using the anime tour 2732 01:23:56,699 --> 01:23:57,699 component okay so to drive this animator 2733 01:23:58,860 --> 01:23:59,860 component we need an NM troller let's go 2734 01:24:01,320 --> 01:24:02,320 into our project files and let's create 2735 01:24:02,880 --> 01:24:03,880 and create a brand new animated control 2736 01:24:04,679 --> 01:24:05,679 let's call this my player animator then 2737 01:24:07,560 --> 01:24:08,560 let's select the player Visual and just 2738 01:24:09,239 --> 01:24:10,239 drag the controller on there okay again 2739 01:24:11,040 --> 01:24:12,040 if you have issues then you cannot drag 2740 01:24:12,840 --> 01:24:13,840 the animator onto the film make sure 2741 01:24:14,699 --> 01:24:15,699 you're using the animator and not the 2742 01:24:16,560 --> 01:24:17,560 animation component okay so with this we 2743 01:24:18,300 --> 01:24:19,300 have assigned our animator controller 2744 01:24:20,040 --> 01:24:21,040 now let's double click on it to open the 2745 01:24:22,080 --> 01:24:23,080 animated window and if you don't see it 2746 01:24:23,699 --> 01:24:24,699 then go into window then go into 2747 01:24:25,380 --> 01:24:26,380 animation and open up the animator 2748 01:24:27,000 --> 01:24:28,000 window and also if you still don't see 2749 01:24:28,739 --> 01:24:29,739 anything that maybe you might have some 2750 01:24:30,420 --> 01:24:31,420 issues with your layout if that's the 2751 01:24:32,159 --> 01:24:33,159 case then go on to the top right corner 2752 01:24:33,780 --> 01:24:34,780 layout and go back into the default and 2753 01:24:35,520 --> 01:24:36,520 then back into your own layout and 2754 01:24:36,960 --> 01:24:37,960 finally if you still don't see anything 2755 01:24:38,280 --> 01:24:39,280 on this window if you don't see defontes 2756 01:24:40,140 --> 01:24:41,140 make sure you have the object selected 2757 01:24:42,480 --> 01:24:43,480 in the hierarchy so with that you should 2758 01:24:43,980 --> 01:24:44,980 be able to see these states so this is 2759 01:24:45,540 --> 01:24:46,540 our animator controller now I have a 2760 01:24:47,340 --> 01:24:48,340 really detailed overview of the animator 2761 01:24:49,080 --> 01:24:50,080 and the animation windows in my ultimate 2762 01:24:50,940 --> 01:24:51,940 unity overview course so you can go 2763 01:24:52,500 --> 01:24:53,500 watch those lectures for some really 2764 01:24:54,000 --> 01:24:55,000 in-depth explanations about everything 2765 01:24:55,679 --> 01:24:56,679 this does basically the animator is a 2766 01:24:57,780 --> 01:24:58,780 state machine so you have various States 2767 01:24:59,640 --> 01:25:00,640 and you can create transitions between 2768 01:25:01,380 --> 01:25:02,380 each state by default you have these 2769 01:25:03,360 --> 01:25:04,360 three special States there's the entry 2770 01:25:05,040 --> 01:25:06,040 State exit and any state these are used 2771 01:25:07,140 --> 01:25:08,140 for making transitions but we don't 2772 01:25:08,520 --> 01:25:09,520 really need to worry about them just for 2773 01:25:09,900 --> 01:25:10,900 now first let's just make a basic new 2774 01:25:11,940 --> 01:25:12,940 animation and for that the easy way to 2775 01:25:13,739 --> 01:25:14,739 do it is to open up the animation window 2776 01:25:15,360 --> 01:25:16,360 so let's go up top into window go into 2777 01:25:17,699 --> 01:25:18,699 animation and open up the animation 2778 01:25:19,380 --> 01:25:20,380 window so here it is again that's a 2779 01:25:21,420 --> 01:25:22,420 different window that's animation not 2780 01:25:23,400 --> 01:25:24,400 anywhere and for me for this window I 2781 01:25:25,199 --> 01:25:26,199 like to dock it down here so there's a 2782 01:25:26,760 --> 01:25:27,760 nice timeline so I think this is good 2783 01:25:28,140 --> 01:25:29,140 okay and now if we select the object in 2784 01:25:30,239 --> 01:25:31,239 the hierarchy that has our animator then 2785 01:25:32,159 --> 01:25:33,159 we can see the text here so to begin 2786 01:25:33,659 --> 01:25:34,659 animating we've got a nice button to 2787 01:25:35,280 --> 01:25:36,280 create an animation so let's go ahead 2788 01:25:37,020 --> 01:25:38,020 and click on this and now let's give it 2789 01:25:38,760 --> 01:25:39,760 a name for now let's first make the 2790 01:25:40,560 --> 01:25:41,560 iPhone animation so let's just call this 2791 01:25:42,300 --> 01:25:43,300 Idol and name just like that we have 2792 01:25:43,980 --> 01:25:44,980 created an animation you can see the 2793 01:25:45,840 --> 01:25:46,840 animation window down here has changed 2794 01:25:47,520 --> 01:25:48,520 we now see a nice timeline showing the 2795 01:25:49,800 --> 01:25:50,800 time and also on the animated controller 2796 01:25:51,780 --> 01:25:52,780 you can see the new animation was added 2797 01:25:53,580 --> 01:25:54,580 as a brand new state so a new state was 2798 01:25:55,739 --> 01:25:56,739 created and if you click to select it on 2799 01:25:57,840 --> 01:25:58,840 the right side in the inspector you see 2800 01:25:59,280 --> 01:26:00,280 the motion so the actual animation 2801 01:26:00,719 --> 01:26:01,719 selected and you can also see that 2802 01:26:02,460 --> 01:26:03,460 there's an arrow pointing from the entry 2803 01:26:04,139 --> 01:26:05,139 onto the unknown state so that means 2804 01:26:05,699 --> 01:26:06,699 this one is going to be the default 2805 01:26:07,020 --> 01:26:08,020 State when the animated controller 2806 01:26:08,699 --> 01:26:09,699 starts it won't start playing right on 2807 01:26:10,440 --> 01:26:11,440 this state let me just point out one 2808 01:26:12,120 --> 01:26:13,120 more thing related to animations so on 2809 01:26:14,219 --> 01:26:15,219 the project window we can see yep here 2810 01:26:16,020 --> 01:26:17,020 is our animation that we just created 2811 01:26:17,460 --> 01:26:18,460 and you can see the inspector unlocks 2812 01:26:19,320 --> 01:26:20,320 just like this now if your inspector 2813 01:26:21,000 --> 01:26:22,000 looks differently that might be because 2814 01:26:22,500 --> 01:26:23,500 you accidentally created the Legacy 2815 01:26:24,480 --> 01:26:25,480 animation that has to do with the 2816 01:26:26,280 --> 01:26:27,280 previous animation system that I talked 2817 01:26:27,780 --> 01:26:28,780 about the one that is Legacy that should 2818 01:26:29,400 --> 01:26:30,400 really no longer be used so if you see a 2819 01:26:31,440 --> 01:26:32,440 different inspector then a quick way to 2820 01:26:33,060 --> 01:26:34,060 fix it is to click on these three dots 2821 01:26:35,040 --> 01:26:36,040 on the inspector these three dots then 2822 01:26:36,780 --> 01:26:37,780 you change the inspector into debug 2823 01:26:38,340 --> 01:26:39,340 inspector and over here you see a toggle 2824 01:26:40,260 --> 01:26:41,260 on foreign legacy so for the animations 2825 01:26:42,060 --> 01:26:43,060 that we want to use right now we do not 2826 01:26:43,920 --> 01:26:44,920 want to be using Legacy animations so 2827 01:26:45,600 --> 01:26:46,600 make sure this one is untoggled if in 2828 01:26:47,340 --> 01:26:48,340 our case is toggle just untoggle it then 2829 01:26:49,199 --> 01:26:50,199 go back into the normal inspector and 2830 01:26:51,300 --> 01:26:52,300 now yep it shouldn't look just like this 2831 01:26:52,920 --> 01:26:53,920 okay so we have our animation and now 2832 01:26:54,960 --> 01:26:55,960 it's on our animator controller now it's 2833 01:26:56,820 --> 01:26:57,820 actually make an animation so let's 2834 01:26:59,040 --> 01:27:00,040 select the animation window though and 2835 01:27:00,900 --> 01:27:01,900 again let's make sure to select the 2836 01:27:02,100 --> 01:27:03,100 objects and let's select the player 2837 01:27:03,300 --> 01:27:04,300 visual game object so here on the 2838 01:27:05,100 --> 01:27:06,100 animation window we see this nice little 2839 01:27:06,600 --> 01:27:07,600 red button this one enables or disables 2840 01:27:08,760 --> 01:27:09,760 recording so if you click on it you can 2841 01:27:10,679 --> 01:27:11,679 see yep the timeline is now red meaning 2842 01:27:12,540 --> 01:27:13,540 that we are now recording and now we can 2843 01:27:14,460 --> 01:27:15,460 do anything to any channel objects and 2844 01:27:16,380 --> 01:27:17,380 it won't record any changes we make now 2845 01:27:18,300 --> 01:27:19,300 note what I said that's very important 2846 01:27:19,860 --> 01:27:20,860 it needs to be challenged objects if you 2847 01:27:21,780 --> 01:27:22,780 select for example the apparent game 2848 01:27:23,100 --> 01:27:24,100 object then all of a sudden it stops 2849 01:27:24,420 --> 01:27:25,420 recording so you can only animate child 2850 01:27:26,460 --> 01:27:27,460 objects so let's select the player 2851 01:27:28,679 --> 01:27:29,679 visual let's enable recording then let's 2852 01:27:30,540 --> 01:27:31,540 expand the player visual let's make sure 2853 01:27:32,159 --> 01:27:33,159 that our timeline is on zero so drag it 2854 01:27:33,960 --> 01:27:34,960 all the way to the left and now for 2855 01:27:35,219 --> 01:27:36,219 example let's grab the head object and 2856 01:27:37,139 --> 01:27:38,139 let's move it just a tiny tiny bit 2857 01:27:39,000 --> 01:27:40,000 basically just move it enough in order 2858 01:27:41,159 --> 01:27:42,159 to make sure that the position over here 2859 01:27:42,659 --> 01:27:43,659 is in red meaning that we have recorded 2860 01:27:44,580 --> 01:27:45,580 a keyframe then let's drag the timeline 2861 01:27:46,679 --> 01:27:47,679 by a little bit let's go over here to 2862 01:27:48,780 --> 01:27:49,780 frame 30. this one is actually going to 2863 01:27:50,820 --> 01:27:51,820 be half a second and soon to be that 2864 01:27:52,500 --> 01:27:53,500 because over here on the samples this is 2865 01:27:54,120 --> 01:27:55,120 the frame rate for the animation so at 2866 01:27:55,860 --> 01:27:56,860 6C that means we have 60 frames this 2867 01:27:57,780 --> 01:27:58,780 makes one second so 30 frames would be 2868 01:28:00,000 --> 01:28:01,000 half a second you can also zoom out by 2869 01:28:02,219 --> 01:28:03,219 scrolling over here or dragging the 2870 01:28:03,840 --> 01:28:04,840 handles down here so let's go into 30 2871 01:28:05,400 --> 01:28:06,400 half a second and on this one let's move 2872 01:28:07,199 --> 01:28:08,199 the head by a little bit something like 2873 01:28:08,639 --> 01:28:09,639 this as you can see down there we can 2874 01:28:10,080 --> 01:28:11,080 note that I record the new keyframe and 2875 01:28:11,760 --> 01:28:12,760 now if we hit on the play button we can 2876 01:28:13,440 --> 01:28:14,440 preview the animation any upon like that 2877 01:28:15,000 --> 01:28:16,000 that does do exactly that so it starts 2878 01:28:16,800 --> 01:28:17,800 off down and then moves up okay so 2879 01:28:18,420 --> 01:28:19,420 that's great but we don't want to snap 2880 01:28:20,219 --> 01:28:21,219 back so let's actually add another 2881 01:28:21,840 --> 01:28:22,840 keyframe right at the end so let's stop 2882 01:28:23,880 --> 01:28:24,880 playing the animation and to make sure 2883 01:28:25,679 --> 01:28:26,679 we have a perfect Loop let's just click 2884 01:28:27,780 --> 01:28:28,780 to select the keyframe let's press Ctrl 2885 01:28:29,760 --> 01:28:30,760 C then let's go down into the one second 2886 01:28:32,100 --> 01:28:33,100 Mark let's press Ctrl V and there you go 2887 01:28:34,199 --> 01:28:35,199 there's the exact same keyframe so now 2888 01:28:36,000 --> 01:28:37,000 if we hit on play the other go we have 2889 01:28:37,980 --> 01:28:38,980 our nice seamless Loop so the head goes 2890 01:28:39,780 --> 01:28:40,780 up and down and repeats forever alright 2891 01:28:41,699 --> 01:28:42,699 awesome okay so that's great now let's 2892 01:28:44,159 --> 01:28:45,159 also do one thing let's also record a 2893 01:28:46,080 --> 01:28:47,080 keyframe on the body however we don't 2894 01:28:48,540 --> 01:28:49,540 want it to move at least not in this 2895 01:28:50,460 --> 01:28:51,460 idle animation we just want to have a 2896 01:28:52,620 --> 01:28:53,620 static keyframe so let's select the body 2897 01:28:54,659 --> 01:28:55,659 and let me actually move it a bit to the 2898 01:28:56,699 --> 01:28:57,699 side just to make sure to record and now 2899 01:28:58,260 --> 01:28:59,260 manually we can modify things over here 2900 01:28:59,940 --> 01:29:00,940 here to modify the actual keyframe data 2901 01:29:02,280 --> 01:29:03,280 so on this one I don't want it to move 2902 01:29:03,719 --> 01:29:04,719 so let's put it all the way back at zero 2903 01:29:05,340 --> 01:29:06,340 just make sure we have a nice keyframe 2904 01:29:07,320 --> 01:29:08,320 recording now the reason why we are 2905 01:29:08,880 --> 01:29:09,880 recording the body position even without 2906 01:29:10,500 --> 01:29:11,500 moving it is because the wonk animation 2907 01:29:12,420 --> 01:29:13,420 will indeed move the body but when we 2908 01:29:14,400 --> 01:29:15,400 get back to idle we want the body to go 2909 01:29:16,380 --> 01:29:17,380 back to this exact position so that is 2910 01:29:18,239 --> 01:29:19,239 why we need the keyframe here okay so 2911 01:29:19,860 --> 01:29:20,860 that's done so we can stop recording so 2912 01:29:21,420 --> 01:29:22,420 let's click on the red button again okay 2913 01:29:23,100 --> 01:29:24,100 great by the way one more note to make 2914 01:29:25,260 --> 01:29:26,260 sure that the animation Loops go into 2915 01:29:27,000 --> 01:29:28,000 the project window and over here select 2916 01:29:29,100 --> 01:29:30,100 the animation and make sure on Loop time 2917 01:29:30,600 --> 01:29:31,600 is enabled it should be there by default 2918 01:29:32,400 --> 01:29:33,400 okay so the animation is set up and if 2919 01:29:34,560 --> 01:29:35,560 we unlock in the animator it's already 2920 01:29:35,940 --> 01:29:36,940 the default set so if we hit point we 2921 01:29:38,280 --> 01:29:39,280 should be able to see the anal animation 2922 01:29:39,719 --> 01:29:40,719 playing non-stop so let's hit play and 2923 01:29:41,639 --> 01:29:42,639 if there it is the anal animation with 2924 01:29:43,139 --> 01:29:44,139 the head moving up and down everything 2925 01:29:44,760 --> 01:29:45,760 works perfectly alright awesome okay so 2926 01:29:47,340 --> 01:29:48,340 next up let's make a wonk animation now 2927 01:29:49,560 --> 01:29:50,560 for me when making an animation that is 2928 01:29:51,360 --> 01:29:52,360 based on another one I like to actually 2929 01:29:52,860 --> 01:29:53,860 duplicate it instead of starting from 2930 01:29:54,480 --> 01:29:55,480 scratch so over here on the project 2931 01:29:55,679 --> 01:29:56,679 window let's select the anal animation 2932 01:29:57,420 --> 01:29:58,420 and let's duplicate it so Ctrl D let's 2933 01:29:59,639 --> 01:30:00,639 learn name this one to the wonk 2934 01:30:01,380 --> 01:30:02,380 animation and now if we select the 2935 01:30:03,360 --> 01:30:04,360 player Visual and then we go into the 2936 01:30:05,159 --> 01:30:06,159 animation window over here we see a nice 2937 01:30:06,960 --> 01:30:07,960 little drop down menu for all of the 2938 01:30:08,639 --> 01:30:09,639 animations except right now we don't see 2939 01:30:10,679 --> 01:30:11,679 the wonk animation we only see the idle 2940 01:30:12,420 --> 01:30:13,420 animation that is because this menu only 2941 01:30:14,340 --> 01:30:15,340 shows animations that are attached to 2942 01:30:16,020 --> 01:30:17,020 the animator so first we need to add the 2943 01:30:18,060 --> 01:30:19,060 animation onto the animator component 2944 01:30:19,800 --> 01:30:20,800 and how we do that is actually super 2945 01:30:21,239 --> 01:30:22,239 simple let's just open up the project 2946 01:30:22,739 --> 01:30:23,739 window and just write the wonk animation 2947 01:30:24,360 --> 01:30:25,360 and drop it here that's it so with this 2948 01:30:26,100 --> 01:30:27,100 we have attached a new state to the 2949 01:30:27,719 --> 01:30:28,719 animated controller and now if once 2950 01:30:29,580 --> 01:30:30,580 again we select the object in the 2951 01:30:30,960 --> 01:30:31,960 hierarchy go into the animation click 2952 01:30:32,580 --> 01:30:33,580 the drop down menu any up now we do see 2953 01:30:34,380 --> 01:30:35,380 the wonk animation so let's click to 2954 01:30:36,000 --> 01:30:37,000 select this one and now for this one 2955 01:30:37,500 --> 01:30:38,500 let's make the animation so let's look 2956 01:30:38,820 --> 01:30:39,820 in scene View and make it bounce just up 2957 01:30:40,679 --> 01:30:41,679 and down so I'm going to enable record 2958 01:30:42,239 --> 01:30:43,239 go back here and for the body this one 2959 01:30:44,820 --> 01:30:45,820 already has a keyframe so let's go up 2960 01:30:46,199 --> 01:30:47,199 here move it a little bit and then copy 2961 01:30:48,540 --> 01:30:49,540 the keyframe put it the same one at the 2962 01:30:50,040 --> 01:30:51,040 end something like this so there you go 2963 01:30:51,719 --> 01:30:52,719 just goes up and down once actually 2964 01:30:53,040 --> 01:30:54,040 input it offsets it looks a bit better 2965 01:30:54,659 --> 01:30:55,659 so something like this by the way in a 2966 01:30:56,520 --> 01:30:57,520 bit we're going to replace these 2967 01:30:57,600 --> 01:30:58,600 animations with the ones that I made 2968 01:30:58,800 --> 01:30:59,800 previously so don't worry about making 2969 01:31:00,480 --> 01:31:01,480 the animations perfect unless you want 2970 01:31:02,100 --> 01:31:03,100 to do that okay so there you go that's 2971 01:31:03,420 --> 01:31:04,420 the animation although for walking 2972 01:31:04,679 --> 01:31:05,679 should be much faster so here's a quick 2973 01:31:06,600 --> 01:31:07,600 animated tip this top bar here lets you 2974 01:31:08,580 --> 01:31:09,580 select all of the keyframes within a 2975 01:31:10,260 --> 01:31:11,260 certain time so if I click the select 2976 01:31:12,000 --> 01:31:13,000 note how it selects both those keyframes 2977 01:31:13,800 --> 01:31:14,800 and also if you click and drag once on 2978 01:31:15,659 --> 01:31:16,659 top of here you can select multiple 2979 01:31:17,100 --> 01:31:18,100 keyframes so for example to select 2980 01:31:18,719 --> 01:31:19,719 everything just click and drag to select 2981 01:31:20,460 --> 01:31:21,460 all of them and now you see these nice 2982 01:31:22,020 --> 01:31:23,020 little vertical bars so if you click on 2983 01:31:24,000 --> 01:31:25,000 those and then you drag them you can 2984 01:31:25,440 --> 01:31:26,440 basically modify the time of all the 2985 01:31:27,060 --> 01:31:28,060 animations and everything matches up so 2986 01:31:29,100 --> 01:31:30,100 for example let's make this one super 2987 01:31:30,360 --> 01:31:31,360 fast let's put it just 20 frames there 2988 01:31:32,460 --> 01:31:33,460 you go now it's a much faster walking 2989 01:31:33,659 --> 01:31:34,659 Mission okay great let's click on the 2990 01:31:35,639 --> 01:31:36,639 right to stop recording all right and 2991 01:31:37,139 --> 01:31:38,139 back in the animator so over here we 2992 01:31:39,000 --> 01:31:40,000 have both animations and now what we 2993 01:31:40,679 --> 01:31:41,679 need is to make a transition going from 2994 01:31:42,480 --> 01:31:43,480 idle into wonk otherwise the wonk 2995 01:31:44,639 --> 01:31:45,639 animation will never play so how we make 2996 01:31:46,560 --> 01:31:47,560 a transition is also super simple let's 2997 01:31:48,360 --> 01:31:49,360 right click on the I don't say let's 2998 01:31:50,219 --> 01:31:51,219 make a transition then now we have a 2999 01:31:52,620 --> 01:31:53,620 nice little arrow under the mouse and 3000 01:31:54,179 --> 01:31:55,179 now if we go into the wonk and click on 3001 01:31:55,739 --> 01:31:56,739 it there you go we have a nice 3002 01:31:57,060 --> 01:31:58,060 transition now we can click on the 3003 01:31:58,500 --> 01:31:59,500 transition itself to select it and over 3004 01:32:00,239 --> 01:32:01,239 here in the inspector we see a bunch of 3005 01:32:01,739 --> 01:32:02,739 transition options so let's expand the 3006 01:32:03,480 --> 01:32:04,480 settings yep there you go everything now 3007 01:32:05,100 --> 01:32:06,100 like I said I covered all of these 3008 01:32:06,540 --> 01:32:07,540 options in a lot of detail in my 3009 01:32:08,460 --> 01:32:09,460 ultimate TNT of recourse so if you want 3010 01:32:10,440 --> 01:32:11,440 to learn more go watch that here on 3011 01:32:12,120 --> 01:32:13,120 let's just learn the basics for how to 3012 01:32:13,560 --> 01:32:14,560 achieve our goal and making a simple 3013 01:32:14,940 --> 01:32:15,940 player animator the important one is 3014 01:32:16,860 --> 01:32:17,860 over here the exit time basically if 3015 01:32:18,900 --> 01:32:19,900 this one is toggled then this transition 3016 01:32:20,400 --> 01:32:21,400 won't be triggered automatically meaning 3017 01:32:21,960 --> 01:32:22,960 it won't play the outline Mission and 3018 01:32:23,639 --> 01:32:24,639 immediately transition into the walk 3019 01:32:25,139 --> 01:32:26,139 animation so for example if we hit play 3020 01:32:26,880 --> 01:32:27,880 and look at it quickly if there go 3021 01:32:28,440 --> 01:32:29,440 there's the idle any of transitions into 3022 01:32:30,000 --> 01:32:31,000 wonk and now it stays there forever okay 3023 01:32:31,920 --> 01:32:32,920 so that's good but not exactly what we 3024 01:32:33,480 --> 01:32:34,480 want we want the Wonka mission to only 3025 01:32:35,639 --> 01:32:36,639 play When the character is walking and 3026 01:32:37,199 --> 01:32:38,199 when it stops we want to go back into 3027 01:32:38,940 --> 01:32:39,940 the idle animation now for that we need 3028 01:32:40,800 --> 01:32:41,800 to use animator parameters so back in 3029 01:32:42,960 --> 01:32:43,960 our animator on the top left corner we 3030 01:32:45,000 --> 01:32:46,000 see something called layers we don't 3031 01:32:46,320 --> 01:32:47,320 need to worry about that for now and 3032 01:32:47,580 --> 01:32:48,580 then next week we see parameters then we 3033 01:32:49,679 --> 01:32:50,679 can click on the plus button or to 3034 01:32:51,300 --> 01:32:52,300 create the brand new parameter and you 3035 01:32:52,620 --> 01:32:53,620 can see all the various types that we 3036 01:32:54,060 --> 01:32:55,060 can create now for wonky we want 3037 01:32:55,620 --> 01:32:56,620 something that we can set to either true 3038 01:32:57,120 --> 01:32:58,120 or false so let's go with a nice bullion 3039 01:32:59,280 --> 01:33:00,280 and for name let's go with is wonky 3040 01:33:01,679 --> 01:33:02,679 again pay very close attention to the 3041 01:33:03,300 --> 01:33:04,300 capitalization this is extremely 3042 01:33:05,040 --> 01:33:06,040 important just like code is walking is 3043 01:33:07,139 --> 01:33:08,139 different from is walking so make sure 3044 01:33:09,060 --> 01:33:10,060 the capitalization is perfect okay so 3045 01:33:11,040 --> 01:33:12,040 with that we have our nice parameter now 3046 01:33:12,719 --> 01:33:13,719 let's click on transition going from 3047 01:33:14,040 --> 01:33:15,040 idling to wonk and now let's untick exit 3048 01:33:16,500 --> 01:33:17,500 time we don't want this transition to 3049 01:33:18,360 --> 01:33:19,360 trigger automatically and as soon as we 3050 01:33:19,980 --> 01:33:20,980 do we see this nice little warning 3051 01:33:21,480 --> 01:33:22,480 basically it's telling us that this 3052 01:33:22,800 --> 01:33:23,800 transition will never happen so over 3053 01:33:25,080 --> 01:33:26,080 here we have the nice conditions if we 3054 01:33:27,120 --> 01:33:28,120 click on the plus icon we can add some 3055 01:33:28,679 --> 01:33:29,679 conditions and for this one we want this 3056 01:33:30,420 --> 01:33:31,420 transition to happen from idling to walk 3057 01:33:32,219 --> 01:33:33,219 when the parameter is walking is set to 3058 01:33:34,380 --> 01:33:35,380 true so that's it this is our transition 3059 01:33:36,120 --> 01:33:37,120 now let you see the reverse so let's 3060 01:33:38,040 --> 01:33:39,040 right click on the wall make Transition 3061 01:33:39,659 --> 01:33:40,659 go back into Idol let's click the select 3062 01:33:41,820 --> 01:33:42,820 transition get rid of the exit time and 3063 01:33:44,040 --> 01:33:45,040 conditions when is Walking is set to 3064 01:33:45,719 --> 01:33:46,719 false okay so just like this our basic 3065 01:33:48,120 --> 01:33:49,120 animation logic should be working so 3066 01:33:50,040 --> 01:33:51,040 let's test so here we are and the 3067 01:33:51,719 --> 01:33:52,719 character is playing the online Mission 3068 01:33:53,159 --> 01:33:54,159 by the way you can look at the end 3069 01:33:54,600 --> 01:33:55,600 better while the game is running so let 3070 01:33:56,400 --> 01:33:57,400 me just drag the animator window just 3071 01:33:58,199 --> 01:33:59,199 drag it and put it on the side of the 3072 01:34:00,000 --> 01:34:01,000 game view so we can see both at the same 3073 01:34:01,800 --> 01:34:02,800 time okay great and right now note how 3074 01:34:04,020 --> 01:34:05,020 it's not updating so there's nothing 3075 01:34:05,520 --> 01:34:06,520 moving over here on the animated 3076 01:34:06,780 --> 01:34:07,780 component that is because like I said 3077 01:34:08,219 --> 01:34:09,219 you must select the object so on the 3078 01:34:09,900 --> 01:34:10,900 hierarchy make sure you select the 3079 01:34:11,159 --> 01:34:12,159 player Visual and you have there go now 3080 01:34:12,480 --> 01:34:13,480 you do see that updating so make sure 3081 01:34:14,159 --> 01:34:15,159 the object is selected in the hierarchy 3082 01:34:15,840 --> 01:34:16,840 and over here we see a nice little 3083 01:34:17,280 --> 01:34:18,280 progress bar showing the Adeline Mission 3084 01:34:19,020 --> 01:34:20,020 constantly playing in looping okay great 3085 01:34:20,820 --> 01:34:21,820 another important thing is over here the 3086 01:34:22,800 --> 01:34:23,800 parameters you can manually change the 3087 01:34:24,540 --> 01:34:25,540 state of these while the game is running 3088 01:34:25,860 --> 01:34:26,860 so for example if I click it's going to 3089 01:34:27,780 --> 01:34:28,780 trigger the is walking parameter which 3090 01:34:29,460 --> 01:34:30,460 should trigger this transition and 3091 01:34:30,840 --> 01:34:31,840 should go into one so if I click and if 3092 01:34:32,760 --> 01:34:33,760 there go transitions into the wonk 3093 01:34:34,380 --> 01:34:35,380 animation and now yep it is playing The 3094 01:34:36,060 --> 01:34:37,060 Walking animation and if I click to 3095 01:34:37,860 --> 01:34:38,860 untick it look at over there what 3096 01:34:39,780 --> 01:34:40,780 happens untake and there you go 3097 01:34:41,400 --> 01:34:42,400 transitions back into idle alright 3098 01:34:43,199 --> 01:34:44,199 awesome so as you can see we have 3099 01:34:44,760 --> 01:34:45,760 overall logic working we have the 3100 01:34:46,500 --> 01:34:47,500 animator with both of our states and by 3101 01:34:48,420 --> 01:34:49,420 changing this parameter we can change 3102 01:34:49,920 --> 01:34:50,920 which animation is playing now of course 3103 01:34:51,480 --> 01:34:52,480 the goal is not to trigger this manually 3104 01:34:53,159 --> 01:34:54,159 by clicking on it but rather doing it 3105 01:34:54,900 --> 01:34:55,900 through code but at least for now we 3106 01:34:56,340 --> 01:34:57,340 know that our animator is fully set up 3107 01:34:58,020 --> 01:34:59,020 again if you want more detail on the 3108 01:34:59,580 --> 01:35:00,580 animator and animation windows and 3109 01:35:01,620 --> 01:35:02,620 everything related to animations then 3110 01:35:03,179 --> 01:35:04,179 check out those lectures in my ultimate 3111 01:35:04,800 --> 01:35:05,800 TNT overview course and also later on 3112 01:35:06,780 --> 01:35:07,780 for more advanced use cases I have video 3113 01:35:08,460 --> 01:35:09,460 on the animation rigging package this 3114 01:35:10,199 --> 01:35:11,199 one is for more advanced use cases for 3115 01:35:11,940 --> 01:35:12,940 making Dynamic procedural animations 3116 01:35:13,679 --> 01:35:14,679 it's really fun so definitely check it 3117 01:35:15,300 --> 01:35:16,300 out but only after finishing this course 3118 01:35:16,860 --> 01:35:17,860 that one is a much more advanced duel 3119 01:35:18,540 --> 01:35:19,540 for now let's continue here so we want 3120 01:35:20,340 --> 01:35:21,340 to trigger our parameter but do it 3121 01:35:21,719 --> 01:35:22,719 through code and again here we have yet 3122 01:35:23,460 --> 01:35:24,460 another clean code question technically 3123 01:35:25,020 --> 01:35:26,020 we could add that code directly over 3124 01:35:26,820 --> 01:35:27,820 here on the player script we could just 3125 01:35:28,739 --> 01:35:29,739 grab the animator component and change 3126 01:35:30,600 --> 01:35:31,600 the parameter and in this case for this 3127 01:35:32,460 --> 01:35:33,460 very simple game that would actually not 3128 01:35:33,900 --> 01:35:34,900 necessarily be a very bad approach since 3129 01:35:35,880 --> 01:35:36,880 the game is so simple with so few 3130 01:35:37,500 --> 01:35:38,500 animations but like I said I want to 3131 01:35:39,300 --> 01:35:40,300 teach you proper good practices so let's 3132 01:35:41,340 --> 01:35:42,340 make it properly and actually separate 3133 01:35:43,199 --> 01:35:44,199 the animations from the logic for then 3134 01:35:44,820 --> 01:35:45,820 let's go into our project right click in 3135 01:35:46,380 --> 01:35:47,380 our scripts folder create a new c-sharp 3136 01:35:48,179 --> 01:35:49,179 script let's come with the player 3137 01:35:49,679 --> 01:35:50,679 animator let's select the player visual 3138 01:35:51,780 --> 01:35:52,780 game object and attach the component 3139 01:35:53,580 --> 01:35:54,580 okay so now here first let's grab the 3140 01:35:55,560 --> 01:35:56,560 animator now one approach is like we've 3141 01:35:57,719 --> 01:35:58,719 seen we could just make a serialized 3142 01:35:59,219 --> 01:36:00,219 film and and drag the reference in the 3143 01:36:00,719 --> 01:36:01,719 editor that's one approach or 3144 01:36:02,340 --> 01:36:03,340 alternatively since the animator is 3145 01:36:04,020 --> 01:36:05,020 attached to the same game object as this 3146 01:36:05,820 --> 01:36:06,820 script then we can just do a get 3147 01:36:07,320 --> 01:36:08,320 component both approaches are really 3148 01:36:08,760 --> 01:36:09,760 valid so here let's use get component 3149 01:36:10,679 --> 01:36:11,679 just to see a different approach so we 3150 01:36:12,540 --> 01:36:13,540 just have a field for our animator so 3151 01:36:14,880 --> 01:36:15,880 animator and then we just do a private 3152 01:36:17,100 --> 01:36:18,100 void awake and then awake lets you get 3153 01:36:19,080 --> 01:36:20,080 component of type animator and we set 3154 01:36:21,780 --> 01:36:22,780 our animator variable again like I 3155 01:36:23,699 --> 01:36:24,699 mentioned very important make sure you 3156 01:36:25,139 --> 01:36:26,139 don't mix animator and animation these 3157 01:36:27,960 --> 01:36:28,960 are two different components we want the 3158 01:36:29,880 --> 01:36:30,880 animator okay so with this we have a 3159 01:36:31,860 --> 01:36:32,860 reference to our end meta component and 3160 01:36:33,540 --> 01:36:34,540 now how we modify the parameter is 3161 01:36:35,100 --> 01:36:36,100 actually very simple we just access the 3162 01:36:37,139 --> 01:36:38,139 animator and then we have a bunch of set 3163 01:36:38,880 --> 01:36:39,880 functions you can see we have one for 3164 01:36:40,739 --> 01:36:41,739 each type so we've got a set bone set 3165 01:36:42,659 --> 01:36:43,659 float then down here a set trigger set 3166 01:36:44,760 --> 01:36:45,760 Vector so function to set any parameter 3167 01:36:46,980 --> 01:36:47,980 type now we made the Boolean so let's 3168 01:36:48,719 --> 01:36:49,719 use the set bone and this one as you can 3169 01:36:50,280 --> 01:36:51,280 see takes the name for the animator 3170 01:36:51,719 --> 01:36:52,719 parameter by the way strings are a 3171 01:36:53,580 --> 01:36:54,580 horrible horrible way of identifying 3172 01:36:55,440 --> 01:36:56,440 things but suddenly this system really 3173 01:36:57,179 --> 01:36:58,179 does require strings to identify the 3174 01:36:58,860 --> 01:36:59,860 parameter we want to change change if 3175 01:37:00,360 --> 01:37:01,360 you're wondering why strings are bad for 3176 01:37:02,100 --> 01:37:03,100 identifying things the reason is because 3177 01:37:03,719 --> 01:37:04,719 it's very easy to make a mistake for 3178 01:37:05,520 --> 01:37:06,520 example if you use is walking here then 3179 01:37:07,980 --> 01:37:08,980 this won't work however if you instead 3180 01:37:10,080 --> 01:37:11,080 right is walking then all of a sudden 3181 01:37:11,520 --> 01:37:12,520 does not work if your right is walking 3182 01:37:13,320 --> 01:37:14,320 like this doesn't work like this doesn't 3183 01:37:15,360 --> 01:37:16,360 work and even though it doesn't work it 3184 01:37:17,460 --> 01:37:18,460 will also not throw any compiler errors 3185 01:37:19,260 --> 01:37:20,260 that is because for the compiler a 3186 01:37:20,760 --> 01:37:21,760 string is a string it's always valid but 3187 01:37:22,440 --> 01:37:23,440 then when the code runs this one is 3188 01:37:24,000 --> 01:37:25,000 going to be different than our parameter 3189 01:37:25,320 --> 01:37:26,320 which is named exam like this always 3190 01:37:26,880 --> 01:37:27,880 remember that strings are case sensitive 3191 01:37:28,920 --> 01:37:29,920 so that's one reason why you should 3192 01:37:30,540 --> 01:37:31,540 never use strings to identify things 3193 01:37:32,219 --> 01:37:33,219 it's very very easy to make tons of 3194 01:37:34,260 --> 01:37:35,260 mistakes that are then very difficult to 3195 01:37:36,000 --> 01:37:37,000 find out but like I said in this 3196 01:37:37,380 --> 01:37:38,380 animator system we have to use strings 3197 01:37:39,120 --> 01:37:40,120 there's no other way in order to 3198 01:37:40,679 --> 01:37:41,679 minimize our usage of strings one thing 3199 01:37:42,780 --> 01:37:43,780 we can do is for example let's define a 3200 01:37:44,699 --> 01:37:45,699 constant up here so let's make a private 3201 01:37:46,679 --> 01:37:47,679 make it cons for a constant meaning this 3202 01:37:48,780 --> 01:37:49,780 will never change make enough type 3203 01:37:50,219 --> 01:37:51,219 string and conlet is wonky again refer 3204 01:37:52,980 --> 01:37:53,980 back into the naming wrong section for 3205 01:37:54,840 --> 01:37:55,840 constants we always use uppercase snake 3206 01:37:57,179 --> 01:37:58,179 case so is walking and let's set it with 3207 01:37:59,100 --> 01:38:00,100 is wonky again make sure you don't make 3208 01:38:01,860 --> 01:38:02,860 a mistake here make sure you type it 3209 01:38:03,360 --> 01:38:04,360 exam like you did on the animator then 3210 01:38:05,280 --> 01:38:06,280 down here let's use is one and now if 3211 01:38:07,199 --> 01:38:08,199 you do make a mistake so if we 3212 01:38:08,580 --> 01:38:09,580 accidentally use something different now 3213 01:38:10,320 --> 01:38:11,320 we do get a compound error so at least 3214 01:38:12,000 --> 01:38:13,000 we have a little bit of protection okay 3215 01:38:13,679 --> 01:38:14,679 so this one takes a string for the name 3216 01:38:15,060 --> 01:38:16,060 and then a simple Boolean for the value 3217 01:38:16,860 --> 01:38:17,860 so this is going to be the value that we 3218 01:38:18,540 --> 01:38:19,540 want to set to our parameter now for 3219 01:38:20,280 --> 01:38:21,280 this one we want to set to True when the 3220 01:38:22,139 --> 01:38:23,139 player is walking and false when it's 3221 01:38:23,639 --> 01:38:24,639 not so for that we need to ask the 3222 01:38:25,199 --> 01:38:26,199 player what it's doing so let's go over 3223 01:38:27,000 --> 01:38:28,000 here into our player class and let's 3224 01:38:29,100 --> 01:38:30,100 make a function to return just that so 3225 01:38:31,199 --> 01:38:32,199 let's make it public because we're going 3226 01:38:32,760 --> 01:38:33,760 to access it from another script we're 3227 01:38:34,500 --> 01:38:35,500 going to return a boom and call it is 3228 01:38:36,300 --> 01:38:37,300 wonky now over here we just need to 3229 01:38:37,920 --> 01:38:38,920 return if the player is walking so let's 3230 01:38:40,020 --> 01:38:41,020 make a local field to store that saved 3231 01:38:41,820 --> 01:38:42,820 so over here private bone is walking 3232 01:38:43,800 --> 01:38:44,800 again note the capitalization for films 3233 01:38:46,980 --> 01:38:47,980 we start with camel case whereas for 3234 01:38:49,139 --> 01:38:50,139 functions we have Pascal case so these 3235 01:38:51,060 --> 01:38:52,060 are different okay so basically in order 3236 01:38:52,800 --> 01:38:53,800 to Define if we are working that's very 3237 01:38:54,540 --> 01:38:55,540 simple it's just down here we have the 3238 01:38:56,040 --> 01:38:57,040 movement Direction so we are walking if 3239 01:38:58,139 --> 01:38:59,139 the move direction is different from 3240 01:38:59,880 --> 01:39:00,880 Vector 3.0 which by the way Vector 3.0 3241 01:39:02,880 --> 01:39:03,880 is just a shorthand for writing zero 3242 01:39:04,620 --> 01:39:05,620 zero zero so if the movement direction 3243 01:39:05,940 --> 01:39:06,940 is different from zero then we are 3244 01:39:07,620 --> 01:39:08,620 indeed walking so we Define that we 3245 01:39:09,179 --> 01:39:10,179 update that film on every update and 3246 01:39:10,860 --> 01:39:11,860 then over here we just return it okay 3247 01:39:12,600 --> 01:39:13,600 just like this and now back in our 3248 01:39:14,340 --> 01:39:15,340 player animated component over here 3249 01:39:15,960 --> 01:39:16,960 first we need a reference to the player 3250 01:39:17,580 --> 01:39:18,580 so let's add it here let's add a 3251 01:39:19,199 --> 01:39:20,199 serialized film of type player and we 3252 01:39:22,500 --> 01:39:23,500 need to compound this in order to drag 3253 01:39:23,820 --> 01:39:24,820 the reference so let's just come without 3254 01:39:25,440 --> 01:39:26,440 this line just make sure the code 3255 01:39:26,639 --> 01:39:27,639 compounds now here with the code 3256 01:39:28,080 --> 01:39:29,080 compound let's write the reference of 3257 01:39:29,699 --> 01:39:30,699 our player okay that's it and then over 3258 01:39:31,860 --> 01:39:32,860 here for the animator set is wonking 3259 01:39:33,900 --> 01:39:34,900 let's go into the player and let's ask 3260 01:39:35,820 --> 01:39:36,820 is walking and of course we don't want 3261 01:39:37,800 --> 01:39:38,800 to do this just on awake we want to do 3262 01:39:39,659 --> 01:39:40,659 it on every single frame so let's do a 3263 01:39:41,940 --> 01:39:42,940 private void update and on update let's 3264 01:39:44,100 --> 01:39:45,100 do this alright that's it so this should 3265 01:39:46,920 --> 01:39:47,920 be working let's test so here we are 3266 01:39:48,840 --> 01:39:49,840 starting off as Idle and as I move yep 3267 01:39:50,880 --> 01:39:51,880 there you go it is playing The Walking 3268 01:39:52,199 --> 01:39:53,199 animation and now if I stop and if there 3269 01:39:54,659 --> 01:39:55,659 go back into idle alright Awesome 3270 01:39:56,520 --> 01:39:57,520 everything does work perfectly okay 3271 01:39:58,380 --> 01:39:59,380 great we can can even look at the 3272 01:40:00,300 --> 01:40:01,300 animator to see the state change so here 3273 01:40:02,159 --> 01:40:03,159 with both side aside and with the 3274 01:40:03,900 --> 01:40:04,900 objects selected in the hierarchy right 3275 01:40:05,580 --> 01:40:06,580 now you can see he's walking his phone 3276 01:40:06,900 --> 01:40:07,900 so it's on idle and as I move that one 3277 01:40:08,639 --> 01:40:09,639 stays true that one goes into wonk and 3278 01:40:10,440 --> 01:40:11,440 now if I don't let go if there and go 3279 01:40:12,179 --> 01:40:13,179 back into falls back into idle all right 3280 01:40:14,280 --> 01:40:15,280 awesome so with this everything is 3281 01:40:16,080 --> 01:40:17,080 working perfectly if you're having 3282 01:40:17,580 --> 01:40:18,580 issues make sure you pay attention to 3283 01:40:19,620 --> 01:40:20,620 the capitalization so make sure the name 3284 01:40:21,960 --> 01:40:22,960 you wrote here is exactly the same one 3285 01:40:24,179 --> 01:40:25,179 that you wrote here and it's exactly the 3286 01:40:26,460 --> 01:40:27,460 same that you're using here alright so 3287 01:40:28,020 --> 01:40:29,020 all of our animations are working 3288 01:40:29,280 --> 01:40:30,280 perfectly now if you want you can go 3289 01:40:31,440 --> 01:40:32,440 ahead and make your own animations or 3290 01:40:33,360 --> 01:40:34,360 you can use the ones that I pre-bumped 3291 01:40:34,920 --> 01:40:35,920 so in the included project files inside 3292 01:40:36,900 --> 01:40:37,900 the assets here we've got the animations 3293 01:40:38,580 --> 01:40:39,580 and we've got the player with the idol 3294 01:40:40,800 --> 01:40:41,800 and the wonk animations if we double 3295 01:40:42,600 --> 01:40:43,600 click on this don't look at it you can 3296 01:40:43,980 --> 01:40:44,980 see yep it looks exactly the same so 3297 01:40:46,080 --> 01:40:47,080 there's a parameter called is walking in 3298 01:40:47,820 --> 01:40:48,820 our transition so everything is exactly 3299 01:40:49,500 --> 01:40:50,500 the same just over here let's select the 3300 01:40:51,179 --> 01:40:52,179 employer Visual and on the prefab like 3301 01:40:52,920 --> 01:40:53,920 we saw we already have the animated 3302 01:40:54,480 --> 01:40:55,480 component we just removed that one from 3303 01:40:56,159 --> 01:40:57,159 the prefab in order to build it on from 3304 01:40:57,960 --> 01:40:58,960 scratch but if you want to use my image 3305 01:40:59,219 --> 01:41:00,219 then we can just go ahead remove the 3306 01:41:01,320 --> 01:41:02,320 animator that we added and then right 3307 01:41:02,880 --> 01:41:03,880 click on this one on the remove 3308 01:41:04,020 --> 01:41:05,020 component let's revert back to changes 3309 01:41:05,880 --> 01:41:06,880 and there you go here we have our 3310 01:41:07,199 --> 01:41:08,199 animator with the player controller so 3311 01:41:09,239 --> 01:41:10,239 that's the one in the animations and 3312 01:41:11,280 --> 01:41:12,280 just like this if we had on play and 3313 01:41:13,139 --> 01:41:14,139 actually over here I found an issue 3314 01:41:14,580 --> 01:41:15,580 although in your case there shouldn't be 3315 01:41:16,080 --> 01:41:17,080 any issue because I've updated the 3316 01:41:17,760 --> 01:41:18,760 assets but this is a good time to teach 3317 01:41:19,380 --> 01:41:20,380 you about any issues with animations so 3318 01:41:21,600 --> 01:41:22,600 if you select the animation and you 3319 01:41:23,040 --> 01:41:24,040 select the animation and over here you 3320 01:41:24,840 --> 01:41:25,840 might see some of them in yellow saying 3321 01:41:26,639 --> 01:41:27,639 missing basically the way that 3322 01:41:27,900 --> 01:41:28,900 animations work is based on the actual 3323 01:41:29,760 --> 01:41:30,760 name of the object if it cannot find an 3324 01:41:31,560 --> 01:41:32,560 object with the exact same name then it 3325 01:41:33,120 --> 01:41:34,120 cannot load the same animation so my 3326 01:41:34,980 --> 01:41:35,980 problem is that when I initially made 3327 01:41:36,420 --> 01:41:37,420 the assets package I made this animation 3328 01:41:38,639 --> 01:41:39,639 and the object was previously named face 3329 01:41:40,800 --> 01:41:41,800 and then I renamed it the head so now it 3330 01:41:42,659 --> 01:41:43,659 normally loads so if you ever have 3331 01:41:44,520 --> 01:41:45,520 problems with loading animations just 3332 01:41:46,080 --> 01:41:47,080 make sure the name is perfectly matched 3333 01:41:47,460 --> 01:41:48,460 so in my case I can just click in here 3334 01:41:49,139 --> 01:41:50,139 in order to rename this keyframe on the 3335 01:41:51,000 --> 01:41:52,000 animation and I'm just going to use the 3336 01:41:52,560 --> 01:41:53,560 name that I renamed it so head and just 3337 01:41:55,020 --> 01:41:56,020 like this yep the animation does play 3338 01:41:56,639 --> 01:41:57,639 correctly so it's just a nice quick tip 3339 01:41:58,260 --> 01:41:59,260 if you ever have problems with and 3340 01:41:59,639 --> 01:42:00,639 missions always remember that the stored 3341 01:42:01,380 --> 01:42:02,380 keyframes their own stored based on name 3342 01:42:02,880 --> 01:42:03,880 so if you rename the thing in here or 3343 01:42:05,280 --> 01:42:06,280 over here on the game object if you're 3344 01:42:06,900 --> 01:42:07,900 in a name you're going to have missing 3345 01:42:08,340 --> 01:42:09,340 animations but if you make sure the 3346 01:42:09,900 --> 01:42:10,900 names match and the animation shouldn't 3347 01:42:11,460 --> 01:42:12,460 work perfectly so let's hit on play and 3348 01:42:13,020 --> 01:42:14,020 if there go there's the anal animation 3349 01:42:14,520 --> 01:42:15,520 and if I move yep there's the nice wonk 3350 01:42:16,739 --> 01:42:17,739 animation so everything still works 3351 01:42:18,360 --> 01:42:19,360 perfectly because it's only using the 3352 01:42:19,679 --> 01:42:20,679 exact same parameter alright awesome so 3353 01:42:22,080 --> 01:42:23,080 like I said if you want film free to 3354 01:42:23,760 --> 01:42:24,760 make your own animations or use the ones 3355 01:42:25,619 --> 01:42:26,619 that I've included for me I'm going to 3356 01:42:27,300 --> 01:42:28,300 be using these ones so the ones that we 3357 01:42:29,280 --> 01:42:30,280 made just for learning which I created 3358 01:42:30,719 --> 01:42:31,719 down here so the multiplier animator and 3359 01:42:32,639 --> 01:42:33,639 these animations I'm just going to 3360 01:42:33,719 --> 01:42:34,719 delete these just to keep the project 3361 01:42:35,100 --> 01:42:36,100 clean so just delete and just like that 3362 01:42:37,500 --> 01:42:38,500 okay so now there we have our character 3363 01:42:39,780 --> 01:42:40,780 fully working let's quickly handle our 3364 01:42:41,760 --> 01:42:42,760 camera 3365 01:42:43,440 --> 01:42:44,440 hello and welcome I'm your code monkey 3366 01:42:45,600 --> 01:42:46,600 in this lecture we're going to quickly 3367 01:42:47,639 --> 01:42:48,639 install cinemachine this is a Unity tool 3368 01:42:49,860 --> 01:42:50,860 that makes handling cameras super easy 3369 01:42:51,420 --> 01:42:52,420 our game isn't really going to have a 3370 01:42:53,159 --> 01:42:54,159 moving camera so this part isn't 3371 01:42:54,780 --> 01:42:55,780 strictly necessary but same machine is a 3372 01:42:56,760 --> 01:42:57,760 super useful tool so I definitely want 3373 01:42:58,260 --> 01:42:59,260 you to learn about okay so let's begin 3374 01:42:59,940 --> 01:43:00,940 by installing the package let's go into 3375 01:43:01,800 --> 01:43:02,800 window open up the package manager then 3376 01:43:03,960 --> 01:43:04,960 up top let's make sure we are in the UNT 3377 01:43:05,580 --> 01:43:06,580 registry make sure you're on the all Tab 3378 01:43:08,040 --> 01:43:09,040 and now just scroll down until you find 3379 01:43:10,020 --> 01:43:11,020 yep there it is send machine okay so 3380 01:43:11,880 --> 01:43:12,880 let's go ahead and install this 3381 01:43:14,159 --> 01:43:15,159 all right Sunstone so let's close this 3382 01:43:16,440 --> 01:43:17,440 and now the way that send machine works 3383 01:43:18,420 --> 01:43:19,420 is by creating what is called a send 3384 01:43:19,980 --> 01:43:20,980 machine virtual camera so let's go up 3385 01:43:21,780 --> 01:43:22,780 top into the game object menu then 3386 01:43:23,760 --> 01:43:24,760 scroll down into cinemachine and over 3387 01:43:25,739 --> 01:43:26,739 here you can see that we can create a 3388 01:43:27,360 --> 01:43:28,360 multitude of virtual camera types now 3389 01:43:29,219 --> 01:43:30,219 just by the names you can see how this 3390 01:43:30,719 --> 01:43:31,719 tool is insanely useful for example 3391 01:43:32,639 --> 01:43:33,639 making a free download camera doing that 3392 01:43:34,560 --> 01:43:35,560 from scratch is a bit tricky but with 3393 01:43:36,179 --> 01:43:37,179 same machine it is super easy for our 3394 01:43:38,040 --> 01:43:39,040 case like I said we want the absolute 3395 01:43:39,960 --> 01:43:40,960 most basic thing possible so let's just 3396 01:43:41,760 --> 01:43:42,760 create an empty virtual camera okay 3397 01:43:43,500 --> 01:43:44,500 that's it this creates a virtual camera 3398 01:43:45,540 --> 01:43:46,540 over here in the hierarchy and turn this 3399 01:43:47,580 --> 01:43:48,580 object has the send machine virtual 3400 01:43:49,080 --> 01:43:50,080 camera component and also importantly 3401 01:43:50,760 --> 01:43:51,760 when we added this it also added over 3402 01:43:52,739 --> 01:43:53,739 here on the main camera if we scroll 3403 01:43:54,239 --> 01:43:55,239 down we can see it has a sin machine 3404 01:43:55,679 --> 01:43:56,679 brain component basically the way send 3405 01:43:57,420 --> 01:43:58,420 machine works is it works on top of the 3406 01:43:59,400 --> 01:44:00,400 main camera so it doesn't replace it it 3407 01:44:01,380 --> 01:44:02,380 works on top of it and drives the main 3408 01:44:03,119 --> 01:44:04,119 camera so now that we're using send 3409 01:44:04,619 --> 01:44:05,619 machine if we try modifying the main 3410 01:44:06,780 --> 01:44:07,780 camera game object so there's one over 3411 01:44:08,340 --> 01:44:09,340 here if I try to drag the field of view 3412 01:44:10,139 --> 01:44:11,139 nope does not work I cannot move it if I 3413 01:44:12,540 --> 01:44:13,540 try to move the position nope can't do 3414 01:44:14,040 --> 01:44:15,040 it it if I try to rotate it nope that 3415 01:44:16,020 --> 01:44:17,020 does not work like I said when working 3416 01:44:17,699 --> 01:44:18,699 with cinemachine the sin machine brain 3417 01:44:19,560 --> 01:44:20,560 is what drives the main camera so rather 3418 01:44:21,300 --> 01:44:22,300 than modifying the things over here on 3419 01:44:22,860 --> 01:44:23,860 the camera itself what we need to do is 3420 01:44:24,600 --> 01:44:25,600 change them on the virtual camera so 3421 01:44:26,340 --> 01:44:27,340 over here we have pretty much the exact 3422 01:44:28,020 --> 01:44:29,020 same options that we have on the main 3423 01:44:29,520 --> 01:44:30,520 camera for example modifying the fov 3424 01:44:31,860 --> 01:44:32,860 over here we've got the lens so we can 3425 01:44:33,540 --> 01:44:34,540 modify the fov and if we look in the 3426 01:44:35,100 --> 01:44:36,100 game scene as we modify this one yep it 3427 01:44:37,199 --> 01:44:38,199 does modify the actual properties on the 3428 01:44:38,880 --> 01:44:39,880 actual main camera now this has tons and 3429 01:44:40,800 --> 01:44:41,800 tons of options related to everything 3430 01:44:42,060 --> 01:44:43,060 the most important ones are all kinds of 3431 01:44:44,100 --> 01:44:45,100 options down here for the body and the 3432 01:44:46,080 --> 01:44:47,080 aim so this is where the camera is 3433 01:44:47,639 --> 01:44:48,639 positioned and where it's looking at 3434 01:44:49,080 --> 01:44:50,080 using this you can make a funnel camera 3435 01:44:50,940 --> 01:44:51,940 in five seconds it really is insanely 3436 01:44:52,920 --> 01:44:53,920 useful if you want to learn about Sim 3437 01:44:54,480 --> 01:44:55,480 machine in more detail I have a 3438 01:44:55,920 --> 01:44:56,920 dedicated video on it I go through what 3439 01:44:57,719 --> 01:44:58,719 all of these options do then I also have 3440 01:44:59,760 --> 01:45:00,760 another super detailed video on how to 3441 01:45:01,440 --> 01:45:02,440 make a camera system with pan Zoom 3442 01:45:03,360 --> 01:45:04,360 scroll in both 2D and 3D and a bunch 3443 01:45:05,639 --> 01:45:06,639 more features again all of it using send 3444 01:45:07,560 --> 01:45:08,560 machine but in our case we really want 3445 01:45:09,239 --> 01:45:10,239 to keep it simple so let's just position 3446 01:45:10,860 --> 01:45:11,860 our virtual camera on the same settings 3447 01:45:12,780 --> 01:45:13,780 that we had previously so for first 3448 01:45:14,520 --> 01:45:15,520 let's set the film review so for a game 3449 01:45:16,320 --> 01:45:17,320 we want something narrow so let's go 3450 01:45:17,699 --> 01:45:18,699 with just 20. then for the position 3451 01:45:19,080 --> 01:45:20,080 let's put it above so zero on the X then 3452 01:45:21,840 --> 01:45:22,840 21.5 on the Y and minus 21.3 on the Zen 3453 01:45:25,199 --> 01:45:26,199 then for the rotation 46 on the X and 3454 01:45:27,719 --> 01:45:28,719 then 0 on the others okay so our camera 3455 01:45:29,400 --> 01:45:30,400 is positioned in the exact same position 3456 01:45:30,840 --> 01:45:31,840 and if we head on 20 yep everything 3457 01:45:32,639 --> 01:45:33,639 still works the same the camera is going 3458 01:45:34,080 --> 01:45:35,080 from the same point of view and the 3459 01:45:35,340 --> 01:45:36,340 character still works everything's still 3460 01:45:36,900 --> 01:45:37,900 exactly the same now since we're using 3461 01:45:38,580 --> 01:45:39,580 cinemachine we can easily add some 3462 01:45:40,080 --> 01:45:41,080 things on top of this like for example 3463 01:45:41,820 --> 01:45:42,820 we can add some noise to our scene 3464 01:45:43,260 --> 01:45:44,260 machine camera to make it smoothly move 3465 01:45:45,000 --> 01:45:46,000 a little bit this one is a fun simple 3466 01:45:47,040 --> 01:45:48,040 effect that can make our game feel a bit 3467 01:45:48,960 --> 01:45:49,960 more Dynamic especially in games like 3468 01:45:50,580 --> 01:45:51,580 this where we have a fixed overhead view 3469 01:45:52,320 --> 01:45:53,320 how we do that is over here on the scene 3470 01:45:53,940 --> 01:45:54,940 Mission virtual camera we've got a film 3471 01:45:55,199 --> 01:45:56,199 for noise so let's click and let's 3472 01:45:57,119 --> 01:45:58,119 select basic multi-channel purlin and 3473 01:45:59,280 --> 01:46:00,280 then over here we've got the noise 3474 01:46:00,360 --> 01:46:01,360 profile so we can choose one of the 3475 01:46:01,980 --> 01:46:02,980 included ones or we can create our own 3476 01:46:03,540 --> 01:46:04,540 profile so for example let's go with 3477 01:46:05,219 --> 01:46:06,219 handheld normal mild and by the way you 3478 01:46:07,139 --> 01:46:08,139 can actually modify these settings while 3479 01:46:08,340 --> 01:46:09,340 the game is playing so here it is the 3480 01:46:09,900 --> 01:46:10,900 game playing and you can see what this 3481 01:46:10,980 --> 01:46:11,980 effect does it adds a nice little wobble 3482 01:46:13,080 --> 01:46:14,080 to the camera and then over here at my 3483 01:46:14,820 --> 01:46:15,820 student frequency so we can play around 3484 01:46:16,199 --> 01:46:17,199 these so you can make it really intense 3485 01:46:17,940 --> 01:46:18,940 so something like this that is way too 3486 01:46:19,560 --> 01:46:20,560 intense so there you go quite a lot so 3487 01:46:21,719 --> 01:46:22,719 for something more subtle maybe put 0.5 3488 01:46:23,400 --> 01:46:24,400 and 0.5 there you go just a slight 3489 01:46:25,500 --> 01:46:26,500 little movement in the camera so this 3490 01:46:27,119 --> 01:46:28,119 would help make the game a little bit 3491 01:46:28,440 --> 01:46:29,440 more Dynamic so this could be a fun 3492 01:46:30,060 --> 01:46:31,060 effect although actually in my case in 3493 01:46:31,739 --> 01:46:32,739 order to make sure that the video 3494 01:46:32,639 --> 01:46:33,639 doesn't get way too compressed I'm 3495 01:46:34,260 --> 01:46:35,260 actually going to disable this on my end 3496 01:46:35,820 --> 01:46:36,820 so just set the channel noise to none 3497 01:46:37,619 --> 01:46:38,619 but you can see how easy it is to add 3498 01:46:39,600 --> 01:46:40,600 complex camera features when using send 3499 01:46:41,280 --> 01:46:42,280 machine and of course when using 3500 01:46:42,420 --> 01:46:43,420 cinemachine if you want you can use it 3501 01:46:44,100 --> 01:46:45,100 to make your game a lot more unique now 3502 01:46:45,659 --> 01:46:46,659 for me I want to design here where the 3503 01:46:47,280 --> 01:46:48,280 camera is fixed but let's say for 3504 01:46:48,540 --> 01:46:49,540 example you wanted the camera to 3505 01:46:50,159 --> 01:46:51,159 actually follow the player like I said 3506 01:46:51,719 --> 01:46:52,719 you'll watch that dedicated video tool 3507 01:46:53,280 --> 01:46:54,280 and learn all about cinemachine but over 3508 01:46:54,900 --> 01:46:55,900 here very quickly let me just show you 3509 01:46:56,639 --> 01:46:57,639 how to do that but at the same time 3510 01:46:57,960 --> 01:46:58,960 don't bother following this part it's 3511 01:46:59,340 --> 01:47:00,340 just to show what scene machine can do 3512 01:47:00,659 --> 01:47:01,659 that I'm going to revert back to this 3513 01:47:02,040 --> 01:47:03,040 state so first of all for testing one 3514 01:47:03,719 --> 01:47:04,719 great thing about scene machine is you 3515 01:47:04,980 --> 01:47:05,980 can have multiple virtual cameras you 3516 01:47:06,780 --> 01:47:07,780 can have as many as you want and then 3517 01:47:08,699 --> 01:47:09,699 the priority and the game object enabled 3518 01:47:10,619 --> 01:47:11,619 state is what defines which camera is 3519 01:47:12,179 --> 01:47:13,179 actually being used so for example on 3520 01:47:13,739 --> 01:47:14,739 this second one let's make it follow the 3521 01:47:15,300 --> 01:47:16,300 camera and put the priority on 20 so 3522 01:47:17,040 --> 01:47:18,040 that it's above then over here for the 3523 01:47:18,600 --> 01:47:19,600 body I'm going to select transposer 3524 01:47:20,040 --> 01:47:21,040 let's put it with World space it 3525 01:47:22,500 --> 01:47:23,500 requires a funnel Target so let me drag 3526 01:47:24,119 --> 01:47:25,119 the player as the final Target and put 3527 01:47:26,280 --> 01:47:27,280 it as slightly above and behind Okay so 3528 01:47:29,340 --> 01:47:30,340 it's pretty similar as before then for 3529 01:47:31,080 --> 01:47:32,080 the aim let me also drag the aim player 3530 01:47:33,360 --> 01:47:34,360 Target and just with this it should 3531 01:47:34,679 --> 01:47:35,679 already work so if I head on play if 3532 01:47:36,420 --> 01:47:37,420 they're going to look at that the camera 3533 01:47:37,500 --> 01:47:38,500 is now moving and following the player 3534 01:47:39,480 --> 01:47:40,480 so I can move the player anywhere and 3535 01:47:40,800 --> 01:47:41,800 yep the camera follows along so as you 3536 01:47:42,540 --> 01:47:43,540 can see it's this simple to really make 3537 01:47:43,980 --> 01:47:44,980 some complex camera movement doing some 3538 01:47:45,840 --> 01:47:46,840 complex camera logic just like this 3539 01:47:47,460 --> 01:47:48,460 would require a ton of work manually but 3540 01:47:49,440 --> 01:47:50,440 with thin machine it is super easy then 3541 01:47:51,420 --> 01:47:52,420 you can even play around with either 3542 01:47:52,679 --> 01:47:53,679 priority or enable and disable and there 3543 01:47:55,139 --> 01:47:56,139 you go see the machine even transitions 3544 01:47:56,699 --> 01:47:57,699 between the state of only your virtual 3545 01:47:58,260 --> 01:47:59,260 cameras so as you can see in lots and 3546 01:47:59,820 --> 01:48:00,820 lots of things you can make with your 3547 01:48:01,020 --> 01:48:02,020 camera very easily all thanks to 3548 01:48:02,699 --> 01:48:03,699 cinemachine like I said in my case I 3549 01:48:04,560 --> 01:48:05,560 just want the fix overhead camera so I'm 3550 01:48:06,179 --> 01:48:07,179 just going to delete this secondary 3551 01:48:07,500 --> 01:48:08,500 virtual camera and there you go just 3552 01:48:09,000 --> 01:48:10,000 this one on top looking at the player 3553 01:48:10,860 --> 01:48:11,860 and looking down with a low fov and Yep 3554 01:48:12,960 --> 01:48:13,960 this is the exactly the kind of camera 3555 01:48:14,580 --> 01:48:15,580 that I want for my game okay so that's 3556 01:48:16,500 --> 01:48:17,500 in machine it's a really awesome tool 3557 01:48:18,360 --> 01:48:19,360 for making camera handling much much 3558 01:48:19,920 --> 01:48:20,920 easier so this was a quick lecture all 3559 01:48:22,020 --> 01:48:23,020 about learning about Sin machine now 3560 01:48:23,880 --> 01:48:24,880 let's handle the tests that was actually 3561 01:48:25,139 --> 01:48:26,139 left and done quite a while ago let's 3562 01:48:26,880 --> 01:48:27,880 finally learn how to refactor code and 3563 01:48:28,739 --> 01:48:29,739 implement the new input system so let's 3564 01:48:30,600 --> 01:48:31,600 do that in the next lecture 3565 01:48:33,060 --> 01:48:34,060 hello and welcome I'm your code monkey 3566 01:48:34,980 --> 01:48:35,980 in this lecture we're going to refactor 3567 01:48:37,260 --> 01:48:38,260 our code from the Legacy input manager 3568 01:48:39,239 --> 01:48:40,239 onto the new input system so the 3569 01:48:41,400 --> 01:48:42,400 simpleton character controller that we 3570 01:48:42,840 --> 01:48:43,840 made is working perfectly fine within 3571 01:48:44,400 --> 01:48:45,400 Legacy input manager like I said this 3572 01:48:46,440 --> 01:48:47,440 one is excellent for making quick 3573 01:48:47,760 --> 01:48:48,760 prototypes and demos as you can see it's 3574 01:48:49,560 --> 01:48:50,560 super easy to use 3575 01:48:50,880 --> 01:48:51,880 but now let's quickly refactor this code 3576 01:48:53,159 --> 01:48:54,159 to use the new input system instead also 3577 01:48:55,260 --> 01:48:56,260 like I said in the beginning of this 3578 01:48:56,400 --> 01:48:57,400 course here I'm going to be focused 3579 01:48:57,840 --> 01:48:58,840 primarily on building this game so for 3580 01:48:59,880 --> 01:49:00,880 example for any Unity tools that I use 3581 01:49:01,560 --> 01:49:02,560 like the new input system I'm going to 3582 01:49:03,360 --> 01:49:04,360 cover enough to be able to use a tool 3583 01:49:04,920 --> 01:49:05,920 and Achieve our goals in building this 3584 01:49:06,480 --> 01:49:07,480 game 3585 01:49:07,320 --> 01:49:08,320 of course every tool does a lot more 3586 01:49:08,820 --> 01:49:09,820 than just what we're going to use so 3587 01:49:10,619 --> 01:49:11,619 definitely make sure to watch the 3588 01:49:11,699 --> 01:49:12,699 dedicated videos Link in the description 3589 01:49:12,960 --> 01:49:13,960 for example the input system tutorial is 3590 01:49:15,239 --> 01:49:16,239 40 minutes long covering everything you 3591 01:49:16,800 --> 01:49:17,800 need to know about system whereas here 3592 01:49:18,420 --> 01:49:19,420 we're just going to learn enough to know 3593 01:49:19,800 --> 01:49:20,800 how to use it so let's refactor this 3594 01:49:21,960 --> 01:49:22,960 code to make it work with new input 3595 01:49:23,400 --> 01:49:24,400 system except before we work with new 3596 01:49:25,739 --> 01:49:26,739 input system let's just refactor this 3597 01:49:27,600 --> 01:49:28,600 code so we can completely decoup on the 3598 01:49:29,760 --> 01:49:30,760 input from the player class again we 3599 01:49:32,040 --> 01:49:33,040 want to focus on writing good clean code 3600 01:49:33,659 --> 01:49:34,659 so we should keep all of our input logic 3601 01:49:36,179 --> 01:49:37,179 in its own class that other scripts can 3602 01:49:37,980 --> 01:49:38,980 access remember the goal with clean code 3603 01:49:40,320 --> 01:49:41,320 is to minimize and manage complexity so 3604 01:49:42,900 --> 01:49:43,900 every class should do one thing and just 3605 01:49:44,820 --> 01:49:45,820 one thing meaning that the player class 3606 01:49:46,800 --> 01:49:47,800 should only handle the player and then 3607 01:49:48,480 --> 01:49:49,480 the input list should only handle the 3608 01:49:50,280 --> 01:49:51,280 input the only reason why I put this 3609 01:49:52,440 --> 01:49:53,440 over here in the beginning is exactly to 3610 01:49:53,940 --> 01:49:54,940 teach you about refactoring and how it's 3611 01:49:55,560 --> 01:49:56,560 a very common thing that you should be 3612 01:49:57,000 --> 01:49:58,000 doing all the time this is exactly how I 3613 01:49:59,340 --> 01:50:00,340 build my own games I start by making a 3614 01:50:01,679 --> 01:50:02,679 prototype and I write the input directly 3615 01:50:03,239 --> 01:50:04,239 inside the player class then at some 3616 01:50:04,920 --> 01:50:05,920 point I refactor the code to split them 3617 01:50:06,600 --> 01:50:07,600 up so don't be afraid to refactor code 3618 01:50:09,000 --> 01:50:10,000 it's a Perfectly Natural part of the 3619 01:50:10,860 --> 01:50:11,860 Game Dev process and actually a very 3620 01:50:12,659 --> 01:50:13,659 very good thing okay so let's make a 3621 01:50:14,940 --> 01:50:15,940 script just to manage our inputs let's 3622 01:50:16,679 --> 01:50:17,679 make a new c-sharp script call this game 3623 01:50:19,739 --> 01:50:20,739 input let's create an empty game object 3624 01:50:22,380 --> 01:50:23,380 give it the same name input as always 3625 01:50:24,360 --> 01:50:25,360 keep things lean so put it on zero zero 3626 01:50:26,400 --> 01:50:27,400 zero let's attach the script and open 3627 01:50:28,619 --> 01:50:29,619 okay so here's our script and let's get 3628 01:50:30,900 --> 01:50:31,900 everything related to the inputs on the 3629 01:50:33,179 --> 01:50:34,179 player for the input we are calculating 3630 01:50:34,800 --> 01:50:35,800 the input Vector then getting the actual 3631 01:50:36,840 --> 01:50:37,840 inputs from the keyboard and returning 3632 01:50:38,520 --> 01:50:39,520 the input vector 3633 01:50:39,780 --> 01:50:40,780 so let's put this on the other script so 3634 01:50:42,600 --> 01:50:43,600 over here let's make a new function 3635 01:50:44,460 --> 01:50:45,460 let's make it public since we want to 3636 01:50:46,380 --> 01:50:47,380 access it from the player we're going to 3637 01:50:48,239 --> 01:50:49,239 return a vector 2 and let's call it get 3638 01:50:50,219 --> 01:50:51,219 movement vector 3639 01:50:53,280 --> 01:50:54,280 now here let's really just copy paste 3640 01:50:55,080 --> 01:50:56,080 the exact same code that we have on 3641 01:50:56,340 --> 01:50:57,340 player so let's copy paste all of this 3642 01:50:58,080 --> 01:50:59,080 let's go and paste it here 3643 01:51:00,239 --> 01:51:01,239 okay so we get the input Vector we get 3644 01:51:02,100 --> 01:51:03,100 the inputs we normalize it and then 3645 01:51:04,380 --> 01:51:05,380 return the input vector 3646 01:51:06,540 --> 01:51:07,540 okay so that's it super simple also by 3647 01:51:09,239 --> 01:51:10,239 the way here we have an interesting 3648 01:51:10,560 --> 01:51:11,560 question 3649 01:51:11,340 --> 01:51:12,340 which is do we normalize the input over 3650 01:51:13,500 --> 01:51:14,500 here or do we do it over here on the 3651 01:51:15,239 --> 01:51:16,239 player both options can be valid you can 3652 01:51:18,540 --> 01:51:19,540 make it so that the game unplug glass 3653 01:51:19,980 --> 01:51:20,980 returns a regular input or you can make 3654 01:51:23,219 --> 01:51:24,219 it return a normalized vector you can 3655 01:51:25,440 --> 01:51:26,440 use either option but whatever you do 3656 01:51:27,060 --> 01:51:28,060 make sure you are explicit so over here 3657 01:51:29,280 --> 01:51:30,280 I am going to normalize input inside the 3658 01:51:31,440 --> 01:51:32,440 game input class however I'm also going 3659 01:51:33,659 --> 01:51:34,659 to make sure to rename this function so 3660 01:51:35,400 --> 01:51:36,400 instead of get movement Vector get 3661 01:51:36,960 --> 01:51:37,960 movement Vector normalize that way it is 3662 01:51:39,420 --> 01:51:40,420 100 clear this returns a movement Vector 3663 01:51:41,820 --> 01:51:42,820 as a normalized vector okay great 3664 01:51:44,460 --> 01:51:45,460 so now let's use this in our player over 3665 01:51:47,340 --> 01:51:48,340 here in our player class we need some 3666 01:51:49,020 --> 01:51:50,020 reference to our input class now later 3667 01:51:51,719 --> 01:51:52,719 on in this course I'm going to teach you 3668 01:51:53,219 --> 01:51:54,219 about the Singleton pattern but for now 3669 01:51:55,199 --> 01:51:56,199 let's just do a simple direct reference 3670 01:51:57,659 --> 01:51:58,659 again remember don't make it public make 3671 01:52:00,179 --> 01:52:01,179 it a serialized film private so over 3672 01:52:02,520 --> 01:52:03,520 here 3673 01:52:03,600 --> 01:52:04,600 let's make a serialized film private of 3674 01:52:05,760 --> 01:52:06,760 type game input and let's call it just 3675 01:52:07,860 --> 01:52:08,860 game input 3676 01:52:10,260 --> 01:52:11,260 okay so we have this we're going to drag 3677 01:52:12,119 --> 01:52:13,119 it in the editor then over here we 3678 01:52:14,159 --> 01:52:15,159 simply grab the vector 2 for the input 3679 01:52:16,199 --> 01:52:17,199 Vector we simply go into this one and we 3680 01:52:18,540 --> 01:52:19,540 get the movement vector normalized and 3681 01:52:20,880 --> 01:52:21,880 okay that's it no more errors let's just 3682 01:52:22,560 --> 01:52:23,560 make sure to save all of our scripts and 3683 01:52:24,780 --> 01:52:25,780 back in the editor let's go into the 3684 01:52:26,100 --> 01:52:27,100 player and just drag the reference for 3685 01:52:27,840 --> 01:52:28,840 the game input okay so just like this 3686 01:52:29,940 --> 01:52:30,940 everything should still work everything 3687 01:52:31,500 --> 01:52:32,500 should work exactly the same as 3688 01:52:33,179 --> 01:52:34,179 previously Let's test and make sure so 3689 01:52:36,239 --> 01:52:37,239 here we are moving and yep everything 3690 01:52:37,679 --> 01:52:38,679 still works I can move in any direction 3691 01:52:39,239 --> 01:52:40,239 okay so far so good 3692 01:52:41,159 --> 01:52:42,159 and what we have done here is 3693 01:52:42,540 --> 01:52:43,540 essentially we have refactor our code 3694 01:52:44,400 --> 01:52:45,400 and conveniently separate the input from 3695 01:52:46,440 --> 01:52:47,440 the player class this is an excellent 3696 01:52:48,600 --> 01:52:49,600 thing so again don't be afraid to 3697 01:52:50,040 --> 01:52:51,040 refactor code also what we did here of 3698 01:52:52,260 --> 01:52:53,260 putting the code in a separate class and 3699 01:52:54,360 --> 01:52:55,360 then doing a quick test to make sure 3700 01:52:55,739 --> 01:52:56,739 that everything soon works the same as 3701 01:52:57,239 --> 01:52:58,239 previously this is exactly what you 3702 01:52:58,980 --> 01:52:59,980 should do whenever you do some kind of 3703 01:53:00,420 --> 01:53:01,420 reorganizational refactoring in the end 3704 01:53:02,699 --> 01:53:03,699 you want to end up with the exact same 3705 01:53:04,500 --> 01:53:05,500 behaviors previously just with the code 3706 01:53:06,239 --> 01:53:07,239 organized in a different way okay so now 3707 01:53:08,699 --> 01:53:09,699 that we have this separate game input 3708 01:53:10,139 --> 01:53:11,139 class now we can very easily refactor 3709 01:53:12,659 --> 01:53:13,659 the Legacy input manager onto the new 3710 01:53:14,699 --> 01:53:15,699 input system so the first thing we need 3711 01:53:16,560 --> 01:53:17,560 is to install the package so let's open 3712 01:53:18,239 --> 01:53:19,239 up the package manager let's make sure 3713 01:53:20,639 --> 01:53:21,639 up here we are in the ENT registry make 3714 01:53:22,739 --> 01:53:23,739 sure we are in all and let's scroll down 3715 01:53:25,020 --> 01:53:26,020 to find the input system so here it is 3716 01:53:27,360 --> 01:53:28,360 let's go ahead and install 3717 01:53:30,360 --> 01:53:31,360 okay the package is installed and right 3718 01:53:32,159 --> 01:53:33,159 away we see this message basically it's 3719 01:53:34,320 --> 01:53:35,320 asking us if we want to enable the new 3720 01:53:36,060 --> 01:53:37,060 input system 3721 01:53:37,199 --> 01:53:38,199 now you could click on yes but let's 3722 01:53:39,239 --> 01:53:40,239 actually go ahead and click on no we're 3723 01:53:40,860 --> 01:53:41,860 going to enable it manually so click on 3724 01:53:42,719 --> 01:53:43,719 no then let's close this window and now 3725 01:53:45,719 --> 01:53:46,719 let's go up here into edit then let's go 3726 01:53:47,639 --> 01:53:48,639 into project settings then on the left 3727 01:53:49,739 --> 01:53:50,739 side let's go into player and now let's 3728 01:53:51,960 --> 01:53:52,960 scroll down expand over here the other 3729 01:53:54,119 --> 01:53:55,119 settings tab 3730 01:53:55,500 --> 01:53:56,500 and keep scrolling down until we see yep 3731 01:53:57,840 --> 01:53:58,840 here it is the active input Henley this 3732 01:54:00,060 --> 01:54:01,060 is where you can select which input 3733 01:54:01,380 --> 01:54:02,380 system you're using basically if you 3734 01:54:03,119 --> 01:54:04,119 click yes on that window it would 3735 01:54:04,739 --> 01:54:05,739 automatically set this option to use the 3736 01:54:06,719 --> 01:54:07,719 new input system so it would only enable 3737 01:54:09,000 --> 01:54:10,000 that one and can only disable the unless 3738 01:54:10,860 --> 01:54:11,860 input manager but like I said the lace 3739 01:54:13,020 --> 01:54:14,020 input manager is still pretty useful so 3740 01:54:14,880 --> 01:54:15,880 normally for me I prefer to enable both 3741 01:54:16,800 --> 01:54:17,800 of them so let's go ahead click on both 3742 01:54:18,780 --> 01:54:19,780 and this will restart the editor so okay 3743 01:54:21,360 --> 01:54:22,360 let's go alright the editor has 3744 01:54:23,520 --> 01:54:24,520 restarted so now the new input system is 3745 01:54:25,380 --> 01:54:26,380 now enabled okay so the way that this 3746 01:54:27,900 --> 01:54:28,900 system works is by creating something 3747 01:54:29,580 --> 01:54:30,580 called an input actions asset so on the 3748 01:54:32,340 --> 01:54:33,340 project files let's click on the plus 3749 01:54:33,719 --> 01:54:34,719 icon let's create something and let's 3750 01:54:35,820 --> 01:54:36,820 find the input actions so we need to 3751 01:54:38,460 --> 01:54:39,460 scroll down here so click on the little 3752 01:54:39,840 --> 01:54:40,840 arrow to go down and find the input 3753 01:54:41,460 --> 01:54:42,460 actions creates this file let's call 3754 01:54:43,500 --> 01:54:44,500 this the player input actions 3755 01:54:46,260 --> 01:54:47,260 okay now let's go ahead and double click 3756 01:54:48,179 --> 01:54:49,179 on it and yep there you go out pops out 3757 01:54:50,340 --> 01:54:51,340 the input system window basically this 3758 01:54:52,679 --> 01:54:53,679 one is where we're going to manage all 3759 01:54:54,000 --> 01:54:55,000 of the settings for all of our inputs 3760 01:54:55,619 --> 01:54:56,619 also by the way and like I've mentioned 3761 01:54:57,060 --> 01:54:58,060 if you're watching this in the future 3762 01:54:58,260 --> 01:54:59,260 and for some reason the input system got 3763 01:55:00,360 --> 01:55:01,360 a new update and changed this window if 3764 01:55:02,400 --> 01:55:03,400 so make sure you check the pinned 3765 01:55:03,719 --> 01:55:04,719 comment I'll keep it updated with any 3766 01:55:05,520 --> 01:55:06,520 changes on anything in this course so 3767 01:55:07,679 --> 01:55:08,679 over here we've got the action Maps then 3768 01:55:10,199 --> 01:55:11,199 we've got the actions and then we've got 3769 01:55:12,000 --> 01:55:13,000 properties now action maps are how you 3770 01:55:14,340 --> 01:55:15,340 can have different maps for example one 3771 01:55:16,920 --> 01:55:17,920 action map would be for the player 3772 01:55:18,300 --> 01:55:19,300 whilst walking normally and you could 3773 01:55:19,860 --> 01:55:20,860 have another one whilst driving a 3774 01:55:21,360 --> 01:55:22,360 vehicle then for the individual actions 3775 01:55:23,580 --> 01:55:24,580 in each action map and finally the 3776 01:55:25,800 --> 01:55:26,800 properties for each action again if you 3777 01:55:27,960 --> 01:55:28,960 want to learn about the entire input 3778 01:55:29,280 --> 01:55:30,280 system itself in more detail go ahead 3779 01:55:31,080 --> 01:55:32,080 and watch my dedicated video on it in 3780 01:55:33,060 --> 01:55:34,060 order for this course to not be 20 hours 3781 01:55:34,560 --> 01:55:35,560 long I'm really only going to use enough 3782 01:55:36,239 --> 01:55:37,239 to make sure that we can achieve our 3783 01:55:37,920 --> 01:55:38,920 goal so over here we just need one 3784 01:55:39,780 --> 01:55:40,780 action map so let's click on the plus 3785 01:55:41,159 --> 01:55:42,159 icon let's name this the player and now 3786 01:55:43,920 --> 01:55:44,920 for the actions right away we have a new 3787 01:55:45,659 --> 01:55:46,659 action 3788 01:55:46,500 --> 01:55:47,500 so let's just rename this one let's call 3789 01:55:49,739 --> 01:55:50,739 this action move then with the section 3790 01:55:51,840 --> 01:55:52,840 selected over here on the Action 3791 01:55:53,219 --> 01:55:54,219 Properties we can select the action type 3792 01:55:55,080 --> 01:55:56,080 again in the dedicated video I cover 3793 01:55:57,360 --> 01:55:58,360 what all of these mean 3794 01:55:58,920 --> 01:55:59,920 for movement we do not want a button we 3795 01:56:01,139 --> 01:56:02,139 want movement in multiple directions so 3796 01:56:02,940 --> 01:56:03,940 let's go with value then over here for 3797 01:56:04,860 --> 01:56:05,860 the control type for this one let's go 3798 01:56:06,900 --> 01:56:07,900 with the vector 2 and then let's expand 3799 01:56:09,179 --> 01:56:10,179 our action over here we can see our 3800 01:56:10,560 --> 01:56:11,560 bindings however we don't want this 3801 01:56:12,719 --> 01:56:13,719 default binding so let's actually delete 3802 01:56:14,580 --> 01:56:15,580 this one instead let's click on the plus 3803 01:56:16,380 --> 01:56:17,380 icon and over here for the type first 3804 01:56:18,480 --> 01:56:19,480 for the keyboard and let's go with this 3805 01:56:19,920 --> 01:56:20,920 one up down left right composite 3806 01:56:21,900 --> 01:56:22,900 so this one adds essentially four 3807 01:56:23,699 --> 01:56:24,699 bindings let's go ahead and name this 3808 01:56:25,739 --> 01:56:26,739 was 3809 01:56:27,000 --> 01:56:28,000 then for the up let's select the 3810 01:56:28,619 --> 01:56:29,619 bindings over here on the path let's 3811 01:56:30,000 --> 01:56:31,000 click on it then we can either find it 3812 01:56:32,040 --> 01:56:33,040 manually over here or click on the 3813 01:56:33,600 --> 01:56:34,600 listen and I'll press the W button yep 3814 01:56:35,520 --> 01:56:36,520 there you go W then for down let's go 3815 01:56:37,800 --> 01:56:38,800 ahead and listen s then for the unless 3816 01:56:40,380 --> 01:56:41,380 listen a and for the right let's listen 3817 01:56:43,560 --> 01:56:44,560 d 3818 01:56:44,520 --> 01:56:45,520 okay great so with this our input as it 3819 01:56:47,400 --> 01:56:48,400 is correctly set up one thing you must 3820 01:56:49,679 --> 01:56:50,679 never forget is up here make sure to 3821 01:56:51,540 --> 01:56:52,540 save the asset you can see this little 3822 01:56:53,940 --> 01:56:54,940 asterisk here that means we have unsafe 3823 01:56:55,980 --> 01:56:56,980 changes also alternatively there's an 3824 01:56:58,139 --> 01:56:59,139 auto save there but for now let's just 3825 01:57:00,119 --> 01:57:01,119 manually save the acid okay great 3826 01:57:02,760 --> 01:57:03,760 so now let's see how to actually use 3827 01:57:04,560 --> 01:57:05,560 this in our code there are many ways we 3828 01:57:06,960 --> 01:57:07,960 can use the input system one way is by 3829 01:57:09,540 --> 01:57:10,540 using the built-in player input 3830 01:57:11,040 --> 01:57:12,040 component so for example on the player 3831 01:57:13,080 --> 01:57:14,080 we would add the player input 3832 01:57:15,599 --> 01:57:16,599 so you could add this one attach and 3833 01:57:17,400 --> 01:57:18,400 input actions asset so this is our 3834 01:57:19,080 --> 01:57:20,080 player input actions then over here we 3835 01:57:21,300 --> 01:57:22,300 have various behaviors in order to be 3836 01:57:22,860 --> 01:57:23,860 able to trigger our actions but in this 3837 01:57:24,960 --> 01:57:25,960 course like I said I'm going to be using 3838 01:57:26,580 --> 01:57:27,580 the exact same code quality that I used 3839 01:57:28,139 --> 01:57:29,139 in my own Steam games so I will not be 3840 01:57:30,540 --> 01:57:31,540 using this component so let's remove 3841 01:57:31,860 --> 01:57:32,860 this instead I won't be using the native 3842 01:57:34,380 --> 01:57:35,380 c-sharp method so what's like the player 3843 01:57:36,960 --> 01:57:37,960 input actions and over here on the 3844 01:57:39,060 --> 01:57:40,060 inspector we see this nice toggle to 3845 01:57:40,679 --> 01:57:41,679 generate a c-sharp class 3846 01:57:42,360 --> 01:57:43,360 let's go ahead enable it and for these 3847 01:57:44,820 --> 01:57:45,820 films we can leave them all on defense 3848 01:57:46,320 --> 01:57:47,320 that's okay let's just go ahead click on 3849 01:57:48,000 --> 01:57:49,000 apply 3850 01:57:48,900 --> 01:57:49,900 and now it's going to generate those 3851 01:57:50,340 --> 01:57:51,340 scripts and compound them okay great 3852 01:57:51,960 --> 01:57:52,960 basically what this is doing is auto 3853 01:57:53,820 --> 01:57:54,820 generating some c-sharp code and on the 3854 01:57:56,219 --> 01:57:57,219 employer input actions we can see over 3855 01:57:57,840 --> 01:57:58,840 here yep we've got the generate script 3856 01:57:59,639 --> 01:58:00,639 if you want you can even open this to 3857 01:58:01,800 --> 01:58:02,800 see all of the source code now all this 3858 01:58:04,199 --> 01:58:05,199 like it says here this was all auto 3859 01:58:05,639 --> 01:58:06,639 generated so don't make any 3860 01:58:07,260 --> 01:58:08,260 modifications here 3861 01:58:08,639 --> 01:58:09,639 if you change anything any manual 3862 01:58:10,619 --> 01:58:11,619 changes won't be lost when you save some 3863 01:58:12,300 --> 01:58:13,300 changes in the input asset so if you 3864 01:58:14,340 --> 01:58:15,340 want go ahead and read through in order 3865 01:58:16,139 --> 01:58:17,139 to see how all this works but in order 3866 01:58:18,300 --> 01:58:19,300 to use it sectionally super simple you 3867 01:58:19,860 --> 01:58:20,860 don't need to worry about this script 3868 01:58:21,179 --> 01:58:22,179 first thing we need is to construct our 3869 01:58:23,280 --> 01:58:24,280 script class that was Auto General so 3870 01:58:25,199 --> 01:58:26,199 let's do it over here in our game input 3871 01:58:27,540 --> 01:58:28,540 let's make a product void awake and on 3872 01:58:29,820 --> 01:58:30,820 awake let's construct it 3873 01:58:31,440 --> 01:58:32,440 so let's do a new player input actions 3874 01:58:35,699 --> 01:58:36,699 so we construct an object of this time 3875 01:58:41,760 --> 01:58:42,760 so we have this although just like this 3876 01:58:43,560 --> 01:58:44,560 it won't be active so we need to 3877 01:58:45,179 --> 01:58:46,179 manually activate whatever action map we 3878 01:58:47,280 --> 01:58:48,280 want so let's go inside and let's go 3879 01:58:49,380 --> 01:58:50,380 inside the player so this is the action 3880 01:58:50,699 --> 01:58:51,699 map that we created and let's call 3881 01:58:52,560 --> 01:58:53,560 enable one okay so just like this it's 3882 01:58:55,320 --> 01:58:56,320 really already working all we need to do 3883 01:58:57,420 --> 01:58:58,420 is modify our code over here on the yet 3884 01:58:59,280 --> 01:59:00,280 movement Vector so for that we're going 3885 01:59:01,020 --> 01:59:02,020 to need to access this so let's actually 3886 01:59:02,460 --> 01:59:03,460 make this a member variable so private 3887 01:59:05,280 --> 01:59:06,280 let's store it up here instead of making 3888 01:59:07,500 --> 01:59:08,500 a local variable in here okay 3889 01:59:09,780 --> 01:59:10,780 so we have this one and then down here 3890 01:59:11,820 --> 01:59:12,820 on the input vector 3891 01:59:13,380 --> 01:59:14,380 let's go inside the player input actions 3892 01:59:15,360 --> 01:59:16,360 inside the player action map and then we 3893 01:59:17,280 --> 01:59:18,280 called it move so we've got this one and 3894 01:59:19,619 --> 01:59:20,619 then we defined it as a vector two so 3895 01:59:21,480 --> 01:59:22,480 over here we can call read value and 3896 01:59:23,880 --> 01:59:24,880 this one takes in the type of the value 3897 01:59:25,380 --> 01:59:26,380 now we Define it as a vector two so 3898 01:59:27,300 --> 01:59:28,300 let's read it as a vector two and just 3899 01:59:29,820 --> 01:59:30,820 like this this returns a vector 2 which 3900 01:59:31,980 --> 01:59:32,980 is really going to be our input Vector 3901 01:59:33,540 --> 01:59:34,540 so let's put it exactly like this and we 3902 01:59:36,360 --> 01:59:37,360 can now get rid of the rest of it all 3903 01:59:39,179 --> 01:59:40,179 right so that's it and just like this we 3904 01:59:40,739 --> 01:59:41,739 should already have everything working 3905 01:59:42,179 --> 01:59:43,179 exactly the same as previously 3906 01:59:44,099 --> 01:59:45,099 so let's just do a debug download just 3907 01:59:46,440 --> 01:59:47,440 to make sure so let's test so here we 3908 01:59:49,320 --> 01:59:50,320 are and the output is zero zero now I 3909 01:59:50,940 --> 01:59:51,940 press W there you go plus one minus one 3910 01:59:53,040 --> 01:59:54,040 left right and all of the ones in 3911 01:59:55,139 --> 01:59:56,139 between all right awesome so we have the 3912 01:59:58,320 --> 01:59:59,320 new input system all of it working 3913 01:59:59,820 --> 02:00:00,820 flawlessly also by the way over here we 3914 02:00:02,460 --> 02:00:03,460 can normalize the input just like we 3915 02:00:03,960 --> 02:00:04,960 were doing previously so we do it over 3916 02:00:05,280 --> 02:00:06,280 here through code or alternatively we 3917 02:00:07,500 --> 02:00:08,500 can also go into the player input 3918 02:00:08,760 --> 02:00:09,760 actions and over here there's something 3919 02:00:10,199 --> 02:00:11,199 called a processor so you can go into 3920 02:00:12,480 --> 02:00:13,480 this action add a processor and make it 3921 02:00:14,580 --> 02:00:15,580 normalized so these processes here can 3922 02:00:17,159 --> 02:00:18,159 be quite useful I cover the modeling 3923 02:00:19,380 --> 02:00:20,380 detail in the other dedicated video but 3924 02:00:21,179 --> 02:00:22,179 over here let's stick with making it 3925 02:00:22,440 --> 02:00:23,440 through code that works just as well 3926 02:00:23,760 --> 02:00:24,760 okay so that's our refactoring done with 3927 02:00:26,580 --> 02:00:27,580 that simple change we are now using the 3928 02:00:28,199 --> 02:00:29,199 new input system 3929 02:00:29,460 --> 02:00:30,460 so you can see how by refactoring our 3930 02:00:31,380 --> 02:00:32,380 code to make sure to use the game input 3931 02:00:33,179 --> 02:00:34,179 less when we change from the input 3932 02:00:35,040 --> 02:00:36,040 manager onto the new input system when 3933 02:00:37,139 --> 02:00:38,139 we made that change we did not have to 3934 02:00:38,760 --> 02:00:39,760 touch a player class at all the player 3935 02:00:40,920 --> 02:00:41,920 class just has the game input to get the 3936 02:00:42,780 --> 02:00:43,780 movement vector and does not care what 3937 02:00:44,820 --> 02:00:45,820 system he uses to get them so here we 3938 02:00:47,280 --> 02:00:48,280 have a very practical very excellent 3939 02:00:49,020 --> 02:00:50,020 example of the power of writing good 3940 02:00:50,460 --> 02:00:51,460 clean code because we separated things 3941 02:00:52,440 --> 02:00:53,440 correctly we managed to change something 3942 02:00:53,940 --> 02:00:54,940 completely and not have to make any 3943 02:00:56,040 --> 02:00:57,040 changes on any other class 3944 02:00:57,840 --> 02:00:58,840 so now that we're using the new input 3945 02:00:59,580 --> 02:01:00,580 system let's just quickly see one of the 3946 02:01:01,739 --> 02:01:02,739 main benefits of this system which is 3947 02:01:03,480 --> 02:01:04,480 easily supporting gamepads and more keys 3948 02:01:05,880 --> 02:01:06,880 for example a lot of people like using 3949 02:01:08,040 --> 02:01:09,040 ones but some people also like to use 3950 02:01:09,900 --> 02:01:10,900 the arrow keys with this system that is 3951 02:01:12,300 --> 02:01:13,300 super easy to add so let's go into the 3952 02:01:14,340 --> 02:01:15,340 move what's another one let's add 3953 02:01:15,719 --> 02:01:16,719 another one up down left right composite 3954 02:01:17,460 --> 02:01:18,460 let's call it arrow keys then let's just 3955 02:01:20,699 --> 02:01:21,699 put them so let's listen on the up Arrow 3956 02:01:22,920 --> 02:01:23,920 then over here we've got the down arrow 3957 02:01:26,159 --> 02:01:27,159 then we have the left arrow and finally 3958 02:01:29,520 --> 02:01:30,520 we have the right arrow alright so we've 3959 02:01:31,860 --> 02:01:32,860 got all the arrows and now we don't even 3960 02:01:33,840 --> 02:01:34,840 need to touch any code at all let's just 3961 02:01:35,639 --> 02:01:36,639 make sure to save the ascent which again 3962 02:01:37,500 --> 02:01:38,500 in turn that is going to Auto generate 3963 02:01:39,179 --> 02:01:40,179 the c-sharp class and go into compound 3964 02:01:40,860 --> 02:01:41,860 okay so we don't need to touch any code 3965 02:01:42,840 --> 02:01:43,840 at all let's just hit on play and now if 3966 02:01:45,060 --> 02:01:46,060 I move we're using the ones Keys yep 3967 02:01:47,099 --> 02:01:48,099 still works and if I go into the arrow 3968 02:01:48,719 --> 02:01:49,719 keys yep also still works alright great 3969 02:01:51,540 --> 02:01:52,540 now for another one let's make it for a 3970 02:01:53,820 --> 02:01:54,820 Gamepad so I just connected an Xbox 3971 02:01:56,460 --> 02:01:57,460 controller and we can see over here on 3972 02:01:58,199 --> 02:01:59,199 the log yep the game did identify it so 3973 02:02:00,420 --> 02:02:01,420 this is the new input system in action 3974 02:02:01,980 --> 02:02:02,980 let's once again open up the input 3975 02:02:04,199 --> 02:02:05,199 actions and over here on the Move let's 3976 02:02:06,360 --> 02:02:07,360 add another one and this time let's just 3977 02:02:08,460 --> 02:02:09,460 make it a regular binding and over here 3978 02:02:10,920 --> 02:02:11,920 on the path once again if we want we can 3979 02:02:13,320 --> 02:02:14,320 go down here and specifically find some 3980 02:02:15,119 --> 02:02:16,119 joysticks so you can find any of them or 3981 02:02:17,940 --> 02:02:18,940 once again let's just use in listen now 3982 02:02:20,159 --> 02:02:21,159 I'm just going to move the thumbstick on 3983 02:02:21,540 --> 02:02:22,540 the controller yep there it is I know if 3984 02:02:23,400 --> 02:02:24,400 you wanted you could go specific and 3985 02:02:24,780 --> 02:02:25,780 make it just work with Xbox controllers 3986 02:02:26,460 --> 02:02:27,460 or you can just use the generic left 3987 02:02:28,440 --> 02:02:29,440 stick this will make it work with an 3988 02:02:30,060 --> 02:02:31,060 Xbox controller or a PlayStation or 3989 02:02:31,980 --> 02:02:32,980 really anything so let's go with this 3990 02:02:33,420 --> 02:02:34,420 one and that's it nothing else we need 3991 02:02:35,280 --> 02:02:36,280 to do let's just save the asset and 3992 02:02:37,320 --> 02:02:38,320 that's it we don't need to touch any of 3993 02:02:39,239 --> 02:02:40,239 our code to make our game playable with 3994 02:02:40,920 --> 02:02:41,920 a controller so let's go ahead and test 3995 02:02:43,440 --> 02:02:44,440 so here we are and first of all if I 3996 02:02:45,420 --> 02:02:46,420 move the keys yep song Works move the 3997 02:02:46,980 --> 02:02:47,980 arrow keys yep both of them works and 3998 02:02:48,960 --> 02:02:49,960 now if I use my Gamepad any up there you 3999 02:02:51,000 --> 02:02:52,000 go everything works perfectly alright 4000 02:02:53,219 --> 02:02:54,219 awesome so as you can see this is one of 4001 02:02:55,440 --> 02:02:56,440 the main benefits of the new input 4002 02:02:57,060 --> 02:02:58,060 system it makes handling different 4003 02:02:58,800 --> 02:02:59,800 inputs really super easily as you saw we 4004 02:03:01,739 --> 02:03:02,739 didn't have to touch our code at all we 4005 02:03:03,900 --> 02:03:04,900 just had new bindings and just like that 4006 02:03:05,520 --> 02:03:06,520 our game is playable with all kinds of 4007 02:03:07,500 --> 02:03:08,500 inputs 4008 02:03:08,580 --> 02:03:09,580 so here you can really see just how 4009 02:03:10,380 --> 02:03:11,380 powerful new input system is okay so 4010 02:03:12,659 --> 02:03:13,659 with this our basic character movement 4011 02:03:14,280 --> 02:03:15,280 is working great we can walk around 4012 02:03:15,840 --> 02:03:16,840 everything looks great now in the next 4013 02:03:18,179 --> 02:03:19,179 lecture let's apply some collisions to 4014 02:03:19,920 --> 02:03:20,920 our player 4015 02:03:22,199 --> 02:03:23,199 hey again here's another quick 4016 02:03:23,820 --> 02:03:24,820 intermission I hope you've already 4017 02:03:25,380 --> 02:03:26,380 learned a ton from the course have you 4018 02:03:27,599 --> 02:03:28,599 seen the benefits of writing good clean 4019 02:03:29,040 --> 02:03:30,040 code has the course already helped you 4020 02:03:30,960 --> 02:03:31,960 understand some more advanced concepts I 4021 02:03:33,060 --> 02:03:34,060 really hope the answer is yes to both 4022 02:03:34,440 --> 02:03:35,440 those remember to follow the website 4023 02:03:36,420 --> 02:03:37,420 page as you follow along I won't be 4024 02:03:38,159 --> 02:03:39,159 adding frequently asked questions to 4025 02:03:39,719 --> 02:03:40,719 every lecture if you ever get stuck you 4026 02:03:42,179 --> 02:03:43,179 can just download the project files for 4027 02:03:43,619 --> 02:03:44,619 a lecture and compare with your own and 4028 02:03:45,960 --> 02:03:46,960 definitely check out the related videos 4029 02:03:47,219 --> 02:03:48,219 when I reference them this course is 4030 02:03:49,199 --> 02:03:50,199 focused on making this game but you 4031 02:03:50,699 --> 02:03:51,699 should definitely learn more about some 4032 02:03:52,139 --> 02:03:53,139 of these Concepts in more detail and you 4033 02:03:54,060 --> 02:03:55,060 can learn that in the videos that I 4034 02:03:55,320 --> 02:03:56,320 mentioned by the way if you're watching 4035 02:03:56,940 --> 02:03:57,940 this right now this is the secret con 4036 02:03:59,099 --> 02:04:00,099 loud so go ahead post the time step in 4037 02:04:00,960 --> 02:04:01,960 the comments with a nice monk Emoji I 4038 02:04:02,940 --> 02:04:03,940 want to see how many people make it this 4039 02:04:04,440 --> 02:04:05,440 far okay so that's it for now let's go 4040 02:04:06,900 --> 02:04:07,900 to the next lecture 4041 02:04:08,880 --> 02:04:09,880 hello and welcome I'm your code monkey 4042 02:04:10,860 --> 02:04:11,860 in this lecture we're going to apply 4043 02:04:12,840 --> 02:04:13,840 some collisions to our player movement 4044 02:04:14,400 --> 02:04:15,400 okay so here we have our game so far we 4045 02:04:17,040 --> 02:04:18,040 have our player walking around and 4046 02:04:18,480 --> 02:04:19,480 everything looks pretty good however now 4047 02:04:20,520 --> 02:04:21,520 let's create over here in the hurricane 4048 02:04:22,199 --> 02:04:23,199 let's right click create a brand new 4049 02:04:24,060 --> 02:04:25,060 Cube so there you go let's place it over 4050 02:04:26,639 --> 02:04:27,639 here and push it down okay there's the 4051 02:04:30,179 --> 02:04:31,179 cube make it just a little bit bigger so 4052 02:04:33,179 --> 02:04:34,179 there's the cube and by default it has a 4053 02:04:34,920 --> 02:04:35,920 boxcon leather component so it has 4054 02:04:36,480 --> 02:04:37,480 physics and the player if I move and 4055 02:04:39,000 --> 02:04:40,000 nope there's our issue the player is 4056 02:04:40,560 --> 02:04:41,560 going right through the object now the 4057 02:04:42,540 --> 02:04:43,540 player is not meant to be a ghost so 4058 02:04:44,099 --> 02:04:45,099 let's fix this over here in our player 4059 02:04:46,619 --> 02:04:47,619 script we are hearing the input Vector 4060 02:04:49,080 --> 02:04:50,080 calculating the move Direction and then 4061 02:04:50,760 --> 02:04:51,760 just moving the transform so right now 4062 02:04:52,800 --> 02:04:53,800 we're moving it no matter what now 4063 02:04:54,360 --> 02:04:55,360 before we do that let's first do a test 4064 02:04:56,219 --> 02:04:57,219 to see if any object is in the way and 4065 02:04:58,560 --> 02:04:59,560 how we're going to do that is by firing 4066 02:05:00,179 --> 02:05:01,179 a raycast this one is a physics 4067 02:05:02,460 --> 02:05:03,460 operation that basically fires on laser 4068 02:05:04,380 --> 02:05:05,380 from a certain point towards a certain 4069 02:05:06,000 --> 02:05:07,000 direction and then tells you if it hits 4070 02:05:07,619 --> 02:05:08,619 something how we do that is let's go 4071 02:05:09,840 --> 02:05:10,840 inside the physics class and let's call 4072 02:05:12,060 --> 02:05:13,060 the raycast function 4073 02:05:14,159 --> 02:05:15,159 this one as you can see has many many 4074 02:05:16,260 --> 02:05:17,260 versions of this function with all kinds 4075 02:05:18,000 --> 02:05:19,000 of parameters let's use this one option 4076 02:05:19,980 --> 02:05:20,980 number seven which takes a vector 3 for 4077 02:05:22,139 --> 02:05:23,139 the origin a direction and a max 4078 02:05:23,820 --> 02:05:24,820 distance so first for the origin that is 4079 02:05:26,400 --> 02:05:27,400 from where we want to fire our recast 4080 02:05:28,199 --> 02:05:29,199 let's put the player object in so that's 4081 02:05:30,540 --> 02:05:31,540 transform dot position 4082 02:05:32,639 --> 02:05:33,639 then for the direction this is going to 4083 02:05:34,320 --> 02:05:35,320 be our move Direction so let's use our 4084 02:05:35,880 --> 02:05:36,880 move there and finally for distance 4085 02:05:37,800 --> 02:05:38,800 let's use some kind of player size 4086 02:05:40,260 --> 02:05:41,260 player width something like that 4087 02:05:42,540 --> 02:05:43,540 some lights to find up here a float for 4088 02:05:44,340 --> 02:05:45,340 the player size and put that 0.7 units 4089 02:05:48,900 --> 02:05:49,900 let's try out with the size just like 4090 02:05:50,639 --> 02:05:51,639 this okay so basically this returns a 4091 02:05:52,860 --> 02:05:53,860 Boolean it's going to return true if it 4092 02:05:54,719 --> 02:05:55,719 hits something and funks if nothing is 4093 02:05:56,400 --> 02:05:57,400 in the way so let's just do a bone call 4094 02:05:58,980 --> 02:05:59,980 it can move and basically we can move if 4095 02:06:01,980 --> 02:06:02,980 this raycast doesn't hit anything so we 4096 02:06:03,719 --> 02:06:04,719 can move if this one is false so if the 4097 02:06:05,940 --> 02:06:06,940 raycast is false then can move is going 4098 02:06:07,679 --> 02:06:08,679 to be true 4099 02:06:09,060 --> 02:06:10,060 that's very simple so if we can move 4100 02:06:11,219 --> 02:06:12,219 then we move the transform position 4101 02:06:12,900 --> 02:06:13,900 otherwise we don't okay that's it super 4102 02:06:15,480 --> 02:06:16,480 simple Let's test 4103 02:06:16,920 --> 02:06:17,920 so here we are I can move around and if 4104 02:06:18,719 --> 02:06:19,719 I go towards the cube and nope no longer 4105 02:06:20,580 --> 02:06:21,580 works so I can no longer go inside that 4106 02:06:22,739 --> 02:06:23,739 Cube okay great now in your case if it's 4107 02:06:25,980 --> 02:06:26,980 not working 4108 02:06:27,239 --> 02:06:28,239 first of all make sure that the cube 4109 02:06:29,099 --> 02:06:30,099 make sure it is touching the floor we 4110 02:06:31,199 --> 02:06:32,199 use the transform position as the origin 4111 02:06:33,179 --> 02:06:34,179 which is right on the floor so if the 4112 02:06:35,340 --> 02:06:36,340 box is raised up then you won't be able 4113 02:06:36,840 --> 02:06:37,840 to go through so make sure the cube is 4114 02:06:38,340 --> 02:06:39,340 touching the form also make sure the 4115 02:06:40,020 --> 02:06:41,020 cube has a box on leather component it 4116 02:06:42,420 --> 02:06:43,420 can be any type of calendar but you if 4117 02:06:43,980 --> 02:06:44,980 you made a cube then it should have a 4118 02:06:45,420 --> 02:06:46,420 box layer by default and it should have 4119 02:06:47,340 --> 02:06:48,340 the same shape as the visual 4120 02:06:49,139 --> 02:06:50,139 and also remember that the 2D and the 3D 4121 02:06:51,480 --> 02:06:52,480 physics systems those are completely 4122 02:06:52,920 --> 02:06:53,920 separate they are completely different 4123 02:06:54,480 --> 02:06:55,480 worlds so make sure you're using 3D 4124 02:06:56,820 --> 02:06:57,820 components and not the 2D ones so for 4125 02:06:58,860 --> 02:06:59,860 example if I add boxing weather 2D if I 4126 02:07:01,260 --> 02:07:02,260 add this one then it will not work so 4127 02:07:03,420 --> 02:07:04,420 make sure you're using the 3D and not 4128 02:07:05,099 --> 02:07:06,099 the 2D components same thing over here 4129 02:07:07,139 --> 02:07:08,139 on the script make sure you're using 4130 02:07:08,639 --> 02:07:09,639 physics and not physics 2D also finally 4131 02:07:11,699 --> 02:07:12,699 if you're still having issues make sure 4132 02:07:13,199 --> 02:07:14,199 you check the player position 4133 02:07:14,820 --> 02:07:15,820 again the player should be on a y of 4134 02:07:16,860 --> 02:07:17,860 zero the only thing that might have an 4135 02:07:18,840 --> 02:07:19,840 offset is the player Vision although if 4136 02:07:20,400 --> 02:07:21,400 you're using the same acid me then this 4137 02:07:22,020 --> 02:07:23,020 one should also be on a y of zero so all 4138 02:07:23,820 --> 02:07:24,820 of these on y of zero and then you can 4139 02:07:26,040 --> 02:07:27,040 also check the four by default this one 4140 02:07:28,320 --> 02:07:29,320 has a mesh calendar but if it is exactly 4141 02:07:30,360 --> 02:07:31,360 on yf0 with no rotation then it 4142 02:07:32,219 --> 02:07:33,219 shouldn't cause any issues alternatively 4143 02:07:34,320 --> 02:07:35,320 you can also just disable or remove the 4144 02:07:36,000 --> 02:07:37,000 mesh con leather from before since we're 4145 02:07:37,560 --> 02:07:38,560 not going to need that so with all that 4146 02:07:39,239 --> 02:07:40,239 yep everything works I can move the 4147 02:07:40,679 --> 02:07:41,679 player but I cannot go through solid 4148 02:07:42,179 --> 02:07:43,179 objects alright awesome so it is working 4149 02:07:45,300 --> 02:07:46,300 but for this particular use case a 4150 02:07:47,760 --> 02:07:48,760 recast isn't necessarily the best method 4151 02:07:49,679 --> 02:07:50,679 we should use basically Rick asses like 4152 02:07:52,320 --> 02:07:53,320 I said kind of like a super thin laser 4153 02:07:54,480 --> 02:07:55,480 but as you can see the player visually 4154 02:07:56,460 --> 02:07:57,460 has an actual body shape so the visual 4155 02:07:59,280 --> 02:08:00,280 and logic are using can only in 4156 02:08:00,719 --> 02:08:01,719 different shapes if I go ahead and push 4157 02:08:02,699 --> 02:08:03,699 towards the box you can see it works 4158 02:08:04,320 --> 02:08:05,320 just fine however if the player is a bit 4159 02:08:07,139 --> 02:08:08,139 more off to the side and the center of 4160 02:08:08,880 --> 02:08:09,880 the player right in front of it is not 4161 02:08:10,440 --> 02:08:11,440 the box and I move and yep there you go 4162 02:08:12,239 --> 02:08:13,239 now I am going through the box the 4163 02:08:14,040 --> 02:08:15,040 reason is because the erase accounts 4164 02:08:15,420 --> 02:08:16,420 being fired from the center of the 4165 02:08:16,560 --> 02:08:17,560 player and like I said it's kind of like 4166 02:08:18,719 --> 02:08:19,719 an infinitely thin laser so it has no 4167 02:08:20,880 --> 02:08:21,880 shape so as long as the center of the 4168 02:08:22,800 --> 02:08:23,800 player is not hitting the box and it can 4169 02:08:24,540 --> 02:08:25,540 go through it whereas what we really 4170 02:08:26,699 --> 02:08:27,699 want is for the visual and logic to have 4171 02:08:28,619 --> 02:08:29,619 pretty much the same shape so let's not 4172 02:08:31,139 --> 02:08:32,139 use a raycast over here on the code 4173 02:08:33,239 --> 02:08:34,239 instead of a recast we can use a physics 4174 02:08:35,580 --> 02:08:36,580 query with an actual shape 4175 02:08:37,380 --> 02:08:38,380 there are all kinds of casts you can use 4176 02:08:39,480 --> 02:08:40,480 as you can see all of them with 4177 02:08:41,219 --> 02:08:42,219 different shapes you've got a box cast 4178 02:08:42,599 --> 02:08:43,599 if you want to have a box a capsule if 4179 02:08:44,340 --> 02:08:45,340 you want the capsule or a sphere cast 4180 02:08:45,659 --> 02:08:46,659 all of these were pretty much the exact 4181 02:08:47,880 --> 02:08:48,880 same way except instead of a raycast 4182 02:08:50,040 --> 02:08:51,040 which fires an infinitely thin laser 4183 02:08:51,960 --> 02:08:52,960 these are going to have an actual shape 4184 02:08:53,760 --> 02:08:54,760 and for player controllers for the most 4185 02:08:55,679 --> 02:08:56,679 part you really want to be using a 4186 02:08:57,179 --> 02:08:58,179 capsule cast that's usually the 4187 02:08:58,619 --> 02:08:59,619 generally accepted player shape although 4188 02:09:00,780 --> 02:09:01,780 alternatively a boxcast also can work 4189 02:09:02,400 --> 02:09:03,400 very well in our case let's just go with 4190 02:09:04,380 --> 02:09:05,380 a simple capsule cast this one to define 4191 02:09:06,719 --> 02:09:07,719 a capsule has a 0.1 and a 0.2 by the way 4192 02:09:09,599 --> 02:09:10,599 if you have no idea what is a capsule 4193 02:09:11,159 --> 02:09:12,159 then we can go over here in the 4194 02:09:12,179 --> 02:09:13,179 hurricane let's right click create a 3D 4195 02:09:13,860 --> 02:09:14,860 object let's make it a capsule and there 4196 02:09:15,960 --> 02:09:16,960 you go this is the capsule it's kind of 4197 02:09:17,219 --> 02:09:18,219 like a stretch sphere so it has around 4198 02:09:19,679 --> 02:09:20,679 the top round bottom and then over here 4199 02:09:21,239 --> 02:09:22,239 in the middle it's just a cylinder and 4200 02:09:23,099 --> 02:09:24,099 over here for the raycast takes a 0.1 4201 02:09:25,020 --> 02:09:26,020 and a 0.2 so that is going to be the 4202 02:09:27,239 --> 02:09:28,239 bottom of the capsule and the top of the 4203 02:09:28,800 --> 02:09:29,800 capsule basically with those two points 4204 02:09:30,840 --> 02:09:31,840 we can Define the height of the actual 4205 02:09:32,280 --> 02:09:33,280 capsule okay so let's just get rid of 4206 02:09:34,199 --> 02:09:35,199 this capsule let's just lean it and over 4207 02:09:36,599 --> 02:09:37,599 in the code let's put those now 4.1 it 4208 02:09:39,599 --> 02:09:40,599 is indeed going to be the transformed 4209 02:09:41,219 --> 02:09:42,219 opposition since that is the point at 4210 02:09:42,719 --> 02:09:43,719 the bottom and for the second point 4211 02:09:45,780 --> 02:09:46,780 for this one it's essentially going to 4212 02:09:47,340 --> 02:09:48,340 be the player head so we can take the 4213 02:09:49,619 --> 02:09:50,619 transform dot position so this is the 4214 02:09:51,420 --> 02:09:52,420 bottom and we can essentially just lift 4215 02:09:53,460 --> 02:09:54,460 it up so let's add a vector 3 dot up and 4216 02:09:56,639 --> 02:09:57,639 multiply by some kind of player height 4217 02:09:58,320 --> 02:09:59,320 let's define up here a float for the 4218 02:10:00,780 --> 02:10:01,780 player height 4219 02:10:02,159 --> 02:10:03,159 and I tested it in the editor and the 4220 02:10:04,260 --> 02:10:05,260 player is about T and Stone 4221 02:10:06,179 --> 02:10:07,179 so over here let's go ahead and move it 4222 02:10:07,679 --> 02:10:08,679 up by that much 4223 02:10:09,000 --> 02:10:10,000 okay so next we want the radius so this 4224 02:10:12,119 --> 02:10:13,119 is pretty much the player size that we 4225 02:10:13,560 --> 02:10:14,560 defined previously so let's use the same 4226 02:10:15,300 --> 02:10:16,300 thing 4227 02:10:16,199 --> 02:10:17,199 but as always let's make sure to write 4228 02:10:17,580 --> 02:10:18,580 good clean code since now we are 4229 02:10:19,679 --> 02:10:20,679 referring to a radius let's actually 4230 02:10:21,480 --> 02:10:22,480 rename this to be a bit more clear and 4231 02:10:23,880 --> 02:10:24,880 by the way here's a quick Visual Studio 4232 02:10:25,320 --> 02:10:26,320 tip you can right click on a symbol and 4233 02:10:28,320 --> 02:10:29,320 then you can click on the rename option 4234 02:10:29,940 --> 02:10:30,940 alternatively use a shortcut Ctrl R 4235 02:10:32,040 --> 02:10:33,040 control R if you do that then now you 4236 02:10:34,139 --> 02:10:35,139 can change the name so for example on 4237 02:10:35,639 --> 02:10:36,639 player radius and note how it changes 4238 02:10:37,860 --> 02:10:38,860 every single instance of that variable 4239 02:10:40,020 --> 02:10:41,020 so this renaming feature is extremely 4240 02:10:42,060 --> 02:10:43,060 useful always make sure to rename 4241 02:10:44,099 --> 02:10:45,099 something if you find the name that 4242 02:10:45,360 --> 02:10:46,360 works best Okay so let's rename this to 4243 02:10:47,699 --> 02:10:48,699 play radius then we have Direction so 4244 02:10:50,159 --> 02:10:51,159 that is as usual going to be our move 4245 02:10:51,719 --> 02:10:52,719 Direction 4246 02:10:52,739 --> 02:10:53,739 and then finally we have the move 4247 02:10:54,300 --> 02:10:55,300 distance for that we can use the actual 4248 02:10:56,460 --> 02:10:57,460 move distance so that is going to be the 4249 02:10:58,679 --> 02:10:59,679 movement speed multiplied by time dot 4250 02:11:00,599 --> 02:11:01,599 all the time 4251 02:11:01,739 --> 02:11:02,739 so I just find here a fluid for the move 4252 02:11:03,960 --> 02:11:04,960 distance 4253 02:11:05,880 --> 02:11:06,880 and you should see that just move speed 4254 02:11:07,619 --> 02:11:08,619 time dot Delta time we have the move 4255 02:11:10,560 --> 02:11:11,560 distance and we use it both in here as 4256 02:11:12,420 --> 02:11:13,420 well as down here 4257 02:11:13,860 --> 02:11:14,860 okay so here we have our cancel cast the 4258 02:11:16,800 --> 02:11:17,800 rest logic is exactly the same so if 4259 02:11:18,420 --> 02:11:19,420 this one is false that means it didn't 4260 02:11:19,920 --> 02:11:20,920 hit anything so if it didn't hit 4261 02:11:21,599 --> 02:11:22,599 anything then we can move and then we 4262 02:11:23,340 --> 02:11:24,340 move the transform okay let's test and 4263 02:11:26,159 --> 02:11:27,159 over here now if I go towards the box 4264 02:11:27,719 --> 02:11:28,719 and the Epson works is only the same as 4265 02:11:29,280 --> 02:11:30,280 previously that's great and now if I go 4266 02:11:30,900 --> 02:11:31,900 towards the end and make sure that the 4267 02:11:32,520 --> 02:11:33,520 center is not hitting the box and I try 4268 02:11:34,320 --> 02:11:35,320 to move forward and nope now we no 4269 02:11:36,239 --> 02:11:37,239 longer go inside the cube so even on the 4270 02:11:38,099 --> 02:11:39,099 edges everything still works perfectly 4271 02:11:39,780 --> 02:11:40,780 alright awesome so it works it looks 4272 02:11:43,320 --> 02:11:44,320 good but it also is a little bit janky 4273 02:11:45,599 --> 02:11:46,599 for example let's stretch this cube out 4274 02:11:47,760 --> 02:11:48,760 a little bit so let's put it just on One 4275 02:11:50,880 --> 02:11:51,880 Direction so stretches like this let's 4276 02:11:53,159 --> 02:11:54,159 see now if I move towards it then nope I 4277 02:11:55,800 --> 02:11:56,800 cannot go through it so that is correct 4278 02:11:57,239 --> 02:11:58,239 and if I move left and right yep that's 4279 02:11:59,400 --> 02:12:00,400 also correct that works however if I now 4280 02:12:01,679 --> 02:12:02,679 press W and D at the same time in order 4281 02:12:03,780 --> 02:12:04,780 to move diagonally and nope right now it 4282 02:12:05,940 --> 02:12:06,940 does not move the reason is because the 4283 02:12:07,860 --> 02:12:08,860 diagonal Vector that one is indeed 4284 02:12:09,360 --> 02:12:10,360 hitting the collider but usually in 4285 02:12:11,580 --> 02:12:12,580 games when you move diagonally and you 4286 02:12:13,380 --> 02:12:14,380 cannot move in when Direction then it 4287 02:12:14,880 --> 02:12:15,880 tries to essentially hug the wall and 4288 02:12:16,440 --> 02:12:17,440 move around it so if I press wnd it 4289 02:12:19,199 --> 02:12:20,199 should essentially be moving straight to 4290 02:12:20,520 --> 02:12:21,520 the right so let's solve that so here in 4291 02:12:22,800 --> 02:12:23,800 our code we're making our Capstone cast 4292 02:12:24,300 --> 02:12:25,300 okay that's great then we need to test 4293 02:12:26,520 --> 02:12:27,520 if we cannot move so let's see if we 4294 02:12:29,699 --> 02:12:30,699 cannot move so it can move is false 4295 02:12:33,960 --> 02:12:34,960 if so then that means we cannot move 4296 02:12:36,179 --> 02:12:37,179 towards this direction 4297 02:12:40,020 --> 02:12:41,020 and if we can then essentially we 4298 02:12:41,639 --> 02:12:42,639 basically want to split the movement 4299 02:12:43,260 --> 02:12:44,260 Direction and just move on the X or just 4300 02:12:45,719 --> 02:12:46,719 on the Z so first let's attempt just the 4301 02:12:48,360 --> 02:12:49,360 X movement 4302 02:12:49,739 --> 02:12:50,739 so attempt only X movement let's create 4303 02:12:53,280 --> 02:12:54,280 a new vector 3. 4304 02:12:55,139 --> 02:12:56,139 let's call it move the year X and we 4305 02:12:57,540 --> 02:12:58,540 make a new Vector three let's take in 4306 02:12:59,639 --> 02:13:00,639 the move there dot X then zero on all 4307 02:13:02,280 --> 02:13:03,280 the other so we only want the test 4308 02:13:03,599 --> 02:13:04,599 moving in the X Direction 4309 02:13:05,520 --> 02:13:06,520 and then let's do literally the same 4310 02:13:07,380 --> 02:13:08,380 thing so let's get our can move try to 4311 02:13:10,260 --> 02:13:11,260 move under this direction so let's go 4312 02:13:12,179 --> 02:13:13,179 inside a move there move there on the X 4313 02:13:14,460 --> 02:13:15,460 so we do that capsule cast 4314 02:13:16,679 --> 02:13:17,679 and if we can move then that means we 4315 02:13:19,079 --> 02:13:20,079 can move only on the x-axis 4316 02:13:22,079 --> 02:13:23,079 so can move only on the X 4317 02:13:25,800 --> 02:13:26,800 and if so let's set the move there 4318 02:13:27,360 --> 02:13:28,360 equals the move there X 4319 02:13:30,119 --> 02:13:31,119 so if we can move them down here when we 4320 02:13:31,920 --> 02:13:32,920 use the move there we're going to move 4321 02:13:33,179 --> 02:13:34,179 only on the X 4322 02:13:34,500 --> 02:13:35,500 and if we cannot move 4323 02:13:36,300 --> 02:13:37,300 then that means we cannot move only on 4324 02:13:38,460 --> 02:13:39,460 the X 4325 02:13:39,659 --> 02:13:40,659 and if so then let's attempt only Zed 4326 02:13:42,300 --> 02:13:43,300 movement so over here again let's do the 4327 02:13:44,699 --> 02:13:45,699 exact same thing so let's copy this 4328 02:13:46,560 --> 02:13:47,560 let's just change this one so instead of 4329 02:13:48,840 --> 02:13:49,840 move to your X we've got moved here on 4330 02:13:50,520 --> 02:13:51,520 the Zen so over here we use 0 on the X 0 4331 02:13:53,340 --> 02:13:54,340 and Y and axis we moved here and get the 4332 02:13:55,800 --> 02:13:56,800 Zen then let's use this movement 4333 02:13:58,079 --> 02:13:59,079 Direction over there and finally the 4334 02:14:00,360 --> 02:14:01,360 same thing so if we can move 4335 02:14:03,480 --> 02:14:04,480 then that means we can move only on the 4336 02:14:05,880 --> 02:14:06,880 Zen and let's set the move there equals 4337 02:14:08,340 --> 02:14:09,340 the move there Z 4338 02:14:10,260 --> 02:14:11,260 and if not then we cannot move in any 4339 02:14:13,260 --> 02:14:14,260 direction 4340 02:14:14,820 --> 02:14:15,820 okay so that's it now this might seem a 4341 02:14:17,040 --> 02:14:18,040 bit confusing but it becomes a lot more 4342 02:14:18,420 --> 02:14:19,420 clear When You See It In Action again 4343 02:14:20,340 --> 02:14:21,340 remember the scenario we're trying to 4344 02:14:21,780 --> 02:14:22,780 solve which is when moving diagonally so 4345 02:14:24,000 --> 02:14:25,000 for example when we're moving forwards 4346 02:14:25,560 --> 02:14:26,560 into the right if we do that then let's 4347 02:14:27,719 --> 02:14:28,719 say this one is going to hit something 4348 02:14:28,860 --> 02:14:29,860 so we cannot move so if we are trying to 4349 02:14:31,199 --> 02:14:32,199 move both forwards and to the right then 4350 02:14:33,179 --> 02:14:34,179 we're going to only attempt the X 4351 02:14:34,320 --> 02:14:35,320 movement so we're only going to try 4352 02:14:35,639 --> 02:14:36,639 moving to the right and then we're going 4353 02:14:37,440 --> 02:14:38,440 to see yep going to the right that does 4354 02:14:39,000 --> 02:14:40,000 work so we can move and we're going to 4355 02:14:40,679 --> 02:14:41,679 move just to the right all right so 4356 02:14:42,719 --> 02:14:43,719 let's test and see if all of this is 4357 02:14:44,159 --> 02:14:45,159 working all right so here we are and if 4358 02:14:46,199 --> 02:14:47,199 I move straight to the wall and nope 4359 02:14:47,760 --> 02:14:48,760 there is 11 so I cannot move anymore 4360 02:14:49,199 --> 02:14:50,199 okay great now if I move just left and 4361 02:14:51,780 --> 02:14:52,780 just right and it does work now if I 4362 02:14:53,520 --> 02:14:54,520 press W and then D and if there you go 4363 02:14:55,739 --> 02:14:56,739 now it does hug the wall and continues 4364 02:14:57,960 --> 02:14:58,960 to move same thing if I go on the left 4365 02:15:00,420 --> 02:15:01,420 over here if I press D no I cannot go 4366 02:15:02,400 --> 02:15:03,400 through it now if I press D and S at the 4367 02:15:04,320 --> 02:15:05,320 same time and there you go it hugs the 4368 02:15:05,639 --> 02:15:06,639 wall and moves around so now our 4369 02:15:07,679 --> 02:15:08,679 controller is much more easy much more 4370 02:15:09,840 --> 02:15:10,840 understandable 4371 02:15:11,040 --> 02:15:12,040 okay so this is great now this is one of 4372 02:15:13,500 --> 02:15:14,500 those tiny things that makes your 4373 02:15:14,760 --> 02:15:15,760 character controller feel much more 4374 02:15:16,079 --> 02:15:17,079 responsive so that's great however we 4375 02:15:18,540 --> 02:15:19,540 also do see one more issue right now you 4376 02:15:21,000 --> 02:15:22,000 can see that I'm right next to the wall 4377 02:15:22,619 --> 02:15:23,619 and if I press A and D then look at that 4378 02:15:24,719 --> 02:15:25,719 I'm moving with this spin however now if 4379 02:15:27,239 --> 02:15:28,239 I press wnd look at that now I'm moving 4380 02:15:29,639 --> 02:15:30,639 diagonally and it's actually moving 4381 02:15:31,139 --> 02:15:32,139 slower basically this is the same issue 4382 02:15:33,360 --> 02:15:34,360 that we saw previously where we had to 4383 02:15:34,920 --> 02:15:35,920 normalize the input so we didn't go 4384 02:15:36,599 --> 02:15:37,599 faster in diagonals basically now we 4385 02:15:38,579 --> 02:15:39,579 have the opposite problem since we are 4386 02:15:40,679 --> 02:15:41,679 normalizing the vector we are cutting 4387 02:15:42,300 --> 02:15:43,300 down on the left right vector and with 4388 02:15:44,699 --> 02:15:45,699 that basically if we are moving 4389 02:15:45,900 --> 02:15:46,900 diagonally then we are essentially going 4390 02:15:47,699 --> 02:15:48,699 slower whereas if I stop moving diagonal 4391 02:15:49,860 --> 02:15:50,860 and just move left right it moves at a 4392 02:15:51,300 --> 02:15:52,300 different speed that solution for this 4393 02:15:53,219 --> 02:15:54,219 is really super simple over here in our 4394 02:15:55,679 --> 02:15:56,679 code when we are constructing the move 4395 02:15:57,300 --> 02:15:58,300 to your X and move the ears in when we 4396 02:15:59,159 --> 02:16:00,159 do this very simple let's just normalize 4397 02:16:01,020 --> 02:16:02,020 it so if this one is less than one then 4398 02:16:03,239 --> 02:16:04,239 it won't be going into one so let's 4399 02:16:04,619 --> 02:16:05,619 normalize that one and down okay that's 4400 02:16:07,020 --> 02:16:08,020 it let's test and now from here move 4401 02:16:09,119 --> 02:16:10,119 forward and hug the wall on left right 4402 02:16:10,739 --> 02:16:11,739 yep does work and if I stop moving 4403 02:16:12,540 --> 02:16:13,540 diagonally just going left right yep all 4404 02:16:14,520 --> 02:16:15,520 still works with the exact same speed 4405 02:16:16,500 --> 02:16:17,500 all right awesome okay so that's really 4406 02:16:19,500 --> 02:16:20,500 it as you can see it's super simple to 4407 02:16:21,480 --> 02:16:22,480 add Collision detection to your movement 4408 02:16:23,159 --> 02:16:24,159 scripts you just do a physics query to 4409 02:16:25,380 --> 02:16:26,380 testify our character should move and 4410 02:16:26,880 --> 02:16:27,880 just move it by the way if you want to 4411 02:16:28,739 --> 02:16:29,739 learn more about collisions and physics 4412 02:16:30,420 --> 02:16:31,420 queries there's a bunch of interesting 4413 02:16:32,580 --> 02:16:33,580 videos that you can watch for example 4414 02:16:34,380 --> 02:16:35,380 one is on various methods of finding a 4415 02:16:36,300 --> 02:16:37,300 Target then another one is on various 4416 02:16:38,580 --> 02:16:39,580 methods of handling projectiles and 4417 02:16:40,920 --> 02:16:41,920 finally another one is a very quick 4418 02:16:42,240 --> 02:16:43,240 checklist on why collisions are not 4419 02:16:43,920 --> 02:16:44,920 working basically there's lots of really 4420 02:16:45,960 --> 02:16:46,960 interesting things you can do with 4421 02:16:47,040 --> 02:16:48,040 physics so make sure you understand 4422 02:16:48,240 --> 02:16:49,240 these functions okay so now that we have 4423 02:16:50,820 --> 02:16:51,820 all of this working let's first just 4424 02:16:52,620 --> 02:16:53,620 clean up our scene so over here our 4425 02:16:54,719 --> 02:16:55,719 default Cube we don't want this so let's 4426 02:16:56,340 --> 02:16:57,340 just get rid of this and with this we 4427 02:16:58,559 --> 02:16:59,559 are ready to build our first kitchen 4428 02:17:00,000 --> 02:17:01,000 counter and let's do that in the next 4429 02:17:01,859 --> 02:17:02,859 lecture 4430 02:17:03,420 --> 02:17:04,420 hello and welcome I'm your code monkey 4431 02:17:05,340 --> 02:17:06,340 in this lecture we're going to begin 4432 02:17:07,139 --> 02:17:08,139 building one of our main game mechanics 4433 02:17:09,059 --> 02:17:10,059 we're going to make a kitchen counter 4434 02:17:10,859 --> 02:17:11,859 and handle the logic for the player to 4435 02:17:12,660 --> 02:17:13,660 be able to interact with that counter 4436 02:17:14,519 --> 02:17:15,519 okay so let's begin by making our 4437 02:17:16,559 --> 02:17:17,559 kitchen counter and just like we did 4438 02:17:18,540 --> 02:17:19,540 when we made the player let's first make 4439 02:17:20,340 --> 02:17:21,340 an empty game object and place the 4440 02:17:21,780 --> 02:17:22,780 visual inside of it so let's right click 4441 02:17:23,820 --> 02:17:24,820 on the hierarchy and create an empty 4442 02:17:25,080 --> 02:17:26,080 game object call this the clear counter 4443 02:17:27,300 --> 02:17:28,300 so it's going to be clear on top so we 4444 02:17:28,979 --> 02:17:29,979 can place and pick up objects let's make 4445 02:17:31,500 --> 02:17:32,500 sure to reset our transform so let's put 4446 02:17:33,179 --> 02:17:34,179 it on zero zero zero let's move it just 4447 02:17:35,099 --> 02:17:36,099 a little bit just so it's not exactly on 4448 02:17:36,840 --> 02:17:37,840 top of the player okay now inside let's 4449 02:17:39,300 --> 02:17:40,300 add the visual so let's go inside the 4450 02:17:40,800 --> 02:17:41,800 assets folder and then over here we've 4451 02:17:42,960 --> 02:17:43,960 got the prefabs visuals and inside we've 4452 02:17:44,639 --> 02:17:45,639 got the counters visuals and over here 4453 02:17:46,559 --> 02:17:47,559 let's find the clear counter Vision so 4454 02:17:48,420 --> 02:17:49,420 let's go ahead and drag it inside the 4455 02:17:50,040 --> 02:17:51,040 game object again make sure the 4456 02:17:52,019 --> 02:17:53,019 challenge visual is on zero zero zero 4457 02:17:53,820 --> 02:17:54,820 the unlockable position okay great now 4458 02:17:56,160 --> 02:17:57,160 just like we did in the online lecture 4459 02:17:58,019 --> 02:17:59,019 where we added Collision detection that 4460 02:18:00,120 --> 02:18:01,120 shouldn't already be working by default 4461 02:18:01,439 --> 02:18:02,439 but in order for it to work it needs a 4462 02:18:02,939 --> 02:18:03,939 physics line either however note how the 4463 02:18:05,219 --> 02:18:06,219 vision over here there's no collider and 4464 02:18:07,139 --> 02:18:08,139 inside there's no collider there's only 4465 02:18:08,639 --> 02:18:09,639 visuals again this is the same thing 4466 02:18:10,620 --> 02:18:11,620 that relates to separating logic and 4467 02:18:12,179 --> 02:18:13,179 visuals basically the visual prefab this 4468 02:18:14,700 --> 02:18:15,700 one only has visual components so only 4469 02:18:16,620 --> 02:18:17,620 meshes animations and that sort of thing 4470 02:18:19,019 --> 02:18:20,019 and the main Parent Game object this is 4471 02:18:20,939 --> 02:18:21,939 the one that is going to have all of the 4472 02:18:22,200 --> 02:18:23,200 logic components set means any kind of 4473 02:18:24,599 --> 02:18:25,599 scripts Behavior as well as any 4474 02:18:26,099 --> 02:18:27,099 colliders 4475 02:18:27,300 --> 02:18:28,300 so over here on the parent game object 4476 02:18:29,040 --> 02:18:30,040 let's add new component let's find a box 4477 02:18:31,260 --> 02:18:32,260 Collider again make sure you add a box 4478 02:18:33,840 --> 02:18:34,840 of leather not a boxing leather 2D and I 4479 02:18:36,300 --> 02:18:37,300 chose a boxing Ledges because this is 4480 02:18:37,679 --> 02:18:38,679 the shape that makes most sense for our 4481 02:18:39,179 --> 02:18:40,179 counter and now let's scale the boxing 4482 02:18:41,340 --> 02:18:42,340 leather again that's the boxing ladder 4483 02:18:43,019 --> 02:18:44,019 not the transform so leave that one with 4484 02:18:44,460 --> 02:18:45,460 a scale of one one that's good and over 4485 02:18:46,500 --> 02:18:47,500 here on the box leather for the size 4486 02:18:48,120 --> 02:18:49,120 let's put it up with a size that fits 4487 02:18:50,760 --> 02:18:51,760 the visual so 1.5 1.5 1.5 and finally we 4488 02:18:54,719 --> 02:18:55,719 just need to lift it up a bit over here 4489 02:18:56,880 --> 02:18:57,880 on the scene view you can see those 4490 02:18:58,080 --> 02:18:59,080 little green tiny lines these refer to 4491 02:19:00,599 --> 02:19:01,599 the boxing leather shape so let's lift 4492 02:19:02,939 --> 02:19:03,939 it up by a little bit in order to make 4493 02:19:04,439 --> 02:19:05,439 it perfect let's put it up by 0.5 on the 4494 02:19:06,540 --> 02:19:07,540 Y alright so there you go that one does 4495 02:19:08,519 --> 02:19:09,519 have the perfect shape 4496 02:19:10,139 --> 02:19:11,139 if we test just like this it should 4497 02:19:11,880 --> 02:19:12,880 already be working it's okay so here's 4498 02:19:13,920 --> 02:19:14,920 my player and if I move towards it and 4499 02:19:15,479 --> 02:19:16,479 yep there you go it does work so it is a 4500 02:19:17,399 --> 02:19:18,399 solid object I cannot go through it okay 4501 02:19:19,439 --> 02:19:20,439 great 4502 02:19:20,460 --> 02:19:21,460 let's just visually rotate the calendar 4503 02:19:22,800 --> 02:19:23,800 so let's do that and again for rotation 4504 02:19:24,780 --> 02:19:25,780 let's make sure we rotate the apparent 4505 02:19:26,399 --> 02:19:27,399 game object and not the visual we want 4506 02:19:28,500 --> 02:19:29,500 the visual to be on rotation zero zero 4507 02:19:30,120 --> 02:19:31,120 zero okay great so on the parent game 4508 02:19:31,620 --> 02:19:32,620 object let's just rotate it around by 4509 02:19:33,840 --> 02:19:34,840 the way here's a quick empty tap if you 4510 02:19:35,519 --> 02:19:36,519 want to rotate hold down control and 4511 02:19:37,559 --> 02:19:38,559 then click to rotate and now instead of 4512 02:19:39,660 --> 02:19:40,660 rotating on every angle it goes on a 15 4513 02:19:41,880 --> 02:19:42,880 angle increment so just hold down this 4514 02:19:44,340 --> 02:19:45,340 way you can easily get it to 180 degrees 4515 02:19:46,139 --> 02:19:47,139 so it's just for fun just make it face 4516 02:19:48,120 --> 02:19:49,120 the player okay great so now let's 4517 02:19:50,160 --> 02:19:51,160 interact with this counter and doing 4518 02:19:52,080 --> 02:19:53,080 this is actually super simple 4519 02:19:53,939 --> 02:19:54,939 we already learned how to do a raycast 4520 02:19:55,979 --> 02:19:56,979 to handle collisions and for 4521 02:19:57,420 --> 02:19:58,420 interactions that's exactly the same 4522 02:19:59,040 --> 02:20:00,040 thing 4523 02:19:59,939 --> 02:20:00,939 so let's go into our player script and 4524 02:20:02,399 --> 02:20:03,399 we're going to do a recast to handle 4525 02:20:03,960 --> 02:20:04,960 that 4526 02:20:04,740 --> 02:20:05,740 but before we do let's organize our code 4527 02:20:07,260 --> 02:20:08,260 here let's make a proper function to 4528 02:20:08,760 --> 02:20:09,760 handle our movement 4529 02:20:10,260 --> 02:20:11,260 so let's make it private since this is 4530 02:20:12,060 --> 02:20:13,060 going to be in local function return 4531 02:20:13,920 --> 02:20:14,920 void and call it handle movement 4532 02:20:17,040 --> 02:20:18,040 and then inside let's put all of this 4533 02:20:19,200 --> 02:20:20,200 code so let's copy all this put it in 4534 02:20:21,359 --> 02:20:22,359 there and then on update we simply call 4535 02:20:23,100 --> 02:20:24,100 this function okay great and now let's 4536 02:20:25,859 --> 02:20:26,859 make another function so private void 4537 02:20:27,540 --> 02:20:28,540 let's call it handle interactions 4538 02:20:33,240 --> 02:20:34,240 and we just call this function on our 4539 02:20:35,340 --> 02:20:36,340 update okay great everything is much 4540 02:20:37,800 --> 02:20:38,800 more organized so now here let's do a 4541 02:20:40,380 --> 02:20:41,380 raycast 4542 02:20:41,819 --> 02:20:42,819 so once again go inside physics do a 4543 02:20:44,160 --> 02:20:45,160 raycast 4544 02:20:45,180 --> 02:20:46,180 for the origin let's start on 4545 02:20:46,680 --> 02:20:47,680 transform.position 4546 02:20:48,540 --> 02:20:49,540 for this obviously we want the move 4547 02:20:50,160 --> 02:20:51,160 Direction so an approach would be to 4548 02:20:52,200 --> 02:20:53,200 make this a film variable sorted up here 4549 02:20:54,180 --> 02:20:55,180 so that way we can access it in both 4550 02:20:55,740 --> 02:20:56,740 functions however if you remember how we 4551 02:20:58,200 --> 02:20:59,200 handled the whole issue with the 4552 02:20:59,939 --> 02:21:00,939 diagonals basically we're modifying the 4553 02:21:01,500 --> 02:21:02,500 move Direction so for moving diagonally 4554 02:21:03,899 --> 02:21:04,899 then this one modifies to only move left 4555 02:21:05,760 --> 02:21:06,760 or right we don't want that for the 4556 02:21:07,680 --> 02:21:08,680 interaction we want pretty much the 4557 02:21:09,060 --> 02:21:10,060 exact same one even if it's pointing 4558 02:21:10,500 --> 02:21:11,500 towards a solid object so let's not make 4559 02:21:12,960 --> 02:21:13,960 the same member variable only reuse it 4560 02:21:14,580 --> 02:21:15,580 instead let's just grab it again create 4561 02:21:16,500 --> 02:21:17,500 it again over here so we get it and we 4562 02:21:18,899 --> 02:21:19,899 want this one even if it's pointing 4563 02:21:20,160 --> 02:21:21,160 towards a solid object so let's use this 4564 02:21:21,899 --> 02:21:22,899 as our move Direction 4565 02:21:23,460 --> 02:21:24,460 and now for the distance let's define a 4566 02:21:25,800 --> 02:21:26,800 fixed distance 4567 02:21:27,000 --> 02:21:28,000 so something like two units would work 4568 02:21:29,460 --> 02:21:30,460 and also here's another very important 4569 02:21:31,380 --> 02:21:32,380 lesson with regards to writing good 4570 02:21:32,939 --> 02:21:33,939 clean code so you would think to write 4571 02:21:34,680 --> 02:21:35,680 code like this so let's put the two 4572 02:21:36,300 --> 02:21:37,300 right in here that would work everything 4573 02:21:38,100 --> 02:21:39,100 would work perfectly but then let's say 4574 02:21:40,439 --> 02:21:41,439 you get back to this code after one week 4575 02:21:42,240 --> 02:21:43,240 would you remember what this 2f means 4576 02:21:44,640 --> 02:21:45,640 the answer is probably not you would 4577 02:21:46,560 --> 02:21:47,560 probably very easily forget exactly what 4578 02:21:48,420 --> 02:21:49,420 this means so because of that you should 4579 02:21:50,460 --> 02:21:51,460 never use numbers directly in the code 4580 02:21:52,200 --> 02:21:53,200 like this instead you can either make a 4581 02:21:54,479 --> 02:21:55,479 field appear if you want to make it 4582 02:21:56,040 --> 02:21:57,040 customizable 4583 02:21:57,240 --> 02:21:58,240 or much simpler is actually what we 4584 02:21:59,040 --> 02:22:00,040 already did previously so let's define a 4585 02:22:00,780 --> 02:22:01,780 local variable with a proper name 4586 02:22:03,000 --> 02:22:04,000 so let's define a float and this one is 4587 02:22:05,640 --> 02:22:06,640 going to represent our interact distance 4588 02:22:07,080 --> 02:22:08,080 so let's call it exactly that interact 4589 02:22:08,939 --> 02:22:09,939 with the distance and let's put 2f and 4590 02:22:11,700 --> 02:22:12,700 over here instead of using a number 4591 02:22:13,200 --> 02:22:14,200 let's just use that variable now if we 4592 02:22:15,720 --> 02:22:16,720 were to get back to this code after a 4593 02:22:17,340 --> 02:22:18,340 long time it would be extremely clear 4594 02:22:18,899 --> 02:22:19,899 what this parameter represents 4595 02:22:21,000 --> 02:22:22,000 the technical term for what we did here 4596 02:22:23,040 --> 02:22:24,040 is called Magic numbers and I've also 4597 02:22:24,840 --> 02:22:25,840 covered them in detail in another quick 4598 02:22:26,100 --> 02:22:27,100 video 4599 02:22:26,939 --> 02:22:27,939 but as I always remember very simply 4600 02:22:29,040 --> 02:22:30,040 never use magic numbers 4601 02:22:31,020 --> 02:22:32,020 okay so with this we have our recast 4602 02:22:33,060 --> 02:22:34,060 it's pointing forwards for this distance 4603 02:22:35,000 --> 02:22:36,000 but this is actually not very useful 4604 02:22:37,500 --> 02:22:38,500 because the rickhouse this one only 4605 02:22:39,120 --> 02:22:40,120 returns a bullion so all this tells us 4606 02:22:41,520 --> 02:22:42,520 is if there's something in front or not 4607 02:22:43,319 --> 02:22:44,319 it does not actually get as the actual 4608 02:22:45,720 --> 02:22:46,720 object reference so for that let's use a 4609 02:22:48,300 --> 02:22:49,300 different version of the raycast 4610 02:22:49,560 --> 02:22:50,560 function so as you can see we've got all 4611 02:22:51,479 --> 02:22:52,479 kinds of versions in order to get the 4612 02:22:53,399 --> 02:22:54,399 object reference let's use this version 4613 02:22:55,319 --> 02:22:56,319 right here this one which has an out 4614 02:22:57,479 --> 02:22:58,479 parameter for a raycast hit note the out 4615 02:23:00,180 --> 02:23:01,180 keyword here this is important this 4616 02:23:02,520 --> 02:23:03,520 means that this is an output parameter 4617 02:23:04,200 --> 02:23:05,200 whereas the other parameters those are 4618 02:23:06,240 --> 02:23:07,240 all essentially inputs that you give to 4619 02:23:07,740 --> 02:23:08,740 the function whereas this output this is 4620 02:23:10,080 --> 02:23:11,080 basically a value that the function 4621 02:23:11,220 --> 02:23:12,220 outputs so let's use this so we've got 4622 02:23:13,140 --> 02:23:14,140 the origin we've got Direction then 4623 02:23:15,180 --> 02:23:16,180 we've got the rake asset in order to use 4624 02:23:17,220 --> 02:23:18,220 it we need to make sure to write the out 4625 02:23:18,960 --> 02:23:19,960 keyword here and then also very 4626 02:23:20,700 --> 02:23:21,700 important we need to write the type 4627 02:23:22,620 --> 02:23:23,620 so let's call it break asset and then 4628 02:23:25,319 --> 02:23:26,319 the name so let's call it break asset 4629 02:23:27,960 --> 02:23:28,960 basically what we're doing here is 4630 02:23:29,520 --> 02:23:30,520 essentially defining a variable of this 4631 02:23:31,200 --> 02:23:32,200 type with this name we're defining it 4632 02:23:33,359 --> 02:23:34,359 and giving it to the function 4633 02:23:34,319 --> 02:23:35,319 immediately so we can use it afterwards 4634 02:23:36,060 --> 02:23:37,060 if you don't include the type if you 4635 02:23:37,920 --> 02:23:38,920 just include the name then you get an 4636 02:23:39,300 --> 02:23:40,300 error because this name Rick has said 4637 02:23:41,280 --> 02:23:42,280 this was never defined alternatively you 4638 02:23:43,319 --> 02:23:44,319 can Define it before you pass it in so 4639 02:23:44,700 --> 02:23:45,700 over here you can do recast it recast it 4640 02:23:47,520 --> 02:23:48,520 and just like this it works because you 4641 02:23:49,260 --> 02:23:50,260 are defining it here and using it here 4642 02:23:50,819 --> 02:23:51,819 but in order to make the code a bit more 4643 02:23:52,680 --> 02:23:53,680 compact you can just Define it here in 4644 02:23:54,720 --> 02:23:55,720 the same place where you get it okay so 4645 02:23:56,640 --> 02:23:57,640 let's use this and with this the 4646 02:23:58,380 --> 02:23:59,380 function still returns just a Boolean so 4647 02:24:00,060 --> 02:24:01,060 just hit something or not but then we've 4648 02:24:02,580 --> 02:24:03,580 got the rake asset output this will be 4649 02:24:05,040 --> 02:24:06,040 filmed with data from the Collision if 4650 02:24:06,600 --> 02:24:07,600 we do hit something 4651 02:24:07,979 --> 02:24:08,979 we can inspect this to see what that it 4652 02:24:09,899 --> 02:24:10,899 contains so you can right click on top 4653 02:24:11,580 --> 02:24:12,580 of the type and then go to definition 4654 02:24:13,500 --> 02:24:14,500 and up here we do see the definition for 4655 02:24:16,080 --> 02:24:17,080 the rake acid struct you can see this is 4656 02:24:18,120 --> 02:24:19,120 a structure to get information back from 4657 02:24:19,859 --> 02:24:20,859 a raycast you can inspect this to see 4658 02:24:22,200 --> 02:24:23,200 all of the kinds of things that this one 4659 02:24:23,700 --> 02:24:24,700 returns for example you have a vector 3 4660 02:24:26,040 --> 02:24:27,040 point for the impact point in workspace 4661 02:24:27,899 --> 02:24:28,899 where the ray actually had a collider it 4662 02:24:30,240 --> 02:24:31,240 can get the normal of the surface and so 4663 02:24:31,979 --> 02:24:32,979 on so you can get all kinds of things 4664 02:24:33,479 --> 02:24:34,479 for a use case what we want is to 4665 02:24:35,640 --> 02:24:36,640 identify the object that we hit and for 4666 02:24:37,319 --> 02:24:38,319 that we can use the transform so it's 4667 02:24:39,180 --> 02:24:40,180 going to be the transform of the rigid 4668 02:24:40,740 --> 02:24:41,740 body or the collider that was hit so 4669 02:24:42,720 --> 02:24:43,720 let's just do a quick test if we hit 4670 02:24:44,340 --> 02:24:45,340 something lets you unlock on that object 4671 02:24:45,960 --> 02:24:46,960 so let's do an if so if this one is true 4672 02:24:48,540 --> 02:24:49,540 then that means we hit something so if 4673 02:24:50,640 --> 02:24:51,640 so let's do a debug unlock go inside the 4674 02:24:52,979 --> 02:24:53,979 rake asset and log the transform okay so 4675 02:24:55,560 --> 02:24:56,560 like this we should be able to see on 4676 02:24:56,819 --> 02:24:57,819 the console if we do hit something let's 4677 02:24:58,800 --> 02:24:59,800 also do an ounce just to be able to 4678 02:25:00,780 --> 02:25:01,780 easily see when we hit something so on 4679 02:25:03,240 --> 02:25:04,240 else let's just log an empty Dash and in 4680 02:25:06,300 --> 02:25:07,300 our game in order to make sure that our 4681 02:25:07,620 --> 02:25:08,620 Collision is working that we are 4682 02:25:09,000 --> 02:25:10,000 correctly detecting it let's just 4683 02:25:10,680 --> 02:25:11,680 duplicate this object but before we do 4684 02:25:12,479 --> 02:25:13,479 let's make this a proper prefab if you 4685 02:25:14,760 --> 02:25:15,760 have an object of a certain tab that you 4686 02:25:16,200 --> 02:25:17,200 want to create multiple instances of it 4687 02:25:17,819 --> 02:25:18,819 you should be using a prefab rather than 4688 02:25:19,620 --> 02:25:20,620 just duplicate an object that way with 4689 02:25:21,300 --> 02:25:22,300 the prefab if you make any changes to 4690 02:25:22,920 --> 02:25:23,920 that prefab it applies to all of the 4691 02:25:24,720 --> 02:25:25,720 copies of that prefab 4692 02:25:26,520 --> 02:25:27,520 so let's first make this one a prefab 4693 02:25:28,380 --> 02:25:29,380 and again since this is our first prefab 4694 02:25:30,359 --> 02:25:31,359 let's first make a nice folder to keep 4695 02:25:32,100 --> 02:25:33,100 things organized so folder for our 4696 02:25:34,140 --> 02:25:35,140 prefabs and to make game module prefab 4697 02:25:36,780 --> 02:25:37,780 is super simple you just click and drag 4698 02:25:38,399 --> 02:25:39,399 directly from the hierarchy and drop it 4699 02:25:40,080 --> 02:25:41,080 inside the folder there you go there's 4700 02:25:41,580 --> 02:25:42,580 our prefront and now let's just 4701 02:25:43,439 --> 02:25:44,439 duplicate this make sure it has a 4702 02:25:45,000 --> 02:25:46,000 different name so it has one so that's 4703 02:25:46,319 --> 02:25:47,319 enough with this we should be able to 4704 02:25:48,300 --> 02:25:49,300 see it just for testing let's put it 4705 02:25:49,859 --> 02:25:50,859 just off to the side okay so let's see 4706 02:25:51,600 --> 02:25:52,600 so here we are in the console we see a 4707 02:25:53,340 --> 02:25:54,340 dash so by default we are not hitting 4708 02:25:54,960 --> 02:25:55,960 anything okay so that makes sense now if 4709 02:25:57,240 --> 02:25:58,240 I move towards this object and if there 4710 02:25:58,979 --> 02:25:59,979 you go it does I didn't find that object 4711 02:26:00,479 --> 02:26:01,479 and if I stop moving it stops 4712 02:26:02,340 --> 02:26:03,340 identifying okay great now if I move 4713 02:26:03,899 --> 02:26:04,899 towards this one and if there we go this 4714 02:26:05,700 --> 02:26:06,700 is the one with the name of one and this 4715 02:26:07,200 --> 02:26:08,200 is the one with the name of none all 4716 02:26:08,939 --> 02:26:09,939 right awesome so just like this we are 4717 02:26:10,920 --> 02:26:11,920 correctly identifying what object is in 4718 02:26:12,780 --> 02:26:13,780 front except we also have an issue so if 4719 02:26:16,140 --> 02:26:17,140 I move towards the object then yep it 4720 02:26:17,640 --> 02:26:18,640 does work but if I stop moving once I'm 4721 02:26:19,740 --> 02:26:20,740 still facing that object right now it's 4722 02:26:21,479 --> 02:26:22,479 returning none now the reason for that 4723 02:26:23,220 --> 02:26:24,220 is because of the move data that we're 4724 02:26:24,600 --> 02:26:25,600 using here if we're not moving in any 4725 02:26:26,700 --> 02:26:27,700 direction then basically this Vector 4726 02:26:28,140 --> 02:26:29,140 won't be zero zero zero so we're going 4727 02:26:30,180 --> 02:26:31,180 to be firing a raycast towards no 4728 02:26:31,740 --> 02:26:32,740 direction at all so obviously it's not 4729 02:26:33,300 --> 02:26:34,300 going to hit anything the solution to 4730 02:26:35,399 --> 02:26:36,399 that is super simple we just need to 4731 02:26:37,080 --> 02:26:38,080 keep track of the last interact move 4732 02:26:38,640 --> 02:26:39,640 Direction so let's go up here to find a 4733 02:26:40,859 --> 02:26:41,859 film for that so let's make a private 4734 02:26:42,660 --> 02:26:43,660 let's make a vector 3 and call it the 4735 02:26:45,060 --> 02:26:46,060 last interact Direction 4736 02:26:47,280 --> 02:26:48,280 and then down here when we have our 4737 02:26:48,899 --> 02:26:49,899 handle interaction so we get the 4738 02:26:50,100 --> 02:26:51,100 movement here okay that's great so then 4739 02:26:52,080 --> 02:26:53,080 we just check if the move direction is 4740 02:26:54,660 --> 02:26:55,660 different from Vector 3.0 by the way 4741 02:26:57,420 --> 02:26:58,420 this is a constant a shorthand for zero 4742 02:26:59,460 --> 02:27:00,460 zero zero so if it is not zero then that 4743 02:27:01,500 --> 02:27:02,500 means we are moving in some Direction 4744 02:27:05,819 --> 02:27:06,819 so so let's set the unless in direct 4745 02:27:07,500 --> 02:27:08,500 direction to this move Direction and 4746 02:27:09,540 --> 02:27:10,540 basically if it is not if move there is 4747 02:27:11,220 --> 02:27:12,220 zero then we are not going to modify 4748 02:27:12,660 --> 02:27:13,660 this so this one is only going to 4749 02:27:14,100 --> 02:27:15,100 contain the unless interact Direction 4750 02:27:15,540 --> 02:27:16,540 and then down here instead of using the 4751 02:27:17,340 --> 02:27:18,340 move Direction Let's just use this one 4752 02:27:18,960 --> 02:27:19,960 so that way even when we stop moving we 4753 02:27:21,180 --> 02:27:22,180 are still going to be using the last 4754 02:27:22,500 --> 02:27:23,500 indirect Direction okay so with this 4755 02:27:24,479 --> 02:27:25,479 let's test so here we are and if I move 4756 02:27:26,700 --> 02:27:27,700 towards it yep it works and if I stop 4757 02:27:28,439 --> 02:27:29,439 moving and yep it still works alright 4758 02:27:30,899 --> 02:27:31,899 great so we can move towards it Point 4759 02:27:32,399 --> 02:27:33,399 towards a certain object and then yep it 4760 02:27:34,740 --> 02:27:35,740 still works okay great now let's 4761 02:27:37,140 --> 02:27:38,140 actually interact with this counter and 4762 02:27:39,359 --> 02:27:40,359 to do that let's make a class for the 4763 02:27:41,040 --> 02:27:42,040 counters itself so let's make a new 4764 02:27:43,140 --> 02:27:44,140 script in the UC sharp script let's come 4765 02:27:45,120 --> 02:27:46,120 with the same name so clear counter 4766 02:27:49,140 --> 02:27:50,140 okay there's our script 4767 02:27:50,939 --> 02:27:51,939 now very importantly for attaching the 4768 02:27:53,580 --> 02:27:54,580 script remember that we have two 4769 02:27:55,680 --> 02:27:56,680 instances of our prefab if you just 4770 02:27:58,200 --> 02:27:59,200 select it in the heart key and you just 4771 02:27:59,939 --> 02:28:00,939 drag it on there if you do that then 4772 02:28:01,979 --> 02:28:02,979 you're not actually adding this script 4773 02:28:03,600 --> 02:28:04,600 to the prefab itself you're only adding 4774 02:28:05,640 --> 02:28:06,640 it to this specific instance of that 4775 02:28:07,319 --> 02:28:08,319 prefab so if you look at this one yep it 4776 02:28:09,420 --> 02:28:10,420 has a script but this other one which is 4777 02:28:11,160 --> 02:28:12,160 a copy of the same prefab this one does 4778 02:28:12,780 --> 02:28:13,780 not have it also over here on the 4779 02:28:14,520 --> 02:28:15,520 inspector you can see the little script 4780 02:28:16,260 --> 02:28:17,260 icon has a nice little plus that means 4781 02:28:18,780 --> 02:28:19,780 it is something that you are adding on 4782 02:28:20,220 --> 02:28:21,220 top of the prefab so that means this 4783 02:28:22,020 --> 02:28:23,020 script is not present on the base prefab 4784 02:28:23,880 --> 02:28:24,880 basically this is not what we want we 4785 02:28:26,220 --> 02:28:27,220 don't want just this object to have this 4786 02:28:28,380 --> 02:28:29,380 script we want all instances of this 4787 02:28:30,600 --> 02:28:31,600 prefab to have this script so instead 4788 02:28:32,760 --> 02:28:33,760 let's get rid of this one from here we 4789 02:28:35,040 --> 02:28:36,040 want to modify the prefab itself so one 4790 02:28:37,500 --> 02:28:38,500 way to do that is to select the prefab 4791 02:28:39,120 --> 02:28:40,120 on the project window so here it is the 4792 02:28:40,740 --> 02:28:41,740 actual prefab and now we can drag the 4793 02:28:43,020 --> 02:28:44,020 script on there so that works or another 4794 02:28:45,300 --> 02:28:46,300 alternative is something like the prefab 4795 02:28:47,100 --> 02:28:48,100 in the hierarchy and on the inspector 4796 02:28:49,800 --> 02:28:50,800 over here we see a nice button to open 4797 02:28:51,240 --> 02:28:52,240 the prefab and if we actually go into 4798 02:28:53,160 --> 02:28:54,160 scene view then we can see what that 4799 02:28:54,660 --> 02:28:55,660 does so with the object selected so this 4800 02:28:56,819 --> 02:28:57,819 is an instance of that prefab but if we 4801 02:28:58,859 --> 02:28:59,859 click on open then essentially we are 4802 02:29:00,359 --> 02:29:01,359 opening and we are working inside the 4803 02:29:01,859 --> 02:29:02,859 prefab so now if we make sure to add our 4804 02:29:04,260 --> 02:29:05,260 script and let's go back outside this 4805 02:29:06,359 --> 02:29:07,359 prefab so on the top left corner over 4806 02:29:08,340 --> 02:29:09,340 here we can see where we are so we were 4807 02:29:10,200 --> 02:29:11,200 inside our scene and then we are inside 4808 02:29:11,819 --> 02:29:12,819 the clear counter prefab so if we click 4809 02:29:14,340 --> 02:29:15,340 on the scenes we can go back now it 4810 02:29:16,080 --> 02:29:17,080 tells us that we made some changes to 4811 02:29:17,399 --> 02:29:18,399 the prefab so let's save them and if we 4812 02:29:19,740 --> 02:29:20,740 add that script and we can see both 4813 02:29:21,120 --> 02:29:22,120 instances of the prefab they both have 4814 02:29:22,920 --> 02:29:23,920 the same script and we can see on there 4815 02:29:24,660 --> 02:29:25,660 on the icon that this is not an override 4816 02:29:26,640 --> 02:29:27,640 this is an actual script at on the base 4817 02:29:28,620 --> 02:29:29,620 prefab so whenever working with prefabs 4818 02:29:30,899 --> 02:29:31,899 always make very sure that you are 4819 02:29:32,280 --> 02:29:33,280 adding it on the right place 4820 02:29:33,960 --> 02:29:34,960 if you want something on the base prefab 4821 02:29:35,760 --> 02:29:36,760 make sure you either add it on the 4822 02:29:37,140 --> 02:29:38,140 prefab itself or go inside the prefab by 4823 02:29:39,540 --> 02:29:40,540 double clicking on it or select an 4824 02:29:41,340 --> 02:29:42,340 instance in there and open to go inside 4825 02:29:42,960 --> 02:29:43,960 the prefab so always keep in mind 4826 02:29:44,399 --> 02:29:45,399 different switches between a prefab and 4827 02:29:46,380 --> 02:29:47,380 an instance of a prefab okay so we have 4828 02:29:48,600 --> 02:29:49,600 our script let's open it and over here 4829 02:29:50,700 --> 02:29:51,700 let's just make one super simple 4830 02:29:52,319 --> 02:29:53,319 function 4831 02:29:53,340 --> 02:29:54,340 so let's make it public because we want 4832 02:29:55,260 --> 02:29:56,260 to call this from our player class let's 4833 02:29:57,300 --> 02:29:58,300 return void and just call it interact 4834 02:30:00,899 --> 02:30:01,899 okay that's it super simple for now 4835 02:30:02,880 --> 02:30:03,880 let's just do a debug.log and just say 4836 02:30:05,160 --> 02:30:06,160 interact 4837 02:30:06,180 --> 02:30:07,180 okay so that's it and now over here on 4838 02:30:08,640 --> 02:30:09,640 the player when we have our handle 4839 02:30:10,319 --> 02:30:11,319 interactions function so interact we do 4840 02:30:12,540 --> 02:30:13,540 our raycast and we find out if we hit 4841 02:30:14,220 --> 02:30:15,220 something so when we do the first thing 4842 02:30:16,380 --> 02:30:17,380 that we should do is identify what this 4843 02:30:18,240 --> 02:30:19,240 transform is so is this something just 4844 02:30:20,340 --> 02:30:21,340 like a dumb Cube or is it an actual 4845 02:30:22,740 --> 02:30:23,740 counter now when it comes to identifying 4846 02:30:24,899 --> 02:30:25,899 things this is another place where a lot 4847 02:30:26,819 --> 02:30:27,819 of beginner tutorials will teach you to 4848 02:30:28,380 --> 02:30:29,380 use the unity attack system so that's 4849 02:30:30,660 --> 02:30:31,660 over here in the editor when you select 4850 02:30:32,220 --> 02:30:33,220 any object over here in the inspector 4851 02:30:34,260 --> 02:30:35,260 you can see a tag so you can see 4852 02:30:35,340 --> 02:30:36,340 untagged and you can add all kinds of 4853 02:30:36,960 --> 02:30:37,960 tags this is something that a lot of 4854 02:30:38,880 --> 02:30:39,880 beginner tutorials teach but Unity tags 4855 02:30:41,460 --> 02:30:42,460 are horrible you should never never use 4856 02:30:43,380 --> 02:30:44,380 them I covered in more detail why that 4857 02:30:45,600 --> 02:30:46,600 is in the advanced concepts video the 4858 02:30:48,060 --> 02:30:49,060 main reason is because of well pretty 4859 02:30:49,740 --> 02:30:50,740 much the same thing that I mentioned a 4860 02:30:51,000 --> 02:30:52,000 while ago when we were handling animator 4861 02:30:52,740 --> 02:30:53,740 parameters so you were doing this and I 4862 02:30:54,840 --> 02:30:55,840 talked about how this one takes a string 4863 02:30:56,520 --> 02:30:57,520 and how strings are horrible way for 4864 02:30:58,260 --> 02:30:59,260 identifying objects they are very 4865 02:31:00,359 --> 02:31:01,359 brittle very error prone it's very easy 4866 02:31:02,220 --> 02:31:03,220 to make mistakes and tags have the exact 4867 02:31:04,319 --> 02:31:05,319 same problems because tags are strings 4868 02:31:06,359 --> 02:31:07,359 so we do not want to use tags to 4869 02:31:08,520 --> 02:31:09,520 identify objects instead over here on 4870 02:31:10,740 --> 02:31:11,740 the player script let's use a different 4871 02:31:12,000 --> 02:31:13,000 method for identifying objects and the 4872 02:31:14,160 --> 02:31:15,160 best way to do that is to Simply get our 4873 02:31:15,899 --> 02:31:16,899 counter component 4874 02:31:17,399 --> 02:31:18,399 so we have our transform and then from 4875 02:31:19,800 --> 02:31:20,800 inside that transform we can call the 4876 02:31:21,420 --> 02:31:22,420 function try get component this one then 4877 02:31:24,060 --> 02:31:25,060 takes the type of component and again 4878 02:31:26,160 --> 02:31:27,160 note how this is an out parameter so 4879 02:31:28,439 --> 02:31:29,439 let's put out and we want to test if 4880 02:31:30,240 --> 02:31:31,240 this is a type clear counter so clear 4881 02:31:32,040 --> 02:31:33,040 counter and call it clear counter 4882 02:31:34,740 --> 02:31:35,740 and this one basically does the same 4883 02:31:36,359 --> 02:31:37,359 thing as a recast so it returns a 4884 02:31:38,100 --> 02:31:39,100 Boolean so either true or false 4885 02:31:40,020 --> 02:31:41,020 so if this one is true then that means 4886 02:31:42,240 --> 02:31:43,240 that object has that component so over 4887 02:31:44,399 --> 02:31:45,399 here we know has clear counter 4888 02:31:47,580 --> 02:31:48,580 by the way if you're not familiar with 4889 02:31:49,080 --> 02:31:50,080 tryget component this is pretty much the 4890 02:31:50,880 --> 02:31:51,880 same thing as the regular get component 4891 02:31:52,800 --> 02:31:53,800 except it automatically handles the null 4892 02:31:54,780 --> 02:31:55,780 check for you 4893 02:31:55,859 --> 02:31:56,859 so if we just did this it's exactly the 4894 02:31:57,840 --> 02:31:58,840 same thing as this so you do an if 4895 02:32:00,300 --> 02:32:01,300 recast it what's X is a transform get 4896 02:32:02,819 --> 02:32:03,819 component 4897 02:32:06,600 --> 02:32:07,600 component of type clear counter 4898 02:32:10,920 --> 02:32:11,920 naturally this one is not inside now but 4899 02:32:12,960 --> 02:32:13,960 let's store this 4900 02:32:14,640 --> 02:32:15,640 well your counter equals this then you 4901 02:32:16,680 --> 02:32:17,680 do if this one is not known 4902 02:32:19,020 --> 02:32:20,020 then we know has a clear counter 4903 02:32:22,439 --> 02:32:23,439 so basically what we have up here is the 4904 02:32:24,300 --> 02:32:25,300 exact same thing that we have down here 4905 02:32:25,560 --> 02:32:26,560 so just using trigate component it's 4906 02:32:27,359 --> 02:32:28,359 just a bit more Compact and I find much 4907 02:32:29,160 --> 02:32:30,160 easier to read than to always get 4908 02:32:30,960 --> 02:32:31,960 component and test if it is not null 4909 02:32:32,580 --> 02:32:33,580 over here we just have one function with 4910 02:32:34,500 --> 02:32:35,500 a nice out parameter and everything 4911 02:32:35,640 --> 02:32:36,640 works perfectly so that's the try get 4912 02:32:37,680 --> 02:32:38,680 component I much prefer that method so 4913 02:32:39,180 --> 02:32:40,180 let's use that by the way on the trackit 4914 02:32:41,399 --> 02:32:42,399 component over here you can see it has a 4915 02:32:43,080 --> 02:32:44,080 type inside some angle brackets 4916 02:32:44,819 --> 02:32:45,819 basically these are called c-sharp 4917 02:32:46,859 --> 02:32:47,859 generics these are an extremely powerful 4918 02:32:49,200 --> 02:32:50,200 c-sharp tool I have a dedicated video on 4919 02:32:51,899 --> 02:32:52,899 them and I've used them in tons of 4920 02:32:53,340 --> 02:32:54,340 videos definitely go ahead and learn 4921 02:32:54,899 --> 02:32:55,899 about them basically this lets you write 4922 02:32:57,060 --> 02:32:58,060 code that works with many classes not 4923 02:32:58,859 --> 02:32:59,859 just one specific type in this case the 4924 02:33:00,899 --> 02:33:01,899 target component can work with any type 4925 02:33:02,760 --> 02:33:03,760 of component 4926 02:33:03,960 --> 02:33:04,960 so it can be Unity built-in components 4927 02:33:05,939 --> 02:33:06,939 or it can be components that you made 4928 02:33:07,200 --> 02:33:08,200 yourself then if it finds a type it 4929 02:33:09,120 --> 02:33:10,120 returns true so for right now it's not 4930 02:33:11,520 --> 02:33:12,520 strictly necessary to know the specifics 4931 02:33:13,859 --> 02:33:14,859 about how c-sharp generics work but 4932 02:33:16,020 --> 02:33:17,020 definitely make sure you add that video 4933 02:33:17,340 --> 02:33:18,340 to your queue and watch it afterwards 4934 02:33:18,899 --> 02:33:19,899 c-sharp generics are an extremely useful 4935 02:33:20,880 --> 02:33:21,880 c-sharp feature okay so we do this and 4936 02:33:23,100 --> 02:33:24,100 basically if we are inside of here then 4937 02:33:24,600 --> 02:33:25,600 we know this object has a clear counter 4938 02:33:26,580 --> 02:33:27,580 and we have our clear counter reference 4939 02:33:28,140 --> 02:33:29,140 so over here it's super simple let's 4940 02:33:29,819 --> 02:33:30,819 just call the interact function 4941 02:33:32,040 --> 02:33:33,040 alright so that's really it let's just 4942 02:33:34,080 --> 02:33:35,080 get ready else we no longer want that 4943 02:33:35,520 --> 02:33:36,520 log so we should be able to see unlock 4944 02:33:36,960 --> 02:33:37,960 whenever we call our interact in a 4945 02:33:38,939 --> 02:33:39,939 counter alright so here we are and if I 4946 02:33:41,220 --> 02:33:42,220 move around okay that's good over here 4947 02:33:42,840 --> 02:33:43,840 the console is empty all right now if I 4948 02:33:44,760 --> 02:33:45,760 move towards the counter if there you go 4949 02:33:46,080 --> 02:33:47,080 I'm interacting with it and if I move 4950 02:33:47,580 --> 02:33:48,580 towards this one if there you go 4951 02:33:48,780 --> 02:33:49,780 interacting all right great so with this 4952 02:33:50,760 --> 02:33:51,760 we are correctly identifying the object 4953 02:33:52,680 --> 02:33:53,680 and interacting with it now let's just 4954 02:33:54,899 --> 02:33:55,899 do one final thing over here we are 4955 02:33:57,180 --> 02:33:58,180 doing a recast to find the counter 4956 02:33:59,640 --> 02:34:00,640 and right now we are doing a raycast 4957 02:34:01,560 --> 02:34:02,560 towards any object that has any kind of 4958 02:34:03,840 --> 02:34:04,840 physics calendar 4959 02:34:05,040 --> 02:34:06,040 so maybe that's our counter or maybe 4960 02:34:06,600 --> 02:34:07,600 just a random wall for example if we had 4961 02:34:09,359 --> 02:34:10,359 an invisible wall in front of our 4962 02:34:11,040 --> 02:34:12,040 counter then this code would not work 4963 02:34:13,080 --> 02:34:14,080 that's because this raycast and this 4964 02:34:14,819 --> 02:34:15,819 raycast set it only Returns the very 4965 02:34:17,220 --> 02:34:18,220 first object that it does hit so if the 4966 02:34:19,260 --> 02:34:20,260 counter was behind the wall then the 4967 02:34:20,819 --> 02:34:21,819 brake acid object here would be a 4968 02:34:22,439 --> 02:34:23,439 reference to that long object perhaps 4969 02:34:24,479 --> 02:34:25,479 that's what you want or perhaps not in 4970 02:34:26,580 --> 02:34:27,580 that scenario one thing you can do is 4971 02:34:28,080 --> 02:34:29,080 instead of using recast you can use the 4972 02:34:30,060 --> 02:34:31,060 function raycast all 4973 02:34:32,220 --> 02:34:33,220 and difference for this one is instead 4974 02:34:33,840 --> 02:34:34,840 of returning just a Boeing just true or 4975 02:34:35,580 --> 02:34:36,580 false instead it returns an array of all 4976 02:34:37,620 --> 02:34:38,620 of the objects that it hit with that 4977 02:34:39,240 --> 02:34:40,240 raycast then you could cycle through 4978 02:34:40,979 --> 02:34:41,979 them and identify the object so that's 4979 02:34:43,319 --> 02:34:44,319 one approach or another option is over 4980 02:34:45,720 --> 02:34:46,720 here on the recast 4981 02:34:47,399 --> 02:34:48,399 if we look at these function versions We 4982 02:34:50,220 --> 02:34:51,220 can see that some of them has what it's 4983 02:34:51,899 --> 02:34:52,899 called a layer mask basically you can 4984 02:34:54,240 --> 02:34:55,240 set a certain game object to a specific 4985 02:34:56,399 --> 02:34:57,399 layer and then if you're using layer 4986 02:34:58,500 --> 02:34:59,500 mask then you can make sure this recast 4987 02:35:00,060 --> 02:35:01,060 will only hit objects within that layer 4988 02:35:01,979 --> 02:35:02,979 anything not on that layer will be 4989 02:35:04,140 --> 02:35:05,140 ignored for that recast this is super 4990 02:35:06,300 --> 02:35:07,300 useful so let's learn how it works for 4991 02:35:08,520 --> 02:35:09,520 layer mask we can go up here and Define 4992 02:35:10,620 --> 02:35:11,620 a type of layer mask so let's make 4993 02:35:12,780 --> 02:35:13,780 another serialized field private let's 4994 02:35:15,120 --> 02:35:16,120 make it of type layer mask let's call it 4995 02:35:17,520 --> 02:35:18,520 the counters layer mask 4996 02:35:20,580 --> 02:35:21,580 okay so we have this and then down here 4997 02:35:22,560 --> 02:35:23,560 when we have our recast let's use it so 4998 02:35:25,439 --> 02:35:26,439 let's find the function that matches up 4999 02:35:27,180 --> 02:35:28,180 these parameters with the layer mask so 5000 02:35:29,640 --> 02:35:30,640 here it is we have the origin then we 5001 02:35:31,920 --> 02:35:32,920 have Direction Drake acid the max 5002 02:35:33,540 --> 02:35:34,540 distance and then finally we have our 5003 02:35:35,700 --> 02:35:36,700 layer mask and let's use our counters 5004 02:35:37,080 --> 02:35:38,080 layer mask okay great now back in the 5005 02:35:39,540 --> 02:35:40,540 editor let's select our player game 5006 02:35:41,880 --> 02:35:42,880 object and yep there we see our field of 5007 02:35:43,920 --> 02:35:44,920 type layer mask and you can see how we 5008 02:35:45,960 --> 02:35:46,960 can select all kinds of layers and how 5009 02:35:48,060 --> 02:35:49,060 we set these layers to an object is 5010 02:35:49,560 --> 02:35:50,560 let's just select our clear counter 5011 02:35:51,780 --> 02:35:52,780 although again we want to make sure that 5012 02:35:53,819 --> 02:35:54,819 this change applies to all encounters 5013 02:35:55,859 --> 02:35:56,859 not just this one specific instance so 5014 02:35:57,720 --> 02:35:58,720 let's go inside the prefab and over here 5015 02:35:59,880 --> 02:36:00,880 we've got a Film Forum layer and you can 5016 02:36:02,040 --> 02:36:03,040 see we've got a bunch of default layers 5017 02:36:03,420 --> 02:36:04,420 and then we can add some more so let's 5018 02:36:05,100 --> 02:36:06,100 add some layers and over here let's go 5019 02:36:07,080 --> 02:36:08,080 to the first empty one and let's call it 5020 02:36:09,120 --> 02:36:10,120 counters okay we've added the layers so 5021 02:36:11,280 --> 02:36:12,280 let's go back select our object and now 5022 02:36:13,560 --> 02:36:14,560 on the layer let's put it on the 5023 02:36:14,819 --> 02:36:15,819 counters now it asks you if you want to 5024 02:36:16,979 --> 02:36:17,979 modify the layer for all Channel objects 5025 02:36:18,720 --> 02:36:19,720 now since we made sure to keep the Dean 5026 02:36:21,060 --> 02:36:22,060 logic and physics components only on the 5027 02:36:22,680 --> 02:36:23,680 parent object let's just modify this one 5028 02:36:24,720 --> 02:36:25,720 and leave the other ones on the default 5029 02:36:26,340 --> 02:36:27,340 so let's just modify this object only 5030 02:36:28,439 --> 02:36:29,439 okay so with that our counter is now on 5031 02:36:30,600 --> 02:36:31,600 the counters layer let's leave the 5032 02:36:32,220 --> 02:36:33,220 prefab make sure to save it okay great 5033 02:36:33,960 --> 02:36:34,960 and now if we go back into the player 5034 02:36:35,760 --> 02:36:36,760 and over here on the counters layer mask 5035 02:36:37,200 --> 02:36:38,200 yep we do see the counters layer so 5036 02:36:39,300 --> 02:36:40,300 let's just click the selected by the way 5037 02:36:41,340 --> 02:36:42,340 this drop down menu can actually select 5038 02:36:43,080 --> 02:36:44,080 multiple so you can select all kinds of 5039 02:36:45,240 --> 02:36:46,240 layers so this is multi-select but we 5040 02:36:47,280 --> 02:36:48,280 only want to counter so only like this 5041 02:36:49,080 --> 02:36:50,080 and just like this if we do test and if 5042 02:36:52,020 --> 02:36:53,020 I move towards it and if there you go 5043 02:36:53,340 --> 02:36:54,340 get the nice interact on both them so 5044 02:36:55,439 --> 02:36:56,439 everything still works is only the same 5045 02:36:56,760 --> 02:36:57,760 but now if we had another physics on 5046 02:36:58,680 --> 02:36:59,680 leather in front of it it would still 5047 02:37:00,120 --> 02:37:01,120 work because we're using a layer mask to 5048 02:37:01,859 --> 02:37:02,859 only recast against counter objects 5049 02:37:03,660 --> 02:37:04,660 alright great now I should point out 5050 02:37:06,180 --> 02:37:07,180 another way to work with layers is with 5051 02:37:08,040 --> 02:37:09,040 something called a bit mask that's a bit 5052 02:37:10,319 --> 02:37:11,319 more advanced usually the layer mask is 5053 02:37:12,120 --> 02:37:13,120 much easier to follow but if you want to 5054 02:37:14,040 --> 02:37:15,040 learn about bitmask go ahead and watch 5055 02:37:15,420 --> 02:37:16,420 that video and also another quick note 5056 02:37:17,460 --> 02:37:18,460 in this game we're only going to 5057 02:37:19,080 --> 02:37:20,080 interact with one single object type 5058 02:37:20,819 --> 02:37:21,819 it's only going to be a counter even 5059 02:37:22,740 --> 02:37:23,740 though we're going to have multiple 5060 02:37:23,880 --> 02:37:24,880 types of counters but for games where 5061 02:37:26,280 --> 02:37:27,280 you want to interact with multiple 5062 02:37:27,540 --> 02:37:28,540 objects like for example having an 5063 02:37:29,520 --> 02:37:30,520 interact action to talk with an NPC 5064 02:37:31,319 --> 02:37:32,319 another one to open a door or push a 5065 02:37:33,240 --> 02:37:34,240 button for those kinds of multiple 5066 02:37:35,160 --> 02:37:36,160 interactions to build the system like 5067 02:37:36,600 --> 02:37:37,600 that make sure you look into my how to 5068 02:37:38,399 --> 02:37:39,399 interact with objects video it covers 5069 02:37:40,560 --> 02:37:41,560 how to do all of that how to interact 5070 02:37:42,120 --> 02:37:43,120 with all kinds of objects it's all based 5071 02:37:44,280 --> 02:37:45,280 on c-sharp interfaces which we're 5072 02:37:45,780 --> 02:37:46,780 actually going to use in a few lectures 5073 02:37:47,280 --> 02:37:48,280 and also have a dedicated video on that 5074 02:37:49,200 --> 02:37:50,200 topic so keep following this course but 5075 02:37:51,120 --> 02:37:52,120 then make sure to watch those videos add 5076 02:37:53,220 --> 02:37:54,220 them to your watch list and make sure 5077 02:37:54,600 --> 02:37:55,600 you do watch them watch out how to 5078 02:37:56,520 --> 02:37:57,520 interact video it is something that is 5079 02:37:58,439 --> 02:37:59,439 necessary in so many games and most 5080 02:37:59,939 --> 02:38:00,939 tutorials don't actually teach you the 5081 02:38:01,500 --> 02:38:02,500 correct way of doing it anyway so back 5082 02:38:03,300 --> 02:38:04,300 in our game we are correctly identifying 5083 02:38:05,220 --> 02:38:06,220 and interacting with each counter but 5084 02:38:07,620 --> 02:38:08,620 obviously we don't want to interact 5085 02:38:09,180 --> 02:38:10,180 automatically just like this instead we 5086 02:38:11,100 --> 02:38:12,100 want to press a nice button to interact 5087 02:38:12,960 --> 02:38:13,960 so that means we're going to need to 5088 02:38:14,340 --> 02:38:15,340 create an interact input action so let's 5089 02:38:16,560 --> 02:38:17,560 do all of that in the next lecture 5090 02:38:19,380 --> 02:38:20,380 hello and welcome I'm your code monkey 5091 02:38:21,300 --> 02:38:22,300 in this lecture we're going to create a 5092 02:38:23,520 --> 02:38:24,520 proper interact input action and in 5093 02:38:25,620 --> 02:38:26,620 doing so we're also going to learn about 5094 02:38:27,180 --> 02:38:28,180 a very powerful and c-sharp feature 5095 02:38:28,920 --> 02:38:29,920 called events 5096 02:38:30,180 --> 02:38:31,180 okay so here we have our game so we have 5097 02:38:32,580 --> 02:38:33,580 the player and if we move towards the 5098 02:38:34,200 --> 02:38:35,200 counter yep we are correctly identifying 5099 02:38:36,240 --> 02:38:37,240 it and interacting with it except of 5100 02:38:38,340 --> 02:38:39,340 course we don't want the interaction to 5101 02:38:39,960 --> 02:38:40,960 happen automatically it should be on a 5102 02:38:41,700 --> 02:38:42,700 player input so let's make our interact 5103 02:38:43,859 --> 02:38:44,859 action let's go inside our player input 5104 02:38:46,380 --> 02:38:47,380 action so let's double click on it and 5105 02:38:48,359 --> 02:38:49,359 let's make a brand new action so we've 5106 02:38:49,800 --> 02:38:50,800 got to move and now we're going to have 5107 02:38:50,880 --> 02:38:51,880 another one so let's click on the plus 5108 02:38:52,140 --> 02:38:53,140 icon for this one let's call it interact 5109 02:38:54,840 --> 02:38:55,840 and for this one action type we do want 5110 02:38:56,939 --> 02:38:57,939 it to be a button okay great then on the 5111 02:38:59,460 --> 02:39:00,460 default binding let's go into path let's 5112 02:39:01,140 --> 02:39:02,140 listen and by default let's bind it to 5113 02:39:03,479 --> 02:39:04,479 the E key just like so many games so 5114 02:39:05,460 --> 02:39:06,460 let's go ahead select this one and once 5115 02:39:07,560 --> 02:39:08,560 again let's make sure to save the asset 5116 02:39:09,300 --> 02:39:10,300 and let the C sharp OS be generated okay 5117 02:39:12,600 --> 02:39:13,600 and over here in our game input script 5118 02:39:14,760 --> 02:39:15,760 in order to listen that is very simple 5119 02:39:16,500 --> 02:39:17,500 so we go inside the player input actions 5120 02:39:18,899 --> 02:39:19,899 then inside the player action map and 5121 02:39:21,240 --> 02:39:22,240 then we can find the interact action 5122 02:39:23,760 --> 02:39:24,760 and then over here we can see a whole 5123 02:39:25,800 --> 02:39:26,800 bunch of events that we can interact 5124 02:39:27,240 --> 02:39:28,240 with we've got these three cancel 5125 02:39:29,280 --> 02:39:30,280 performed and started these are the 5126 02:39:31,800 --> 02:39:32,800 three phases of every input again I 5127 02:39:34,680 --> 02:39:35,680 cover these stages in detail in the 5128 02:39:36,300 --> 02:39:37,300 input system video the important thing 5129 02:39:38,160 --> 02:39:39,160 is that these are c-sharp events which I 5130 02:39:40,680 --> 02:39:41,680 also covered in another dedicated video 5131 02:39:42,420 --> 02:39:43,420 essentially they are a way for how you 5132 02:39:44,340 --> 02:39:45,340 can write code to then get notified when 5133 02:39:46,500 --> 02:39:47,500 something happens rather than running 5134 02:39:48,720 --> 02:39:49,720 code on every single update constantly 5135 02:39:50,580 --> 02:39:51,580 testing something for example over here 5136 02:39:52,740 --> 02:39:53,740 on the movement movement is a 5137 02:39:54,720 --> 02:39:55,720 pre-constant action so it does make 5138 02:39:56,280 --> 02:39:57,280 sense to ask the input on every single 5139 02:39:58,560 --> 02:39:59,560 update if any movement is pressed but 5140 02:40:00,899 --> 02:40:01,899 for an action like the interact the 5141 02:40:03,060 --> 02:40:04,060 player is only going to press that say 5142 02:40:04,500 --> 02:40:05,500 once every five seconds so it makes no 5143 02:40:06,720 --> 02:40:07,720 sense to constantly check for that 5144 02:40:08,040 --> 02:40:09,040 action on every single update instead we 5145 02:40:11,040 --> 02:40:12,040 just want to be notified when that 5146 02:40:12,660 --> 02:40:13,660 action is triggered and that is exactly 5147 02:40:14,520 --> 02:40:15,520 what an event does again watch the 5148 02:40:16,680 --> 02:40:17,680 dedicated video to learn all about 5149 02:40:18,000 --> 02:40:19,000 c-sharp events in detail they are 5150 02:40:19,920 --> 02:40:20,920 insanely powerful and we won't be using 5151 02:40:21,720 --> 02:40:22,720 them more and more as we go through this 5152 02:40:23,220 --> 02:40:24,220 course 5153 02:40:23,939 --> 02:40:24,939 for now here are the absolute Basics 5154 02:40:25,680 --> 02:40:26,680 events have Publishers and subscribers 5155 02:40:28,140 --> 02:40:29,140 the publisher creates and fires the 5156 02:40:30,540 --> 02:40:31,540 event when something happens and the 5157 02:40:32,640 --> 02:40:33,640 subscriber listens that event and gets 5158 02:40:34,439 --> 02:40:35,439 the enlisting function called when the 5159 02:40:35,880 --> 02:40:36,880 event is fired now on the generated 5160 02:40:37,740 --> 02:40:38,740 c-sharp class we've got these three 5161 02:40:39,899 --> 02:40:40,899 events the one that we want for this 5162 02:40:42,120 --> 02:40:43,120 case is the performed event so let's go 5163 02:40:44,760 --> 02:40:45,760 into this one and basically we want to 5164 02:40:46,200 --> 02:40:47,200 add a listener to that event 5165 02:40:48,000 --> 02:40:49,000 and we can subscribe to that by doing 5166 02:40:50,220 --> 02:40:51,220 plus equals so this assigns a listener 5167 02:40:52,380 --> 02:40:53,380 to that event and now Visual Studio has 5168 02:40:54,479 --> 02:40:55,479 a nice shortcut so if we press on Tab if 5169 02:40:56,880 --> 02:40:57,880 there go it automatically creates a 5170 02:40:58,260 --> 02:40:59,260 function now if you're not using visual 5171 02:41:00,300 --> 02:41:01,300 studio you can just manually write this 5172 02:41:01,859 --> 02:41:02,859 function the only thing you need to make 5173 02:41:03,479 --> 02:41:04,479 sure is that the function signature 5174 02:41:04,979 --> 02:41:05,979 personally matches the event signature 5175 02:41:06,540 --> 02:41:07,540 as usual we can inspect the event so we 5176 02:41:08,580 --> 02:41:09,580 can right click on it and go to the 5177 02:41:10,020 --> 02:41:11,020 definition and up here is the definition 5178 02:41:12,020 --> 02:41:13,020 and you can see that this is an event of 5179 02:41:15,060 --> 02:41:16,060 type action with a combat context action 5180 02:41:17,760 --> 02:41:18,760 is what is called a dungit I also have a 5181 02:41:20,100 --> 02:41:21,100 video on delegates if you want to learn 5182 02:41:21,479 --> 02:41:22,479 more about them in detail for now we 5183 02:41:23,340 --> 02:41:24,340 don't really need to worry about what is 5184 02:41:24,720 --> 02:41:25,720 delegate we just need to use it so in 5185 02:41:26,880 --> 02:41:27,880 order to subscribe to the event we need 5186 02:41:28,439 --> 02:41:29,439 to make sure that this one returns voyne 5187 02:41:30,180 --> 02:41:31,180 because an action returns void and needs 5188 02:41:32,520 --> 02:41:33,520 to have a parameter of this type combat 5189 02:41:34,380 --> 02:41:35,380 context if I erase this parameter if 5190 02:41:37,680 --> 02:41:38,680 there go now we have an error because 5191 02:41:39,000 --> 02:41:40,000 the function signature does not match so 5192 02:41:41,340 --> 02:41:42,340 it always needs to match the exact same 5193 02:41:42,899 --> 02:41:43,899 signature okay and also one more note 5194 02:41:45,060 --> 02:41:46,060 over here when subscribing to the event 5195 02:41:46,740 --> 02:41:47,740 make sure you only add the function name 5196 02:41:48,720 --> 02:41:49,720 meaning you do not add parentheses we do 5197 02:41:51,180 --> 02:41:52,180 not want to count function we just want 5198 02:41:52,740 --> 02:41:53,740 to pass in the function itself as a 5199 02:41:54,479 --> 02:41:55,479 reference okay so now when the player 5200 02:41:56,399 --> 02:41:57,399 presses the interact action it's going 5201 02:41:57,899 --> 02:41:58,899 to fire off this event which in turn 5202 02:41:59,880 --> 02:42:00,880 will call this function so over here 5203 02:42:01,740 --> 02:42:02,740 let's do a debug download just see what 5204 02:42:03,720 --> 02:42:04,720 this contains for example let's print 5205 02:42:05,700 --> 02:42:06,700 out the compact context okay so let's 5206 02:42:07,740 --> 02:42:08,740 see so here we are and if I press on E 5207 02:42:10,200 --> 02:42:11,200 if there you go I've got a nice event 5208 02:42:11,819 --> 02:42:12,819 okay great so with this we know when the 5209 02:42:13,979 --> 02:42:14,979 player presses the key now the next step 5210 02:42:15,960 --> 02:42:16,960 is how do we get the player class how do 5211 02:42:18,300 --> 02:42:19,300 we get this one to know when this is 5212 02:42:19,979 --> 02:42:20,979 performed and the answer is we're going 5213 02:42:21,720 --> 02:42:22,720 to do the exact same thing we're going 5214 02:42:23,399 --> 02:42:24,399 to make an event over here on the game 5215 02:42:24,899 --> 02:42:25,899 input class and the player won't listen 5216 02:42:26,760 --> 02:42:27,760 to that which in turn the game input 5217 02:42:28,500 --> 02:42:29,500 grabs from the input system again the 5218 02:42:30,780 --> 02:42:31,780 home point is separating our concerns so 5219 02:42:33,180 --> 02:42:34,180 the player does not care about the input 5220 02:42:34,800 --> 02:42:35,800 system does not care about the interact 5221 02:42:36,420 --> 02:42:37,420 action it only wants to know when 5222 02:42:37,920 --> 02:42:38,920 something related to interact happens so 5223 02:42:40,200 --> 02:42:41,200 over here let's make that nice event 5224 02:42:41,700 --> 02:42:42,700 first of all let's make it public 5225 02:42:43,560 --> 02:42:44,560 because we want the player to access it 5226 02:42:45,420 --> 02:42:46,420 then we need to add the event keyword 5227 02:42:47,700 --> 02:42:48,700 next we add the donkey type like I said 5228 02:42:50,640 --> 02:42:51,640 you can learn more about delegates in my 5229 02:42:52,200 --> 02:42:53,200 dedicated video you can create your own 5230 02:42:54,420 --> 02:42:55,420 custom Delegate for your event or you 5231 02:42:56,640 --> 02:42:57,640 can just follow the c-sharp standard and 5232 02:42:58,620 --> 02:42:59,620 just use the standard event handler and 5233 02:43:01,319 --> 02:43:02,319 this one exists inside system 5234 02:43:03,720 --> 02:43:04,720 so let's make sure to go up here and add 5235 02:43:05,939 --> 02:43:06,939 using system and this one has the event 5236 02:43:08,340 --> 02:43:09,340 handler class this one is pretty much 5237 02:43:10,439 --> 02:43:11,439 easy sharp standard for events as you 5238 02:43:12,720 --> 02:43:13,720 can see it returns void it has an object 5239 02:43:14,760 --> 02:43:15,760 for the sender and an event RX parameter 5240 02:43:17,220 --> 02:43:18,220 like I mentioned in the events video you 5241 02:43:19,380 --> 02:43:20,380 are not forced to use this target you 5242 02:43:21,000 --> 02:43:22,000 can use whatever delegate you want like 5243 02:43:22,859 --> 02:43:23,859 for example you saw that the performed 5244 02:43:24,840 --> 02:43:25,840 uses an action delegate so you can use 5245 02:43:26,760 --> 02:43:27,760 anything you want to choose that the 5246 02:43:28,140 --> 02:43:29,140 event handler is the c-sharp standard so 5247 02:43:30,180 --> 02:43:31,180 it's easier to follow unless you have a 5248 02:43:32,520 --> 02:43:33,520 specific reason to deviate from the 5249 02:43:34,080 --> 02:43:35,080 standard you should probably use this 5250 02:43:35,399 --> 02:43:36,399 one so let's use this and then finally 5251 02:43:37,500 --> 02:43:38,500 for the name usually you start the name 5252 02:43:39,720 --> 02:43:40,720 with on and then whatever happened so in 5253 02:43:41,819 --> 02:43:42,819 our case let's go with on interact 5254 02:43:43,560 --> 02:43:44,560 action 5255 02:43:45,840 --> 02:43:46,840 okay so we have defined our event and 5256 02:43:48,240 --> 02:43:49,240 now for firing it let's go down here 5257 02:43:50,460 --> 02:43:51,460 into when we have the interact performed 5258 02:43:52,500 --> 02:43:53,500 and let's go into the event and for 5259 02:43:54,479 --> 02:43:55,479 finding it it's pretty much exactly the 5260 02:43:55,979 --> 02:43:56,979 same thing as calling a regular function 5261 02:43:57,479 --> 02:43:58,479 so we just call it with parentheses then 5262 02:43:59,939 --> 02:44:00,939 usually for the object sender this is a 5263 02:44:01,800 --> 02:44:02,800 reference to whoever is sending this 5264 02:44:03,120 --> 02:44:04,120 event so usually the this keyword and 5265 02:44:05,580 --> 02:44:06,580 then for the event RX this is in case 5266 02:44:07,439 --> 02:44:08,439 you want to send some arguments with the 5267 02:44:08,880 --> 02:44:09,880 event in our case we don't really need 5268 02:44:10,800 --> 02:44:11,800 to send any extra data for this one just 5269 02:44:12,600 --> 02:44:13,600 firing the event is going to be enough 5270 02:44:13,920 --> 02:44:14,920 so for that we can use the constant 5271 02:44:15,960 --> 02:44:16,960 event RX dot empty okay so that's it 5272 02:44:19,020 --> 02:44:20,020 with this we are firing an event except 5273 02:44:21,420 --> 02:44:22,420 just like this we're actually going to 5274 02:44:22,680 --> 02:44:23,680 have one potential error if we have no 5275 02:44:25,620 --> 02:44:26,620 subscribers no listeners to this event 5276 02:44:27,479 --> 02:44:28,479 then essentially this field won't be 5277 02:44:29,460 --> 02:44:30,460 known so this one over here is going to 5278 02:44:31,020 --> 02:44:32,020 trigger a non-reference exception let's 5279 02:44:33,180 --> 02:44:34,180 do a quick test just to see this 5280 02:44:34,500 --> 02:44:35,500 happening so here if I press on E if 5281 02:44:37,020 --> 02:44:38,020 there go we have a null reference 5282 02:44:38,340 --> 02:44:39,340 exception 5283 02:44:39,240 --> 02:44:40,240 so when working with events you need to 5284 02:44:40,859 --> 02:44:41,859 first test if there are any listeners 5285 02:44:42,540 --> 02:44:43,540 and only then do you actually trigger 5286 02:44:44,220 --> 02:44:45,220 the event 5287 02:44:45,479 --> 02:44:46,479 so you do if this one is not null if it 5288 02:44:48,300 --> 02:44:49,300 is not known that means there are some 5289 02:44:49,680 --> 02:44:50,680 subscribers so we can fire the event so 5290 02:44:52,080 --> 02:44:53,080 like this it won't work but there's an 5291 02:44:53,880 --> 02:44:54,880 even more compact way to do this which 5292 02:44:55,439 --> 02:44:56,439 is perfect for events so instead of this 5293 02:44:59,220 --> 02:45:00,220 we've got our on interact action then we 5294 02:45:01,500 --> 02:45:02,500 can add a question mark this is called 5295 02:45:03,720 --> 02:45:04,720 the non-conditional operator basically 5296 02:45:06,180 --> 02:45:07,180 the code is going to execute from left 5297 02:45:07,920 --> 02:45:08,920 to right 5298 02:45:09,000 --> 02:45:10,000 and then when it gets to this question 5299 02:45:10,620 --> 02:45:11,620 mark it's going to evaluate the left 5300 02:45:12,840 --> 02:45:13,840 side and if it is null then the 5301 02:45:15,060 --> 02:45:16,060 execution won't stop right here on the 5302 02:45:16,740 --> 02:45:17,740 question mark and will not throw any 5303 02:45:18,120 --> 02:45:19,120 errors whereas if this one is not null 5304 02:45:20,520 --> 02:45:21,520 then it continues executing to the right 5305 02:45:22,140 --> 02:45:23,140 except with this syntax we have an error 5306 02:45:24,540 --> 02:45:25,540 We cannot put parentheses directly after 5307 02:45:26,760 --> 02:45:27,760 the question mark but what we can do is 5308 02:45:29,280 --> 02:45:30,280 simply just call invoke and that does 5309 02:45:31,380 --> 02:45:32,380 the exact same thing that console 5310 02:45:32,640 --> 02:45:33,640 function so what we have here is exactly 5311 02:45:35,100 --> 02:45:36,100 the same thing that we had previously 5312 02:45:45,180 --> 02:45:46,180 so what we have over here and over here 5313 02:45:47,460 --> 02:45:48,460 these are the exact same thing it's just 5314 02:45:49,680 --> 02:45:50,680 this one is much nice much more Compact 5315 02:45:51,899 --> 02:45:52,899 and especially for events this one is 5316 02:45:54,060 --> 02:45:55,060 super useful okay so with this we are 5317 02:45:56,160 --> 02:45:57,160 correctly firing for our event now let's 5318 02:45:58,140 --> 02:45:59,140 actually listen to it so let's go over 5319 02:46:00,240 --> 02:46:01,240 here into the player class 5320 02:46:01,979 --> 02:46:02,979 and let's listen to our event 5321 02:46:04,020 --> 02:46:05,020 let's do it on a private void start make 5322 02:46:06,720 --> 02:46:07,720 it on start not an awake this is a very 5323 02:46:09,060 --> 02:46:10,060 important rule which I'm actually going 5324 02:46:10,319 --> 02:46:11,319 to cover in detail in the next lecture 5325 02:46:11,880 --> 02:46:12,880 but for now just make sure to listen on 5326 02:46:13,740 --> 02:46:14,740 start and not on awake so over here we 5327 02:46:16,020 --> 02:46:17,020 access the game input then let's access 5328 02:46:18,600 --> 02:46:19,600 the on interact action event and as 5329 02:46:20,460 --> 02:46:21,460 usual let's listen to it so let's use 5330 02:46:22,080 --> 02:46:23,080 press tab to listen to it so it is 5331 02:46:24,300 --> 02:46:25,300 exactly over here that we want to run 5332 02:46:25,920 --> 02:46:26,920 our interact code so let's go down into 5333 02:46:28,439 --> 02:46:29,439 the handle interaction code that we had 5334 02:46:30,060 --> 02:46:31,060 previously so this one 5335 02:46:31,680 --> 02:46:32,680 so let's copy paste all this code put it 5336 02:46:34,800 --> 02:46:35,800 up here 5337 02:46:35,640 --> 02:46:36,640 so we get the interaction going to the 5338 02:46:37,380 --> 02:46:38,380 object and Trigger the interact now 5339 02:46:39,240 --> 02:46:40,240 obviously code duplication is a big 5340 02:46:40,979 --> 02:46:41,979 No-No so we're only duplicating our code 5341 02:46:43,620 --> 02:46:44,620 just for a quick test just make sure it 5342 02:46:45,120 --> 02:46:46,120 works 5343 02:46:46,020 --> 02:46:47,020 once again refactoring is super useful 5344 02:46:47,880 --> 02:46:48,880 so we're going to refactor this code to 5345 02:46:49,560 --> 02:46:50,560 get rid of code duplication in the next 5346 02:46:51,300 --> 02:46:52,300 lecture but for now we just want to test 5347 02:46:53,340 --> 02:46:54,340 to make sure that this does work 5348 02:46:55,020 --> 02:46:56,020 so let's just remove the interact over 5349 02:46:56,700 --> 02:46:57,700 here from the handle interactions so the 5350 02:46:58,859 --> 02:46:59,859 only interact function being called is 5351 02:47:00,540 --> 02:47:01,540 over here when we have our actual input 5352 02:47:02,399 --> 02:47:03,399 so let's test and see if we can press to 5353 02:47:04,500 --> 02:47:05,500 interact with the counter alright so 5354 02:47:06,540 --> 02:47:07,540 here we are and as I move around if I 5355 02:47:08,280 --> 02:47:09,280 approach a counter yep there you go we 5356 02:47:09,899 --> 02:47:10,899 no longer have the automated interaction 5357 02:47:12,300 --> 02:47:13,300 and now if I'm facing the counter and I 5358 02:47:14,220 --> 02:47:15,220 press the enter I key if there go here 5359 02:47:16,200 --> 02:47:17,200 we have our nice interaction all right 5360 02:47:18,240 --> 02:47:19,240 awesome so I can approach I can interact 5361 02:47:20,160 --> 02:47:21,160 and do whatever I want 5362 02:47:21,899 --> 02:47:22,899 alright so here we learned about c-sharp 5363 02:47:24,420 --> 02:47:25,420 events these are super powerful so if 5364 02:47:26,700 --> 02:47:27,700 this is the first time you're hearing 5365 02:47:27,960 --> 02:47:28,960 about them then you've just had an 5366 02:47:29,700 --> 02:47:30,700 awesome new tool to your tone box 5367 02:47:31,020 --> 02:47:32,020 definitely make sure you watch my 5368 02:47:32,580 --> 02:47:33,580 dedicated video to learn about them in 5369 02:47:34,020 --> 02:47:35,020 more detail events are super useful the 5370 02:47:36,960 --> 02:47:37,960 next thing we're going to need is just a 5371 02:47:38,399 --> 02:47:39,399 visual to highlight the current selected 5372 02:47:40,080 --> 02:47:41,080 counter so let's do that in the next 5373 02:47:41,700 --> 02:47:42,700 lecture 5374 02:47:43,020 --> 02:47:44,020 hello and welcome I'm your code monkey 5375 02:47:45,060 --> 02:47:46,060 in this lecture we're going to add a 5376 02:47:47,160 --> 02:47:48,160 visual to our selected counter and in 5377 02:47:48,899 --> 02:47:49,899 doing so we're also going to learn about 5378 02:47:50,580 --> 02:47:51,580 the very useful Singleton pattern okay 5379 02:47:52,859 --> 02:47:53,859 so over here we already have the logic 5380 02:47:54,780 --> 02:47:55,780 to identify the counter in front of the 5381 02:47:56,220 --> 02:47:57,220 player and we can interact with it 5382 02:47:57,899 --> 02:47:58,899 however once the logic works there is no 5383 02:48:00,540 --> 02:48:01,540 visual indicator at all so let's add 5384 02:48:02,340 --> 02:48:03,340 that now as usual the super quick and 5385 02:48:05,100 --> 02:48:06,100 dirty way of doing it would be pretty 5386 02:48:06,600 --> 02:48:07,600 simple over here on the player script we 5387 02:48:08,700 --> 02:48:09,700 could just directly enable a visual mesh 5388 02:48:10,740 --> 02:48:11,740 on the target counter so down here on 5389 02:48:12,960 --> 02:48:13,960 the handle interaction when we have this 5390 02:48:14,520 --> 02:48:15,520 over here we can tell the clear counter 5391 02:48:16,260 --> 02:48:17,260 to enable some kind of visual 5392 02:48:17,580 --> 02:48:18,580 technically that would work but that 5393 02:48:19,920 --> 02:48:20,920 would be some pretty dirty code we would 5394 02:48:22,319 --> 02:48:23,319 basically be making the player 5395 02:48:23,700 --> 02:48:24,700 responsible for enabling some kind of 5396 02:48:25,319 --> 02:48:26,319 visual which would mean that we were 5397 02:48:27,359 --> 02:48:28,359 mixing logic with visuals again we 5398 02:48:30,060 --> 02:48:31,060 always want to try separating the logic 5399 02:48:31,800 --> 02:48:32,800 from the visuals as much as possible to 5400 02:48:33,479 --> 02:48:34,479 keep our code nice and organized so 5401 02:48:35,399 --> 02:48:36,399 instead of doing the quick and dirty 5402 02:48:36,840 --> 02:48:37,840 route let's do it properly back in the 5403 02:48:39,240 --> 02:48:40,240 editor let's create a brand new c-sharp 5404 02:48:41,160 --> 02:48:42,160 script call this the selected counter 5405 02:48:43,920 --> 02:48:44,920 visual 5406 02:48:45,060 --> 02:48:46,060 and now let's go into the prefab again 5407 02:48:48,000 --> 02:48:49,000 let's go inside it so let's select the 5408 02:48:49,560 --> 02:48:50,560 clear counter on the hierarchy then on 5409 02:48:51,120 --> 02:48:52,120 the inspector let's open up go inside 5410 02:48:52,740 --> 02:48:53,740 the prefab and now let's select the 5411 02:48:55,020 --> 02:48:56,020 visual inside it and let's duplicate 5412 02:48:56,760 --> 02:48:57,760 this so you can press Ctrl D to 5413 02:48:58,140 --> 02:48:59,140 duplicate it let's name this when it's 5414 02:49:00,359 --> 02:49:01,359 selected and then inside there's a 5415 02:49:02,819 --> 02:49:03,819 visual with a mesh filter and a mesh 5416 02:49:04,680 --> 02:49:05,680 render so over here let's swap out the 5417 02:49:06,720 --> 02:49:07,720 material 5418 02:49:07,800 --> 02:49:08,800 so let's click on the circle icon and 5419 02:49:10,319 --> 02:49:11,319 now included in the assets is this 5420 02:49:12,660 --> 02:49:13,660 material counter selected so it's all 5421 02:49:15,120 --> 02:49:16,120 the way yep up here the counter selected 5422 02:49:16,979 --> 02:49:17,979 basically it's just a solid white color 5423 02:49:19,319 --> 02:49:20,319 within low Alpha so on the kitchen 5424 02:49:21,300 --> 02:49:22,300 counter inside the sunlight game object 5425 02:49:23,160 --> 02:49:24,160 let's make sure to use this one with 5426 02:49:25,200 --> 02:49:26,200 this we have kind of like a ghost visual 5427 02:49:27,180 --> 02:49:28,180 so if we enable and disable this game 5428 02:49:29,160 --> 02:49:30,160 object we can see the difference Also 5429 02:49:31,020 --> 02:49:32,020 let's do one tiny thing which is right 5430 02:49:33,359 --> 02:49:34,359 now we duplicated the actual visual 5431 02:49:35,340 --> 02:49:36,340 meaning that these objects are exactly 5432 02:49:37,260 --> 02:49:38,260 the same they have the exact same size 5433 02:49:39,060 --> 02:49:40,060 and when that happens you might end up 5434 02:49:41,220 --> 02:49:42,220 with some rendering bugs if two meshes 5435 02:49:43,500 --> 02:49:44,500 are on the exact same position you might 5436 02:49:45,000 --> 02:49:46,000 sometimes see the colors constantly flip 5437 02:49:46,979 --> 02:49:47,979 back and forth 5438 02:49:48,120 --> 02:49:49,120 so in order to make sure that doesn't 5439 02:49:49,620 --> 02:49:50,620 happen let's make this one deselected a 5440 02:49:52,140 --> 02:49:53,140 tiny tiny bit bigger so over here with 5441 02:49:54,240 --> 02:49:55,240 the selected game object selected on the 5442 02:49:56,760 --> 02:49:57,760 inspector over here we've got the scale 5443 02:49:58,020 --> 02:49:59,020 and also we've got this nice little 5444 02:49:59,520 --> 02:50:00,520 button here if it's like this then we 5445 02:50:01,800 --> 02:50:02,800 can modify each proportion differently 5446 02:50:03,540 --> 02:50:04,540 from one another whereas if we click now 5447 02:50:06,240 --> 02:50:07,240 these are all linked so now I'm 5448 02:50:08,580 --> 02:50:09,580 modifying one will modify all of them so 5449 02:50:10,140 --> 02:50:11,140 let's put this on 1.01 meaning this one 5450 02:50:13,439 --> 02:50:14,439 is going to be literally just one 5451 02:50:15,000 --> 02:50:16,000 percent bigger so that's enough of a 5452 02:50:16,859 --> 02:50:17,859 difference to make sure we don't have 5453 02:50:18,000 --> 02:50:19,000 any rendering bugs and by default let's 5454 02:50:20,280 --> 02:50:21,280 also start with the visual hidden so 5455 02:50:22,319 --> 02:50:23,319 let's do that not on the parent select 5456 02:50:24,060 --> 02:50:25,060 game object but rather on the kitchen 5457 02:50:25,500 --> 02:50:26,500 counter inside of it let's make sure to 5458 02:50:27,479 --> 02:50:28,479 disable this game object by the way the 5459 02:50:29,939 --> 02:50:30,939 quick shortcut is shift alt and a you 5460 02:50:32,280 --> 02:50:33,280 can enable or disable the object very 5461 02:50:34,020 --> 02:50:35,020 useful so let's start with this one 5462 02:50:35,700 --> 02:50:36,700 disabled so that it's hidden and 5463 02:50:37,500 --> 02:50:38,500 basically the goal is that when this 5464 02:50:39,840 --> 02:50:40,840 counter is selected we're going to 5465 02:50:41,100 --> 02:50:42,100 enable it and show this Visual and when 5466 02:50:42,960 --> 02:50:43,960 it's not selected we're going to disable 5467 02:50:44,399 --> 02:50:45,399 it okay so over here on the selected 5468 02:50:46,560 --> 02:50:47,560 let's add the script that we made so 5469 02:50:47,760 --> 02:50:48,760 these selected comes revision all right 5470 02:50:49,380 --> 02:50:50,380 so let's open it now here first thing we 5471 02:50:51,899 --> 02:50:52,899 need to know is know which counter is 5472 02:50:53,700 --> 02:50:54,700 selected meaning we need to know which 5473 02:50:56,220 --> 02:50:57,220 counter the player is currently looking 5474 02:50:57,720 --> 02:50:58,720 at so let's go over here onto the player 5475 02:51:00,000 --> 02:51:01,000 script and let's basically just do some 5476 02:51:01,979 --> 02:51:02,979 simple logic to keep track of the 5477 02:51:03,359 --> 02:51:04,359 selected counter so over here let's make 5478 02:51:05,460 --> 02:51:06,460 a field so a private 5479 02:51:07,859 --> 02:51:08,859 let's make it a type clear counter and 5480 02:51:10,620 --> 02:51:11,620 just come with the selected counter 5481 02:51:13,680 --> 02:51:14,680 then down here we have our handle 5482 02:51:15,780 --> 02:51:16,780 interactions logic okay so we do all of 5483 02:51:17,760 --> 02:51:18,760 this we try to find the counter in front 5484 02:51:19,859 --> 02:51:20,859 and if we do find it then we have it 5485 02:51:21,420 --> 02:51:22,420 here so here on let's just check if it's 5486 02:51:23,580 --> 02:51:24,580 different so if this clear counter if 5487 02:51:25,680 --> 02:51:26,680 the one in front is different from the 5488 02:51:27,300 --> 02:51:28,300 current selected then let's set the 5489 02:51:29,280 --> 02:51:30,280 selected to this one 5490 02:51:32,280 --> 02:51:33,280 and let's also make sure to essentially 5491 02:51:34,260 --> 02:51:35,260 unselect so we want to make sure to set 5492 02:51:36,240 --> 02:51:37,240 this one to know when there's nothing in 5493 02:51:37,800 --> 02:51:38,800 front of the player so if the raycast 5494 02:51:39,899 --> 02:51:40,899 does not hit anything then there is 5495 02:51:41,340 --> 02:51:42,340 nothing in front of the player so let's 5496 02:51:42,479 --> 02:51:43,479 set this like the counter back into null 5497 02:51:44,280 --> 02:51:45,280 and also if there is something but that 5498 02:51:46,200 --> 02:51:47,200 something does not have the clear 5499 02:51:47,399 --> 02:51:48,399 counter script then it's also not a 5500 02:51:48,899 --> 02:51:49,899 counter so over here let's also do an 5501 02:51:50,760 --> 02:51:51,760 else selected counter equals no so 5502 02:51:53,160 --> 02:51:54,160 basically if there's a counter in from 5503 02:51:54,359 --> 02:51:55,359 the player then it's going to set it if 5504 02:51:55,800 --> 02:51:56,800 not then it's going to be no 5505 02:51:57,540 --> 02:51:58,540 let's just do a simple debug download to 5506 02:52:00,180 --> 02:52:01,180 check on the selected counter okay and 5507 02:52:02,640 --> 02:52:03,640 also just briefly now that we've made 5508 02:52:04,560 --> 02:52:05,560 this selected counter logic actually up 5509 02:52:06,720 --> 02:52:07,720 here when we have our interact action 5510 02:52:08,460 --> 02:52:09,460 like we saw we were previously copying 5511 02:52:11,460 --> 02:52:12,460 some duplicated code 5512 02:52:12,960 --> 02:52:13,960 but now we no longer need this since we 5513 02:52:14,819 --> 02:52:15,819 already know the selected counter so 5514 02:52:16,560 --> 02:52:17,560 over here when we've got the interact 5515 02:52:17,939 --> 02:52:18,939 action 5516 02:52:18,899 --> 02:52:19,899 let's just check if we do have a 5517 02:52:20,580 --> 02:52:21,580 selected counter so if it is not null if 5518 02:52:23,220 --> 02:52:24,220 so then we go there and we call the 5519 02:52:24,779 --> 02:52:25,779 interact function so that's it we no 5520 02:52:26,340 --> 02:52:27,340 longer need all of this logic okay 5521 02:52:28,140 --> 02:52:29,140 that's great so let's test back in the 5522 02:52:30,540 --> 02:52:31,540 editor and let's go back into scenes 5523 02:52:31,859 --> 02:52:32,859 let's make sure to save the prefab 5524 02:52:33,960 --> 02:52:34,960 make sure the script was attached save 5525 02:52:35,819 --> 02:52:36,819 it and let's hit on play and right now 5526 02:52:37,920 --> 02:52:38,920 if I'm down here yep there you go we've 5527 02:52:39,479 --> 02:52:40,479 got null and as I approach if there go 5528 02:52:41,460 --> 02:52:42,460 that one is a clear counter and if I 5529 02:52:42,960 --> 02:52:43,960 move towards this one yep it's that one 5530 02:52:44,520 --> 02:52:45,520 okay so basically we are keeping track 5531 02:52:46,560 --> 02:52:47,560 of the kernel selected counter now 5532 02:52:48,779 --> 02:52:49,779 basically we just need to notify the 5533 02:52:50,460 --> 02:52:51,460 visual whenever this one changes so when 5534 02:52:52,260 --> 02:52:53,260 this one is pointing at that one or 5535 02:52:53,580 --> 02:52:54,580 pointing at no or pointing at that one 5536 02:52:54,899 --> 02:52:55,899 we need to know when that happens 5537 02:52:56,939 --> 02:52:57,939 and for that we basically have two 5538 02:52:58,920 --> 02:52:59,920 options now one option is pretty much 5539 02:53:01,020 --> 02:53:02,020 what I mentioned a while ago which is 5540 02:53:03,000 --> 02:53:04,000 over here we have the selected counter 5541 02:53:04,500 --> 02:53:05,500 so we can run some kind of logic on the 5542 02:53:06,420 --> 02:53:07,420 sunlight counter we can do that over 5543 02:53:08,460 --> 02:53:09,460 here on the player then perhaps over 5544 02:53:10,680 --> 02:53:11,680 here the counter would fire off some 5545 02:53:12,600 --> 02:53:13,600 kind of event saying it has been 5546 02:53:13,859 --> 02:53:14,859 selected and then the counter visual 5547 02:53:16,260 --> 02:53:17,260 would listen to that event and update 5548 02:53:17,880 --> 02:53:18,880 itself now that approach would be useful 5549 02:53:20,160 --> 02:53:21,160 if we wanted to add some kind of logic 5550 02:53:22,140 --> 02:53:23,140 on the clear counter while selected and 5551 02:53:24,540 --> 02:53:25,540 that approach would also have the 5552 02:53:25,680 --> 02:53:26,680 benefit where the visual encounter would 5553 02:53:27,540 --> 02:53:28,540 only listen to events on its own counter 5554 02:53:29,279 --> 02:53:30,279 so that's one approach pretty much a 5555 02:53:31,140 --> 02:53:32,140 very direct approach but another one is 5556 02:53:33,960 --> 02:53:34,960 very simple the player would simply fire 5557 02:53:36,180 --> 02:53:37,180 off an event whenever the selected 5558 02:53:37,800 --> 02:53:38,800 counter changes and then all of the 5559 02:53:39,779 --> 02:53:40,779 counter visuals would listen to that 5560 02:53:41,160 --> 02:53:42,160 event then they would identify if the 5561 02:53:43,439 --> 02:53:44,439 event relates to that counter and if so 5562 02:53:45,300 --> 02:53:46,300 update their state 5563 02:53:46,680 --> 02:53:47,680 now the benefit of this approach is that 5564 02:53:48,540 --> 02:53:49,540 the logic doesn't get bothered with any 5565 02:53:50,220 --> 02:53:51,220 selection logic so over here the clear 5566 02:53:52,380 --> 02:53:53,380 counter script never really knows if 5567 02:53:54,060 --> 02:53:55,060 it's light or not and that's a good 5568 02:53:55,500 --> 02:53:56,500 thing because it doesn't need to know 5569 02:53:56,760 --> 02:53:57,760 although the potential con with that 5570 02:53:58,800 --> 02:53:59,800 approach is that all of these selected 5571 02:54:00,779 --> 02:54:01,779 countervisions are only going to listen 5572 02:54:02,340 --> 02:54:03,340 to the same event so both approaches 5573 02:54:04,680 --> 02:54:05,680 have pros and cons here on let's go with 5574 02:54:06,840 --> 02:54:07,840 the second approach where all the 5575 02:54:08,100 --> 02:54:09,100 counters listen to a player event 5576 02:54:09,840 --> 02:54:10,840 the potential performance con doesn't 5577 02:54:11,819 --> 02:54:12,819 really matter on a game of this scale 5578 02:54:13,979 --> 02:54:14,979 we're only going to have about a dozen 5579 02:54:15,960 --> 02:54:16,960 counters so even if 11 of them are just 5580 02:54:18,600 --> 02:54:19,600 wasting on listening to the event it's 5581 02:54:20,460 --> 02:54:21,460 really not going to matter and going in 5582 02:54:22,680 --> 02:54:23,680 with this approach will actually help us 5583 02:54:24,000 --> 02:54:25,000 learn about the Singleton pattern which 5584 02:54:25,800 --> 02:54:26,800 is extremely useful so first let's go 5585 02:54:28,020 --> 02:54:29,020 over here onto the player class and 5586 02:54:29,640 --> 02:54:30,640 let's make the event that we're going to 5587 02:54:30,899 --> 02:54:31,899 fire 5588 02:54:31,680 --> 02:54:32,680 so as usual let's make it public so we 5589 02:54:33,479 --> 02:54:34,479 can access it let's make it an event and 5590 02:54:36,000 --> 02:54:37,000 as usual let's also use the standard 5591 02:54:37,920 --> 02:54:38,920 event handler let's make sure to add 5592 02:54:40,080 --> 02:54:41,080 using system so here Visual Studio adds 5593 02:54:42,479 --> 02:54:43,479 it automatically okay 5594 02:54:44,040 --> 02:54:45,040 then let's call this on selected counter 5595 02:54:46,979 --> 02:54:47,979 changed 5596 02:54:52,920 --> 02:54:53,920 also this is a great moment to learn 5597 02:54:54,960 --> 02:54:55,960 about the event arcs this is how you can 5598 02:54:57,479 --> 02:54:58,479 extend a c-sharp event in order to pass 5599 02:54:59,939 --> 02:55:00,939 in some more data so how you do it by 5600 02:55:02,340 --> 02:55:03,340 following the c-sharp standard is very 5601 02:55:03,960 --> 02:55:04,960 simple we just create a class 5602 02:55:06,060 --> 02:55:07,060 so over here let's make a public class 5603 02:55:08,819 --> 02:55:09,819 then for name usually you include the 5604 02:55:11,100 --> 02:55:12,100 name of the event with eventars at the 5605 02:55:12,840 --> 02:55:13,840 end so in this case on selected counter 5606 02:55:15,840 --> 02:55:16,840 changed and then event arcs then on this 5607 02:55:18,840 --> 02:55:19,840 class we make it extend event arcs 5608 02:55:22,319 --> 02:55:23,319 and finally inside the class we add 5609 02:55:24,180 --> 02:55:25,180 whatever that we want like for example 5610 02:55:26,220 --> 02:55:27,220 we want the current selected counter so 5611 02:55:28,439 --> 02:55:29,439 let's make a public clear counter and 5612 02:55:31,620 --> 02:55:32,620 put the selected counter 5613 02:55:34,740 --> 02:55:35,740 okay so we have this nice event arcs 5614 02:55:37,020 --> 02:55:38,020 with a bunch of extra data and then over 5615 02:55:38,460 --> 02:55:39,460 here on the event handler we use the 5616 02:55:40,140 --> 02:55:41,140 version that takes a generic and we pass 5617 02:55:41,939 --> 02:55:42,939 in our event arcs again I covered the 5618 02:55:44,760 --> 02:55:45,760 generics in more detail in a separate 5619 02:55:46,439 --> 02:55:47,439 video definitely go watch that one if 5620 02:55:48,420 --> 02:55:49,420 you haven't seen it yet c-sharp generics 5621 02:55:50,340 --> 02:55:51,340 are one of c-sharp's most powerful 5622 02:55:51,899 --> 02:55:52,899 features okay great so we now have our 5623 02:55:54,600 --> 02:55:55,600 nice event now let's fire it off so 5624 02:55:57,000 --> 02:55:58,000 let's go down here to when we're 5625 02:55:58,560 --> 02:55:59,560 modifying the selected counter so here 5626 02:56:00,600 --> 02:56:01,600 it is we've got all of these ones so 5627 02:56:02,460 --> 02:56:03,460 when we modify let's fire off the event 5628 02:56:04,020 --> 02:56:05,020 so we go into this event and as usual 5629 02:56:05,760 --> 02:56:06,760 let's use the question mark and then 5630 02:56:07,200 --> 02:56:08,200 call invoke then for the object sender 5631 02:56:09,540 --> 02:56:10,540 it's going to be this so pretty much is 5632 02:56:10,859 --> 02:56:11,859 centered and then for our custom 5633 02:56:12,479 --> 02:56:13,479 eventarics let's construct an object of 5634 02:56:14,520 --> 02:56:15,520 that type so construct a new object and 5635 02:56:17,340 --> 02:56:18,340 then inside we pass in the selected 5636 02:56:18,840 --> 02:56:19,840 counter and we set it to this selected 5637 02:56:20,460 --> 02:56:21,460 counter now don't be confused by the 5638 02:56:22,500 --> 02:56:23,500 fact that we're using the exact same 5639 02:56:23,640 --> 02:56:24,640 name if you actually Mouse over the 5640 02:56:25,620 --> 02:56:26,620 cursor Visual Studio actually helps you 5641 02:56:27,240 --> 02:56:28,240 by telling you which object refers to 5642 02:56:29,279 --> 02:56:30,279 this so with the cursor here note how 5643 02:56:31,740 --> 02:56:32,740 all of these are highlighted but this 5644 02:56:33,300 --> 02:56:34,300 one is not highlighted that's because 5645 02:56:35,160 --> 02:56:36,160 this field this is the film inside the 5646 02:56:37,319 --> 02:56:38,319 unselected counter change event RX 5647 02:56:39,120 --> 02:56:40,120 whereas this one out here is the object 5648 02:56:40,920 --> 02:56:41,920 that we're referencing in here so even 5649 02:56:42,899 --> 02:56:43,899 though these two have the exact same 5650 02:56:44,160 --> 02:56:45,160 name here we're accessing the film 5651 02:56:45,840 --> 02:56:46,840 inside of that and we're assigning it to 5652 02:56:47,700 --> 02:56:48,700 the reference that we have down here 5653 02:56:48,899 --> 02:56:49,899 okay so that's really it we're firing 5654 02:56:50,760 --> 02:56:51,760 off the event when the selected changes 5655 02:56:52,380 --> 02:56:53,380 and we're passing it in and let's also 5656 02:56:54,540 --> 02:56:55,540 make sure to do it over here so let's 5657 02:56:56,220 --> 02:56:57,220 copy and paste some code and there you 5658 02:56:58,380 --> 02:56:59,380 go just like this except of course we 5659 02:57:00,540 --> 02:57:01,540 can already see a bunch of code 5660 02:57:01,800 --> 02:57:02,800 duplication usually that means it's time 5661 02:57:03,899 --> 02:57:04,899 to refactor so let's do that pretty 5662 02:57:05,520 --> 02:57:06,520 quickly let's go down and make a brand 5663 02:57:08,100 --> 02:57:09,100 new function so let's make a private 5664 02:57:10,020 --> 02:57:11,020 Droid let's call it set selected counter 5665 02:57:13,620 --> 02:57:14,620 and we're going to receive a clear 5666 02:57:15,840 --> 02:57:16,840 counter for the selected counter 5667 02:57:20,220 --> 02:57:21,220 then over here we just set this dot 5668 02:57:22,140 --> 02:57:23,140 selected counter so we're modifying the 5669 02:57:23,520 --> 02:57:24,520 member variable with the one that we 5670 02:57:25,080 --> 02:57:26,080 receive on the parameter and then let's 5671 02:57:27,120 --> 02:57:28,120 also fire off the event so let's copy 5672 02:57:28,979 --> 02:57:29,979 paste the event 5673 02:57:30,120 --> 02:57:31,120 just like this the exact same thing okay 5674 02:57:32,520 --> 02:57:33,520 so that's it and now up there instead of 5675 02:57:34,380 --> 02:57:35,380 code duplication we just do this 5676 02:57:36,960 --> 02:57:37,960 so over here we set the clear counter 5677 02:57:38,760 --> 02:57:39,760 just call the function pass in that one 5678 02:57:40,800 --> 02:57:41,800 and get rid of this and on that one just 5679 02:57:43,680 --> 02:57:44,680 pass a null just like this get rid of 5680 02:57:46,439 --> 02:57:47,439 all this and here the same thing just 5681 02:57:48,600 --> 02:57:49,600 pass in no alright so with this our code 5682 02:57:51,060 --> 02:57:52,060 is much cleaner and everything still 5683 02:57:52,500 --> 02:57:53,500 works is all the same so here we have 5684 02:57:54,840 --> 02:57:55,840 everything done on the player side let's 5685 02:57:56,520 --> 02:57:57,520 just get rid of unlock we know we need 5686 02:57:58,200 --> 02:57:59,200 this so we're still handling the 5687 02:58:00,479 --> 02:58:01,479 selected counter logic and then down 5688 02:58:02,279 --> 02:58:03,279 here we're firing off the event now we 5689 02:58:04,380 --> 02:58:05,380 need to do is go over here into the 5690 02:58:06,120 --> 02:58:07,120 selected counter visual script and here 5691 02:58:08,399 --> 02:58:09,399 what we want to do is to listen to that 5692 02:58:09,840 --> 02:58:10,840 event in order to do that we need a 5693 02:58:11,760 --> 02:58:12,760 reference to the player object now so 5694 02:58:14,100 --> 02:58:15,100 far when we've been listening to events 5695 02:58:15,779 --> 02:58:16,779 like for example any player class up 5696 02:58:18,120 --> 02:58:19,120 here we were listening to some events on 5697 02:58:19,979 --> 02:58:20,979 the game input so there you go the 5698 02:58:21,359 --> 02:58:22,359 uninteract action so for the game input 5699 02:58:23,880 --> 02:58:24,880 reference we just added as a serialized 5700 02:58:25,979 --> 02:58:26,979 field 5701 02:58:26,760 --> 02:58:27,760 we did this and then we drag the 5702 02:58:28,439 --> 02:58:29,439 reference directly and technically we 5703 02:58:30,060 --> 02:58:31,060 could do the same thing over here on the 5704 02:58:31,859 --> 02:58:32,859 sound like the counter visual but we're 5705 02:58:33,840 --> 02:58:34,840 going to have like a dozen counters in 5706 02:58:35,520 --> 02:58:36,520 our map so it would be pretty tedious to 5707 02:58:37,560 --> 02:58:38,560 drag and drop the play reference to 5708 02:58:39,060 --> 02:58:40,060 every single one of them so instead of 5709 02:58:41,580 --> 02:58:42,580 using a serialized field another 5710 02:58:43,020 --> 02:58:44,020 approach is to use the Singleton pattern 5711 02:58:44,760 --> 02:58:45,760 this one is an extremely useful 5712 02:58:46,439 --> 02:58:47,439 programming pattern it's very useful for 5713 02:58:48,899 --> 02:58:49,899 things where you only have one instance 5714 02:58:50,580 --> 02:58:51,580 of something 5715 02:58:51,960 --> 02:58:52,960 in this case we're making this game 5716 02:58:53,399 --> 02:58:54,399 single players so we're only ever going 5717 02:58:55,140 --> 02:58:56,140 to have a single player by the way 5718 02:58:57,420 --> 02:58:58,420 here's one obvious quick note like I 5719 02:58:59,939 --> 02:59:00,939 mentioned in the beginning of this 5720 02:59:01,140 --> 02:59:02,140 course 5721 02:59:01,979 --> 02:59:02,979 after this video there's going to be 5722 02:59:03,899 --> 02:59:04,899 another one converting this game into 5723 02:59:05,460 --> 02:59:06,460 multiplayer and in that case we will 5724 02:59:07,319 --> 02:59:08,319 have multiple player instances but this 5725 02:59:09,779 --> 02:59:10,779 is also an excellent reminder of how 5726 02:59:11,340 --> 02:59:12,340 refactoring code is perfectly fine for 5727 02:59:13,859 --> 02:59:14,859 right now for this game it is intended 5728 02:59:15,720 --> 02:59:16,720 as single player so for now we're going 5729 02:59:17,220 --> 02:59:18,220 to use the Singleton pattern then in the 5730 02:59:19,740 --> 02:59:20,740 future when we convert this to 5731 02:59:21,060 --> 02:59:22,060 multiplayer we won't simply refactor 5732 02:59:22,800 --> 02:59:23,800 that logic again don't be afraid of 5733 02:59:25,140 --> 02:59:26,140 refactoring code it's a Perfectly 5734 02:59:27,060 --> 02:59:28,060 Natural part of programming and game 5735 02:59:28,740 --> 02:59:29,740 development okay so let's implement the 5736 02:59:30,779 --> 02:59:31,779 single note pattern this is actually 5737 02:59:32,399 --> 02:59:33,399 super simple the name sounds 5738 02:59:33,840 --> 02:59:34,840 intimidating but it really is very 5739 02:59:35,520 --> 02:59:36,520 simple 5740 02:59:36,359 --> 02:59:37,359 over here on the player script 5741 02:59:38,460 --> 02:59:39,460 let's make a public field this one let's 5742 02:59:41,580 --> 02:59:42,580 make it static 5743 02:59:43,260 --> 02:59:44,260 if you don't know static basically it 5744 02:59:45,300 --> 02:59:46,300 means that this film belongs to the 5745 02:59:47,040 --> 02:59:48,040 player class itself and not to any 5746 02:59:48,779 --> 02:59:49,779 instance of a player so for example if 5747 02:59:50,939 --> 02:59:51,939 you had a hundred players you would have 5748 02:59:53,340 --> 02:59:54,340 a hundred instances of moose mean you 5749 02:59:55,380 --> 02:59:56,380 would have one for each player but there 5750 02:59:57,720 --> 02:59:58,720 would only be a single static film 5751 02:59:59,399 --> 03:00:00,399 because this static film belongs to the 5752 03:00:01,140 --> 03:00:02,140 class itself and not to any instance so 5753 03:00:03,720 --> 03:00:04,720 let's make a field of Thai player and 5754 03:00:05,880 --> 03:00:06,880 then for the name the convention is to 5755 03:00:07,560 --> 03:00:08,560 call it instance and the reason why I'm 5756 03:00:09,779 --> 03:00:10,779 using Pascal case here so capitalized in 5757 03:00:12,120 --> 03:00:13,120 the beginning the reason for that is 5758 03:00:13,859 --> 03:00:14,859 because this is actually not going to be 5759 03:00:15,479 --> 03:00:16,479 a film but instead it's going to be a 5760 03:00:17,340 --> 03:00:18,340 property 5761 03:00:18,359 --> 03:00:19,359 remember the naming rooms that we 5762 03:00:20,220 --> 03:00:21,220 covered in the beginning of this course 5763 03:00:21,680 --> 03:00:22,680 it's very important you follow your 5764 03:00:23,819 --> 03:00:24,819 naming rules always be consistent so 5765 03:00:25,859 --> 03:00:26,859 your code is easier to understand 5766 03:00:27,600 --> 03:00:28,600 so with that said since this is the 5767 03:00:29,100 --> 03:00:30,100 first time we're using a property let me 5768 03:00:30,779 --> 03:00:31,779 quickly explain what it is 5769 03:00:32,399 --> 03:00:33,399 basically it's the exact same thing as a 5770 03:00:34,260 --> 03:00:35,260 regular variable except you can add some 5771 03:00:36,540 --> 03:00:37,540 logic when getting and setting that 5772 03:00:37,979 --> 03:00:38,979 field so here let me write some quick 5773 03:00:40,260 --> 03:00:41,260 code just to show difference between a 5774 03:00:41,880 --> 03:00:42,880 property and a regular field so for a 5775 03:00:44,520 --> 03:00:45,520 regular field you would call this maybe 5776 03:00:45,899 --> 03:00:46,899 instance field something like this so 5777 03:00:47,819 --> 03:00:48,819 this is a regular field 5778 03:00:49,500 --> 03:00:50,500 then you would have some kind of public 5779 03:00:51,660 --> 03:00:52,660 static 5780 03:00:54,899 --> 03:00:55,899 return the player and call it get 5781 03:00:56,700 --> 03:00:57,700 instance field 5782 03:00:59,100 --> 03:01:00,100 then over here you would return the 5783 03:01:00,960 --> 03:01:01,960 instance field 5784 03:01:02,340 --> 03:01:03,340 and then maybe another public static 5785 03:01:04,439 --> 03:01:05,439 void set instance field where you 5786 03:01:07,439 --> 03:01:08,439 receive a player for the instance field 5787 03:01:11,220 --> 03:01:12,220 and you would set the player that 5788 03:01:12,660 --> 03:01:13,660 instance film into this instance field 5789 03:01:14,340 --> 03:01:15,340 so this is how you do this logic with 5790 03:01:16,800 --> 03:01:17,800 fields and now with properties 5791 03:01:19,740 --> 03:01:20,740 you would do public static Flair then 5792 03:01:22,319 --> 03:01:23,319 call it instance 5793 03:01:23,939 --> 03:01:24,939 then on the property itself you open up 5794 03:01:26,040 --> 03:01:27,040 the currently brackets 5795 03:01:27,960 --> 03:01:28,960 inside the property you put a get then 5796 03:01:30,840 --> 03:01:31,840 you return something 5797 03:01:32,340 --> 03:01:33,340 so for that something usually a property 5798 03:01:34,380 --> 03:01:35,380 has a field underneath it 5799 03:01:36,359 --> 03:01:37,359 so you'd have a private static player 5800 03:01:39,840 --> 03:01:40,840 for the instance that's a different name 5801 03:01:41,700 --> 03:01:42,700 from this one 5802 03:01:43,200 --> 03:01:44,200 on the get you would return that 5803 03:01:45,600 --> 03:01:46,600 and on the set 5804 03:01:47,580 --> 03:01:48,580 you would set the instance equals z 5805 03:01:49,380 --> 03:01:50,380 value 5806 03:01:50,760 --> 03:01:51,760 if you're confused here don't worry 5807 03:01:52,319 --> 03:01:53,319 basically I'm just repeating just so you 5808 03:01:54,479 --> 03:01:55,479 can see difference here we have a field 5809 03:01:56,279 --> 03:01:57,279 with a get and a set function so regular 5810 03:01:58,560 --> 03:01:59,560 functions and up here we have a property 5811 03:02:00,840 --> 03:02:01,840 and inside the property the property 5812 03:02:02,520 --> 03:02:03,520 itself has a get and set functions which 5813 03:02:05,220 --> 03:02:06,220 can also do some logic so you can do 5814 03:02:06,899 --> 03:02:07,899 some logic in between or you can just 5815 03:02:09,240 --> 03:02:10,240 return the underlying value so basically 5816 03:02:11,700 --> 03:02:12,700 using your property is pretty much the 5817 03:02:13,680 --> 03:02:14,680 exact same thing as using a separate get 5818 03:02:15,540 --> 03:02:16,540 and set function also one more bonus 5819 03:02:18,300 --> 03:02:19,300 thing which is that c-sharp is smart 5820 03:02:20,760 --> 03:02:21,760 enough to automatically create the 5821 03:02:22,260 --> 03:02:23,260 underlying film for a certain property 5822 03:02:24,359 --> 03:02:25,359 so if you just want to do a get and a 5823 03:02:26,520 --> 03:02:27,520 set then you don't need to Define all 5824 03:02:27,779 --> 03:02:28,779 this you can just Define a property and 5825 03:02:30,479 --> 03:02:31,479 then inside you can just do get and set 5826 03:02:33,840 --> 03:02:34,840 and there you go this code here works 5827 03:02:35,819 --> 03:02:36,819 the exact same thing as we had 5828 03:02:37,140 --> 03:02:38,140 previously which in turn is the exact 5829 03:02:39,060 --> 03:02:40,060 same thing as all the code we have here 5830 03:02:40,560 --> 03:02:41,560 with the getter and a Setter function so 5831 03:02:42,660 --> 03:02:43,660 here it is a valid functional c-sharp 5832 03:02:44,939 --> 03:02:45,939 property now I have to say that 5833 03:02:46,620 --> 03:02:47,620 personally I very very rarely use 5834 03:02:48,720 --> 03:02:49,720 properties in fact the only place where 5835 03:02:51,000 --> 03:02:52,000 I use them is over here on the Singleton 5836 03:02:52,740 --> 03:02:53,740 pattern for everything else I normally 5837 03:02:55,140 --> 03:02:56,140 use regular films with get and set 5838 03:02:56,880 --> 03:02:57,880 functions personally that's just the way 5839 03:02:58,800 --> 03:02:59,800 that I like to code but that's really 5840 03:03:00,660 --> 03:03:01,660 just personal preference so if you don't 5841 03:03:02,939 --> 03:03:03,939 like to use properties then go ahead and 5842 03:03:04,560 --> 03:03:05,560 use them anyway so the reason why I like 5843 03:03:07,319 --> 03:03:08,319 using a property specifically for the 5844 03:03:09,120 --> 03:03:10,120 single pattern is because the implicit 5845 03:03:11,700 --> 03:03:12,700 implementation allows you to do 5846 03:03:13,080 --> 03:03:14,080 something really nice again remember to 5847 03:03:15,300 --> 03:03:16,300 go on with clean code we want to 5848 03:03:17,760 --> 03:03:18,760 minimize complexity and the best way to 5849 03:03:19,500 --> 03:03:20,500 do that is minimize access here if we 5850 03:03:21,960 --> 03:03:22,960 set this property and we set it as 5851 03:03:23,460 --> 03:03:24,460 public then that means that any other 5852 03:03:25,380 --> 03:03:26,380 class can both get and set so anyone 5853 03:03:27,899 --> 03:03:28,899 else can have both read and write access 5854 03:03:29,779 --> 03:03:30,779 so we have the exact same problems that 5855 03:03:32,279 --> 03:03:33,279 I warned you about when I spoke about 5856 03:03:33,600 --> 03:03:34,600 why you should not make everything 5857 03:03:34,920 --> 03:03:35,920 public and of course if we make this 5858 03:03:37,200 --> 03:03:38,200 private 5859 03:03:38,340 --> 03:03:39,340 then at that point we kind of lose the 5860 03:03:40,140 --> 03:03:41,140 purpose of our Singleton since no one 5861 03:03:41,700 --> 03:03:42,700 else will be able to access this 5862 03:03:43,020 --> 03:03:44,020 basically we want to be able to access 5863 03:03:45,060 --> 03:03:46,060 this reference from classes outside of 5864 03:03:46,859 --> 03:03:47,859 this one we just don't want those 5865 03:03:48,420 --> 03:03:49,420 classes to also have right access 5866 03:03:50,700 --> 03:03:51,700 now thankfully properties have an 5867 03:03:52,560 --> 03:03:53,560 excellent thing which is you can Define 5868 03:03:53,760 --> 03:03:54,760 accessors for here both the get and the 5869 03:03:55,800 --> 03:03:56,800 set so we can make the property itself 5870 03:03:57,840 --> 03:03:58,840 public which means by default both of 5871 03:04:00,420 --> 03:04:01,420 these won't be public but then we can 5872 03:04:02,399 --> 03:04:03,399 also add the accessor over here private 5873 03:04:04,680 --> 03:04:05,680 which in turn means that the get won't 5874 03:04:06,359 --> 03:04:07,359 be public so any other class can get 5875 03:04:08,220 --> 03:04:09,220 this but private means that only this 5876 03:04:10,319 --> 03:04:11,319 class can set it this way we have the 5877 03:04:12,840 --> 03:04:13,840 exact level of accessibility that we 5878 03:04:14,640 --> 03:04:15,640 want this is the reason why for this 5879 03:04:16,500 --> 03:04:17,500 specific use case properties are very 5880 03:04:18,180 --> 03:04:19,180 useful with just this one line of code 5881 03:04:20,520 --> 03:04:21,520 we already have our instance with the 5882 03:04:22,200 --> 03:04:23,200 perfect level of accessibility 5883 03:04:24,060 --> 03:04:25,060 so now that we have this field to set it 5884 03:04:27,000 --> 03:04:28,000 let's make a simple awake so let's go 5885 03:04:28,800 --> 03:04:29,800 over here private void awake and on 5886 03:04:30,779 --> 03:04:31,779 awake we just set instance equals this 5887 03:04:33,479 --> 03:04:34,479 however remember that a key point of the 5888 03:04:35,700 --> 03:04:36,700 Singleton pattern is you only have a 5889 03:04:37,740 --> 03:04:38,740 single instance of something 5890 03:04:39,600 --> 03:04:40,600 so in this case we should never have 5891 03:04:41,399 --> 03:04:42,399 more than one player if we do then 5892 03:04:43,200 --> 03:04:44,200 something went wrong 5893 03:04:44,640 --> 03:04:45,640 so we can add a nice safety feature here 5894 03:04:46,859 --> 03:04:47,859 let's just check if instance if it is 5895 03:04:50,100 --> 03:04:51,100 not known meaning it has already been 5896 03:04:51,779 --> 03:04:52,779 set to something 5897 03:04:53,160 --> 03:04:54,160 if so then that's an error something bad 5898 03:04:55,260 --> 03:04:56,260 happened similar to a debug.log error 5899 03:04:58,380 --> 03:04:59,380 because this should never happen so 5900 03:05:00,359 --> 03:05:01,359 let's say there is more than one player 5901 03:05:03,120 --> 03:05:04,120 instance this way we have a nice safety 5902 03:05:05,640 --> 03:05:06,640 check just in case something goes wrong 5903 03:05:07,340 --> 03:05:08,340 alright so that's really it for the 5904 03:05:09,540 --> 03:05:10,540 Singleton pattern we just defined a 5905 03:05:11,220 --> 03:05:12,220 property with a public yet in a private 5906 03:05:13,080 --> 03:05:14,080 set and on the Wake we just set the 5907 03:05:14,939 --> 03:05:15,939 instance that's it as you can see it's 5908 03:05:17,040 --> 03:05:18,040 super simple and now for the really 5909 03:05:19,140 --> 03:05:20,140 useful part over here on the selected 5910 03:05:21,540 --> 03:05:22,540 counter visual now we can access the 5911 03:05:23,760 --> 03:05:24,760 Singleton instance in a super easy way 5912 03:05:25,560 --> 03:05:26,560 let's make a private void start and on 5913 03:05:28,439 --> 03:05:29,439 start we just access the player class 5914 03:05:30,180 --> 03:05:31,180 and from the class we can access the 5915 03:05:32,460 --> 03:05:33,460 static instance so we can access the 5916 03:05:33,899 --> 03:05:34,899 Singleton and now we can listen to The 5917 03:05:36,060 --> 03:05:37,060 unselected Counter event and over here 5918 03:05:38,279 --> 03:05:39,279 by default Visual Studio gives this 5919 03:05:40,380 --> 03:05:41,380 function the name of the event and also 5920 03:05:42,180 --> 03:05:43,180 the property 5921 03:05:43,200 --> 03:05:44,200 this is in the very descriptive name so 5922 03:05:45,060 --> 03:05:46,060 I like to rename this so control RR and 5923 03:05:47,819 --> 03:05:48,819 just rename the instance here instead of 5924 03:05:49,680 --> 03:05:50,680 instance let's rename it to player okay 5925 03:05:51,840 --> 03:05:52,840 great so over here we can listen to this 5926 03:05:54,000 --> 03:05:55,000 event 5927 03:05:54,720 --> 03:05:55,720 however here is yet another extremely 5928 03:05:56,580 --> 03:05:57,580 important thing note how I made this on 5929 03:05:58,859 --> 03:05:59,859 start that is very important if you do 5930 03:06:01,319 --> 03:06:02,319 this over here on a week instead of 5931 03:06:03,060 --> 03:06:04,060 start and over here on the player you're 5932 03:06:05,100 --> 03:06:06,100 also setting the instance on awake if 5933 03:06:07,260 --> 03:06:08,260 you do that basically there is a chance 5934 03:06:08,819 --> 03:06:09,819 that this code won't run before this 5935 03:06:10,680 --> 03:06:11,680 code and if that happens well then this 5936 03:06:12,840 --> 03:06:13,840 one the player instance has not been set 5937 03:06:14,399 --> 03:06:15,399 yet so this will be null and don't throw 5938 03:06:16,319 --> 03:06:17,319 a known reference exception now whether 5939 03:06:18,420 --> 03:06:19,420 this happens or not it's actually 5940 03:06:19,680 --> 03:06:20,680 somewhat random it depends on the order 5941 03:06:22,260 --> 03:06:23,260 in which Unity decides to run both these 5942 03:06:24,240 --> 03:06:25,240 scripts if Unity decides to run the 5943 03:06:26,580 --> 03:06:27,580 player first and this one second 5944 03:06:29,340 --> 03:06:30,340 if that happens then there's no problem 5945 03:06:30,899 --> 03:06:31,899 but if Unity decides to run this first 5946 03:06:32,880 --> 03:06:33,880 and then this one then we have a problem 5947 03:06:34,500 --> 03:06:35,500 let me do a quick test and see if in my 5948 03:06:36,359 --> 03:06:37,359 case it triggers that error any up in my 5949 03:06:38,520 --> 03:06:39,520 case it did trigger that error so here 5950 03:06:40,439 --> 03:06:41,439 we have a no reference exception 5951 03:06:42,660 --> 03:06:43,660 any app it is being fired on this line 5952 03:06:44,460 --> 03:06:45,460 now one solution to this problem is you 5953 03:06:46,800 --> 03:06:47,800 can tell Unity specifically which order 5954 03:06:48,479 --> 03:06:49,479 the script should run in so you can go 5955 03:06:50,700 --> 03:06:51,700 up here into edit then go into the 5956 03:06:52,620 --> 03:06:53,620 project settings 5957 03:06:53,760 --> 03:06:54,760 then on the left side you've got 5958 03:06:55,380 --> 03:06:56,380 something called The Script execution 5959 03:06:56,819 --> 03:06:57,819 order and basically over here you can 5960 03:06:58,979 --> 03:06:59,979 set the order in which all of these 5961 03:07:00,420 --> 03:07:01,420 scripts run so if you were to make the 5962 03:07:02,760 --> 03:07:03,760 player script run before the default 5963 03:07:04,319 --> 03:07:05,319 time that would make sure that even 5964 03:07:06,120 --> 03:07:07,120 though both these scripts aren't awake 5965 03:07:07,560 --> 03:07:08,560 this one would run before this one so 5966 03:07:09,359 --> 03:07:10,359 that would fix that problem however you 5967 03:07:11,640 --> 03:07:12,640 should really only use this approach in 5968 03:07:12,960 --> 03:07:13,960 the last case possible where there 5969 03:07:14,520 --> 03:07:15,520 really is no other way in this case we 5970 03:07:16,920 --> 03:07:17,920 do have another better Wing personally I 5971 03:07:19,500 --> 03:07:20,500 have a very simple room that I like to 5972 03:07:21,000 --> 03:07:22,000 follow that helps solve this issue as 5973 03:07:23,040 --> 03:07:24,040 you know Unity has both an awake and a 5974 03:07:25,260 --> 03:07:26,260 start 5975 03:07:26,100 --> 03:07:27,100 and all of the awakes on all the objects 5976 03:07:28,319 --> 03:07:29,319 will all run before all these starts so 5977 03:07:31,020 --> 03:07:32,020 the simple rule that I follow is that I 5978 03:07:32,700 --> 03:07:33,700 use a wake for the initialization of 5979 03:07:34,439 --> 03:07:35,439 that script and for any external 5980 03:07:36,779 --> 03:07:37,779 reference for that I use it on start so 5981 03:07:39,420 --> 03:07:40,420 in this case for initializing the player 5982 03:07:41,220 --> 03:07:42,220 and setting the instance that will lead 5983 03:07:43,260 --> 03:07:44,260 to the initialization of the player so 5984 03:07:44,760 --> 03:07:45,760 let's do it on the Wake whereas over 5985 03:07:46,439 --> 03:07:47,439 here on the visual 5986 03:07:47,939 --> 03:07:48,939 since here we're going to access the 5987 03:07:49,680 --> 03:07:50,680 player which is an external reference 5988 03:07:51,359 --> 03:07:52,359 for this one instead of doing it on Wake 5989 03:07:53,760 --> 03:07:54,760 let's do it on start this way we are 5990 03:07:56,580 --> 03:07:57,580 guaranteed to make sure that this 5991 03:07:58,020 --> 03:07:59,020 instance has been set okay so with all 5992 03:08:00,420 --> 03:08:01,420 of that here we have our instance so 5993 03:08:01,800 --> 03:08:02,800 that works great and we have our events 5994 03:08:03,300 --> 03:08:04,300 so that's great then here we have our 5995 03:08:05,340 --> 03:08:06,340 event and inside we've got our event 5996 03:08:07,020 --> 03:08:08,020 arcs so we can go inside the event arcs 5997 03:08:09,720 --> 03:08:10,720 object and inside we have our selected 5998 03:08:11,580 --> 03:08:12,580 counter so we need to do is just compare 5999 03:08:14,160 --> 03:08:15,160 which counter this Vision belongs to 6000 03:08:16,859 --> 03:08:17,859 so let's actually make a film up here so 6001 03:08:19,020 --> 03:08:20,020 as usual let's make a serialized film of 6002 03:08:21,660 --> 03:08:22,660 type clear counter 6003 03:08:25,080 --> 03:08:26,080 so we have this one and before we go 6004 03:08:27,060 --> 03:08:28,060 into the editor just make sure it 6005 03:08:28,200 --> 03:08:29,200 compiles and let's comment this out so 6006 03:08:30,120 --> 03:08:31,120 now let's go back into the editor and 6007 03:08:32,340 --> 03:08:33,340 over here let's drag the reference but 6008 03:08:34,020 --> 03:08:35,020 again remember we're working with a 6009 03:08:35,640 --> 03:08:36,640 prefab so let's click on open to go 6010 03:08:37,620 --> 03:08:38,620 inside the prefab and now once inside it 6011 03:08:40,500 --> 03:08:41,500 let's select the selected game object 6012 03:08:42,420 --> 03:08:43,420 and just drag the clear counter 6013 03:08:44,100 --> 03:08:45,100 reference okay great let's go back 6014 03:08:46,200 --> 03:08:47,200 outside and save the changes all right 6015 03:08:48,120 --> 03:08:49,120 so now here in the code it's actually 6016 03:08:49,740 --> 03:08:50,740 very simple so we just do an if 6017 03:08:52,080 --> 03:08:53,080 if the selected counter matches this 6018 03:08:54,180 --> 03:08:55,180 clear counter 6019 03:08:55,680 --> 03:08:56,680 if so then we want to show this visual 6020 03:08:57,540 --> 03:08:58,540 if not we want to hide it so let's also 6021 03:08:59,760 --> 03:09:00,760 add a reference for that visual so let's 6022 03:09:02,100 --> 03:09:03,100 add another serialized field of type 6023 03:09:03,600 --> 03:09:04,600 game object for the visual game object 6024 03:09:08,520 --> 03:09:09,520 then back in the editor again let's go 6025 03:09:10,319 --> 03:09:11,319 inside the prefab and on the select 6026 03:09:11,819 --> 03:09:12,819 let's drag the channel kitchen counter 6027 03:09:13,560 --> 03:09:14,560 so drag down that is the visual game 6028 03:09:15,300 --> 03:09:16,300 object okay let's go back save and back 6029 03:09:18,000 --> 03:09:19,000 in the code here let's make some simple 6030 03:09:19,859 --> 03:09:20,859 show and hide functions so private void 6031 03:09:21,960 --> 03:09:22,960 show 6032 03:09:22,859 --> 03:09:23,859 and a private void hides 6033 03:09:25,439 --> 03:09:26,439 and now on the show just going to visual 6034 03:09:27,540 --> 03:09:28,540 game object and call set active so this 6035 03:09:30,060 --> 03:09:31,060 enables or disables the game object so 6036 03:09:32,279 --> 03:09:33,279 for sure let's set it to true and for 6037 03:09:34,380 --> 03:09:35,380 hiding let's set it back into fonts okay 6038 03:09:36,300 --> 03:09:37,300 so now it's super simple if the selected 6039 03:09:38,160 --> 03:09:39,160 counter is this counter then let's show 6040 03:09:39,840 --> 03:09:40,840 the visual if it is not then let's hide 6041 03:09:42,540 --> 03:09:43,540 the visual alright that's it super 6042 03:09:44,580 --> 03:09:45,580 simple let's test so here we are and if 6043 03:09:47,160 --> 03:09:48,160 I approach that counter yep there you go 6044 03:09:49,080 --> 03:09:50,080 look at that nice selected Visual and if 6045 03:09:50,939 --> 03:09:51,939 I get into this one yep there you go I 6046 03:09:52,319 --> 03:09:53,319 can see it all right great so here we 6047 03:09:55,920 --> 03:09:56,920 had a really nice visual to our selected 6048 03:09:58,080 --> 03:09:59,080 counter and more importantly we'll learn 6049 03:10:00,120 --> 03:10:01,120 about the super useful Singleton pattern 6050 03:10:02,160 --> 03:10:03,160 as well as learning about c-sharp 6051 03:10:04,020 --> 03:10:05,020 properties and a very helpful room for 6052 03:10:06,420 --> 03:10:07,420 how to avoid code timing issues so this 6053 03:10:08,939 --> 03:10:09,939 was a really detailed really important 6054 03:10:10,500 --> 03:10:11,500 lecture if you're feeling confused about 6055 03:10:12,540 --> 03:10:13,540 anything go ahead watch it again or just 6056 03:10:14,700 --> 03:10:15,700 post a question in the comments and I'll 6057 03:10:16,020 --> 03:10:17,020 do my best to help so with all of this 6058 03:10:18,120 --> 03:10:19,120 this is all great we have these unlike 6059 03:10:19,800 --> 03:10:20,800 the counter and we can see which one is 6060 03:10:21,300 --> 03:10:22,300 actually being selected then by pressing 6061 03:10:23,460 --> 03:10:24,460 a button we can actually interact with 6062 03:10:25,200 --> 03:10:26,200 it so I can move and interact with any 6063 03:10:27,000 --> 03:10:28,000 of these counters but right now just 6064 03:10:29,399 --> 03:10:30,399 interacting with them doesn't really do 6065 03:10:30,840 --> 03:10:31,840 anything so the next thing we need is to 6066 03:10:33,120 --> 03:10:34,120 create some proper objects for all of 6067 03:10:34,680 --> 03:10:35,680 our ingredients so we can later pick 6068 03:10:36,479 --> 03:10:37,479 them up and drop them on counters so 6069 03:10:38,580 --> 03:10:39,580 let's begin doing that in the next 6070 03:10:40,080 --> 03:10:41,080 lecture 6071 03:10:41,819 --> 03:10:42,819 hey again quick intermission your pass 6072 03:10:43,979 --> 03:10:44,979 C15 lecture marks so congratulations 6073 03:10:45,859 --> 03:10:46,859 looking at my regular core stats it 6074 03:10:48,420 --> 03:10:49,420 seems about 80 of people give up by this 6075 03:10:50,580 --> 03:10:51,580 point so great job with sticking with it 6076 03:10:52,439 --> 03:10:53,439 the difficulty in complexity is 6077 03:10:54,720 --> 03:10:55,720 increasing over the lectures so I just 6078 03:10:56,340 --> 03:10:57,340 want to check in to make sure you're 6079 03:10:57,540 --> 03:10:58,540 understanding everything remember to 6080 03:10:59,760 --> 03:11:00,760 post in the comments if you need extra 6081 03:11:01,080 --> 03:11:02,080 clarification on anything and I'll do my 6082 03:11:03,240 --> 03:11:04,240 best to answer 6083 03:11:04,439 --> 03:11:05,439 also check the website to see what 6084 03:11:06,120 --> 03:11:07,120 questions others have asked and of 6085 03:11:07,859 --> 03:11:08,859 course remember this is your Learning 6086 03:11:09,300 --> 03:11:10,300 Journey you're not competing with anyone 6087 03:11:10,920 --> 03:11:11,920 but yourself so take your time re-watch 6088 03:11:13,620 --> 03:11:14,620 some lectures if you need to just focus 6089 03:11:15,300 --> 03:11:16,300 on learning okay let's go to the next 6090 03:11:17,640 --> 03:11:18,640 lecture 6091 03:11:19,080 --> 03:11:20,080 hello and welcome I'm your code monkey 6092 03:11:21,060 --> 03:11:22,060 in this lecture we're going to learn how 6093 03:11:23,160 --> 03:11:24,160 to create the kitchen objects like the 6094 03:11:25,080 --> 03:11:26,080 various ingredients okay so far we have 6095 03:11:27,479 --> 03:11:28,479 our player we can walk around I can 6096 03:11:29,460 --> 03:11:30,460 approach each of these counters and I 6097 03:11:31,140 --> 03:11:32,140 can interact with now the next one is to 6098 03:11:33,000 --> 03:11:34,000 create objects the player can pick up 6099 03:11:34,620 --> 03:11:35,620 and drop when interacting with a clear 6100 03:11:36,300 --> 03:11:37,300 counter so let's begin by making the 6101 03:11:38,520 --> 03:11:39,520 actual objects so let's create a new 6102 03:11:40,319 --> 03:11:41,319 empty game object call this one the 6103 03:11:42,300 --> 03:11:43,300 Tomato then again as usual let's 6104 03:11:44,220 --> 03:11:45,220 separate the visual so in the included 6105 03:11:46,560 --> 03:11:47,560 assets let's go inside of it then we've 6106 03:11:48,420 --> 03:11:49,420 got the prefab visuals and we've got the 6107 03:11:50,160 --> 03:11:51,160 kitchen objects visuals and inside we've 6108 03:11:52,439 --> 03:11:53,439 got all of the ingredients so let's just 6109 03:11:54,479 --> 03:11:55,479 find the Tomato Visual and drag it as a 6110 03:11:56,220 --> 03:11:57,220 child of the tomato and again as usual 6111 03:11:58,319 --> 03:11:59,319 make sure to put on position low 6112 03:11:59,880 --> 03:12:00,880 composition zero zero zero and for the 6113 03:12:02,640 --> 03:12:03,640 main one let's put it on a y of zero and 6114 03:12:04,740 --> 03:12:05,740 just push it a little bit off to the 6115 03:12:06,000 --> 03:12:07,000 side just so we can see okay great 6116 03:12:07,979 --> 03:12:08,979 now this one is obviously not going to 6117 03:12:10,140 --> 03:12:11,140 exist over here in our world instead 6118 03:12:11,700 --> 03:12:12,700 we're going to spawn it so let's make it 6119 03:12:13,920 --> 03:12:14,920 a prefab let's just drag it over here 6120 03:12:15,479 --> 03:12:16,479 into our prefabs okay there it is let's 6121 03:12:18,120 --> 03:12:19,120 delete it from our scene and actually on 6122 03:12:20,700 --> 03:12:21,700 our prefabs let's make a nice folder to 6123 03:12:22,680 --> 03:12:23,680 keep things nicely separated 6124 03:12:24,479 --> 03:12:25,479 so inside the prefabs let's make a 6125 03:12:26,399 --> 03:12:27,399 subfolder 6126 03:12:27,899 --> 03:12:28,899 currently the kitchen objects 6127 03:12:30,300 --> 03:12:31,300 let's put the tomato inside of it and 6128 03:12:32,399 --> 03:12:33,399 let's also make another folder 6129 03:12:34,380 --> 03:12:35,380 for the counters and let's put the clear 6130 03:12:36,660 --> 03:12:37,660 counter inside of it okay so everything 6131 03:12:38,279 --> 03:12:39,279 is nicely organized all right now that 6132 03:12:40,560 --> 03:12:41,560 we have this let's go inside our clear 6133 03:12:42,720 --> 03:12:43,720 counter script and over here let's add a 6134 03:12:45,300 --> 03:12:46,300 simple reference to our prefab 6135 03:12:47,460 --> 03:12:48,460 so let's make a type transform called 6136 03:12:49,920 --> 03:12:50,920 the Tomato prefab 6137 03:12:52,740 --> 03:12:53,740 by the way here you could make this 6138 03:12:54,479 --> 03:12:55,479 prefab reference of type game object 6139 03:12:56,340 --> 03:12:57,340 which type you use in this scenario is 6140 03:12:58,260 --> 03:12:59,260 pretty interchangeable I talked about 6141 03:13:00,240 --> 03:13:01,240 those differences in another video so 6142 03:13:02,279 --> 03:13:03,279 when using prefabs using them as 6143 03:13:04,319 --> 03:13:05,319 transforms or game objects that's pretty 6144 03:13:06,000 --> 03:13:07,000 much personal preference and personally 6145 03:13:07,800 --> 03:13:08,800 I just prefer to use them as transforms 6146 03:13:10,020 --> 03:13:11,020 okay so we have this let's just make 6147 03:13:11,819 --> 03:13:12,819 this a serialized field so we can set it 6148 03:13:13,620 --> 03:13:14,620 in the editor and over here in the 6149 03:13:15,540 --> 03:13:16,540 editor let's open up go inside the 6150 03:13:17,580 --> 03:13:18,580 counter prefab and just drag the Tomato 6151 03:13:19,439 --> 03:13:20,439 reference okay great let's go back 6152 03:13:21,240 --> 03:13:22,240 outside save now back in the code here 6153 03:13:24,000 --> 03:13:25,000 when the player interacts with it let's 6154 03:13:25,859 --> 03:13:26,859 just spawn it so let's call instantiate 6155 03:13:27,899 --> 03:13:28,899 pass in the Tomato prefab and now here 6156 03:13:30,840 --> 03:13:31,840 is a good question which is where 6157 03:13:32,340 --> 03:13:33,340 exactly do we spawn this we don't want 6158 03:13:34,800 --> 03:13:35,800 to spawn on this counter's origin 6159 03:13:36,479 --> 03:13:37,479 remember that the counter the way we set 6160 03:13:38,700 --> 03:13:39,700 it up the origin on the actual object is 6161 03:13:40,560 --> 03:13:41,560 over there on the bottom we don't want 6162 03:13:42,600 --> 03:13:43,600 to spawn the tomato inside the mesh that 6163 03:13:44,580 --> 03:13:45,580 would not make sense instead what we 6164 03:13:46,500 --> 03:13:47,500 want is to spawn up here so the next 6165 03:13:48,779 --> 03:13:49,779 question is okay so how do we get this 6166 03:13:50,460 --> 03:13:51,460 point on top of the counter one approach 6167 03:13:52,500 --> 03:13:53,500 would be to use a vector 3 directly in 6168 03:13:54,359 --> 03:13:55,359 the code that would work but not very 6169 03:13:56,279 --> 03:13:57,279 usable so a more designer friendly 6170 03:13:58,620 --> 03:13:59,620 method is to Simply use an empty game 6171 03:14:00,240 --> 03:14:01,240 object as a Target so on the counter 6172 03:14:02,460 --> 03:14:03,460 let's first go inside our prefab 6173 03:14:04,859 --> 03:14:05,859 and over here let's create an empty game 6174 03:14:06,720 --> 03:14:07,720 object inside of it let's call this the 6175 03:14:09,120 --> 03:14:10,120 counter top point 6176 03:14:10,979 --> 03:14:11,979 let's make sure to leave this one as 6177 03:14:12,479 --> 03:14:13,479 empty so no components just a transform 6178 03:14:14,520 --> 03:14:15,520 and now let's just position it so let's 6179 03:14:16,439 --> 03:14:17,439 lift it up by just about enough so let's 6180 03:14:18,540 --> 03:14:19,540 make sure we see so there you go just 6181 03:14:21,000 --> 03:14:22,000 about that so let's put it on position a 6182 03:14:23,640 --> 03:14:24,640 y of 1.3 all right so this point is 6183 03:14:26,340 --> 03:14:27,340 going to be our spawn point let's make 6184 03:14:28,260 --> 03:14:29,260 sure to save the prefab 6185 03:14:29,819 --> 03:14:30,819 then back in the code here let's add a 6186 03:14:31,680 --> 03:14:32,680 reference to our point 6187 03:14:33,180 --> 03:14:34,180 and for reference let's also use a 6188 03:14:35,100 --> 03:14:36,100 transform reference currently the 6189 03:14:37,260 --> 03:14:38,260 countertop point 6190 03:14:39,479 --> 03:14:40,479 okay now let's just come this line just 6191 03:14:41,580 --> 03:14:42,580 so the code compiles so we can drag the 6192 03:14:43,020 --> 03:14:44,020 reference back in the editor inside the 6193 03:14:45,000 --> 03:14:46,000 prefab let's just write the countertop 6194 03:14:46,680 --> 03:14:47,680 Point reference okay great so now here 6195 03:14:49,140 --> 03:14:50,140 when we call instantiate let's 6196 03:14:51,060 --> 03:14:52,060 instantiate it inside the countertop 6197 03:14:53,220 --> 03:14:54,220 point so this one's found the object so 6198 03:14:55,319 --> 03:14:56,319 let's say the transform for the Tomato 6199 03:14:57,420 --> 03:14:58,420 transform 6200 03:14:59,100 --> 03:15:00,100 and then we go inside this one and let's 6201 03:15:01,140 --> 03:15:02,140 just make sure we position it correctly 6202 03:15:02,939 --> 03:15:03,939 so let's put it on in local position of 6203 03:15:04,740 --> 03:15:05,740 vector 3.0 so this one put the object 6204 03:15:07,020 --> 03:15:08,020 exactly on top of our countertop point 6205 03:15:09,180 --> 03:15:10,180 also here very important don't make a 6206 03:15:11,640 --> 03:15:12,640 mistake make sure you're modifying the 6207 03:15:13,439 --> 03:15:14,439 low composition and not the global 6208 03:15:15,300 --> 03:15:16,300 position okay so with this let's test 6209 03:15:17,880 --> 03:15:18,880 over here in the editor let's go back 6210 03:15:19,920 --> 03:15:20,920 save our prefab and hit on play so here 6211 03:15:22,080 --> 03:15:23,080 we are let's approach a counter and 6212 03:15:23,580 --> 03:15:24,580 interact with it and if there you go it 6213 03:15:25,319 --> 03:15:26,319 does work the Tomato was indeed spawned 6214 03:15:27,240 --> 03:15:28,240 all right awesome okay so with this we 6215 03:15:29,700 --> 03:15:30,700 have pretty much our Basics working 6216 03:15:31,680 --> 03:15:32,680 we can move up to a counter we can 6217 03:15:33,960 --> 03:15:34,960 interact with it and spawn an object but 6218 03:15:36,000 --> 03:15:37,000 now let's say that we want to spawn a 6219 03:15:37,740 --> 03:15:38,740 different object so let's say now we 6220 03:15:39,300 --> 03:15:40,300 want to spawn some genes first of all 6221 03:15:41,220 --> 03:15:42,220 let's make the actual object so on the 6222 03:15:43,080 --> 03:15:44,080 Tomato let's press Ctrl D to duplicate 6223 03:15:45,060 --> 03:15:46,060 this one let's rename this to the cheese 6224 03:15:47,220 --> 03:15:48,220 block and let's go inside of it 6225 03:15:50,279 --> 03:15:51,279 now in here instead of the Tomato visual 6226 03:15:52,620 --> 03:15:53,620 let's drag here it is the cheeseboard 6227 03:15:54,600 --> 03:15:55,600 visual so let's use this one instead 6228 03:15:56,460 --> 03:15:57,460 okay there's our nice visual 6229 03:15:58,620 --> 03:15:59,620 let's make sure to save the prefab and 6230 03:16:00,420 --> 03:16:01,420 go back out and now let's say that we 6231 03:16:02,520 --> 03:16:03,520 want this one to spawn a tomato and this 6232 03:16:04,200 --> 03:16:05,200 one on the left to spawn some cheese so 6233 03:16:06,420 --> 03:16:07,420 let's override the prefab and over here 6234 03:16:07,920 --> 03:16:08,920 drag the cheese block and now if we hit 6235 03:16:10,200 --> 03:16:11,200 on play 6236 03:16:11,100 --> 03:16:12,100 can go up to this one yep there's a 6237 03:16:12,960 --> 03:16:13,960 tomato go this one any up there's some 6238 03:16:14,460 --> 03:16:15,460 cheese okay so it all looks great but 6239 03:16:17,340 --> 03:16:18,340 now let's say we want to know what 6240 03:16:18,779 --> 03:16:19,779 object we just spawned like what object 6241 03:16:20,880 --> 03:16:21,880 is on top of this spawn transform just 6242 03:16:22,979 --> 03:16:23,979 like this in the code all we have is a 6243 03:16:24,840 --> 03:16:25,840 transform reference so with this the 6244 03:16:27,180 --> 03:16:28,180 only way to know what type we spawned 6245 03:16:28,859 --> 03:16:29,859 would be if we had different prefabs for 6246 03:16:30,960 --> 03:16:31,960 every single object then we could 6247 03:16:32,700 --> 03:16:33,700 compare them one by one and see which 6248 03:16:34,319 --> 03:16:35,319 one this matches but then let's say what 6249 03:16:36,600 --> 03:16:37,600 if we wanted an actual string for the 6250 03:16:38,520 --> 03:16:39,520 object well then we would need to add 6251 03:16:40,800 --> 03:16:41,800 tons of fields for all these strings for 6252 03:16:42,720 --> 03:16:43,720 all of the objects then what about an 6253 03:16:45,000 --> 03:16:46,000 icon for each type once again we would 6254 03:16:46,859 --> 03:16:47,859 need tons of fields each one for each 6255 03:16:49,020 --> 03:16:50,020 icon but if we did it just like that 6256 03:16:51,060 --> 03:16:52,060 with a bunch of lists then they would be 6257 03:16:52,680 --> 03:16:53,680 separate that's not very good we should 6258 03:16:54,960 --> 03:16:55,960 have a proper way of defining our object 6259 03:16:56,819 --> 03:16:57,819 types and all the data related to them 6260 03:16:59,279 --> 03:17:00,279 so this is exactly where scriptable 6261 03:17:01,200 --> 03:17:02,200 objects come in these are objects you 6262 03:17:03,420 --> 03:17:04,420 can create in your project funnels which 6263 03:17:05,100 --> 03:17:06,100 are perfect for anything where you have 6264 03:17:06,720 --> 03:17:07,720 multiple instances of a type like for 6265 03:17:08,939 --> 03:17:09,939 example multiple weapons multiple armors 6266 03:17:11,040 --> 03:17:12,040 multiple recipes or maybe multiple 6267 03:17:13,140 --> 03:17:14,140 ingredients as usual I have a dedicated 6268 03:17:15,600 --> 03:17:16,600 video on script along objects they are 6269 03:17:17,760 --> 03:17:18,760 super useful definitely watch out for 6270 03:17:19,260 --> 03:17:20,260 more detail over here on let's just use 6271 03:17:21,000 --> 03:17:22,000 them so the first thing we're going to 6272 03:17:22,859 --> 03:17:23,859 need is to actually Define the type and 6273 03:17:24,660 --> 03:17:25,660 we do that in a c-sharp script so in our 6274 03:17:27,000 --> 03:17:28,000 scripts folder let's create new c-sharp 6275 03:17:28,620 --> 03:17:29,620 script call this the kitchen object so 6276 03:17:32,279 --> 03:17:33,279 now personally so is just what I like to 6277 03:17:34,680 --> 03:17:35,680 open to my scriptable object definitions 6278 03:17:36,600 --> 03:17:37,600 just to make it very clear that it's a 6279 03:17:38,640 --> 03:17:39,640 script mode object however this is not a 6280 03:17:40,859 --> 03:17:41,859 requirement it's just a naming room that 6281 03:17:42,540 --> 03:17:43,540 I like to follow and we're calling this 6282 03:17:44,340 --> 03:17:45,340 kitchen object because we're going to 6283 03:17:45,720 --> 03:17:46,720 use this to Define any kitchen object we 6284 03:17:47,700 --> 03:17:48,700 want to interact with 6285 03:17:49,020 --> 03:17:50,020 so that's going to be our ingredients 6286 03:17:50,760 --> 03:17:51,760 like for example the tomato and cheese 6287 03:17:52,140 --> 03:17:53,140 but also things like a plate and then 6288 03:17:54,540 --> 03:17:55,540 potentially you could Implement things 6289 03:17:55,920 --> 03:17:56,920 like a frying pan or framing signature 6290 03:17:57,840 --> 03:17:58,840 or anything like that so it's going to 6291 03:17:59,640 --> 03:18:00,640 represent any kind of kitchen object the 6292 03:18:01,500 --> 03:18:02,500 player can interact with Okay so let's 6293 03:18:03,479 --> 03:18:04,479 make the script and now let's open it 6294 03:18:05,880 --> 03:18:06,880 and over here okay first things first is 6295 03:18:08,640 --> 03:18:09,640 this is not a monobehavior instead let's 6296 03:18:11,580 --> 03:18:12,580 extend scriptable object and then 6297 03:18:14,220 --> 03:18:15,220 technically you can have functions 6298 03:18:15,720 --> 03:18:16,720 inside a straight ball object but for 6299 03:18:17,640 --> 03:18:18,640 now let's just get rid of this so just 6300 03:18:19,140 --> 03:18:20,140 an empty class and over here on let's 6301 03:18:21,180 --> 03:18:22,180 just Place whatever fields we need to 6302 03:18:22,800 --> 03:18:23,800 store whatever that we want so like I 6303 03:18:24,899 --> 03:18:25,899 said first we want a prefab so let's 6304 03:18:26,760 --> 03:18:27,760 make a public transform for our prefab 6305 03:18:29,279 --> 03:18:30,279 by the way here note how I am indeed 6306 03:18:31,380 --> 03:18:32,380 using public this is pretty much the one 6307 03:18:33,660 --> 03:18:34,660 exception to the room I only use 6308 03:18:35,700 --> 03:18:36,700 scripting objects as read-only data 6309 03:18:37,500 --> 03:18:38,500 containers I never write to them so 6310 03:18:39,960 --> 03:18:40,960 since I found that rule I usually make 6311 03:18:41,640 --> 03:18:42,640 the fields in the description object 6312 03:18:42,899 --> 03:18:43,899 public that way I can access them 6313 03:18:44,939 --> 03:18:45,939 directly without having to make a public 6314 03:18:46,560 --> 03:18:47,560 getter but if you want to feel free to 6315 03:18:48,899 --> 03:18:49,899 keep following the general rule of not 6316 03:18:50,340 --> 03:18:51,340 making anything public you could 6317 03:18:52,080 --> 03:18:53,080 definitely make this just a regular 6318 03:18:53,520 --> 03:18:54,520 serialized film then exposed with a get 6319 03:18:55,200 --> 03:18:56,200 function that would work personally I 6320 03:18:57,420 --> 03:18:58,420 just find it simpler to make it public 6321 03:18:58,920 --> 03:18:59,920 since I know that as a personal rule I 6322 03:19:01,080 --> 03:19:02,080 will never write to a script mode object 6323 03:19:02,760 --> 03:19:03,760 field okay so we have a transform for 6324 03:19:04,859 --> 03:19:05,859 our prefab let's also add a Sprite for 6325 03:19:07,859 --> 03:19:08,859 the icon Sprite and finally let's just 6326 03:19:10,319 --> 03:19:11,319 add a simple string for the object name 6327 03:19:13,680 --> 03:19:14,680 all right so we have our scribble object 6328 03:19:15,840 --> 03:19:16,840 definition we have all of the fields for 6329 03:19:17,939 --> 03:19:18,939 all of the data we want to store now how 6330 03:19:20,220 --> 03:19:21,220 do we actually create a scribble object 6331 03:19:22,260 --> 03:19:23,260 for that let's go up here before the 6332 03:19:24,060 --> 03:19:25,060 class name and we're going to add the 6333 03:19:25,740 --> 03:19:26,740 attribute so let's add the square 6334 03:19:27,120 --> 03:19:28,120 brackets and the attribute is the create 6335 03:19:29,640 --> 03:19:30,640 asset menu this takes some optional 6336 03:19:31,800 --> 03:19:32,800 parameters again I cover them in detail 6337 03:19:33,899 --> 03:19:34,899 in the dedicated script and objects 6338 03:19:35,520 --> 03:19:36,520 video for now let's just leave all the 6339 03:19:37,500 --> 03:19:38,500 parameters as empty just use defaults 6340 03:19:39,600 --> 03:19:40,600 and close the attribute okay so that's 6341 03:19:41,580 --> 03:19:42,580 it let's save this and go back into the 6342 03:19:43,200 --> 03:19:44,200 editor and over here if we go into the 6343 03:19:45,660 --> 03:19:46,660 project window click on the plus icon 6344 03:19:47,220 --> 03:19:48,220 and right up top yep we do see a kitchen 6345 03:19:49,260 --> 03:19:50,260 object so 6346 03:19:50,520 --> 03:19:51,520 so if we selected if there you go it 6347 03:19:52,680 --> 03:19:53,680 creates a brand new object inside of our 6348 03:19:54,420 --> 03:19:55,420 project files let's name this one tomato 6349 03:19:57,359 --> 03:19:58,359 and obviously let's keep our project 6350 03:19:58,979 --> 03:19:59,979 nice and organized so we don't want this 6351 03:20:00,720 --> 03:20:01,720 inside the scripts folder instead let's 6352 03:20:03,060 --> 03:20:04,060 make a proper folder so create a new 6353 03:20:04,859 --> 03:20:05,859 folder come with our scriptable objects 6354 03:20:07,380 --> 03:20:08,380 and then inside let's put a different 6355 03:20:09,540 --> 03:20:10,540 folder for each type so let's make 6356 03:20:11,520 --> 03:20:12,520 another subfolder call it the kitchen 6357 03:20:13,680 --> 03:20:14,680 object so and let's place the tomato 6358 03:20:16,380 --> 03:20:17,380 inside of it okay now with the Tomato 6359 03:20:18,720 --> 03:20:19,720 selected we can look in the inspector 6360 03:20:20,520 --> 03:20:21,520 and you can see yup it does have all of 6361 03:20:22,920 --> 03:20:23,920 the fields that we Define okay great so 6362 03:20:25,200 --> 03:20:26,200 now we can just assign them so this is 6363 03:20:27,120 --> 03:20:28,120 the tomatoes let's drag the Tomato 6364 03:20:28,740 --> 03:20:29,740 prefab for the icon Sprite let's find it 6365 03:20:31,740 --> 03:20:32,740 so there are Sprites included in the 6366 03:20:33,600 --> 03:20:34,600 regular assets so here is the Tomato 6367 03:20:35,040 --> 03:20:36,040 Sprite so it's inside the acids then 6368 03:20:37,620 --> 03:20:38,620 inside textures icons and we have all 6369 03:20:39,720 --> 03:20:40,720 the icons and finally for the readable 6370 03:20:42,060 --> 03:20:43,060 name let's just call it tomato alright 6371 03:20:44,100 --> 03:20:45,100 so that's it here we have a really nice 6372 03:20:46,380 --> 03:20:47,380 scribble object containing all the data 6373 03:20:48,240 --> 03:20:49,240 required for our tomato okay awesome 6374 03:20:50,100 --> 03:20:51,100 with that then we can now go back into 6375 03:20:52,200 --> 03:20:53,200 our clear counter script and here 6376 03:20:54,300 --> 03:20:55,300 instead of having a field for our tomato 6377 03:20:56,160 --> 03:20:57,160 prefab instead of this let's sort of 6378 03:20:58,500 --> 03:20:59,500 reference of type kitchen object so and 6379 03:21:01,260 --> 03:21:02,260 let's go on with kitchen object so and 6380 03:21:03,600 --> 03:21:04,600 then when spawning let's go inside our 6381 03:21:05,340 --> 03:21:06,340 scriptball object and just spawn the 6382 03:21:07,020 --> 03:21:08,020 prefab reference so this is going to be 6383 03:21:09,300 --> 03:21:10,300 the kitchen object transform then over 6384 03:21:13,080 --> 03:21:14,080 here in the editor let's go inside the 6385 03:21:14,700 --> 03:21:15,700 clear counter and let's assign the 6386 03:21:16,800 --> 03:21:17,800 Tomato Kitchen object okay so let's save 6387 03:21:18,960 --> 03:21:19,960 it and test 6388 03:21:20,220 --> 03:21:21,220 so here we are on let's approach hit any 6389 03:21:22,319 --> 03:21:23,319 up there you go it still spawns eat 6390 03:21:23,760 --> 03:21:24,760 tomato okay great now let's make another 6391 03:21:26,160 --> 03:21:27,160 type for our cheese block so let's 6392 03:21:28,439 --> 03:21:29,439 create a brand new kitchen object so 6393 03:21:30,120 --> 03:21:31,120 called the cheese block and again let's 6394 03:21:32,939 --> 03:21:33,939 assign first of all the prefab there it 6395 03:21:34,920 --> 03:21:35,920 is then for the Sprite of the cheese 6396 03:21:36,540 --> 03:21:37,540 walk and finally this is the cheese well 6397 03:21:39,300 --> 03:21:40,300 okay so now for example let's go into 6398 03:21:41,220 --> 03:21:42,220 the second one and on the second counter 6399 03:21:43,560 --> 03:21:44,560 let's override and say this one spawn a 6400 03:21:45,660 --> 03:21:46,660 cheese block so let's test so here we 6401 03:21:48,120 --> 03:21:49,120 are approach this one yep there's tomato 6402 03:21:49,560 --> 03:21:50,560 this one any of there's some cheese okay 6403 03:21:51,240 --> 03:21:52,240 great so everything is working so far 6404 03:21:53,760 --> 03:21:54,760 however the original problem that we're 6405 03:21:55,859 --> 03:21:56,859 trying to solve identifying the spawn 6406 03:21:57,840 --> 03:21:58,840 prefab we still don't have a solution 6407 03:21:59,640 --> 03:22:00,640 for that basically when we spawn a 6408 03:22:01,979 --> 03:22:02,979 prefab we need to know from which script 6409 03:22:03,960 --> 03:22:04,960 No Object this prefab came from so 6410 03:22:06,000 --> 03:22:07,000 essentially what I like to do is just 6411 03:22:07,380 --> 03:22:08,380 attach some reference to the scripting 6412 03:22:08,760 --> 03:22:09,760 object in our prefab however again 6413 03:22:10,859 --> 03:22:11,859 remember that scripting objects are not 6414 03:22:12,840 --> 03:22:13,840 mono behaviors so if I select the prefab 6415 03:22:15,479 --> 03:22:16,479 and I try dragging the description 6416 03:22:16,680 --> 03:22:17,680 object nope it does not work so what we 6417 03:22:18,960 --> 03:22:19,960 can do is just create a new script so 6418 03:22:21,600 --> 03:22:22,600 let's make a brand new c-sharp script 6419 03:22:23,399 --> 03:22:24,399 let's call it kitchen object 6420 03:22:26,160 --> 03:22:27,160 let's attach this to both prefab so both 6421 03:22:28,680 --> 03:22:29,680 the cheese and the block attach the same 6422 03:22:30,359 --> 03:22:31,359 one to both of them and let's open 6423 03:22:32,880 --> 03:22:33,880 and over here very simple let's just add 6424 03:22:34,740 --> 03:22:35,740 a serialized film for our kitchen object 6425 03:22:36,479 --> 03:22:37,479 so a serialized film of type 6426 03:22:39,840 --> 03:22:40,840 kitchen object so for the kitchen object 6427 03:22:42,240 --> 03:22:43,240 the cell 6428 03:22:43,380 --> 03:22:44,380 then let's also make a quick function to 6429 03:22:45,120 --> 03:22:46,120 expose it so we're going to return 6430 03:22:46,200 --> 03:22:47,200 kitchen object as so get kitchen object 6431 03:22:48,840 --> 03:22:49,840 so and we just return the kitchen object 6432 03:22:51,180 --> 03:22:52,180 as well yep just like this so now here 6433 03:22:53,640 --> 03:22:54,640 in the editor for the Tomato yep we've 6434 03:22:55,380 --> 03:22:56,380 got the film so let's say this one is a 6435 03:22:57,000 --> 03:22:58,000 tomato and the cheese block this one is 6436 03:22:58,920 --> 03:22:59,920 a cheese block now here obviously we 6437 03:23:01,439 --> 03:23:02,439 need to make very very sure to drag the 6438 03:23:03,660 --> 03:23:04,660 correct reference to the right scriven 6439 03:23:05,220 --> 03:23:06,220 object if you drag the wrong one like 6440 03:23:07,080 --> 03:23:08,080 for example over here on cheese you 6441 03:23:08,580 --> 03:23:09,580 would say this one is a tomato if you 6442 03:23:10,380 --> 03:23:11,380 did that then obviously you would get 6443 03:23:11,700 --> 03:23:12,700 some very weird results so make sure to 6444 03:23:14,279 --> 03:23:15,279 check and double check that you drag the 6445 03:23:16,140 --> 03:23:17,140 right preferences both over here on the 6446 03:23:18,300 --> 03:23:19,300 prefabs make sure they are referencing 6447 03:23:19,739 --> 03:23:20,739 the correct Circle object and on the 6448 03:23:21,840 --> 03:23:22,840 script module itself make sure they are 6449 03:23:23,399 --> 03:23:24,399 referencing the correct prefont okay so 6450 03:23:25,500 --> 03:23:26,500 now if you go here on the clear counter 6451 03:23:27,479 --> 03:23:28,479 we spawn our object okay great then on 6452 03:23:30,540 --> 03:23:31,540 this object we can do get component of 6453 03:23:32,700 --> 03:23:33,700 type kitchen object and then we can just 6454 03:23:35,340 --> 03:23:36,340 ask it to give us the kitchen object as 6455 03:23:37,319 --> 03:23:38,319 well so for example let's do a debug 6456 03:23:39,540 --> 03:23:40,540 download on this one 6457 03:23:41,399 --> 03:23:42,399 so inside you get the kitchen object to 6458 03:23:43,319 --> 03:23:44,319 sew and then let's print out the object 6459 03:23:44,939 --> 03:23:45,939 name all right so here we are let's 6460 03:23:46,920 --> 03:23:47,920 interact with this one and if there you 6461 03:23:48,359 --> 03:23:49,359 go interacted and spawn the tomato and 6462 03:23:50,160 --> 03:23:51,160 on this one yep interacted and spawned a 6463 03:23:52,200 --> 03:23:53,200 cheese block okay awesome we spawned a 6464 03:23:54,720 --> 03:23:55,720 transform prefab and we identify the 6465 03:23:56,760 --> 03:23:57,760 spawn object is indeed this type of 6466 03:23:58,620 --> 03:23:59,620 object all right so here we'll learn 6467 03:24:00,720 --> 03:24:01,720 about one of the most powerful ENT 6468 03:24:02,399 --> 03:24:03,399 features scribble objects these are 6469 03:24:04,800 --> 03:24:05,800 extremely useful for defining a type and 6470 03:24:06,660 --> 03:24:07,660 then creating multiple instances of that 6471 03:24:08,460 --> 03:24:09,460 type with whatever that we want so there 6472 03:24:10,800 --> 03:24:11,800 can be some ingredients like we have 6473 03:24:12,239 --> 03:24:13,239 here or it could be some weapons could 6474 03:24:14,640 --> 03:24:15,640 even be some NPC data maybe some Quest 6475 03:24:16,739 --> 03:24:17,739 data and so on it really is an insanely 6476 03:24:19,260 --> 03:24:20,260 very useful feature definitely go ahead 6477 03:24:21,420 --> 03:24:22,420 and watch a dedicated video on script on 6478 03:24:23,340 --> 03:24:24,340 objects then if you want you can also 6479 03:24:25,260 --> 03:24:26,260 watch some more videos where I've used 6480 03:24:26,700 --> 03:24:27,700 scriven objects for example in the 6481 03:24:28,739 --> 03:24:29,739 Minecraft crafting system using 6482 03:24:30,120 --> 03:24:31,120 scripting objects or the hydrogenated 6483 03:24:32,520 --> 03:24:33,520 crafting system which again also uses 6484 03:24:34,080 --> 03:24:35,080 scribdon objects okay so this is done 6485 03:24:36,359 --> 03:24:37,359 it's working great now let's continue to 6486 03:24:38,760 --> 03:24:39,760 the next lecture where we're going to 6487 03:24:40,260 --> 03:24:41,260 help the kitchen object know where it 6488 03:24:42,120 --> 03:24:43,120 belongs and help each counter know what 6489 03:24:44,220 --> 03:24:45,220 kitchen object is on top of it 6490 03:24:46,859 --> 03:24:47,859 hello and welcome I'm your code monkey 6491 03:24:49,020 --> 03:24:50,020 in this lecture we're going to create a 6492 03:24:51,420 --> 03:24:52,420 kitchen object parent meaning that the 6493 03:24:53,520 --> 03:24:54,520 kitchen object will know where it is and 6494 03:24:55,500 --> 03:24:56,500 the counter will know if something is on 6495 03:24:57,359 --> 03:24:58,359 it this is important so that later on we 6496 03:24:59,460 --> 03:25:00,460 can pick up a kitchen object from one 6497 03:25:01,380 --> 03:25:02,380 place and drop it in another okay so 6498 03:25:03,720 --> 03:25:04,720 here we have our player I can move 6499 03:25:05,520 --> 03:25:06,520 towards this counter interact with it 6500 03:25:07,080 --> 03:25:08,080 and yep spawn a tomato then on this 6501 03:25:08,819 --> 03:25:09,819 one's want some cheese okay great but I 6502 03:25:11,580 --> 03:25:12,580 cannot do anything else in fact if I 6503 03:25:13,739 --> 03:25:14,739 interact a bunch more times really all I 6504 03:25:16,319 --> 03:25:17,319 did was just spawn a whole bunch more 6505 03:25:17,760 --> 03:25:18,760 cheese so instead I want to be able to 6506 03:25:20,040 --> 03:25:21,040 spawn some cheese and then pick it up so 6507 03:25:22,319 --> 03:25:23,319 let's think about exactly what that 6508 03:25:23,700 --> 03:25:24,700 means we want a kitchen object to 6509 03:25:25,979 --> 03:25:26,979 essentially be placed on a specific 6510 03:25:27,479 --> 03:25:28,479 Place based on the design that we're 6511 03:25:29,580 --> 03:25:30,580 trying to implement we're never going to 6512 03:25:31,020 --> 03:25:32,020 have a kitchen object just randomly 6513 03:25:32,760 --> 03:25:33,760 thrown around the world we're not going 6514 03:25:34,739 --> 03:25:35,739 to have tomatoes all over the floor 6515 03:25:36,380 --> 03:25:37,380 instead the objects will always need to 6516 03:25:38,700 --> 03:25:39,700 be placed somewhere and that somewhere 6517 03:25:40,560 --> 03:25:41,560 can be either a counter or it can be 6518 03:25:42,359 --> 03:25:43,359 being held by the player so essentially 6519 03:25:44,460 --> 03:25:45,460 that means that each kitchen object is 6520 03:25:46,260 --> 03:25:47,260 going to have some kind of parent that 6521 03:25:47,700 --> 03:25:48,700 it's attached to we're going to make 6522 03:25:49,380 --> 03:25:50,380 sure the counter knows if there is a 6523 03:25:50,939 --> 03:25:51,939 kitchen object placed on top of it and 6524 03:25:52,920 --> 03:25:53,920 we're also going to make sure the 6525 03:25:53,939 --> 03:25:54,939 kitchen object itself knows where it is 6526 03:25:55,739 --> 03:25:56,739 so first let's do that logic over here 6527 03:25:57,840 --> 03:25:58,840 on the counter 6528 03:25:58,920 --> 03:25:59,920 so on the clear counter script let's 6529 03:26:01,140 --> 03:26:02,140 keep a field for a kitchen object 6530 03:26:03,960 --> 03:26:04,960 so just a simple private of type kitchen 6531 03:26:06,359 --> 03:26:07,359 object kitchen object 6532 03:26:10,080 --> 03:26:11,080 then when the player interacts with it 6533 03:26:12,060 --> 03:26:13,060 by the way we can get rid of these debug 6534 03:26:14,640 --> 03:26:15,640 transforms debug logs in all you need 6535 03:26:16,439 --> 03:26:17,439 them okay so when the plane interacts so 6536 03:26:18,840 --> 03:26:19,840 if the kitchen object is known 6537 03:26:20,760 --> 03:26:21,760 if so then we're going to spawn it then 6538 03:26:23,460 --> 03:26:24,460 when we spawn it let's assign it so this 6539 03:26:25,319 --> 03:26:26,319 one equals the kitchen object get 6540 03:26:27,239 --> 03:26:28,239 component of type kitchen object okay 6541 03:26:30,359 --> 03:26:31,359 so if that one is no we spawn it and we 6542 03:26:32,220 --> 03:26:33,220 assign it and just with this we should 6543 03:26:34,439 --> 03:26:35,439 have fixed the issue where we can spawn 6544 03:26:36,060 --> 03:26:37,060 infinite objects 6545 03:26:37,680 --> 03:26:38,680 so over here I can interact and now I've 6546 03:26:40,020 --> 03:26:41,020 interact a bunch more times 6547 03:26:41,700 --> 03:26:42,700 and now look in the hierarchy inside the 6548 03:26:43,739 --> 03:26:44,739 clear counter 6549 03:26:44,939 --> 03:26:45,939 and I go inside the counter top Point 6550 03:26:47,100 --> 03:26:48,100 nope there's only one tomato okay great 6551 03:26:49,080 --> 03:26:50,080 so with this basically we made the clear 6552 03:26:51,180 --> 03:26:52,180 counter know if there's something on top 6553 03:26:52,739 --> 03:26:53,739 of it 6554 03:26:53,580 --> 03:26:54,580 now let's do the other side so let's go 6555 03:26:56,220 --> 03:26:57,220 into the kitchen object and make sure 6556 03:26:57,540 --> 03:26:58,540 that it knows where it is so over here 6557 03:26:59,880 --> 03:27:00,880 on the kitchen object script 6558 03:27:01,620 --> 03:27:02,620 let's add a simple field for a counter 6559 03:27:03,899 --> 03:27:04,899 so private of type clear counter for the 6560 03:27:06,359 --> 03:27:07,359 clear counter 6561 03:27:08,100 --> 03:27:09,100 and now let's just basically make two 6562 03:27:09,720 --> 03:27:10,720 functions one to set it and one to get 6563 03:27:11,580 --> 03:27:12,580 it so a public void set clear counter 6564 03:27:18,420 --> 03:27:19,420 and we're going to receive a parameter 6565 03:27:20,399 --> 03:27:21,399 of type clear counter okay great and 6566 03:27:22,920 --> 03:27:23,920 then we're going to have a public return 6567 03:27:24,479 --> 03:27:25,479 a clear counter for the get clear 6568 03:27:26,340 --> 03:27:27,340 counter 6569 03:27:27,660 --> 03:27:28,660 and we're just going to return our clear 6570 03:27:29,819 --> 03:27:30,819 counter and on this one just set this 6571 03:27:32,160 --> 03:27:33,160 dark layer counter equals this layer 6572 03:27:33,899 --> 03:27:34,899 counter 6573 03:27:34,859 --> 03:27:35,859 all right so on this function we're 6574 03:27:36,180 --> 03:27:37,180 assigning this field and on this 6575 03:27:37,380 --> 03:27:38,380 function we're returning this field 6576 03:27:39,300 --> 03:27:40,300 so now back on the counter script we get 6577 03:27:41,640 --> 03:27:42,640 the kitchen object reference so on this 6578 03:27:43,620 --> 03:27:44,620 one let's call set clear counter and 6579 03:27:45,779 --> 03:27:46,779 pass it in this one 6580 03:27:47,220 --> 03:27:48,220 and if it is not known so if there's 6581 03:27:48,660 --> 03:27:49,660 something on top of this let's just do a 6582 03:27:51,000 --> 03:27:52,000 debug.log let's go on to the kitchen 6583 03:27:53,220 --> 03:27:54,220 object and get the clear counter 6584 03:27:56,580 --> 03:27:57,580 so we should be able to click once and 6585 03:27:58,319 --> 03:27:59,319 spawn an object and click twice and the 6586 03:28:00,420 --> 03:28:01,420 second time we should be able to see the 6587 03:28:01,979 --> 03:28:02,979 name of this layer counter 6588 03:28:03,660 --> 03:28:04,660 all right so over here let's approach 6589 03:28:05,460 --> 03:28:06,460 and click and yep it's spawn now click 6590 03:28:07,319 --> 03:28:08,319 again 6591 03:28:08,100 --> 03:28:09,100 and if we've got the message this one is 6592 03:28:10,200 --> 03:28:11,200 on the planet counter okay great so far 6593 03:28:13,020 --> 03:28:14,020 so good 6594 03:28:13,920 --> 03:28:14,920 so the counter knows if there's a 6595 03:28:15,720 --> 03:28:16,720 kitchen object on top of it and the 6596 03:28:17,580 --> 03:28:18,580 kitchen object itself knows where it is 6597 03:28:19,260 --> 03:28:20,260 now let's add some logic to be able to 6598 03:28:21,359 --> 03:28:22,359 change a parent counter it's over here 6599 03:28:23,939 --> 03:28:24,939 on the clear counter script we basically 6600 03:28:26,340 --> 03:28:27,340 just need to call the set layer counter 6601 03:28:28,200 --> 03:28:29,200 function with a different counter 6602 03:28:30,120 --> 03:28:31,120 reference so just for testing let's add 6603 03:28:32,580 --> 03:28:33,580 a serialized film for the second counter 6604 03:28:34,500 --> 03:28:35,500 so clear counter for the second clear 6605 03:28:37,080 --> 03:28:38,080 counter 6606 03:28:38,939 --> 03:28:39,939 now we're doing this just for testing 6607 03:28:40,739 --> 03:28:41,739 just make sure the logic Works before we 6608 03:28:42,359 --> 03:28:43,359 come up with a more General system 6609 03:28:44,580 --> 03:28:45,580 so just for testing let's come up with 6610 03:28:46,319 --> 03:28:47,319 some input and again for testing using 6611 03:28:48,660 --> 03:28:49,660 the lazy input manager to get something 6612 03:28:50,340 --> 03:28:51,340 quickly up and running is a great thing 6613 03:28:52,560 --> 03:28:53,560 so let's quickly get a button input on 6614 03:28:54,660 --> 03:28:55,660 the counter so let's make a private void 6615 03:28:56,460 --> 03:28:57,460 update 6616 03:28:57,420 --> 03:28:58,420 and for testing we only want the testing 6617 03:28:59,580 --> 03:29:00,580 to work on one counter so let's also add 6618 03:29:01,800 --> 03:29:02,800 up here just a ball testing 6619 03:29:04,859 --> 03:29:05,859 and then on update if we are testing and 6620 03:29:08,279 --> 03:29:09,279 we have the input.getkeydown on let's 6621 03:29:11,220 --> 03:29:12,220 say the T key 6622 03:29:12,840 --> 03:29:13,840 so if you have that then we can run some 6623 03:29:14,640 --> 03:29:15,640 kind of testing code so let's say for 6624 03:29:16,500 --> 03:29:17,500 example if the kitchen object does not 6625 03:29:18,180 --> 03:29:19,180 know so if we have something on top of 6626 03:29:20,760 --> 03:29:21,760 this kitchen counter let's go into the 6627 03:29:22,920 --> 03:29:23,920 kitchen object and call set counter and 6628 03:29:25,739 --> 03:29:26,739 let's pass in the second clear counter 6629 03:29:28,620 --> 03:29:29,620 so basically with this we should be able 6630 03:29:30,420 --> 03:29:31,420 to interact to spawn an object and then 6631 03:29:32,700 --> 03:29:33,700 press the T key and we should be able to 6632 03:29:34,739 --> 03:29:35,739 see that object be set to a different 6633 03:29:36,540 --> 03:29:37,540 parent 6634 03:29:37,560 --> 03:29:38,560 so here in the after I'll let you set 6635 03:29:39,180 --> 03:29:40,180 down let's say this one is our main 6636 03:29:40,680 --> 03:29:41,680 counter so let's drag a reference to the 6637 03:29:43,140 --> 03:29:44,140 second one the second higher counter 6638 03:29:44,640 --> 03:29:45,640 drag it and make this one the testing 6639 03:29:46,200 --> 03:29:47,200 script and also just to verify that it 6640 03:29:48,300 --> 03:29:49,300 worked over here and lets you a get on 6641 03:29:49,920 --> 03:29:50,920 the clear counter all right so let's 6642 03:29:52,140 --> 03:29:53,140 test and see 6643 03:29:53,279 --> 03:29:54,279 okay so here we are let's approach this 6644 03:29:55,380 --> 03:29:56,380 one interact and there you go spawn 6645 03:29:57,060 --> 03:29:58,060 tomato and now if I interact again yep 6646 03:29:59,279 --> 03:30:00,279 it says the tomato is on the similar 6647 03:30:00,600 --> 03:30:01,600 counter now if I press the testing key 6648 03:30:02,700 --> 03:30:03,700 if there go the Tomato was moved onto 6649 03:30:04,979 --> 03:30:05,979 the other counter 6650 03:30:06,300 --> 03:30:07,300 okay so the parent change the logic 6651 03:30:08,279 --> 03:30:09,279 worked however obviously we have two big 6652 03:30:10,800 --> 03:30:11,800 issues the first one is just a visual 6653 03:30:12,960 --> 03:30:13,960 you can see the object is still placed 6654 03:30:14,700 --> 03:30:15,700 on top of this counter even though 6655 03:30:15,960 --> 03:30:16,960 technically now it belongs to this one 6656 03:30:18,000 --> 03:30:19,000 and the second issue is that this 6657 03:30:19,560 --> 03:30:20,560 counter still thinks that it owns this 6658 03:30:21,239 --> 03:30:22,239 kitchen object and this other counter 6659 03:30:23,399 --> 03:30:24,399 does not know that it now owns this 6660 03:30:25,080 --> 03:30:26,080 object so we need to sort all of that 6661 03:30:27,600 --> 03:30:28,600 first for the visual it's actually very 6662 03:30:29,520 --> 03:30:30,520 simple 6663 03:30:30,479 --> 03:30:31,479 here when spawning we are spawning it 6664 03:30:32,340 --> 03:30:33,340 inside the counter top point and then 6665 03:30:33,840 --> 03:30:34,840 setting the alarm position to zero so 6666 03:30:36,180 --> 03:30:37,180 whenever we move to a different second 6667 03:30:38,279 --> 03:30:39,279 parent when we do that we can just ask 6668 03:30:40,620 --> 03:30:41,620 that second parent to return the 6669 03:30:42,000 --> 03:30:43,000 countertop point and move it there so 6670 03:30:43,979 --> 03:30:44,979 for that let's make a function to return 6671 03:30:45,660 --> 03:30:46,660 that 6672 03:30:46,620 --> 03:30:47,620 so public we're going to return 6673 03:30:48,479 --> 03:30:49,479 transform so get the kitchen object 6674 03:30:50,760 --> 03:30:51,760 follow transform so it's going to be our 6675 03:30:53,520 --> 03:30:54,520 countertop point 6676 03:30:55,020 --> 03:30:56,020 so let's return the counter top point 6677 03:30:58,380 --> 03:30:59,380 then let's go into the function on the 6678 03:31:00,420 --> 03:31:01,420 kitchen object when we set the clear 6679 03:31:01,739 --> 03:31:02,739 counter so over here on the kitchen 6680 03:31:03,840 --> 03:31:04,840 object on this function so we set the 6681 03:31:05,399 --> 03:31:06,399 color counter 6682 03:31:06,540 --> 03:31:07,540 then let's modify this transform.parent 6683 03:31:08,760 --> 03:31:09,760 go into the nuclear counter in order to 6684 03:31:11,700 --> 03:31:12,700 get the kitchen object funnel transform 6685 03:31:13,200 --> 03:31:14,200 and again let's make sure to set the low 6686 03:31:15,660 --> 03:31:16,660 composition back into Vector 3.0 6687 03:31:18,840 --> 03:31:19,840 okay so with this when we set the clear 6688 03:31:21,000 --> 03:31:22,000 counter to a different one it should 6689 03:31:22,620 --> 03:31:23,620 automatically teleport to the other 6690 03:31:24,420 --> 03:31:25,420 counter so let's test so here we are in 6691 03:31:27,180 --> 03:31:28,180 first let's interact with this one there 6692 03:31:28,439 --> 03:31:29,439 you go it's Pawn now if I press C 6693 03:31:29,880 --> 03:31:30,880 testing key and if there go it does move 6694 03:31:31,500 --> 03:31:32,500 visually okay great so far so good 6695 03:31:33,660 --> 03:31:34,660 however the counters still have the 6696 03:31:35,520 --> 03:31:36,520 wrong data by the way here's a quick 6697 03:31:37,739 --> 03:31:38,739 empty tub on the inspector you already 6698 03:31:40,620 --> 03:31:41,620 know that you can only see the public 6699 03:31:42,300 --> 03:31:43,300 and the serialized Fields however there 6700 03:31:44,640 --> 03:31:45,640 is actually a way to look at private 6701 03:31:46,260 --> 03:31:47,260 fields on the inspector on the top right 6702 03:31:48,479 --> 03:31:49,479 there's these three dots and if you 6703 03:31:50,220 --> 03:31:51,220 click on it over here you can modify it 6704 03:31:52,080 --> 03:31:53,080 into a debug inspector 6705 03:31:54,180 --> 03:31:55,180 and when you go into this one Yep this 6706 03:31:55,859 --> 03:31:56,859 one does show all the private fields 6707 03:31:58,140 --> 03:31:59,140 so you can see for example on the clear 6708 03:31:59,700 --> 03:32:00,700 counter so that's the right one this one 6709 03:32:01,319 --> 03:32:02,319 over here the kitchen object is indeed 6710 03:32:02,819 --> 03:32:03,819 assigned and we can go into the other 6711 03:32:04,920 --> 03:32:05,920 one and we can see this one has it as 6712 03:32:06,540 --> 03:32:07,540 null so debug inspector is really useful 6713 03:32:08,819 --> 03:32:09,819 in these kinds of cases if you want to 6714 03:32:10,500 --> 03:32:11,500 inspect any kind of private Fields you 6715 03:32:12,060 --> 03:32:13,060 can go to this and see it now let's swap 6716 03:32:14,640 --> 03:32:15,640 back into the regular inspector and 6717 03:32:17,100 --> 03:32:18,100 let's fix that issue by notifying the 6718 03:32:18,600 --> 03:32:19,600 counters that the object has changed 6719 03:32:20,939 --> 03:32:21,939 so over here basically we have two 6720 03:32:22,680 --> 03:32:23,680 options over here on the calendar 6721 03:32:24,420 --> 03:32:25,420 counter when we modify the parent when 6722 03:32:26,760 --> 03:32:27,760 we tell the kitchen object to go to a 6723 03:32:28,319 --> 03:32:29,319 new parent when we do that we can make 6724 03:32:30,359 --> 03:32:31,359 the new parent responsible to updating 6725 03:32:32,040 --> 03:32:33,040 itself or we can just make the kitchen 6726 03:32:34,380 --> 03:32:35,380 object itself be the one responsible for 6727 03:32:36,540 --> 03:32:37,540 notifying the new parent both approaches 6728 03:32:39,060 --> 03:32:40,060 can work personally I think it makes 6729 03:32:41,220 --> 03:32:42,220 more sense for the kitchen object to 6730 03:32:42,720 --> 03:32:43,720 handle itself 6731 03:32:44,040 --> 03:32:45,040 so we just call this function to set the 6732 03:32:46,260 --> 03:32:47,260 new parent and when this happens 6733 03:32:48,000 --> 03:32:49,000 basically this kitchen object needs to 6734 03:32:49,680 --> 03:32:50,680 tell the old parent that it is no longer 6735 03:32:52,260 --> 03:32:53,260 there and needs to tell the new parent 6736 03:32:53,700 --> 03:32:54,700 that it is on there so on the counter 6737 03:32:55,859 --> 03:32:56,859 let's make some function to set and get 6738 03:32:57,720 --> 03:32:58,720 a kitchen object 6739 03:32:59,160 --> 03:33:00,160 so over here on the calendar counter 6740 03:33:00,720 --> 03:33:01,720 script let's go down 6741 03:33:02,460 --> 03:33:03,460 let's make first one to set so public 6742 03:33:04,680 --> 03:33:05,680 void set kitchen object and receive a 6743 03:33:07,800 --> 03:33:08,800 kitchen object 6744 03:33:10,859 --> 03:33:11,859 and just do this dot kitchen object 6745 03:33:12,779 --> 03:33:13,779 equals this kitchen object okay great 6746 03:33:14,520 --> 03:33:15,520 then let's make a getter so public 6747 03:33:16,739 --> 03:33:17,739 return a kitchen object get the kitchen 6748 03:33:19,380 --> 03:33:20,380 object 6749 03:33:20,520 --> 03:33:21,520 and just return this kitchen object okay 6750 03:33:23,460 --> 03:33:24,460 then let's also make one just to clear 6751 03:33:25,380 --> 03:33:26,380 it so probably avoid clear kitchen 6752 03:33:27,899 --> 03:33:28,899 object 6753 03:33:30,479 --> 03:33:31,479 and this one just sets the kitchen 6754 03:33:32,040 --> 03:33:33,040 object into null 6755 03:33:34,020 --> 03:33:35,020 and finally just a nice sample function 6756 03:33:35,819 --> 03:33:36,819 to test if this counter has anything on 6757 03:33:37,680 --> 03:33:38,680 top so just a public Bowl has kitchen 6758 03:33:40,439 --> 03:33:41,439 object 6759 03:33:42,359 --> 03:33:43,359 and over here we just return if the 6760 03:33:44,279 --> 03:33:45,279 kitchen object is not known 6761 03:33:46,140 --> 03:33:47,140 okay so some four very simple functions 6762 03:33:49,200 --> 03:33:50,200 now if we go into our kitchen of the 6763 03:33:51,060 --> 03:33:52,060 script 6764 03:33:51,899 --> 03:33:52,899 over here when we tell it to change the 6765 03:33:53,880 --> 03:33:54,880 parent let's first go into the current 6766 03:33:55,979 --> 03:33:56,979 parent and clear it 6767 03:33:58,560 --> 03:33:59,560 so let's first of all do a quick test 6768 03:34:00,840 --> 03:34:01,840 for null so if this documentary counter 6769 03:34:02,939 --> 03:34:03,939 which is the current parent so if this 6770 03:34:04,920 --> 03:34:05,920 one is not null then we go into the 6771 03:34:07,020 --> 03:34:08,020 current parent so the clear counter and 6772 03:34:09,359 --> 03:34:10,359 we tell it to clear the kitchen object 6773 03:34:12,000 --> 03:34:13,000 and then we go into the new parent 6774 03:34:14,460 --> 03:34:15,460 and we tell new parent to set the 6775 03:34:16,140 --> 03:34:17,140 kitchen object and the kitchen object is 6776 03:34:18,420 --> 03:34:19,420 this one 6777 03:34:19,439 --> 03:34:20,439 now here will be very very important 6778 03:34:21,300 --> 03:34:22,300 don't make the mistake of clearing the 6779 03:34:23,160 --> 03:34:24,160 wrong counter keep in mind that over 6780 03:34:25,380 --> 03:34:26,380 here this documentary counter this 6781 03:34:27,000 --> 03:34:28,000 refers to the previous player counter 6782 03:34:29,279 --> 03:34:30,279 whereas the one in the parameter this is 6783 03:34:31,439 --> 03:34:32,439 the one this is the new one so make sure 6784 03:34:33,779 --> 03:34:34,779 you clear the kitchen object from the 6785 03:34:35,460 --> 03:34:36,460 previous clear counter before you assign 6786 03:34:37,200 --> 03:34:38,200 it and then you set it on the new clear 6787 03:34:39,180 --> 03:34:40,180 counter so be very very careful here 6788 03:34:41,760 --> 03:34:42,760 make sure you don't make mistakes 6789 03:34:43,560 --> 03:34:44,560 between the quote unquote old color 6790 03:34:45,359 --> 03:34:46,359 counter and the nuclear counter 6791 03:34:47,520 --> 03:34:48,520 okay so that's it basically we have this 6792 03:34:49,560 --> 03:34:50,560 function to set the nuclear counter so 6793 03:34:51,239 --> 03:34:52,239 set the new parent we clear the kitchen 6794 03:34:53,520 --> 03:34:54,520 object from the old player counter we 6795 03:34:55,500 --> 03:34:56,500 added a new one and we update the visual 6796 03:34:57,840 --> 03:34:58,840 now we can also add some nice safety 6797 03:34:59,939 --> 03:35:00,939 checks here just to make sure we never 6798 03:35:01,319 --> 03:35:02,319 make a mistake the kitchen object should 6799 03:35:03,779 --> 03:35:04,779 never be set to a parent that is already 6800 03:35:05,520 --> 03:35:06,520 holding something so before we set the 6801 03:35:08,160 --> 03:35:09,160 kitchen object before we do that let's 6802 03:35:10,140 --> 03:35:11,140 make sure that one is empty 6803 03:35:11,939 --> 03:35:12,939 so over here just do an if if the clear 6804 03:35:14,040 --> 03:35:15,040 counter so that's a new one if this one 6805 03:35:16,260 --> 03:35:17,260 has a kitchen object then it already has 6806 03:35:18,840 --> 03:35:19,840 something on there this should never 6807 03:35:20,819 --> 03:35:21,819 ever happen so let's see what debug.log 6808 03:35:23,040 --> 03:35:24,040 error and say counter already has a 6809 03:35:26,340 --> 03:35:27,340 kitchen object 6810 03:35:28,439 --> 03:35:29,439 we're going to eventually add tests to 6811 03:35:30,239 --> 03:35:31,239 make sure that this never ever happens 6812 03:35:31,739 --> 03:35:32,739 but having the air here won't be helpful 6813 03:35:33,960 --> 03:35:34,960 just in case we missed something 6814 03:35:35,939 --> 03:35:36,939 so far as the kitchen object we're going 6815 03:35:37,620 --> 03:35:38,620 to fire an error but this should never 6816 03:35:39,479 --> 03:35:40,479 happen so we just set the error update 6817 03:35:40,979 --> 03:35:41,979 to visual and so on 6818 03:35:42,479 --> 03:35:43,479 okay so finally let's just go over here 6819 03:35:44,640 --> 03:35:45,640 into the clear counter script and down 6820 03:35:47,100 --> 03:35:48,100 here we have the interact action so we 6821 03:35:49,680 --> 03:35:50,680 instantiate the kitchen object we're 6822 03:35:51,960 --> 03:35:52,960 currently repositioning it and then 6823 03:35:53,819 --> 03:35:54,819 we're setting this field assigning it to 6824 03:35:55,979 --> 03:35:56,979 this one now we made the kitchen object 6825 03:35:58,020 --> 03:35:59,020 responsible for doing all that for 6826 03:35:59,640 --> 03:36:00,640 modifying the position and for setting 6827 03:36:01,260 --> 03:36:02,260 the field so we don't need to do this 6828 03:36:02,640 --> 03:36:03,640 instead we really just need to go and 6829 03:36:05,580 --> 03:36:06,580 get the component of that 6830 03:36:07,260 --> 03:36:08,260 and just pass in set for your counter 6831 03:36:09,420 --> 03:36:10,420 and pass in as this one 6832 03:36:12,359 --> 03:36:13,359 so we no longer need all this now our 6833 03:36:14,399 --> 03:36:15,399 code is much more simple also 6834 03:36:16,319 --> 03:36:17,319 importantly up here we were previously 6835 03:36:18,060 --> 03:36:19,060 setting the color counter and then doing 6836 03:36:19,620 --> 03:36:20,620 a debug.log but when we set it a new one 6837 03:36:22,260 --> 03:36:23,260 that is actually going to clear this 6838 03:36:23,520 --> 03:36:24,520 field so if we leave this then this is 6839 03:36:25,140 --> 03:36:26,140 going to throw a null reference 6840 03:36:26,279 --> 03:36:27,279 exception so let's just get rid of the 6841 03:36:28,260 --> 03:36:29,260 slog here we normally need it okay so 6842 03:36:30,779 --> 03:36:31,779 let's test and see if all of our logic 6843 03:36:32,399 --> 03:36:33,399 is working 6844 03:36:33,540 --> 03:36:34,540 all right so here we are let's go to 6845 03:36:35,340 --> 03:36:36,340 this one interactive spawn it okay great 6846 03:36:38,100 --> 03:36:39,100 and once again we can look in the debug 6847 03:36:40,200 --> 03:36:41,200 inspector so let's put it on debug look 6848 03:36:42,300 --> 03:36:43,300 at this layer counter so that's the 6849 03:36:43,620 --> 03:36:44,620 right one and yep there you go it does 6850 03:36:45,239 --> 03:36:46,239 have the kitchen object and if I'm 6851 03:36:46,500 --> 03:36:47,500 looking the other one Yep this one has 6852 03:36:47,939 --> 03:36:48,939 no okay great 6853 03:36:49,439 --> 03:36:50,439 now if I press the testing key yep 6854 03:36:51,479 --> 03:36:52,479 visually it did change and if you look 6855 03:36:53,700 --> 03:36:54,700 at the counter so if you look at the old 6856 03:36:55,080 --> 03:36:56,080 ones that's the right one this one is at 6857 03:36:56,760 --> 03:36:57,760 no okay that's great correct and if you 6858 03:36:58,859 --> 03:36:59,859 look at the new one Yep this one does 6859 03:37:00,300 --> 03:37:01,300 have the reference all right awesome 6860 03:37:03,000 --> 03:37:04,000 so now that we are correctly changing 6861 03:37:04,920 --> 03:37:05,920 the kitchen object parent for example we 6862 03:37:07,140 --> 03:37:08,140 can now interact again with this one and 6863 03:37:08,580 --> 03:37:09,580 yep it does spawn a brand new one and of 6864 03:37:11,160 --> 03:37:12,160 course if we try moving it to the other 6865 03:37:12,720 --> 03:37:13,720 one then we should have our error as 6866 03:37:14,640 --> 03:37:15,640 intended this one is currently already 6867 03:37:16,800 --> 03:37:17,800 occupied the kitchen object so we should 6868 03:37:18,600 --> 03:37:19,600 not be able to drop something on there 6869 03:37:20,100 --> 03:37:21,100 but if I press the testing key if there 6870 03:37:22,020 --> 03:37:23,020 go nicer okay so that's great 6871 03:37:24,180 --> 03:37:25,180 we're basically going to fix this error 6872 03:37:25,859 --> 03:37:26,859 later on when we check to make sure the 6873 03:37:27,660 --> 03:37:28,660 object can only be spawned when it can 6874 03:37:29,399 --> 03:37:30,399 be spawned but for now all of our basic 6875 03:37:31,620 --> 03:37:32,620 logic is working we can spawn an object 6876 03:37:33,420 --> 03:37:34,420 and change a parent alright so with that 6877 03:37:35,819 --> 03:37:36,819 here we have added a really important 6878 03:37:37,380 --> 03:37:38,380 feature to our game that is the ability 6879 03:37:39,479 --> 03:37:40,479 to know where a kitchen object is now 6880 03:37:42,000 --> 03:37:43,000 the next step is to enable the player to 6881 03:37:43,859 --> 03:37:44,859 be able to pick it up and drop it 6882 03:37:45,300 --> 03:37:46,300 somewhere so let's do that in the next 6883 03:37:46,920 --> 03:37:47,920 lecture 6884 03:37:48,899 --> 03:37:49,899 hello and welcome I'm your code monkey 6885 03:37:50,880 --> 03:37:51,880 in this lecture we're going to enable 6886 03:37:52,859 --> 03:37:53,859 the player to pick up a kitchen object 6887 03:37:54,840 --> 03:37:55,840 and in doing so we're going to learn 6888 03:37:56,399 --> 03:37:57,399 about another awesome c-sharp feature 6889 03:37:58,319 --> 03:37:59,319 called interfaces 6890 03:37:59,880 --> 03:38:00,880 okay so right now with our game I can 6891 03:38:01,859 --> 03:38:02,859 already move the player I can approach a 6892 03:38:03,420 --> 03:38:04,420 counter and try to spawn an object and 6893 03:38:05,819 --> 03:38:06,819 with the testing key I can move it to a 6894 03:38:07,439 --> 03:38:08,439 different parent 6895 03:38:08,520 --> 03:38:09,520 so all of that logic is working now 6896 03:38:10,380 --> 03:38:11,380 let's make it work actually with the 6897 03:38:11,939 --> 03:38:12,939 player let's say when we interact once 6898 03:38:14,399 --> 03:38:15,399 we want to spawn it and if there's an 6899 03:38:16,680 --> 03:38:17,680 object already on top of it and I 6900 03:38:18,120 --> 03:38:19,120 interact again then I want to give it to 6901 03:38:19,620 --> 03:38:20,620 the player 6902 03:38:20,700 --> 03:38:21,700 okay so here on the clear counter script 6903 03:38:22,979 --> 03:38:23,979 we've got our interact function in order 6904 03:38:24,899 --> 03:38:25,899 to make that work we need to have a 6905 03:38:26,580 --> 03:38:27,580 reference to the player so I just passed 6906 03:38:28,620 --> 03:38:29,620 it in over here as an argument for our 6907 03:38:30,540 --> 03:38:31,540 interaction so just pass in the player 6908 03:38:32,880 --> 03:38:33,880 reference 6909 03:38:33,779 --> 03:38:34,779 now over here let's do the logic that I 6910 03:38:35,520 --> 03:38:36,520 send so if the kitchen object is known 6911 03:38:37,500 --> 03:38:38,500 so if there's nothing here then let's 6912 03:38:38,760 --> 03:38:39,760 spawn it okay great but if there is 6913 03:38:40,979 --> 03:38:41,979 something 6914 03:38:42,180 --> 03:38:43,180 then let's give the object to the player 6915 03:38:45,840 --> 03:38:46,840 so how we change the object parent is 6916 03:38:48,120 --> 03:38:49,120 just like what we did up here so let's 6917 03:38:50,340 --> 03:38:51,340 go into that one set the clear counter 6918 03:38:51,899 --> 03:38:52,899 and pass in deploy a reference except of 6919 03:38:54,180 --> 03:38:55,180 course this obviously does not work the 6920 03:38:56,640 --> 03:38:57,640 parameter on this function is supposed 6921 03:38:58,500 --> 03:38:59,500 to be of clear counter it does not work 6922 03:39:00,359 --> 03:39:01,359 with the type of player recently on the 6923 03:39:02,880 --> 03:39:03,880 logic that we built for setting the 6924 03:39:04,380 --> 03:39:05,380 parent and change the parent this whole 6925 03:39:06,540 --> 03:39:07,540 thing only works with the counter so it 6926 03:39:08,279 --> 03:39:09,279 does not work with any other type so we 6927 03:39:10,200 --> 03:39:11,200 cannot set the player as a parent now to 6928 03:39:12,720 --> 03:39:13,720 solve this problem is exactly where 6929 03:39:14,100 --> 03:39:15,100 c-sharp interfaces come in again I have 6930 03:39:16,680 --> 03:39:17,680 a video going through them in detail 6931 03:39:18,120 --> 03:39:19,120 definitely watch it and learn everything 6932 03:39:19,739 --> 03:39:20,739 about interfaces basically what it is is 6933 03:39:22,500 --> 03:39:23,500 a contract you define some functions in 6934 03:39:24,840 --> 03:39:25,840 the interface and then any type can 6935 03:39:27,180 --> 03:39:28,180 Implement that interface and you can 6936 03:39:29,040 --> 03:39:30,040 write some code that works with the 6937 03:39:30,479 --> 03:39:31,479 interface which in turn means that the 6938 03:39:32,040 --> 03:39:33,040 code won't work with any type as long as 6939 03:39:33,899 --> 03:39:34,899 it implements that interface 6940 03:39:35,760 --> 03:39:36,760 so in this specific example we're going 6941 03:39:38,040 --> 03:39:39,040 to make an interface to represent a 6942 03:39:39,840 --> 03:39:40,840 kitchen object parent then we're going 6943 03:39:41,880 --> 03:39:42,880 to implement that interface on both the 6944 03:39:43,620 --> 03:39:44,620 counter and the player and that way both 6945 03:39:45,600 --> 03:39:46,600 of them won't be able to be parents of a 6946 03:39:47,399 --> 03:39:48,399 kitchen object so let's do exactly that 6947 03:39:49,439 --> 03:39:50,439 now the first thing we do to Define an 6948 03:39:51,359 --> 03:39:52,359 interface is Let's Make a c-sharp script 6949 03:39:53,220 --> 03:39:54,220 so let's right click create new c-sharp 6950 03:39:55,439 --> 03:39:56,439 script and now the standard is to start 6951 03:39:57,660 --> 03:39:58,660 interface names with the capital I and 6952 03:40:00,000 --> 03:40:01,000 then the name so in this case let's name 6953 03:40:01,979 --> 03:40:02,979 it I 6954 03:40:03,120 --> 03:40:04,120 kitchen object parents 6955 03:40:05,760 --> 03:40:06,760 and let's open it okay so now to make an 6956 03:40:09,120 --> 03:40:10,120 interface first of all this does not 6957 03:40:11,100 --> 03:40:12,100 extend mono Behavior nope and secondly 6958 03:40:13,800 --> 03:40:14,800 this is not a class instead this is an 6959 03:40:16,380 --> 03:40:17,380 interface now like I said an interface 6960 03:40:18,720 --> 03:40:19,720 is essentially a contract where each 6961 03:40:20,520 --> 03:40:21,520 class that implements that interface 6962 03:40:22,080 --> 03:40:23,080 must follow that contract 6963 03:40:23,880 --> 03:40:24,880 what that really means is you can define 6964 03:40:25,680 --> 03:40:26,680 a bunch of functions here by the way 6965 03:40:27,899 --> 03:40:28,899 quick note you can also define 6966 03:40:29,040 --> 03:40:30,040 properties but not Fields I cover all of 6967 03:40:31,500 --> 03:40:32,500 that in the dedicated interface video 6968 03:40:33,060 --> 03:40:34,060 but for now here we just want some 6969 03:40:35,100 --> 03:40:36,100 functions like for example let's just 6970 03:40:37,319 --> 03:40:38,319 put all of the parent functions that we 6971 03:40:38,939 --> 03:40:39,939 made previously on the counter 6972 03:40:40,859 --> 03:40:41,859 so over here on the corner counter a 6973 03:40:42,479 --> 03:40:43,479 while ago we made all these functions 6974 03:40:44,040 --> 03:40:45,040 that we needed to make it work as a 6975 03:40:45,779 --> 03:40:46,779 kitchen object parent 6976 03:40:47,340 --> 03:40:48,340 so we got the transform set kitchen 6977 03:40:49,140 --> 03:40:50,140 object get it clear it then has it so 6978 03:40:51,000 --> 03:40:52,000 let's just copy all this and paste it 6979 03:40:52,739 --> 03:40:53,739 over here on the interface 6980 03:40:54,420 --> 03:40:55,420 however one important note is on the 6981 03:40:56,399 --> 03:40:57,399 interfaces you don't actually include 6982 03:40:58,080 --> 03:40:59,080 any function implementation 6983 03:41:00,120 --> 03:41:01,120 the implementation is up to the class 6984 03:41:01,979 --> 03:41:02,979 that implements this interface although 6985 03:41:03,960 --> 03:41:04,960 again I should also point out another 6986 03:41:05,160 --> 03:41:06,160 quick note as of c-sharp 7 you can 6987 03:41:07,439 --> 03:41:08,439 include a default implementation but 6988 03:41:09,239 --> 03:41:10,239 that's for more advanced use cases so 6989 03:41:11,340 --> 03:41:12,340 for here let's just use the basic and 6990 03:41:13,020 --> 03:41:14,020 not apply any default implementation 6991 03:41:15,060 --> 03:41:16,060 right here so we just defined the 6992 03:41:17,100 --> 03:41:18,100 function 6993 03:41:17,880 --> 03:41:18,880 and put a semicolon so just like this 6994 03:41:20,460 --> 03:41:21,460 just the function definition with the 6995 03:41:22,560 --> 03:41:23,560 exact signature so just like this okay 6996 03:41:25,380 --> 03:41:26,380 so now that we have defined our 6997 03:41:27,300 --> 03:41:28,300 interface and all the functions that we 6998 03:41:28,979 --> 03:41:29,979 want to have with this now let's go on 6999 03:41:31,560 --> 03:41:32,560 to the counter script so over here on 7000 03:41:33,300 --> 03:41:34,300 the clear counter script over here let's 7001 03:41:35,520 --> 03:41:36,520 implement the interface and the way we 7002 03:41:37,260 --> 03:41:38,260 do that is pretty much exactly the same 7003 03:41:39,000 --> 03:41:40,000 as by extending a class so over here we 7004 03:41:41,700 --> 03:41:42,700 are already extending Model Behavior 7005 03:41:43,200 --> 03:41:44,200 then let's set a comment and let's say 7006 03:41:44,939 --> 03:41:45,939 we are also implementing the ikitchen 7007 03:41:47,040 --> 03:41:48,040 object parent interface 7008 03:41:48,840 --> 03:41:49,840 so right now you might be wondering so 7009 03:41:51,060 --> 03:41:52,060 this is pretty much the same thing as 7010 03:41:52,680 --> 03:41:53,680 extending a base class and kind of 7011 03:41:55,020 --> 03:41:56,020 except for one huge difference 7012 03:41:57,420 --> 03:41:58,420 when extending a base class you can only 7013 03:41:59,580 --> 03:42:00,580 have a single Base Class like for 7014 03:42:02,160 --> 03:42:03,160 example over here we have monobehavior 7015 03:42:04,200 --> 03:42:05,200 you cannot extend multiple base classes 7016 03:42:06,600 --> 03:42:07,600 there can only be one however when it 7017 03:42:09,060 --> 03:42:10,060 comes to interfaces you can Implement as 7018 03:42:11,040 --> 03:42:12,040 many interfaces as you want so over here 7019 03:42:13,319 --> 03:42:14,319 we have defined our interface and right 7020 03:42:15,720 --> 03:42:16,720 now we don't even have any errors that's 7021 03:42:17,520 --> 03:42:18,520 because we already implemented pretty 7022 03:42:19,439 --> 03:42:20,439 much all the exact functions also Visual 7023 03:42:21,960 --> 03:42:22,960 Studio has a really nice software icon 7024 03:42:23,700 --> 03:42:24,700 over here on the left side it is 7025 03:42:25,739 --> 03:42:26,739 basically saying that this function this 7026 03:42:27,000 --> 03:42:28,000 implementation is based on the interface 7027 03:42:28,739 --> 03:42:29,739 but let's see what happens if I decide 7028 03:42:30,899 --> 03:42:31,899 to comment out these functions so if I 7029 03:42:33,479 --> 03:42:34,479 comment out all of this 7030 03:42:35,040 --> 03:42:36,040 and if there we go over here we have an 7031 03:42:37,140 --> 03:42:38,140 error it is telling us that this class 7032 03:42:39,239 --> 03:42:40,239 does not implement the members for the 7033 03:42:41,100 --> 03:42:42,100 interface like I said an interface is 7034 03:42:43,560 --> 03:42:44,560 like a contract so you must write all of 7035 03:42:46,080 --> 03:42:47,080 the functions included in the interface 7036 03:42:48,300 --> 03:42:49,300 so we must Implement these so let's get 7037 03:42:50,460 --> 03:42:51,460 rid of the comments okay 7038 03:42:52,560 --> 03:42:53,560 with this our interface is perfectly 7039 03:42:54,300 --> 03:42:55,300 working over here on the calendar 7040 03:42:55,319 --> 03:42:56,319 counter 7041 03:42:56,700 --> 03:42:57,700 now let's just go into the kitchen 7042 03:42:58,439 --> 03:42:59,439 object over here on this script 7043 03:43:00,779 --> 03:43:01,779 for now we're still working with the 7044 03:43:02,580 --> 03:43:03,580 type clear counter so let's just 7045 03:43:04,620 --> 03:43:05,620 refactor this to instead of working with 7046 03:43:06,239 --> 03:43:07,239 a clear counter let's make it work with 7047 03:43:07,979 --> 03:43:08,979 a kitchen object parent 7048 03:43:09,660 --> 03:43:10,660 so let's just change this from type that 7049 03:43:12,060 --> 03:43:13,060 to Kitchen object parent let's also 7050 03:43:14,460 --> 03:43:15,460 rename this so let's use Ctrl RR for the 7051 03:43:16,859 --> 03:43:17,859 kitchen object parent 7052 03:43:19,319 --> 03:43:20,319 then we've got a function to return the 7053 03:43:20,700 --> 03:43:21,700 kitchen object okay that's good for this 7054 03:43:22,260 --> 03:43:23,260 one instead of setting your counter and 7055 03:43:23,700 --> 03:43:24,700 let's once again rename this to set 7056 03:43:25,859 --> 03:43:26,859 kitchen object parent 7057 03:43:28,500 --> 03:43:29,500 and inside again we receive of type I 7058 03:43:31,739 --> 03:43:32,739 kitchen object parent 7059 03:43:34,319 --> 03:43:35,319 then let's also rename the parameter to 7060 03:43:36,420 --> 03:43:37,420 Kitchen object parents 7061 03:43:38,640 --> 03:43:39,640 okay so all the names here I have 7062 03:43:40,560 --> 03:43:41,560 changed okay they're all correct we set 7063 03:43:42,359 --> 03:43:43,359 it we assign it over here instead of 7064 03:43:44,460 --> 03:43:45,460 counter let's say kitchen object parent 7065 03:43:46,319 --> 03:43:47,319 already has that so just like this 7066 03:43:49,560 --> 03:43:50,560 and finally down here let's return I 7067 03:43:51,960 --> 03:43:52,960 kitchen object parent and rename this to 7068 03:43:54,720 --> 03:43:55,720 get kitchen object parent 7069 03:43:57,180 --> 03:43:58,180 and we return that 7070 03:43:59,100 --> 03:44:00,100 all right so we have changed everything 7071 03:44:00,660 --> 03:44:01,660 I can even do control F to search for 7072 03:44:02,580 --> 03:44:03,580 counter and nope there's no instance of 7073 03:44:04,380 --> 03:44:05,380 any counter so all this code has now 7074 03:44:06,660 --> 03:44:07,660 been Rewritten to work with a kitchen 7075 03:44:08,220 --> 03:44:09,220 object parent 7076 03:44:09,540 --> 03:44:10,540 something like this everything should be 7077 03:44:11,040 --> 03:44:12,040 working it's only the same as previously 7078 03:44:12,540 --> 03:44:13,540 we have no errors here 7079 03:44:14,520 --> 03:44:15,520 and over here on the clear counter we 7080 03:44:16,319 --> 03:44:17,319 just have this error on the player and 7081 03:44:17,460 --> 03:44:18,460 let's fix this in a little bit for now 7082 03:44:19,080 --> 03:44:20,080 let's just comment it let's just test it 7083 03:44:21,180 --> 03:44:22,180 out to see if everything still works 7084 03:44:22,620 --> 03:44:23,620 exactly the same as previously also one 7085 03:44:24,899 --> 03:44:25,899 final thing since we modified the 7086 03:44:26,340 --> 03:44:27,340 interact function over here on the 7087 03:44:27,840 --> 03:44:28,840 player class when we have the interact 7088 03:44:29,399 --> 03:44:30,399 we just need to pass in this reference 7089 03:44:31,439 --> 03:44:32,439 okay so let's test 7090 03:44:33,420 --> 03:44:34,420 all right so here we are let's approach 7091 03:44:35,340 --> 03:44:36,340 this one interact yep there it is now 7092 03:44:37,800 --> 03:44:38,800 let me press the testing key and if 7093 03:44:39,300 --> 03:44:40,300 there go it does move okay so everything 7094 03:44:41,279 --> 03:44:42,279 is still working exactly the same as 7095 03:44:42,960 --> 03:44:43,960 previously once again another successful 7096 03:44:44,880 --> 03:44:45,880 refactoring now here comes the magical 7097 03:44:47,460 --> 03:44:48,460 moment so right now again everything is 7098 03:44:49,560 --> 03:44:50,560 still working exactly the same as 7099 03:44:50,700 --> 03:44:51,700 previously so we can only have counters 7100 03:44:52,500 --> 03:44:53,500 as parents but now let's go over here 7101 03:44:54,660 --> 03:44:55,660 onto the player script and over here 7102 03:44:56,760 --> 03:44:57,760 let's also implement the same interface 7103 03:44:58,560 --> 03:44:59,560 so let's implement the eye kitchen 7104 03:45:00,060 --> 03:45:01,060 object parent 7105 03:45:01,260 --> 03:45:02,260 and again as usual we have our error so 7106 03:45:03,300 --> 03:45:04,300 we need to implement this 7107 03:45:04,800 --> 03:45:05,800 also again Visual Studio is very helpful 7108 03:45:06,720 --> 03:45:07,720 so we can click on the light bulb icon 7109 03:45:09,180 --> 03:45:10,180 and let's say implement the interface 7110 03:45:11,640 --> 03:45:12,640 and if we scroll down here it will 7111 03:45:13,800 --> 03:45:14,800 automatically create all these functions 7112 03:45:15,479 --> 03:45:16,479 so let's just actually Implement them 7113 03:45:18,239 --> 03:45:19,239 so for implementing this interface the 7114 03:45:20,100 --> 03:45:21,100 code is really going to be exactly the 7115 03:45:21,540 --> 03:45:22,540 same 7116 03:45:22,739 --> 03:45:23,739 so let's go up here into the clear 7117 03:45:24,180 --> 03:45:25,180 counter let's go down find all of these 7118 03:45:26,279 --> 03:45:27,279 functions let's copy them and on the 7119 03:45:28,319 --> 03:45:29,319 player let's paste them down here at the 7120 03:45:30,300 --> 03:45:31,300 bottom 7121 03:45:31,200 --> 03:45:32,200 so we just need to also pick up the 7122 03:45:33,239 --> 03:45:34,239 kitchen object as well as a reference to 7123 03:45:35,100 --> 03:45:36,100 the top point so over here on the clear 7124 03:45:37,500 --> 03:45:38,500 counter and let's just grab both those 7125 03:45:40,140 --> 03:45:41,140 so let's just grab the kitchen object so 7126 03:45:42,000 --> 03:45:43,000 go into the player and over here let's 7127 03:45:43,800 --> 03:45:44,800 add a film for the kitchen object and 7128 03:45:46,319 --> 03:45:47,319 finally let's add another one for the 7129 03:45:47,640 --> 03:45:48,640 counter top point so over here a 7130 03:45:49,620 --> 03:45:50,620 serialized film for the counter top 7131 03:45:50,939 --> 03:45:51,939 point 7132 03:45:51,899 --> 03:45:52,899 except obviously the player is not a 7133 03:45:53,700 --> 03:45:54,700 counter so this name makes no sense on 7134 03:45:55,319 --> 03:45:56,319 the player so let's just quickly rename 7135 03:45:57,180 --> 03:45:58,180 this and set call it kitchen object home 7136 03:46:00,180 --> 03:46:01,180 point 7137 03:46:01,500 --> 03:46:02,500 okay here we have our new name we've got 7138 03:46:03,779 --> 03:46:04,779 the kitchen object and down here all of 7139 03:46:05,939 --> 03:46:06,939 our functions they're all working no 7140 03:46:07,200 --> 03:46:08,200 errors all right now let's just assign 7141 03:46:09,540 --> 03:46:10,540 this in the editor 7142 03:46:11,580 --> 03:46:12,580 so over here let's just go into our 7143 03:46:13,260 --> 03:46:14,260 player there's a player script and 7144 03:46:14,700 --> 03:46:15,700 requires a reference to the kitchen 7145 03:46:16,200 --> 03:46:17,200 object home point 7146 03:46:17,700 --> 03:46:18,700 so for that let's do it just like we did 7147 03:46:19,920 --> 03:46:20,920 for the Counterpoint so inside the 7148 03:46:21,120 --> 03:46:22,120 player let's create an empty game object 7149 03:46:23,340 --> 03:46:24,340 currently the kitchen object hold points 7150 03:46:26,939 --> 03:46:27,939 and I always just position it just 7151 03:46:29,040 --> 03:46:30,040 slightly in front of the player 7152 03:46:31,140 --> 03:46:32,140 so let's put it on a x of 0 on a y of 7153 03:46:34,140 --> 03:46:35,140 1.3 and on a set of one so there you go 7154 03:46:36,899 --> 03:46:37,899 just ahead that's where the player is 7155 03:46:38,880 --> 03:46:39,880 going to be holding the objects finally 7156 03:46:40,979 --> 03:46:41,979 over here on the player let's just drag 7157 03:46:42,359 --> 03:46:43,359 that reference 7158 03:46:43,800 --> 03:46:44,800 okay so far so good also one note here 7159 03:46:46,739 --> 03:46:47,739 like I mentioned previously in order to 7160 03:46:48,420 --> 03:46:49,420 implement the interface it requires you 7161 03:46:50,160 --> 03:46:51,160 to write the function code 7162 03:46:51,899 --> 03:46:52,899 basically what this means is that 7163 03:46:53,460 --> 03:46:54,460 different objects can implement the 7164 03:46:55,020 --> 03:46:56,020 exact same interface whilst having 7165 03:46:56,580 --> 03:46:57,580 different implementations 7166 03:46:58,319 --> 03:46:59,319 so for example over here on the player 7167 03:47:00,300 --> 03:47:01,300 when setting the kitchen object 7168 03:47:02,340 --> 03:47:03,340 perhaps over here you could play some 7169 03:47:04,439 --> 03:47:05,439 kind of item grab animation or maybe 7170 03:47:06,540 --> 03:47:07,540 when clearing a kitchen object you could 7171 03:47:08,279 --> 03:47:09,279 do some kind of logging 7172 03:47:09,960 --> 03:47:10,960 the only thing that needs to match 7173 03:47:11,580 --> 03:47:12,580 perfectly is just the function signature 7174 03:47:13,739 --> 03:47:14,739 and the function signature that means 7175 03:47:15,600 --> 03:47:16,600 the return type as well as the name and 7176 03:47:17,460 --> 03:47:18,460 any parameters the implementation itself 7177 03:47:19,680 --> 03:47:20,680 that is up to the class that wants to 7178 03:47:21,420 --> 03:47:22,420 implement that interface but in this 7179 03:47:23,279 --> 03:47:24,279 case we wanted to behave pretty much 7180 03:47:25,020 --> 03:47:26,020 exam the same way so like this it should 7181 03:47:26,939 --> 03:47:27,939 be working 7182 03:47:28,080 --> 03:47:29,080 so we can now go back here onto the 7183 03:47:29,939 --> 03:47:30,939 clear counter script and okay we have 7184 03:47:32,100 --> 03:47:33,100 our interaction all right great 7185 03:47:33,840 --> 03:47:34,840 so if there's nothing we're going to 7186 03:47:35,160 --> 03:47:36,160 spawn it and if there is something on 7187 03:47:36,779 --> 03:47:37,779 top of it we want to give it to the 7188 03:47:38,100 --> 03:47:39,100 player so now let's go into the kitchen 7189 03:47:39,899 --> 03:47:40,899 object and call the function set kitchen 7190 03:47:42,000 --> 03:47:43,000 object parent and pass in the play 7191 03:47:43,680 --> 03:47:44,680 reference 7192 03:47:44,760 --> 03:47:45,760 and that's it no errors because again 7193 03:47:46,800 --> 03:47:47,800 this takes a parameter of type kitchen 7194 03:47:48,660 --> 03:47:49,660 object parent and the player does 7195 03:47:50,160 --> 03:47:51,160 implement that interface so that's all 7196 03:47:51,840 --> 03:47:52,840 valid 7197 03:47:52,979 --> 03:47:53,979 now with this let's says and see if our 7198 03:47:54,720 --> 03:47:55,720 code is working 7199 03:47:55,800 --> 03:47:56,800 alright so here we are and let's 7200 03:47:57,300 --> 03:47:58,300 interact with this counter and there you 7201 03:47:58,979 --> 03:47:59,979 go the object has been spawned and now 7202 03:48:01,260 --> 03:48:02,260 if I interact again if they're going to 7203 03:48:03,060 --> 03:48:04,060 look that the player picked up the 7204 03:48:04,319 --> 03:48:05,319 object and since our logic is using a 7205 03:48:06,779 --> 03:48:07,779 transform home Point as the parent the 7206 03:48:09,239 --> 03:48:10,239 player is automatically carrying this 7207 03:48:10,800 --> 03:48:11,800 tomato alright awesome so this is really 7208 03:48:13,920 --> 03:48:14,920 great 7209 03:48:15,060 --> 03:48:16,060 now over here on the counter we no 7210 03:48:16,680 --> 03:48:17,680 longer need all of this testing code we 7211 03:48:18,960 --> 03:48:19,960 now have the ability to actually pick up 7212 03:48:20,700 --> 03:48:21,700 objects from the player so let's get rid 7213 03:48:23,160 --> 03:48:24,160 of all this so we don't need this 7214 03:48:24,479 --> 03:48:25,479 testing code don't need a reference to 7215 03:48:26,399 --> 03:48:27,399 the second color counter or the testing 7216 03:48:28,140 --> 03:48:29,140 okay great so here you can see the power 7217 03:48:31,200 --> 03:48:32,200 of interfaces by just implementing the 7218 03:48:33,660 --> 03:48:34,660 interface we can now place an item 7219 03:48:35,460 --> 03:48:36,460 anywhere we want and importantly on any 7220 03:48:38,160 --> 03:48:39,160 type we want 7221 03:48:39,600 --> 03:48:40,600 so the counter can hold a kitchen object 7222 03:48:41,880 --> 03:48:42,880 the player can also hold it we could 7223 03:48:44,100 --> 03:48:45,100 make a dog character and make it hold a 7224 03:48:46,080 --> 03:48:47,080 kitchen object we could make a vehicle 7225 03:48:47,819 --> 03:48:48,819 hold it or anything again interfaces are 7226 03:48:50,520 --> 03:48:51,520 really really awesome one of the best C 7227 03:48:52,500 --> 03:48:53,500 sharp features definitely go ahead pause 7228 03:48:54,779 --> 03:48:55,779 this course for now and watch a 7229 03:48:56,220 --> 03:48:57,220 dedicated video on them you should be 7230 03:48:58,319 --> 03:48:59,319 very very familiar with interfaces they 7231 03:49:00,479 --> 03:49:01,479 will help you in making all kinds of 7232 03:49:01,979 --> 03:49:02,979 systems and games 7233 03:49:03,180 --> 03:49:04,180 if you want to see a clear example of 7234 03:49:04,979 --> 03:49:05,979 the power of interface you can go watch 7235 03:49:06,600 --> 03:49:07,600 my how to interact with NPC's video that 7236 03:49:09,420 --> 03:49:10,420 video takes advantage of interface to 7237 03:49:10,920 --> 03:49:11,920 make sure that the player can interact 7238 03:49:12,300 --> 03:49:13,300 with any kind of object alright so 7239 03:49:14,460 --> 03:49:15,460 thanks to interface we can now change 7240 03:49:16,319 --> 03:49:17,319 the parent of the kitchen object and put 7241 03:49:18,239 --> 03:49:19,239 it on either a counter or the player now 7242 03:49:20,520 --> 03:49:21,520 in the next lecture let's make a proper 7243 03:49:22,439 --> 03:49:23,439 different counter type 7244 03:49:24,300 --> 03:49:25,300 hello and welcome I'm your code monkey 7245 03:49:26,220 --> 03:49:27,220 in this lecture we're going to create a 7246 03:49:28,739 --> 03:49:29,739 different counter type from where we can 7247 03:49:30,420 --> 03:49:31,420 grab some ingredients 7248 03:49:32,279 --> 03:49:33,279 okay so far here we have our character 7249 03:49:34,319 --> 03:49:35,319 working and we have an empty counter and 7250 03:49:36,300 --> 03:49:37,300 by interacting with it we can spawn an 7251 03:49:37,979 --> 03:49:38,979 object but obviously that's not the 7252 03:49:40,020 --> 03:49:41,020 behavior we want in the final game we 7253 03:49:42,000 --> 03:49:43,000 want different counter types that do 7254 03:49:43,500 --> 03:49:44,500 different things the cleaner counter 7255 03:49:45,420 --> 03:49:46,420 should only be used as a place for 7256 03:49:46,680 --> 03:49:47,680 putting down and grabbing objects it 7257 03:49:48,479 --> 03:49:49,479 should not spawn anything 7258 03:49:50,040 --> 03:49:51,040 so let's build a new counter type 7259 03:49:52,560 --> 03:49:53,560 and for that one option is to make a 7260 03:49:54,960 --> 03:49:55,960 brand new prefab and build it on from 7261 03:49:56,640 --> 03:49:57,640 scratch another option is we can 7262 03:49:58,739 --> 03:49:59,739 duplicate this counter and change a 7263 03:50:00,479 --> 03:50:01,479 bunch of things or there's a third 7264 03:50:02,220 --> 03:50:03,220 option that was added in recent TNT 7265 03:50:03,899 --> 03:50:04,899 versions 7266 03:50:04,920 --> 03:50:05,920 you can now have what is called prefab 7267 03:50:07,020 --> 03:50:08,020 variants meaning that we can have a base 7268 03:50:09,660 --> 03:50:10,660 counter and then we can make variants 7269 03:50:11,700 --> 03:50:12,700 for all the types so let's do exactly 7270 03:50:14,279 --> 03:50:15,279 that to learn about prefab variants now 7271 03:50:16,739 --> 03:50:17,739 first let's duplicate this one just so 7272 03:50:18,180 --> 03:50:19,180 we don't lose any changes 7273 03:50:19,920 --> 03:50:20,920 let's rename this prefab to underscore 7274 03:50:22,439 --> 03:50:23,439 base counter 7275 03:50:23,939 --> 03:50:24,939 no I'd like to add an underscore just so 7276 03:50:26,040 --> 03:50:27,040 that the bass prefab is on top since 7277 03:50:27,720 --> 03:50:28,720 this window is sorted alphabetically 7278 03:50:30,000 --> 03:50:31,000 now let's go inside the base counter 7279 03:50:31,979 --> 03:50:32,979 let's go into the scene view so here it 7280 03:50:33,840 --> 03:50:34,840 is 7281 03:50:34,920 --> 03:50:35,920 and recently over here we only want to 7282 03:50:37,080 --> 03:50:38,080 have all of the things that all of the 7283 03:50:38,580 --> 03:50:39,580 counters will have so all the counters 7284 03:50:40,979 --> 03:50:41,979 will have a boxing ladder only the same 7285 03:50:43,020 --> 03:50:44,020 shape so that's good they will also all 7286 03:50:45,420 --> 03:50:46,420 have a counter top point 7287 03:50:47,760 --> 03:50:48,760 however for the visual different 7288 03:50:49,260 --> 03:50:50,260 counters will have different Visions so 7289 03:50:50,939 --> 03:50:51,939 let's get rid of this same thing for the 7290 03:50:52,739 --> 03:50:53,739 selected let's get rid of this 7291 03:50:54,840 --> 03:50:55,840 and on the actual object different 7292 03:50:56,340 --> 03:50:57,340 encounters will have different Scripts 7293 03:50:58,680 --> 03:50:59,680 so let's also get rid of this 7294 03:51:00,779 --> 03:51:01,779 okay so that's it this is the base 7295 03:51:02,640 --> 03:51:03,640 counter it only has all the things that 7296 03:51:05,279 --> 03:51:06,279 every single encounter will have so 7297 03:51:07,439 --> 03:51:08,439 let's go ahead save this prefab go back 7298 03:51:09,420 --> 03:51:10,420 outside and now let's right click on the 7299 03:51:11,760 --> 03:51:12,760 base counter 7300 03:51:13,080 --> 03:51:14,080 and go into create and over here let's 7301 03:51:16,080 --> 03:51:17,080 scroll down and find the prefab variant 7302 03:51:18,180 --> 03:51:19,180 now let's name this the clear counter 7303 03:51:20,460 --> 03:51:21,460 except obviously we can't have two 7304 03:51:22,200 --> 03:51:23,200 different names so let's put this one 7305 03:51:24,000 --> 03:51:25,000 into backup we're going to get rid of 7306 03:51:26,399 --> 03:51:27,399 this one in a little bit 7307 03:51:27,779 --> 03:51:28,779 so on the very end let's name it clear 7308 03:51:29,640 --> 03:51:30,640 counter 7309 03:51:31,020 --> 03:51:32,020 let's open up this variant 7310 03:51:33,060 --> 03:51:34,060 and now here let's add everything just 7311 03:51:34,800 --> 03:51:35,800 like we had on the own player counter so 7312 03:51:37,560 --> 03:51:38,560 since it's going to be exactly let's 7313 03:51:38,819 --> 03:51:39,819 actually go inside the backup one so 7314 03:51:41,460 --> 03:51:42,460 here let's just copy the visual in the 7315 03:51:43,080 --> 03:51:44,080 selected so let's copy this 7316 03:51:45,239 --> 03:51:46,239 go back inside the clear counter variant 7317 03:51:47,460 --> 03:51:48,460 and over here only let's paste it so 7318 03:51:48,960 --> 03:51:49,960 Ctrl V 7319 03:51:50,399 --> 03:51:51,399 see if there it is he selected any 7320 03:51:52,140 --> 03:51:53,140 visual 7321 03:51:53,220 --> 03:51:54,220 finally just scripts over here let's add 7322 03:51:55,560 --> 03:51:56,560 the clear counter script 7323 03:51:57,779 --> 03:51:58,779 and now let's just write the references 7324 03:51:59,760 --> 03:52:00,760 so the kitchen object we're actually 7325 03:52:01,020 --> 03:52:02,020 going to remove this in a little bit but 7326 03:52:02,399 --> 03:52:03,399 for now let's assign it the counter top 7327 03:52:04,500 --> 03:52:05,500 Point Let's drag it and on the selected 7328 03:52:06,600 --> 03:52:07,600 we also need to drag the kitchen counter 7329 03:52:08,580 --> 03:52:09,580 reference 7330 03:52:09,660 --> 03:52:10,660 okay so here is our clear counter as a 7331 03:52:12,779 --> 03:52:13,779 variant of the base counter so let's go 7332 03:52:15,000 --> 03:52:16,000 ahead save this and go back outside 7333 03:52:17,760 --> 03:52:18,760 and now we can finally delete the owned 7334 03:52:20,100 --> 03:52:21,100 prefab of the clear counter so let's go 7335 03:52:21,899 --> 03:52:22,899 ahead and delete this 7336 03:52:23,460 --> 03:52:24,460 and of course over here on the scene 7337 03:52:24,840 --> 03:52:25,840 we've got some broken prefabs so let's 7338 03:52:26,460 --> 03:52:27,460 get rid of both these and let's drop the 7339 03:52:28,920 --> 03:52:29,920 clear counter variant so let's drop it 7340 03:52:30,720 --> 03:52:31,720 place it over here so let's put it on X 7341 03:52:33,239 --> 03:52:34,239 of 0 y of zero and Z of 3.5 7342 03:52:37,859 --> 03:52:38,859 okay so that's the clear counter and 7343 03:52:39,540 --> 03:52:40,540 let's just put another one to the side 7344 03:52:40,920 --> 03:52:41,920 and perfectly on the side so on an X of 7345 03:52:42,960 --> 03:52:43,960 minus 1.5 okay now we can begin making 7346 03:52:45,840 --> 03:52:46,840 our container counter 7347 03:52:47,819 --> 03:52:48,819 so for that once again let's make a 7348 03:52:49,620 --> 03:52:50,620 variant so right click on the base 7349 03:52:51,120 --> 03:52:52,120 counter and go into create and let's 7350 03:52:52,800 --> 03:52:53,800 create a prefab variant 7351 03:52:54,600 --> 03:52:55,600 call this the container counter 7352 03:52:57,359 --> 03:52:58,359 and let's go inside of it now here first 7353 03:52:59,819 --> 03:53:00,819 thing we need is the visual so let's go 7354 03:53:01,620 --> 03:53:02,620 inside our assets we've got the prefab 7355 03:53:03,960 --> 03:53:04,960 visuals inside we have the counters 7356 03:53:05,939 --> 03:53:06,939 visuals and let's find the container 7357 03:53:08,279 --> 03:53:09,279 counter so let's drag it inside again 7358 03:53:10,439 --> 03:53:11,439 for the low composition make sure it's 7359 03:53:12,000 --> 03:53:13,000 on zero zero zero okay great 7360 03:53:14,220 --> 03:53:15,220 then we need to make the selected so 7361 03:53:16,380 --> 03:53:17,380 let's duplicate this visual let's rename 7362 03:53:18,359 --> 03:53:19,359 this to selecton 7363 03:53:20,100 --> 03:53:21,100 let's go inside on all of these 7364 03:53:23,220 --> 03:53:24,220 then let's modify the material for the 7365 03:53:25,260 --> 03:53:26,260 selected material so let's click on the 7366 03:53:27,000 --> 03:53:28,000 circle icon and select the counter 7367 03:53:28,500 --> 03:53:29,500 select material okay we've got our nice 7368 03:53:30,540 --> 03:53:31,540 little ghost icon 7369 03:53:32,340 --> 03:53:33,340 and just like we did previously let's 7370 03:53:34,020 --> 03:53:35,020 start with these disabled so all these 7371 03:53:35,700 --> 03:53:36,700 game options disabled so they are hidden 7372 03:53:37,380 --> 03:53:38,380 and on the selected let's make sure the 7373 03:53:39,479 --> 03:53:40,479 scale is one percent bigger so 1.01 7374 03:53:42,779 --> 03:53:43,779 also in the selected this one does not 7375 03:53:44,340 --> 03:53:45,340 need an animator so let's get rid of 7376 03:53:45,840 --> 03:53:46,840 this 7377 03:53:46,739 --> 03:53:47,739 now let's add the selected counter 7378 03:53:49,439 --> 03:53:50,439 visual and obviously for this one we're 7379 03:53:51,779 --> 03:53:52,779 eventually going to need to refactor it 7380 03:53:53,460 --> 03:53:54,460 to support multiple visual objects as 7381 03:53:55,560 --> 03:53:56,560 you can see this selected has multiple 7382 03:53:57,600 --> 03:53:58,600 but for now just make sure that it works 7383 03:53:59,520 --> 03:54:00,520 let's just drag just the first one okay 7384 03:54:01,380 --> 03:54:02,380 great 7385 03:54:02,340 --> 03:54:03,340 so our container counter has been built 7386 03:54:04,560 --> 03:54:05,560 the only thing that we need is the main 7387 03:54:06,120 --> 03:54:07,120 logic script so let's do that 7388 03:54:08,399 --> 03:54:09,399 let's go into our scripts folder let's 7389 03:54:10,620 --> 03:54:11,620 create a brand new c-sharp script 7390 03:54:12,960 --> 03:54:13,960 name it the container counter 7391 03:54:15,720 --> 03:54:16,720 and let's select the main game object 7392 03:54:17,760 --> 03:54:18,760 attach a script and let's open it 7393 03:54:20,279 --> 03:54:21,279 alright so now here let's first think 7394 03:54:22,319 --> 03:54:23,319 what we want for this counter we want 7395 03:54:24,600 --> 03:54:25,600 the player to interact with it and when 7396 03:54:26,460 --> 03:54:27,460 it does we want to spawn an ingredient 7397 03:54:28,020 --> 03:54:29,020 and give it to the player so that means 7398 03:54:30,420 --> 03:54:31,420 that we're going to want pretty much the 7399 03:54:31,680 --> 03:54:32,680 exact same behavior that we made over 7400 03:54:33,180 --> 03:54:34,180 here on the clear counter so when the 7401 03:54:35,520 --> 03:54:36,520 player interacts we spawn and we give it 7402 03:54:37,319 --> 03:54:38,319 to the player so let's actually copy all 7403 03:54:39,300 --> 03:54:40,300 of this code let's go into the Container 7404 03:54:41,760 --> 03:54:42,760 counter and over here let's face this 7405 03:54:44,399 --> 03:54:45,399 we just need to grab the references to 7406 03:54:46,560 --> 03:54:47,560 the kitchen object and the kitchen 7407 03:54:47,699 --> 03:54:48,699 object as so so again just like we did 7408 03:54:49,620 --> 03:54:50,620 on the container counter let's copy all 7409 03:54:51,779 --> 03:54:52,779 these references 7410 03:54:53,100 --> 03:54:54,100 and over here let's paste all of them 7411 03:54:55,680 --> 03:54:56,680 and of course here we have an error in 7412 03:54:57,600 --> 03:54:58,600 order for this work this needs to 7413 03:54:58,979 --> 03:54:59,979 implement our interface and let's do 7414 03:55:00,540 --> 03:55:01,540 exactly that so let's implement the eye 7415 03:55:02,279 --> 03:55:03,279 kitchen object parent 7416 03:55:04,140 --> 03:55:05,140 and back in the clear counter let's just 7417 03:55:06,180 --> 03:55:07,180 copy the exact same code so all of these 7418 03:55:07,979 --> 03:55:08,979 functions let's just copy them and on 7419 03:55:09,840 --> 03:55:10,840 the container counter just paste them 7420 03:55:11,220 --> 03:55:12,220 okay great 7421 03:55:12,720 --> 03:55:13,720 so we don't have any more errors here so 7422 03:55:15,000 --> 03:55:16,000 everything should work we should be able 7423 03:55:17,220 --> 03:55:18,220 to interact with the container counter 7424 03:55:18,779 --> 03:55:19,779 and we should be able to see an object 7425 03:55:20,340 --> 03:55:21,340 being spawned on top of it 7426 03:55:22,140 --> 03:55:23,140 over here in the editor let's just make 7427 03:55:23,880 --> 03:55:24,880 sure to assign it so let's assign a 7428 03:55:25,859 --> 03:55:26,859 default kitchen object so let's say 7429 03:55:27,300 --> 03:55:28,300 tomato and the counter top Point Let's 7430 03:55:29,580 --> 03:55:30,580 drag the reference and okay everything 7431 03:55:31,560 --> 03:55:32,560 else should be working so over here on 7432 03:55:33,840 --> 03:55:34,840 the selected we've got the visual game 7433 03:55:35,460 --> 03:55:36,460 object on the container counter we've 7434 03:55:36,840 --> 03:55:37,840 got this okay great so let's go outside 7435 03:55:38,460 --> 03:55:39,460 into scene View 7436 03:55:39,899 --> 03:55:40,899 and over here let's just Place some 7437 03:55:41,939 --> 03:55:42,939 container counters so let's drag one up 7438 03:55:43,920 --> 03:55:44,920 there 7439 03:55:44,880 --> 03:55:45,880 let's place it on an X of 1.5 on a y of 7440 03:55:47,819 --> 03:55:48,819 0 and Z of 3.5 and let's also Place 7441 03:55:50,939 --> 03:55:51,939 another one down here so let's rotate it 7442 03:55:53,399 --> 03:55:54,399 to face it upwards 7443 03:55:55,439 --> 03:55:56,439 okay so on position zero zero minus five 7444 03:55:57,899 --> 03:55:58,899 okay great 7445 03:55:59,220 --> 03:56:00,220 and let's make them spawn different 7446 03:56:00,660 --> 03:56:01,660 things 7447 03:56:01,920 --> 03:56:02,920 so on this one up here let's actually 7448 03:56:03,600 --> 03:56:04,600 spawn a cheese block and on this one 7449 03:56:05,699 --> 03:56:06,699 down here let's one tomato so let's also 7450 03:56:07,920 --> 03:56:08,920 modify the icon here 7451 03:56:09,540 --> 03:56:10,540 so from cheese block and let's put a 7452 03:56:12,000 --> 03:56:13,000 tomato icon so here it is 7453 03:56:14,520 --> 03:56:15,520 okay we've got two counters and two 7454 03:56:16,439 --> 03:56:17,439 clear counters so let's test 7455 03:56:18,300 --> 03:56:19,300 so here we are and if I approach a 7456 03:56:20,279 --> 03:56:21,279 container counter and I press the 7457 03:56:21,720 --> 03:56:22,720 interact button and nope nothing 7458 03:56:23,580 --> 03:56:24,580 happened we cannot interact with that at 7459 03:56:25,920 --> 03:56:26,920 all even the selection visual even that 7460 03:56:28,199 --> 03:56:29,199 one is broken so as I approach note the 7461 03:56:30,420 --> 03:56:31,420 visual is not showing up 7462 03:56:32,100 --> 03:56:33,100 now the reason for this is actually 7463 03:56:33,300 --> 03:56:34,300 pretty obvious 7464 03:56:34,859 --> 03:56:35,859 if we go over here on the player script 7465 03:56:36,960 --> 03:56:37,960 down here when we're handling our 7466 03:56:39,180 --> 03:56:40,180 interactions so let's go into the handle 7467 03:56:41,220 --> 03:56:42,220 interactions function 7468 03:56:42,720 --> 03:56:43,720 over here we are doing a recast and we 7469 03:56:45,180 --> 03:56:46,180 are trying to get component of type 7470 03:56:46,560 --> 03:56:47,560 clear counter 7471 03:56:48,060 --> 03:56:49,060 so basically we're not doing anything if 7472 03:56:50,100 --> 03:56:51,100 that object has a container counter 7473 03:56:51,779 --> 03:56:52,779 instead of a clear counter so again we 7474 03:56:54,180 --> 03:56:55,180 have a similar issue to the one that we 7475 03:56:55,920 --> 03:56:56,920 had in the object parent logic basically 7476 03:56:58,199 --> 03:56:59,199 we have two types a clear counter and a 7477 03:57:00,660 --> 03:57:01,660 container counter and we want the player 7478 03:57:02,580 --> 03:57:03,580 to be able to interact with both them 7479 03:57:04,680 --> 03:57:05,680 so as a solution for this exact same 7480 03:57:07,020 --> 03:57:08,020 problem we could also Implement an 7481 03:57:08,399 --> 03:57:09,399 interface just like we did that would 7482 03:57:10,800 --> 03:57:11,800 work that would enable the player to 7483 03:57:12,479 --> 03:57:13,479 interact with multiple counters but in 7484 03:57:14,520 --> 03:57:15,520 this case since the counters are all 7485 03:57:16,020 --> 03:57:17,020 very similar very related objects 7486 03:57:18,000 --> 03:57:19,000 they're all going to be kitchen counters 7487 03:57:19,920 --> 03:57:20,920 as opposed to object parents where the 7488 03:57:21,779 --> 03:57:22,779 player and encounter are completely 7489 03:57:23,040 --> 03:57:24,040 different 7490 03:57:23,939 --> 03:57:24,939 in this case since they are all very 7491 03:57:25,620 --> 03:57:26,620 similar a better approach is actually to 7492 03:57:27,479 --> 03:57:28,479 use inheritance now here I should point 7493 03:57:29,819 --> 03:57:30,819 out that inheritance is one of those 7494 03:57:31,500 --> 03:57:32,500 things that is simultaneously very 7495 03:57:33,000 --> 03:57:34,000 powerful but also very dangerous usually 7496 03:57:35,520 --> 03:57:36,520 beginners get really excited when they 7497 03:57:37,140 --> 03:57:38,140 first hear about inheritance but after 7498 03:57:38,760 --> 03:57:39,760 gaining some experience they start to 7499 03:57:40,319 --> 03:57:41,319 see the massive downsides 7500 03:57:42,060 --> 03:57:43,060 one funny joke about it is let's say you 7501 03:57:44,580 --> 03:57:45,580 want to write some code that all it 7502 03:57:45,899 --> 03:57:46,899 needs is a Banana class but because of 7503 03:57:48,180 --> 03:57:49,180 messy inheritance you end up with a 7504 03:57:49,680 --> 03:57:50,680 monkey and the entire jungle behind it 7505 03:57:51,779 --> 03:57:52,779 basically the banana extends a monkey 7506 03:57:53,399 --> 03:57:54,399 which extends a tree which extends the 7507 03:57:55,140 --> 03:57:56,140 jungle and so on so you just want a 7508 03:57:57,239 --> 03:57:58,239 small thing but because of a complex 7509 03:57:59,040 --> 03:58:00,040 inheritance you end up picking up a huge 7510 03:58:00,840 --> 03:58:01,840 object some of that to say inheritance 7511 03:58:02,880 --> 03:58:03,880 is something you must use very very 7512 03:58:04,560 --> 03:58:05,560 carefully it's a powerful tool 7513 03:58:06,779 --> 03:58:07,779 definitely but you need to make sure 7514 03:58:08,220 --> 03:58:09,220 that you absolutely use it in the right 7515 03:58:10,020 --> 03:58:11,020 approach for the problem you're trying 7516 03:58:11,399 --> 03:58:12,399 to solve now in this case like I said 7517 03:58:13,620 --> 03:58:14,620 since all of the counters are going to 7518 03:58:15,120 --> 03:58:16,120 be very closely related in this case it 7519 03:58:17,580 --> 03:58:18,580 does make sense 7520 03:58:18,840 --> 03:58:19,840 and of course in the future if that does 7521 03:58:20,640 --> 03:58:21,640 change we can always refactor 7522 03:58:22,680 --> 03:58:23,680 if you're a beginner definitely go ahead 7523 03:58:24,420 --> 03:58:25,420 and research a bit more on c-sharp 7524 03:58:26,340 --> 03:58:27,340 inheritance the pros and cons 7525 03:58:28,439 --> 03:58:29,439 I don't have any dedicated video on that 7526 03:58:30,420 --> 03:58:31,420 topic myself but if you search I'm sure 7527 03:58:32,100 --> 03:58:33,100 you'll find tons of content again it's a 7528 03:58:34,620 --> 03:58:35,620 very powerful but also very dangerous 7529 03:58:36,359 --> 03:58:37,359 tool so definitely use it wisely 7530 03:58:38,580 --> 03:58:39,580 over here let's make sure we rise so 7531 03:58:40,680 --> 03:58:41,680 let's use it 7532 03:58:42,060 --> 03:58:43,060 first thing we need to do is to find the 7533 03:58:43,859 --> 03:58:44,859 base counter class so let's create a new 7534 03:58:45,899 --> 03:58:46,899 c-sharp script let's call it the base 7535 03:58:48,120 --> 03:58:49,120 counter 7536 03:58:49,859 --> 03:58:50,859 so over here on the script let's get rid 7537 03:58:51,840 --> 03:58:52,840 of the functions we don't want any 7538 03:58:53,279 --> 03:58:54,279 default functions and let's also make 7539 03:58:55,199 --> 03:58:56,199 sure that we do extend mono Behavior we 7540 03:58:57,899 --> 03:58:58,899 do want that we still want to use this 7541 03:58:59,460 --> 03:59:00,460 as a component 7542 03:59:00,779 --> 03:59:01,779 so let's leave the script just like this 7543 03:59:02,340 --> 03:59:03,340 let's save it 7544 03:59:03,720 --> 03:59:04,720 then let's go over here into the clear 7545 03:59:06,120 --> 03:59:07,120 counter script 7546 03:59:07,500 --> 03:59:08,500 and on this one instead of extending 7547 03:59:09,060 --> 03:59:10,060 Model Behavior let's extend the base 7548 03:59:10,800 --> 03:59:11,800 counter 7549 03:59:12,000 --> 03:59:13,000 okay that's it that's the only change 7550 03:59:13,620 --> 03:59:14,620 and now let's go into the Container 7551 03:59:15,239 --> 03:59:16,239 counter and over here same thing let's 7552 03:59:16,739 --> 03:59:17,739 extend the base counter inside of Model 7553 03:59:18,420 --> 03:59:19,420 Behavior so now both these counters 7554 03:59:20,640 --> 03:59:21,640 extend the exact same base counter 7555 03:59:22,439 --> 03:59:23,439 script so now if we go into the player 7556 03:59:24,600 --> 03:59:25,600 score so here we are on the player 7557 03:59:26,100 --> 03:59:27,100 script and on the handle interactions 7558 03:59:28,620 --> 03:59:29,620 function over here instead of trying to 7559 03:59:30,540 --> 03:59:31,540 get a component of type player counter 7560 03:59:32,279 --> 03:59:33,279 let's try to get component of type base 7561 03:59:34,500 --> 03:59:35,500 counter so let's also rename the so 7562 03:59:36,840 --> 03:59:37,840 control RR to rename rename this to base 7563 03:59:39,479 --> 03:59:40,479 counter and of course we need to rename 7564 03:59:42,060 --> 03:59:43,060 all these references that expect a clear 7565 03:59:44,100 --> 03:59:45,100 counter instead of the base counter so 7566 03:59:46,080 --> 03:59:47,080 over here for the selected counter let's 7567 03:59:47,699 --> 03:59:48,699 modify the type to base counter then 7568 03:59:50,939 --> 03:59:51,939 also up here when we've got the event RX 7569 03:59:53,520 --> 03:59:54,520 let's modify the type okay 7570 03:59:55,680 --> 03:59:56,680 so over here we have the interactor 7571 03:59:57,479 --> 03:59:58,479 let's leave this for a bit let's go down 7572 03:59:59,160 --> 04:00:00,160 and let's fix this issue so let's go 7573 04:00:01,140 --> 04:00:02,140 down into that function to set the 7574 04:00:02,580 --> 04:00:03,580 selected counter instead of this time 7575 04:00:04,380 --> 04:00:05,380 let's receive a base counter 7576 04:00:06,479 --> 04:00:07,479 okay so all of these errors have been 7577 04:00:08,699 --> 04:00:09,699 solved there's only one left and it's 7578 04:00:10,199 --> 04:00:11,199 this one the interact 7579 04:00:11,819 --> 04:00:12,819 we see this error because obviously the 7580 04:00:13,620 --> 04:00:14,620 base less does not have any kind of 7581 04:00:15,120 --> 04:00:16,120 interact method so let's add that 7582 04:00:18,000 --> 04:00:19,000 now for adding methods to a base layer 7583 04:00:20,100 --> 04:00:21,100 it's sectionally very simple it's really 7584 04:00:21,420 --> 04:00:22,420 just like any other method so first the 7585 04:00:23,819 --> 04:00:24,819 accessor for the interact we want the 7586 04:00:25,920 --> 04:00:26,920 player to be able to access it so let's 7587 04:00:27,359 --> 04:00:28,359 make it public 7588 04:00:28,620 --> 04:00:29,620 and also since we're talking about 7589 04:00:29,939 --> 04:00:30,939 inheritance I should probably mention 7590 04:00:31,319 --> 04:00:32,319 the other accessor now you already know 7591 04:00:33,899 --> 04:00:34,899 about public and you also already know 7592 04:00:35,520 --> 04:00:36,520 about private but there's another one 7593 04:00:37,560 --> 04:00:38,560 you might not know which is called 7594 04:00:38,939 --> 04:00:39,939 protected 7595 04:00:40,319 --> 04:00:41,319 basically this one means that whatever 7596 04:00:42,239 --> 04:00:43,239 function we defined with this successor 7597 04:00:43,979 --> 04:00:44,979 it is going to be accessible to this 7598 04:00:45,960 --> 04:00:46,960 class and any class that extends it so 7599 04:00:48,540 --> 04:00:49,540 for example if we had a function that 7600 04:00:50,520 --> 04:00:51,520 was protected the clear counter could 7601 04:00:52,920 --> 04:00:53,920 count this function because it does 7602 04:00:54,300 --> 04:00:55,300 extend this Base Class however the 7603 04:00:56,460 --> 04:00:57,460 player would not be able to call this 7604 04:00:57,899 --> 04:00:58,899 because it is protected now in our case 7605 04:01:00,180 --> 04:01:01,180 for the interact action we do want to 7606 04:01:01,800 --> 04:01:02,800 play the comet so let's make it public 7607 04:01:03,420 --> 04:01:04,420 just like we had previously then another 7608 04:01:05,760 --> 04:01:06,760 keyword for every function that we want 7609 04:01:08,399 --> 04:01:09,399 the chunk lesses to be able to implement 7610 04:01:10,020 --> 04:01:11,020 in their own way we can Define it as 7611 04:01:11,819 --> 04:01:12,819 virtual 7612 04:01:12,840 --> 04:01:13,840 and finally the function signature as 7613 04:01:14,819 --> 04:01:15,819 normal so for the interact we made a 7614 04:01:16,979 --> 04:01:17,979 return void call it interact and we 7615 04:01:19,500 --> 04:01:20,500 received a player argument 7616 04:01:24,120 --> 04:01:25,120 okay so that's it that's our basic 7617 04:01:25,979 --> 04:01:26,979 signature 7618 04:01:27,060 --> 04:01:28,060 for the implementation let's leave it 7619 04:01:28,680 --> 04:01:29,680 empty over here on the base counter so 7620 04:01:30,540 --> 04:01:31,540 by default it's not going to do anything 7621 04:01:32,939 --> 04:01:33,939 in the game design that we're building 7622 04:01:34,260 --> 04:01:35,260 we're never actually going to end up 7623 04:01:35,699 --> 04:01:36,699 with anything like this 7624 04:01:37,140 --> 04:01:38,140 so if you want for safety we can just 7625 04:01:38,880 --> 04:01:39,880 add a debug.log error 7626 04:01:41,880 --> 04:01:42,880 to say just base counter.interact 7627 04:01:44,160 --> 04:01:45,160 because this should never be triggered 7628 04:01:46,319 --> 04:01:47,319 also I shouldn't point out for a more 7629 04:01:48,239 --> 04:01:49,239 advanced method 7630 04:01:49,500 --> 04:01:50,500 instead of making it virtual you could 7631 04:01:51,239 --> 04:01:52,239 make it abstract and basically what that 7632 04:01:53,699 --> 04:01:54,699 does is that forces all the classes to 7633 04:01:55,859 --> 04:01:56,859 implement their own implementation 7634 04:01:58,260 --> 04:01:59,260 so you would make this extract and just 7635 04:02:00,779 --> 04:02:01,779 put it just like this as if this were an 7636 04:02:02,699 --> 04:02:03,699 interface but in doing so you would also 7637 04:02:05,100 --> 04:02:06,100 need to define a base counter as 7638 04:02:06,600 --> 04:02:07,600 abstract and so on so basically this is 7639 04:02:08,580 --> 04:02:09,580 a more advanced method so don't worry 7640 04:02:10,080 --> 04:02:11,080 about it for now let's keep it a bit 7641 04:02:11,880 --> 04:02:12,880 more simple so let's make it just 7642 04:02:14,040 --> 04:02:15,040 virtual void interact okay great 7643 04:02:17,100 --> 04:02:18,100 so we have this let's save this and now 7644 04:02:19,380 --> 04:02:20,380 if we go on the calendar counter 7645 04:02:21,779 --> 04:02:22,779 over here on the interact notice how we 7646 04:02:24,180 --> 04:02:25,180 have a green screen line 7647 04:02:26,340 --> 04:02:27,340 basically this is a warning it's telling 7648 04:02:28,140 --> 04:02:29,140 us that we are hiding the base function 7649 04:02:30,540 --> 04:02:31,540 now in reality we don't want to hide it 7650 04:02:32,580 --> 04:02:33,580 instead we want to override it so before 7651 04:02:35,340 --> 04:02:36,340 the void before the return type we just 7652 04:02:37,140 --> 04:02:38,140 have the keyword override 7653 04:02:39,779 --> 04:02:40,779 and Yep this will now override the base 7654 04:02:41,939 --> 04:02:42,939 function so when the player interacts 7655 04:02:44,340 --> 04:02:45,340 with an object of type based counter and 7656 04:02:46,080 --> 04:02:47,080 that object is actually a clear counter 7657 04:02:47,760 --> 04:02:48,760 when the player calls the interact 7658 04:02:49,380 --> 04:02:50,380 function instead of running this code 7659 04:02:51,120 --> 04:02:52,120 it's actually going to run this code 7660 04:02:53,580 --> 04:02:54,580 now let's do the same thing on the 7661 04:02:55,199 --> 04:02:56,199 container counter so over here let's 7662 04:02:56,880 --> 04:02:57,880 also add the 7663 04:02:58,380 --> 04:02:59,380 keyword override to override the base 7664 04:03:01,080 --> 04:03:02,080 function okay great so we have no errors 7665 04:03:03,660 --> 04:03:04,660 here and on the player we also don't 7666 04:03:05,399 --> 04:03:06,399 have any more errors since that one does 7667 04:03:07,020 --> 04:03:08,020 now implement the interact function 7668 04:03:09,180 --> 04:03:10,180 so with this one it says and everything 7669 04:03:10,620 --> 04:03:11,620 should still be working so over here 7670 04:03:12,779 --> 04:03:13,779 let's approach the entire counter and 7671 04:03:14,819 --> 04:03:15,819 let's interact with it any up it does 7672 04:03:16,380 --> 04:03:17,380 work it spawn some cheese and down here 7673 04:03:18,120 --> 04:03:19,120 yep it's on the tomato and then if we go 7674 04:03:20,699 --> 04:03:21,699 on to the empty counter and interact and 7675 04:03:22,620 --> 04:03:23,620 yep it still works okay so here we added 7676 04:03:25,680 --> 04:03:26,680 the ability to interact with two 7677 04:03:27,120 --> 04:03:28,120 different counter types alright great 7678 04:03:28,920 --> 04:03:29,920 now knows how the selected logic isn't 7679 04:03:31,380 --> 04:03:32,380 really working well you can see the 7680 04:03:33,779 --> 04:03:34,779 container counters they are both 7681 04:03:35,040 --> 04:03:36,040 selected even though the player is not 7682 04:03:37,199 --> 04:03:38,199 looking at them and actually if I 7683 04:03:39,180 --> 04:03:40,180 approach it then it actually becomes 7684 04:03:40,500 --> 04:03:41,500 deselected basically the reason for that 7685 04:03:42,840 --> 04:03:43,840 is because these selected square of that 7686 04:03:44,939 --> 04:03:45,939 one is still referencing the clear 7687 04:03:46,080 --> 04:03:47,080 counter inside of the base counter 7688 04:03:48,180 --> 04:03:49,180 so right now it's only being selected 7689 04:03:49,739 --> 04:03:50,739 when the sunlight the counter is known 7690 04:03:51,120 --> 04:03:52,120 so that is why as I approach it actually 7691 04:03:52,859 --> 04:03:53,859 hides itself so let's fix this let's go 7692 04:03:56,100 --> 04:03:57,100 inside the container counter prefab and 7693 04:03:58,140 --> 04:03:59,140 inside we've got the selected any up 7694 04:04:00,239 --> 04:04:01,239 over there we have a reference to that 7695 04:04:01,620 --> 04:04:02,620 so let's open up this script and over 7696 04:04:03,779 --> 04:04:04,779 here all we need to do is just modify 7697 04:04:05,279 --> 04:04:06,279 this time so let's make it a type base 7698 04:04:07,080 --> 04:04:08,080 counter and let's rename this to base 7699 04:04:09,540 --> 04:04:10,540 counter 7700 04:04:12,120 --> 04:04:13,120 okay that's the only change we need 7701 04:04:14,279 --> 04:04:15,279 and by the way since we're here let's 7702 04:04:15,899 --> 04:04:16,899 also fix the other issue the issue we 7703 04:04:18,300 --> 04:04:19,300 had where we need to support more than 7704 04:04:20,460 --> 04:04:21,460 one visual game object 7705 04:04:22,380 --> 04:04:23,380 so instead of having a field of type 7706 04:04:24,000 --> 04:04:25,000 just game object let's receive a game 7707 04:04:25,620 --> 04:04:26,620 object ring 7708 04:04:27,000 --> 04:04:28,000 so let's modify this to game object 7709 04:04:28,859 --> 04:04:29,859 array 7710 04:04:30,000 --> 04:04:31,000 and then down here on the show hide is 7711 04:04:32,040 --> 04:04:33,040 actually very simple so let's just do a 7712 04:04:33,960 --> 04:04:34,960 four inch game object for the visual 7713 04:04:36,600 --> 04:04:37,600 game object 7714 04:04:40,680 --> 04:04:41,680 in the visual game object ring we go 7715 04:04:43,560 --> 04:04:44,560 inside set it to true and on this one we 7716 04:04:46,319 --> 04:04:47,319 set it to false 7717 04:04:48,840 --> 04:04:49,840 okay that's it super simple 7718 04:04:51,060 --> 04:04:52,060 now let's just update the prefabs so 7719 04:04:53,760 --> 04:04:54,760 first over here on the container counter 7720 04:04:55,439 --> 04:04:56,439 let's write the container counter 7721 04:04:56,760 --> 04:04:57,760 reference as the base counter okay great 7722 04:04:59,460 --> 04:05:00,460 and for divisions let's just drag all of 7723 04:05:01,739 --> 04:05:02,739 them 7724 04:05:02,580 --> 04:05:03,580 so let's write the counters only drag it 7725 04:05:04,620 --> 04:05:05,620 on top then the counter hole drag it on 7726 04:05:06,660 --> 04:05:07,660 top then the single door drag it and the 7727 04:05:09,120 --> 04:05:10,120 black drag it and also by the way over 7728 04:05:11,640 --> 04:05:12,640 here on this counter this one actually 7729 04:05:13,380 --> 04:05:14,380 has an objects right 7730 04:05:15,120 --> 04:05:16,120 this is the actual Sprite in there but 7731 04:05:17,460 --> 04:05:18,460 for the selected we really don't want 7732 04:05:18,960 --> 04:05:19,960 that so if I enable this game object 7733 04:05:21,120 --> 04:05:22,120 here we've got the object Sprite let's 7734 04:05:22,500 --> 04:05:23,500 actually delete this 7735 04:05:24,239 --> 04:05:25,239 we don't need the actual icon Sprite to 7736 04:05:26,460 --> 04:05:27,460 be highlighted so let's leave it just 7737 04:05:27,720 --> 04:05:28,720 like this so we only have these four 7738 04:05:29,220 --> 04:05:30,220 objects and all four of them are on the 7739 04:05:31,140 --> 04:05:32,140 list 7740 04:05:31,859 --> 04:05:32,859 okay that's right so all the references 7741 04:05:33,960 --> 04:05:34,960 in here they're all working perfectly 7742 04:05:36,239 --> 04:05:37,239 so let's go back outside let's save the 7743 04:05:38,220 --> 04:05:39,220 prefab let's go inside the empty clear 7744 04:05:40,439 --> 04:05:41,439 counter 7745 04:05:41,760 --> 04:05:42,760 and on this one same thing on the 7746 04:05:43,380 --> 04:05:44,380 selected let's Drag The Insider 7747 04:05:45,239 --> 04:05:46,239 reference and for the base counter let's 7748 04:05:47,399 --> 04:05:48,399 also drag that reference 7749 04:05:49,319 --> 04:05:50,319 okay so let's go outside save it and 7750 04:05:51,779 --> 04:05:52,779 let's test 7751 04:05:53,040 --> 04:05:54,040 and now let's see if the selected Works 7752 04:05:54,779 --> 04:05:55,779 once I approach this one yep it works 7753 04:05:56,340 --> 04:05:57,340 yep it works and on this one yep it 7754 04:05:58,080 --> 04:05:59,080 works and down here yep it works all 7755 04:06:00,300 --> 04:06:01,300 right awesome so we can interact and we 7756 04:06:02,819 --> 04:06:03,819 can highlight our selection okay 7757 04:06:04,680 --> 04:06:05,680 everything is working great so now that 7758 04:06:07,020 --> 04:06:08,020 all the code is working we can inspect 7759 04:06:08,819 --> 04:06:09,819 the code to see if we can refactor 7760 04:06:10,500 --> 04:06:11,500 anything 7761 04:06:11,939 --> 04:06:12,939 we can see for example if there's any 7762 04:06:13,920 --> 04:06:14,920 kind of common logic that all of the 7763 04:06:15,479 --> 04:06:16,479 counters share that we should probably 7764 04:06:16,979 --> 04:06:17,979 write in the base counter 7765 04:06:19,140 --> 04:06:20,140 and you can see right away that both the 7766 04:06:20,939 --> 04:06:21,939 clear counter and the container counter 7767 04:06:22,560 --> 04:06:23,560 both of them implement the kitchen 7768 04:06:24,359 --> 04:06:25,359 object parent interface that behavior is 7769 04:06:26,939 --> 04:06:27,939 something that all of the encounters 7770 04:06:28,140 --> 04:06:29,140 will share 7771 04:06:29,160 --> 04:06:30,160 so instead of defining it on each 7772 04:06:30,960 --> 04:06:31,960 counter itself let's actually do it on 7773 04:06:32,699 --> 04:06:33,699 the base class instead 7774 04:06:34,560 --> 04:06:35,560 so let's get rid of the interface 7775 04:06:36,239 --> 04:06:37,239 implementation here and also on the 7776 04:06:38,460 --> 04:06:39,460 container counter let's get rid of that 7777 04:06:40,439 --> 04:06:41,439 and set on base counter and let's 7778 04:06:42,060 --> 04:06:43,060 Implement that one so I catch an object 7779 04:06:44,220 --> 04:06:45,220 parent and for the functions let's do 7780 04:06:46,859 --> 04:06:47,859 the same thing so let's cut this one 7781 04:06:49,080 --> 04:06:50,080 from here and let's paste it on the base 7782 04:06:51,000 --> 04:06:52,000 counter 7783 04:06:52,260 --> 04:06:53,260 it's okay now we need these two points 7784 04:06:54,000 --> 04:06:55,000 so let's go ahead copy all of this let's 7785 04:06:56,880 --> 04:06:57,880 go into the base counter and paste in 7786 04:06:58,920 --> 04:06:59,920 except for the base one doesn't need a 7787 04:07:00,779 --> 04:07:01,779 kitchen object so so just the counter 7788 04:07:02,460 --> 04:07:03,460 top point and the kitchen object 7789 04:07:04,439 --> 04:07:05,439 okay so there are no errors on this one 7790 04:07:06,479 --> 04:07:07,479 let's go into the container 7791 04:07:08,399 --> 04:07:09,399 let's get rid of the kitchen object and 7792 04:07:10,080 --> 04:07:11,080 the counter top Point okay great 7793 04:07:12,239 --> 04:07:13,239 now we see an error but before we worry 7794 04:07:14,040 --> 04:07:15,040 about that let's actually go into the 7795 04:07:15,359 --> 04:07:16,359 clear counter and let's do the same 7796 04:07:16,979 --> 04:07:17,979 thing so let's get rid of this get rid 7797 04:07:18,660 --> 04:07:19,660 of this and down here get rid of all 7798 04:07:20,819 --> 04:07:21,819 these functions 7799 04:07:22,260 --> 04:07:23,260 okay so now the counter scripts are much 7800 04:07:24,479 --> 04:07:25,479 much more simple 7801 04:07:25,800 --> 04:07:26,800 all of the common code is now written 7802 04:07:27,600 --> 04:07:28,600 directly on the base counter 7803 04:07:29,699 --> 04:07:30,699 now for solving this the container 7804 04:07:31,979 --> 04:07:32,979 counter needs to know if there's a 7805 04:07:33,300 --> 04:07:34,300 kitchen object on top of it so now here 7806 04:07:35,819 --> 04:07:36,819 we have an interesting question with two 7807 04:07:37,739 --> 04:07:38,739 possible approaches 7808 04:07:39,479 --> 04:07:40,479 basically we need access to this object 7809 04:07:42,180 --> 04:07:43,180 so one approach would be to make this 7810 04:07:44,340 --> 04:07:45,340 protected like I said protected means 7811 04:07:46,739 --> 04:07:47,739 that any classes that extend this base 7812 04:07:48,840 --> 04:07:49,840 counter class any of those classes can 7813 04:07:51,239 --> 04:07:52,239 then modify that field something like 7814 04:07:52,739 --> 04:07:53,739 this yep there is no more errors that's 7815 04:07:54,779 --> 04:07:55,779 one approach 7816 04:07:55,979 --> 04:07:56,979 and the other approach is to instead 7817 04:07:57,720 --> 04:07:58,720 keep this one as private and whenever we 7818 04:08:00,540 --> 04:08:01,540 want to interact with it we simply 7819 04:08:02,160 --> 04:08:03,160 interact through these functions both 7820 04:08:04,319 --> 04:08:05,319 approaches can work and when in doubt as 7821 04:08:06,660 --> 04:08:07,660 usual you should probably go with the 7822 04:08:08,160 --> 04:08:09,160 more limited option so let's leave it as 7823 04:08:10,500 --> 04:08:11,500 private and work with these functions 7824 04:08:12,060 --> 04:08:13,060 and send 7825 04:08:13,020 --> 04:08:14,020 over here on the container counter 7826 04:08:14,699 --> 04:08:15,699 instead of testing if the kitchen object 7827 04:08:16,380 --> 04:08:17,380 is no let's just test has kitchen object 7828 04:08:19,080 --> 04:08:20,080 so if it does not have a kitchen object 7829 04:08:21,180 --> 04:08:22,180 then we're going to spawn it and for 7830 04:08:23,100 --> 04:08:24,100 spawning over here we could grab the 7831 04:08:25,199 --> 04:08:26,199 actual transform funnel 7832 04:08:27,479 --> 04:08:28,479 so this one up here we could call this 7833 04:08:29,220 --> 04:08:30,220 function to get it or since that is 7834 04:08:31,140 --> 04:08:32,140 actually going to be handled 7835 04:08:32,040 --> 04:08:33,040 automatically when we call this function 7836 04:08:33,420 --> 04:08:34,420 to set the parent then let's actually 7837 04:08:35,100 --> 04:08:36,100 not use this at all 7838 04:08:37,500 --> 04:08:38,500 so we just spawn it and set the kitchen 7839 04:08:39,300 --> 04:08:40,300 object parent okay great 7840 04:08:41,340 --> 04:08:42,340 so now let's just look at the clear 7841 04:08:43,080 --> 04:08:44,080 counter for this one like I said it's 7842 04:08:45,420 --> 04:08:46,420 not really meant to spawn anything solid 7843 04:08:47,460 --> 04:08:48,460 sectionally remove all of this code 7844 04:08:49,859 --> 04:08:50,859 this one is only going to serve to pick 7845 04:08:51,960 --> 04:08:52,960 up and drop items we're going to handle 7846 04:08:53,880 --> 04:08:54,880 that in the next lecture but for now 7847 04:08:55,920 --> 04:08:56,920 let's just go back into the Container 7848 04:08:57,479 --> 04:08:58,479 counter and let's do the proper logic 7849 04:08:59,819 --> 04:09:00,819 that I mentioned in the beginning 7850 04:09:00,620 --> 04:09:01,620 basically on this one we want to spawn 7851 04:09:02,880 --> 04:09:03,880 the object and we want to immediately 7852 04:09:04,560 --> 04:09:05,560 give it to the player so when we call 7853 04:09:06,600 --> 04:09:07,600 set kitchen object parent instead of 7854 04:09:08,279 --> 04:09:09,279 passing in this let's pass in the player 7855 04:09:10,020 --> 04:09:11,020 reference 7856 04:09:10,920 --> 04:09:11,920 and that's really it for the container 7857 04:09:12,540 --> 04:09:13,540 counter this is all we're going to do so 7858 04:09:14,279 --> 04:09:15,279 the player interacts and it spawns an 7859 04:09:16,380 --> 04:09:17,380 object and gives it to the player okay 7860 04:09:18,600 --> 04:09:19,600 so that's it with this as you can see 7861 04:09:20,520 --> 04:09:21,520 the code for all of our counters is much 7862 04:09:23,040 --> 04:09:24,040 much more simplified so basically it 7863 04:09:25,020 --> 04:09:26,020 only handles the logic related to that 7864 04:09:26,819 --> 04:09:27,819 specific counter everything else is on 7865 04:09:28,680 --> 04:09:29,680 the base counter so let's test this 7866 04:09:31,800 --> 04:09:32,800 so here we are and if I approach the 7867 04:09:33,779 --> 04:09:34,779 counter interact any of their go spawn 7868 04:09:35,580 --> 04:09:36,580 some cheese and gave it to the player 7869 04:09:37,080 --> 04:09:38,080 okay great now just for fun when I made 7870 04:09:40,199 --> 04:09:41,199 these assets I shall include a nice 7871 04:09:41,819 --> 04:09:42,819 animation 7872 04:09:42,779 --> 04:09:43,779 so if you go inside the container 7873 04:09:44,580 --> 04:09:45,580 counter over here on the visual note how 7874 04:09:46,739 --> 04:09:47,739 this already has an animator with an 7875 04:09:48,600 --> 04:09:49,600 animator control and attached to it 7876 04:09:50,520 --> 04:09:51,520 you can double click to open it up and 7877 04:09:52,859 --> 04:09:53,859 over here you can see it's very simple 7878 04:09:54,380 --> 04:09:55,380 basically just has two animations one is 7879 04:09:56,819 --> 04:09:57,819 the container close and one is container 7880 04:09:58,620 --> 04:09:59,620 opening and closing these transitions 7881 04:10:00,779 --> 04:10:01,779 are basically triggered by this 7882 04:10:01,979 --> 04:10:02,979 parameter this is a trigger parameter so 7883 04:10:04,500 --> 04:10:05,500 when triggers goes into the open close 7884 04:10:06,239 --> 04:10:07,239 and when this one ends goes back into 7885 04:10:07,739 --> 04:10:08,739 closed so let's just quickly add these 7886 04:10:10,020 --> 04:10:11,020 nice animations however again as usual 7887 04:10:12,420 --> 04:10:13,420 let's make sure to write some good clean 7888 04:10:13,920 --> 04:10:14,920 code so let's not add the visual over 7889 04:10:16,439 --> 04:10:17,439 here on the logic script instead let's 7890 04:10:18,359 --> 04:10:19,359 make a proper new script over here let's 7891 04:10:20,939 --> 04:10:21,939 create a new c-sharp script 7892 04:10:23,699 --> 04:10:24,699 call this the container counter visual 7893 04:10:27,600 --> 04:10:28,600 okay now we want to attach this only to 7894 04:10:29,819 --> 04:10:30,819 the visual game object so only this one 7895 04:10:31,620 --> 04:10:32,620 let's attach okay 7896 04:10:33,359 --> 04:10:34,359 and over here the first thing we need is 7897 04:10:35,220 --> 04:10:36,220 to get the animator 7898 04:10:37,020 --> 04:10:38,020 so let's sort of film for the animator 7899 04:10:39,000 --> 04:10:40,000 and since it's on the exact same object 7900 04:10:41,340 --> 04:10:42,340 we can just make an awake and get 7901 04:10:43,560 --> 04:10:44,560 component of type animator 7902 04:10:46,560 --> 04:10:47,560 and we just assigned this field okay 7903 04:10:51,239 --> 04:10:52,239 so with this we have the animator now we 7904 04:10:53,580 --> 04:10:54,580 just need to know when we should play 7905 04:10:55,140 --> 04:10:56,140 the animation so let's go over here on 7906 04:10:57,120 --> 04:10:58,120 the container counter script and 7907 04:10:58,380 --> 04:10:59,380 basically let's make an event that we're 7908 04:10:59,699 --> 04:11:00,699 going to fire when the player grabs an 7909 04:11:01,140 --> 04:11:02,140 object 7910 04:11:02,580 --> 04:11:03,580 so let's make a public event of time 7911 04:11:05,220 --> 04:11:06,220 let's stick with the standard so let's 7912 04:11:06,840 --> 04:11:07,840 use event handler inside using system 7913 04:11:08,640 --> 04:11:09,640 okay 7914 04:11:09,840 --> 04:11:10,840 let's name this on player grabbed object 7915 04:11:14,640 --> 04:11:15,640 then down here when the player interacts 7916 04:11:16,319 --> 04:11:17,319 and gets an object let's fire off this 7917 04:11:17,699 --> 04:11:18,699 event so invoke 7918 04:11:19,439 --> 04:11:20,439 let's invoke with this and event RX dot 7919 04:11:21,899 --> 04:11:22,899 empty 7920 04:11:24,120 --> 04:11:25,120 okay so we are firing off this event 7921 04:11:27,060 --> 04:11:28,060 and over here on the visual first we 7922 04:11:28,620 --> 04:11:29,620 need the film for the container counter 7923 04:11:30,120 --> 04:11:31,120 so let's set it up here let's add a 7924 04:11:31,739 --> 04:11:32,739 serialized field of tribe container 7925 04:11:34,080 --> 04:11:35,080 counter 7926 04:11:37,380 --> 04:11:38,380 okay we have this build now let's listen 7927 04:11:39,479 --> 04:11:40,479 to the event but again we're accessing 7928 04:11:41,819 --> 04:11:42,819 an external reference so let's make sure 7929 04:11:43,680 --> 04:11:44,680 to do it on start and not on awake 7930 04:11:46,080 --> 04:11:47,080 so let's go into this one and listen to 7931 04:11:48,060 --> 04:11:49,060 the on player grabbed object event okay 7932 04:11:49,920 --> 04:11:50,920 so here we have the event and it's over 7933 04:11:52,020 --> 04:11:53,020 here that we want to access the animator 7934 04:11:53,640 --> 04:11:54,640 and call set trigger in order to play 7935 04:11:55,859 --> 04:11:56,859 the animation again when working with 7936 04:11:57,960 --> 04:11:58,960 animator parameters suddenly we do need 7937 04:11:59,699 --> 04:12:00,699 to use strings there's no way around 7938 04:12:01,380 --> 04:12:02,380 that but at least we can make it a bit 7939 04:12:03,180 --> 04:12:04,180 more clean by defining a constant 7940 04:12:05,460 --> 04:12:06,460 so here a private con string call it 7941 04:12:08,040 --> 04:12:09,040 open close and let's make sure to use 7942 04:12:10,739 --> 04:12:11,739 the exact same parameter name so open 7943 04:12:12,720 --> 04:12:13,720 close 7944 04:12:15,300 --> 04:12:16,300 and then down here on the set trigger 7945 04:12:17,580 --> 04:12:18,580 let's call this trigger 7946 04:12:19,380 --> 04:12:20,380 okay so that said some very simple 7947 04:12:21,060 --> 04:12:22,060 visual logic 7948 04:12:22,620 --> 04:12:23,620 and now over here inside the prefab all 7949 04:12:24,840 --> 04:12:25,840 we need is to drag the container counter 7950 04:12:26,460 --> 04:12:27,460 reference so let's drag it also make 7951 04:12:28,500 --> 04:12:29,500 sure that it has the animator and the 7952 04:12:30,120 --> 04:12:31,120 animated controller so with that 7953 04:12:31,920 --> 04:12:32,920 everything should already be set up so 7954 04:12:33,479 --> 04:12:34,479 let's go back into the scenes save the 7955 04:12:35,220 --> 04:12:36,220 changes and let's hit on play 7956 04:12:37,439 --> 04:12:38,439 so here we are and if I go towards the 7957 04:12:39,300 --> 04:12:40,300 tomato and interact any of that I go it 7958 04:12:41,100 --> 04:12:42,100 plays a nice little animation alright 7959 04:12:43,380 --> 04:12:44,380 awesome okay so here we created a brand 7960 04:12:46,260 --> 04:12:47,260 new counter type and we refactored our 7961 04:12:48,540 --> 04:12:49,540 interact code to be able to interact 7962 04:12:50,160 --> 04:12:51,160 with any counter type the player can 7963 04:12:52,439 --> 04:12:53,439 interact with the container counter to 7964 04:12:54,000 --> 04:12:55,000 pick up an object now the next obvious 7965 04:12:56,460 --> 04:12:57,460 thing that we need is to enable the 7966 04:12:57,840 --> 04:12:58,840 player to drop an object on the clear 7967 04:12:59,460 --> 04:13:00,460 counter so let's do that in the next 7968 04:13:01,560 --> 04:13:02,560 lecture 7969 04:13:02,819 --> 04:13:03,819 hello and welcome I'm your code monkey 7970 04:13:04,859 --> 04:13:05,859 in this lecture we're going to enable 7971 04:13:06,899 --> 04:13:07,899 the player to pick up and drop objects 7972 04:13:09,600 --> 04:13:10,600 okay so we already have the player 7973 04:13:11,580 --> 04:13:12,580 working I can approach this container 7974 04:13:13,260 --> 04:13:14,260 counter interact with it and yep the 7975 04:13:14,819 --> 04:13:15,819 player picks up something now that's 7976 04:13:16,680 --> 04:13:17,680 left is being able to put our shade 7977 04:13:18,300 --> 04:13:19,300 clear counter and being able to drop 7978 04:13:19,739 --> 04:13:20,739 this object so let's do that 7979 04:13:21,660 --> 04:13:22,660 let's go over here on the clear counter 7980 04:13:23,580 --> 04:13:24,580 script and when we interact with it 7981 04:13:25,800 --> 04:13:26,800 we're going to do a bit of logic first 7982 04:13:27,960 --> 04:13:28,960 let's just check if this counter is 7983 04:13:29,760 --> 04:13:30,760 empty meaning if there is no kitchen 7984 04:13:31,680 --> 04:13:32,680 object on it so let's test if has 7985 04:13:34,380 --> 04:13:35,380 kitchen object or if not so let's say if 7986 04:13:37,920 --> 04:13:38,920 we don't have a kitchen object then 7987 04:13:40,199 --> 04:13:41,199 there is no kitchen object here 7988 04:13:43,500 --> 04:13:44,500 and if not then there is a kitchen 7989 04:13:46,439 --> 04:13:47,439 object here 7990 04:13:50,279 --> 04:13:51,279 okay these are the two valid options 7991 04:13:52,920 --> 04:13:53,920 so if there is nothing here then let's 7992 04:13:55,680 --> 04:13:56,680 check the player itself so we go into 7993 04:13:57,720 --> 04:13:58,720 the player and we can ask the same 7994 04:13:59,220 --> 04:14:00,220 question so it has kitchen object 7995 04:14:01,380 --> 04:14:02,380 so if the player is carrying something 7996 04:14:05,100 --> 04:14:06,100 so over here the player is carrying 7997 04:14:07,739 --> 04:14:08,739 something 7998 04:14:09,660 --> 04:14:10,660 if so then basically we just want to 7999 04:14:11,460 --> 04:14:12,460 drop that object from the player and 8000 04:14:13,319 --> 04:14:14,319 drop it in here so that's very simple we 8001 04:14:15,960 --> 04:14:16,960 just go into the player we get the 8002 04:14:17,819 --> 04:14:18,819 kitchen object that the player is 8003 04:14:19,080 --> 04:14:20,080 holding and we just modify the kitchen 8004 04:14:21,180 --> 04:14:22,180 object parent onto this object 8005 04:14:24,420 --> 04:14:25,420 all right so that's it just with this it 8006 04:14:26,340 --> 04:14:27,340 should already be working let's do a 8007 04:14:28,020 --> 04:14:29,020 quick test before we handle the rest of 8008 04:14:29,580 --> 04:14:30,580 the interactions 8009 04:14:30,899 --> 04:14:31,899 okay so here moving the player and if I 8010 04:14:33,060 --> 04:14:34,060 just interact with a clear counter and 8011 04:14:34,500 --> 04:14:35,500 nope nothing happens okay great since 8012 04:14:36,120 --> 04:14:37,120 the player is not carrying anything nope 8013 04:14:37,680 --> 04:14:38,680 nothing happens all right great 8014 04:14:39,420 --> 04:14:40,420 now let's pick up something from the 8015 04:14:41,160 --> 04:14:42,160 container counter okay so now the player 8016 04:14:42,779 --> 04:14:43,779 is carrying a tomato approaching clear 8017 04:14:44,399 --> 04:14:45,399 counter press a button and yep there you 8018 04:14:46,260 --> 04:14:47,260 go there it is alright Awesome 8019 04:14:48,359 --> 04:14:49,359 everything worked 8020 04:14:49,859 --> 04:14:50,859 now this is an excellent point to know 8021 04:14:51,720 --> 04:14:52,720 just how easy this was to implement and 8022 04:14:54,180 --> 04:14:55,180 the reason why it was so easy was 8023 04:14:55,800 --> 04:14:56,800 because we focus hard on running some 8024 04:14:57,479 --> 04:14:58,479 good clean code for how the object and 8025 04:14:59,340 --> 04:15:00,340 the appearance system works because we 8026 04:15:01,319 --> 04:15:02,319 took some time to think about that it 8027 04:15:03,359 --> 04:15:04,359 was now very easy to implement this 8028 04:15:04,920 --> 04:15:05,920 brand new action so this is a very very 8029 04:15:07,560 --> 04:15:08,560 clear example of the power of writing 8030 04:15:09,239 --> 04:15:10,239 good clean code okay so with that now 8031 04:15:11,819 --> 04:15:12,819 let's implement the rest so over here 8032 04:15:14,040 --> 04:15:15,040 there's no kitchen object here and the 8033 04:15:15,660 --> 04:15:16,660 player is carrying something but if not 8034 04:15:17,460 --> 04:15:18,460 we've got the L so player has nothing 8035 04:15:21,779 --> 04:15:22,779 so if the player doesn't have anything 8036 04:15:23,279 --> 04:15:24,279 so let's not do anything so player not 8037 04:15:25,920 --> 04:15:26,920 carrying anything 8038 04:15:28,560 --> 04:15:29,560 so those are all the possible States up 8039 04:15:30,239 --> 04:15:31,239 there and then down here if there is a 8040 04:15:31,800 --> 04:15:32,800 kitchen object on this layer counter if 8041 04:15:34,020 --> 04:15:35,020 so then let's check if the player has a 8042 04:15:36,600 --> 04:15:37,600 kitchen object 8043 04:15:38,399 --> 04:15:39,399 so in this deep layer is carrying 8044 04:15:41,399 --> 04:15:42,399 something 8045 04:15:42,660 --> 04:15:43,660 and if not 8046 04:15:44,880 --> 04:15:45,880 then the player is not carrying anything 8047 04:15:49,080 --> 04:15:50,080 so basically if there is a kitchen 8048 04:15:50,580 --> 04:15:51,580 object here and the player is carrying 8049 04:15:52,080 --> 04:15:53,080 something if so then we don't want to do 8050 04:15:53,640 --> 04:15:54,640 anything since we can't give the player 8051 04:15:55,380 --> 04:15:56,380 two items however if there is a kitchen 8052 04:15:57,899 --> 04:15:58,899 object here and the player is not 8053 04:15:59,279 --> 04:16:00,279 carrying anything then we want to give 8054 04:16:01,020 --> 04:16:02,020 it to the player so let's just get the 8055 04:16:03,180 --> 04:16:04,180 kitchen object the one that is on this 8056 04:16:04,979 --> 04:16:05,979 clear counter 8057 04:16:06,239 --> 04:16:07,239 and let's do the exact same thing so set 8058 04:16:08,220 --> 04:16:09,220 the parent and set the parent onto the 8059 04:16:10,140 --> 04:16:11,140 player okay so that's it as you can see 8060 04:16:12,300 --> 04:16:13,300 some very simple logic so let's test 8061 04:16:14,760 --> 04:16:15,760 okay here we are and if we interact nope 8062 04:16:17,100 --> 04:16:18,100 nothing happens okay great now pick up a 8063 04:16:18,960 --> 04:16:19,960 tomato go there drop it yep there it is 8064 04:16:20,880 --> 04:16:21,880 now if I interact again yeah there you 8065 04:16:22,620 --> 04:16:23,620 go I picked it up again so I can go 8066 04:16:24,660 --> 04:16:25,660 somewhere pick it up drop it and 8067 04:16:26,279 --> 04:16:27,279 everything works perfectly all right 8068 04:16:28,260 --> 04:16:29,260 awesome 8069 04:16:29,520 --> 04:16:30,520 now the last thing that we need to fix 8070 04:16:30,899 --> 04:16:31,899 is the container counter 8071 04:16:32,819 --> 04:16:33,819 right now it's giving out an object 8072 04:16:34,319 --> 04:16:35,319 every time even if the player has 8073 04:16:35,939 --> 04:16:36,939 something so if I pick up the other 8074 04:16:37,979 --> 04:16:38,979 works now if I pick up again there you 8075 04:16:39,779 --> 04:16:40,779 go we've got our nice helpful error this 8076 04:16:41,760 --> 04:16:42,760 should never happen 8077 04:16:43,020 --> 04:16:44,020 so let's add some nice checks 8078 04:16:45,300 --> 04:16:46,300 so over here on the container counter 8079 04:16:46,979 --> 04:16:47,979 okay we have our interaction 8080 04:16:48,779 --> 04:16:49,779 and before we spawn anything let's just 8081 04:16:50,819 --> 04:16:51,819 see if the player can pick up something 8082 04:16:52,199 --> 04:16:53,199 so once again very simple let's just go 8083 04:16:54,660 --> 04:16:55,660 into the player and we check does the 8084 04:16:56,220 --> 04:16:57,220 player have a kitchen object if so we're 8085 04:16:58,199 --> 04:16:59,199 not going to give it anything but if the 8086 04:17:00,060 --> 04:17:01,060 pointer does not have a kitchen object 8087 04:17:01,680 --> 04:17:02,680 then yep the player picks it up and we 8088 04:17:03,540 --> 04:17:04,540 give it the object 8089 04:17:10,800 --> 04:17:11,800 okay so that's it it's this simple Let's 8090 04:17:13,080 --> 04:17:14,080 test 8091 04:17:14,040 --> 04:17:15,040 so here we are let's pick up some cheese 8092 04:17:15,720 --> 04:17:16,720 okay great now pick up another one and 8093 04:17:17,399 --> 04:17:18,399 nope nothing happens okay great we're 8094 04:17:19,140 --> 04:17:20,140 already carrying something so we cannot 8095 04:17:20,640 --> 04:17:21,640 drop anything now drop it in there now 8096 04:17:22,739 --> 04:17:23,739 pick up a tomato any of it works I can 8097 04:17:24,660 --> 04:17:25,660 pick it up drop it and yep everything 8098 04:17:26,100 --> 04:17:27,100 works okay great let you see one more 8099 04:17:29,399 --> 04:17:30,399 thing 8100 04:17:30,180 --> 04:17:31,180 over here the container counter is 8101 04:17:32,220 --> 04:17:33,220 spawning the object and the object is 8102 04:17:34,199 --> 04:17:35,199 the one that we assigned 8103 04:17:35,699 --> 04:17:36,699 so over here in scene view we've got the 8104 04:17:37,739 --> 04:17:38,739 container counter this one is placed on 8105 04:17:40,140 --> 04:17:41,140 the scene and we made an override to 8106 04:17:41,819 --> 04:17:42,819 spawn a cheese block 8107 04:17:43,260 --> 04:17:44,260 technically we could keep doing this 8108 04:17:45,600 --> 04:17:46,600 pretty much just duplicate objects 8109 04:17:47,399 --> 04:17:48,399 modify the Sprite modify over here the 8110 04:17:49,140 --> 04:17:50,140 kitchen object that would work but 8111 04:17:51,720 --> 04:17:52,720 another better approach would be to 8112 04:17:53,100 --> 04:17:54,100 Simply make some prefab variants and yep 8113 04:17:55,319 --> 04:17:56,319 that does work you can make a variant of 8114 04:17:57,239 --> 04:17:58,239 a variant so let's do examine that over 8115 04:17:59,939 --> 04:18:00,939 here on the container counter let's 8116 04:18:02,100 --> 04:18:03,100 right click going to create and let's 8117 04:18:03,779 --> 04:18:04,779 create another prefab variant and let's 8118 04:18:06,300 --> 04:18:07,300 say container counter this one will be 8119 04:18:08,040 --> 04:18:09,040 the Tomato now let's go inside the 8120 04:18:10,380 --> 04:18:11,380 prefab and over here make sure it has 8121 04:18:12,660 --> 04:18:13,660 the kitchen object for the Tomato okay 8122 04:18:14,040 --> 04:18:15,040 great and over there on the Sprite so 8123 04:18:16,560 --> 04:18:17,560 let's find the object Sprite and choose 8124 04:18:19,199 --> 04:18:20,199 the Tomato Sprite so there you go this 8125 04:18:21,359 --> 04:18:22,359 one okay let's exit and Save 8126 04:18:24,479 --> 04:18:25,479 all right now once again let's right 8127 04:18:26,040 --> 04:18:27,040 click on the container and let's make it 8128 04:18:27,779 --> 04:18:28,779 another one this is going to be the one 8129 04:18:29,939 --> 04:18:30,939 for the cheese block 8130 04:18:31,920 --> 04:18:32,920 so let's go inside of it and over here 8131 04:18:34,140 --> 04:18:35,140 modify it for the cheese block and 8132 04:18:36,479 --> 04:18:37,479 inside the actual visual let's modify 8133 04:18:38,880 --> 04:18:39,880 the Sprite and sectionally down so the 8134 04:18:40,560 --> 04:18:41,560 cheese block okay great let's go back 8135 04:18:42,359 --> 04:18:43,359 outside 8136 04:18:43,260 --> 04:18:44,260 and since we're here doing this let's 8137 04:18:45,180 --> 04:18:46,180 make all of the other grab my objects 8138 04:18:47,040 --> 04:18:48,040 from the containers 8139 04:18:48,300 --> 04:18:49,300 so let's first make the kitchen object a 8140 04:18:50,340 --> 04:18:51,340 so so let's go over here we can right 8141 04:18:52,500 --> 04:18:53,500 click go into create create new kitchen 8142 04:18:54,359 --> 04:18:55,359 object so let's make one for the brand 8143 04:18:58,620 --> 04:18:59,620 then let's see if we get this one we're 8144 04:19:00,239 --> 04:19:01,239 going to have a cabbage and finally 8145 04:19:02,160 --> 04:19:03,160 we're going to have the meat Patty 8146 04:19:04,020 --> 04:19:05,020 uncooked 8147 04:19:05,460 --> 04:19:06,460 all right so now let's make sure to 8148 04:19:06,899 --> 04:19:07,899 assign all the data for all these script 8149 04:19:08,580 --> 04:19:09,580 along objects 8150 04:19:09,720 --> 04:19:10,720 first we need to make the actual kitchen 8151 04:19:11,520 --> 04:19:12,520 object so let's duplicate tomato name 8152 04:19:13,920 --> 04:19:14,920 this one bread let's go inside of it 8153 04:19:16,439 --> 04:19:17,439 and first for the kitchen object the 8154 04:19:18,180 --> 04:19:19,180 song Let's make sure to drag the correct 8155 04:19:19,680 --> 04:19:20,680 one okay there's the bread and for the 8156 04:19:21,660 --> 04:19:22,660 visual this one is not a tomato so let's 8157 04:19:23,939 --> 04:19:24,939 go inside our visual acids inside the 8158 04:19:26,279 --> 04:19:27,279 prefab visuals let's pick up the bread 8159 04:19:27,899 --> 04:19:28,899 visual okay there it is 8160 04:19:30,479 --> 04:19:31,479 that's all we need so let's go outside 8161 04:19:31,800 --> 04:19:32,800 save the changes and then select the 8162 04:19:34,319 --> 04:19:35,319 bread scripting object drag the prefab 8163 04:19:36,300 --> 04:19:37,300 reference okay for the Sprite this is 8164 04:19:38,640 --> 04:19:39,640 the bread and finally just call it bread 8165 04:19:40,560 --> 04:19:41,560 okay let's do the same thing for the 8166 04:19:42,359 --> 04:19:43,359 other one so next up for the Cabbage 8167 04:19:44,279 --> 04:19:45,279 let's do the Cabbage drag the Cabbage 8168 04:19:47,040 --> 04:19:48,040 script object let's go inside and modify 8169 04:19:49,620 --> 04:19:50,620 the visual so the Cabbage visual 8170 04:19:52,500 --> 04:19:53,500 okay that's it 8171 04:19:54,600 --> 04:19:55,600 then on the Cabbage scorpion object drag 8172 04:19:56,699 --> 04:19:57,699 the reference for the prefab let's 8173 04:19:58,620 --> 04:19:59,620 assign the Sprite and finally give it a 8174 04:20:00,840 --> 04:20:01,840 name cabbage 8175 04:20:02,520 --> 04:20:03,520 and finally the meat Patty and cooked so 8176 04:20:04,560 --> 04:20:05,560 let's do that one so let's duplicate it 8177 04:20:06,120 --> 04:20:07,120 name it meet Patty uncooked 8178 04:20:11,340 --> 04:20:12,340 let's go inside modify the kitchen 8179 04:20:14,040 --> 04:20:15,040 object so for this one and for the 8180 04:20:16,859 --> 04:20:17,859 visual let's select here it is the meat 8181 04:20:19,080 --> 04:20:20,080 Patty uncooked 8182 04:20:20,640 --> 04:20:21,640 okay let's go back outside and on the 8183 04:20:23,880 --> 04:20:24,880 escort mode object 8184 04:20:25,380 --> 04:20:26,380 let's just drag the prefab 8185 04:20:27,600 --> 04:20:28,600 assign the Sprites so this one is the 8186 04:20:29,760 --> 04:20:30,760 uncooked so it's this one 8187 04:20:31,319 --> 04:20:32,319 and finally meet Patty uncooked okay 8188 04:20:34,500 --> 04:20:35,500 great so we added all of these squared 8189 04:20:36,300 --> 04:20:37,300 more objects 8190 04:20:37,560 --> 04:20:38,560 we also have the pre-files with the 8191 04:20:39,359 --> 04:20:40,359 visuals and the electric scripts now 8192 04:20:41,160 --> 04:20:42,160 let's just make the container counter so 8193 04:20:42,779 --> 04:20:43,779 once again let's create another variant 8194 04:20:44,460 --> 04:20:45,460 so prefab variant this one is for let's 8195 04:20:47,819 --> 04:20:48,819 say for the brand 8196 04:20:49,260 --> 04:20:50,260 then let's make all the other ones 8197 04:20:51,060 --> 04:20:52,060 already so let's go make another prefab 8198 04:20:53,399 --> 04:20:54,399 variant 8199 04:20:54,300 --> 04:20:55,300 this one is going to be for the meat 8200 04:20:56,220 --> 04:20:57,220 Patty uncooked 8201 04:20:58,620 --> 04:20:59,620 and finally another variant also here 8202 04:21:00,899 --> 04:21:01,899 make sure you're creating a variant of 8203 04:21:02,399 --> 04:21:03,399 the container counter don't make an 8204 04:21:04,439 --> 04:21:05,439 accident of creating a variant of 8205 04:21:05,760 --> 04:21:06,760 something else let's make another 8206 04:21:07,020 --> 04:21:08,020 variant one final one 8207 04:21:09,060 --> 04:21:10,060 and this one is going to be for the 8208 04:21:11,279 --> 04:21:12,279 cabbage 8209 04:21:13,020 --> 04:21:14,020 okay we have all the variants now let's 8210 04:21:14,760 --> 04:21:15,760 just sign them so let's go inside the 8211 04:21:16,319 --> 04:21:17,319 bread and over there modify the 8212 04:21:18,300 --> 04:21:19,300 description object for the brand and for 8213 04:21:20,460 --> 04:21:21,460 the icon modify for the bread icon okay 8214 04:21:23,279 --> 04:21:24,279 let's go to the Cabbage save the changes 8215 04:21:25,979 --> 04:21:26,979 modify that one for the cabbage 8216 04:21:28,680 --> 04:21:29,680 go into the icon and modify the icon and 8217 04:21:32,279 --> 04:21:33,279 finally the meat Patty uncooked let's go 8218 04:21:34,439 --> 04:21:35,439 ahead modify this one for that one and 8219 04:21:37,020 --> 04:21:38,020 the icon put it on that one all right 8220 04:21:39,720 --> 04:21:40,720 everything is working 8221 04:21:41,399 --> 04:21:42,399 now let's just place them over here in 8222 04:21:43,680 --> 04:21:44,680 our scene so let's get rid of the ones 8223 04:21:45,180 --> 04:21:46,180 that we made some overrides 8224 04:21:46,920 --> 04:21:47,920 so let's get rid of that container 8225 04:21:48,840 --> 04:21:49,840 counter and set for that one let's drag 8226 04:21:51,359 --> 04:21:52,359 the cheese block put it right in there 8227 04:21:52,920 --> 04:21:53,920 let's put it on X 1.5 y of 0 Z of 3.5 8228 04:21:57,660 --> 04:21:58,660 okay 8229 04:21:58,859 --> 04:21:59,859 then down here for this one let's put 8230 04:22:01,199 --> 04:22:02,199 the Cabbage next to it let's rotate it 8231 04:22:03,779 --> 04:22:04,779 to face upwards 8232 04:22:05,340 --> 04:22:06,340 so like that let's put it on next of 8233 04:22:08,220 --> 04:22:09,220 minus 1.5 y of 0 and -5 on the Zen then 8234 04:22:12,180 --> 04:22:13,180 for tomato let's get rid of this one and 8235 04:22:13,920 --> 04:22:14,920 use the proper tomato one 8236 04:22:16,020 --> 04:22:17,020 so let's rotate it put it on an X of 0 y 8237 04:22:18,779 --> 04:22:19,779 0 and -5 8238 04:22:20,640 --> 04:22:21,640 okay next we want some bread so let's 8239 04:22:23,520 --> 04:22:24,520 put the bread up here on the left side 8240 04:22:24,960 --> 04:22:25,960 let's put it on X of minus three zero on 8241 04:22:28,560 --> 04:22:29,560 the Y and 3.5 on the Zen 8242 04:22:31,620 --> 04:22:32,620 and finally the meat Patty and Coke 8243 04:22:33,300 --> 04:22:34,300 let's put it over here a bit more on the 8244 04:22:34,739 --> 04:22:35,739 side 8245 04:22:35,580 --> 04:22:36,580 let's put it over here on X of 7.50 and 8246 04:22:38,880 --> 04:22:39,880 3.5 alright so we have positioned all of 8247 04:22:41,699 --> 04:22:42,699 them let's just make some more clear 8248 04:22:43,080 --> 04:22:44,080 counters so we can actually place the 8249 04:22:45,000 --> 04:22:46,000 objects so let's put this one over here 8250 04:22:47,160 --> 04:22:48,160 on minus 4.5 this one over there let's 8251 04:22:49,800 --> 04:22:50,800 also put some counters let's say one on 8252 04:22:52,140 --> 04:22:53,140 the right side and a bunch more down 8253 04:22:54,239 --> 04:22:55,239 here let's rotate them upwards 8254 04:22:58,380 --> 04:22:59,380 let's put this one on 1.5 minus 5. 8255 04:23:02,699 --> 04:23:03,699 and one more over here on the side 8256 04:23:06,239 --> 04:23:07,239 okay great so we have all of our 8257 04:23:08,160 --> 04:23:09,160 container counters as well as a bunch of 8258 04:23:09,720 --> 04:23:10,720 clear counters so let's test and make 8259 04:23:11,279 --> 04:23:12,279 sure that everything works okay so here 8260 04:23:13,319 --> 04:23:14,319 we are let's go down pick up a tomato 8261 04:23:14,699 --> 04:23:15,699 yep there's tomato now a cabbage yep 8262 04:23:17,040 --> 04:23:18,040 there's a cabbage now some bread there's 8263 04:23:18,720 --> 04:23:19,720 some bread and some cheese there's some 8264 04:23:20,699 --> 04:23:21,699 cheese and some meat and yep there's 8265 04:23:22,260 --> 04:23:23,260 some meat all right Awesome everything 8266 04:23:24,420 --> 04:23:25,420 works 8267 04:23:25,620 --> 04:23:26,620 so with this over here we added the 8268 04:23:27,300 --> 04:23:28,300 ability to pick up and drop objects on 8269 04:23:29,460 --> 04:23:30,460 an empty container and spawn them from 8270 04:23:31,199 --> 04:23:32,199 all kinds of container counters now in 8271 04:23:33,660 --> 04:23:34,660 the next lecture let's build the counter 8272 04:23:35,279 --> 04:23:36,279 we can interact with in a very 8273 04:23:36,720 --> 04:23:37,720 interesting way 8274 04:23:37,979 --> 04:23:38,979 hello and welcome I'm your code monkey 8275 04:23:39,899 --> 04:23:40,899 in this lecture we're going to create a 8276 04:23:42,300 --> 04:23:43,300 cutting counter so this is going to be a 8277 04:23:44,160 --> 04:23:45,160 counter where we can place an object 8278 04:23:45,600 --> 04:23:46,600 like for example tomato and after doing 8279 04:23:47,760 --> 04:23:48,760 a secondary interaction we can slice it 8280 04:23:50,040 --> 04:23:51,040 however before we do that let's just fix 8281 04:23:52,260 --> 04:23:53,260 one slightly annoying issue 8282 04:23:54,359 --> 04:23:55,359 so right now the player is walking 8283 04:23:55,680 --> 04:23:56,680 around okay that's great I can approach 8284 04:23:57,180 --> 04:23:58,180 a counter and interact with it that's 8285 04:23:58,680 --> 04:23:59,680 great however if I approach account from 8286 04:24:00,960 --> 04:24:01,960 the sign look how the player is pointing 8287 04:24:02,819 --> 04:24:03,819 towards the right and if I press the 8288 04:24:05,100 --> 04:24:06,100 double key I can indeed select it but 8289 04:24:07,260 --> 04:24:08,260 the player does not rotate to face the 8290 04:24:08,760 --> 04:24:09,760 counter so that's just a minor visual 8291 04:24:10,680 --> 04:24:11,680 issue but still I'd like to fix it so 8292 04:24:12,060 --> 04:24:13,060 let's do that very quickly basically the 8293 04:24:14,100 --> 04:24:15,100 issue is over here on our player script 8294 04:24:15,840 --> 04:24:16,840 so we scroll down and find our handle 8295 04:24:18,060 --> 04:24:19,060 movement function okay 8296 04:24:19,680 --> 04:24:20,680 so here we were doing a bunch of 8297 04:24:21,479 --> 04:24:22,479 Capstone cans in order to fix the 8298 04:24:23,520 --> 04:24:24,520 problem with the diagonal movement so 8299 04:24:25,739 --> 04:24:26,739 you try to move in One Direction if not 8300 04:24:27,420 --> 04:24:28,420 try to move in just one of those and if 8301 04:24:29,939 --> 04:24:30,939 we can move then we assign a move 8302 04:24:31,380 --> 04:24:32,380 Direction and then move it basically the 8303 04:24:33,660 --> 04:24:34,660 problem that we have here is that if I 8304 04:24:36,000 --> 04:24:37,000 press W to face towards the counter then 8305 04:24:38,699 --> 04:24:39,699 over here when we do this logic so it's 8306 04:24:40,439 --> 04:24:41,439 going to first attempt the X movement 8307 04:24:42,120 --> 04:24:43,120 only and the x is going to be zero so 8308 04:24:44,220 --> 04:24:45,220 the move there X is going to be zero 8309 04:24:45,899 --> 04:24:46,899 zero zero so it won't actually move 8310 04:24:47,760 --> 04:24:48,760 anywhere which means it won't be able to 8311 04:24:49,439 --> 04:24:50,439 move so this one becomes true which then 8312 04:24:52,260 --> 04:24:53,260 sets the move direction to zero zero 8313 04:24:54,060 --> 04:24:55,060 zero which then down here when we have 8314 04:24:55,859 --> 04:24:56,859 our rotation it's not actually going to 8315 04:24:57,420 --> 04:24:58,420 rotate to anything so we want the player 8316 04:24:59,580 --> 04:25:00,580 to still not go through any objects but 8317 04:25:02,279 --> 04:25:03,279 we only want to modify the move there 8318 04:25:04,020 --> 04:25:05,020 over here if we actually move in any of 8319 04:25:05,939 --> 04:25:06,939 these directions so the solution is 8320 04:25:07,680 --> 04:25:08,680 actually super simple it's over here for 8321 04:25:09,660 --> 04:25:10,660 the can move we can move if there's 8322 04:25:11,220 --> 04:25:12,220 nothing on there and if the move 8323 04:25:13,560 --> 04:25:14,560 direction.x is not zero 8324 04:25:16,979 --> 04:25:17,979 so that's really it if we are attempting 8325 04:25:20,160 --> 04:25:21,160 to move in the X at all and if there is 8326 04:25:22,140 --> 04:25:23,140 nothing on there then we can move which 8327 04:25:23,880 --> 04:25:24,880 means we then assign the move direction 8328 04:25:25,260 --> 04:25:26,260 if not then we don't touch this and same 8329 04:25:28,080 --> 04:25:29,080 thing down here so we can move if 8330 04:25:30,540 --> 04:25:31,540 there's nothing on it and if the move 8331 04:25:32,399 --> 04:25:33,399 there dot Zed is not zero 8332 04:25:35,819 --> 04:25:36,819 so that's it just this one simple change 8333 04:25:38,040 --> 04:25:39,040 and now the player should be able to 8334 04:25:39,779 --> 04:25:40,779 rotate 8335 04:25:40,920 --> 04:25:41,920 so here we are and if I look over there 8336 04:25:42,899 --> 04:25:43,899 and the player is currently unlocking to 8337 04:25:44,399 --> 04:25:45,399 the left and if I press W to point 8338 04:25:46,680 --> 04:25:47,680 towards the container counter and if 8339 04:25:48,120 --> 04:25:49,120 there you go the player does rotate a 8340 04:25:49,859 --> 04:25:50,859 little bit so that feels a bit more 8341 04:25:51,479 --> 04:25:52,479 natural 8342 04:25:52,260 --> 04:25:53,260 all right so that's just a tiny visual 8343 04:25:54,239 --> 04:25:55,239 thing that I wanted to fix okay so let's 8344 04:25:56,040 --> 04:25:57,040 keep going 8345 04:25:57,300 --> 04:25:58,300 now let's handle the actual cutting 8346 04:25:59,279 --> 04:26:00,279 counter 8347 04:26:00,239 --> 04:26:01,239 so first of all as usual let's make a 8348 04:26:02,220 --> 04:26:03,220 counter variant so let's right click on 8349 04:26:04,439 --> 04:26:05,439 the base counter create a new prefab 8350 04:26:06,120 --> 04:26:07,120 variant call it the cutting counter 8351 04:26:09,000 --> 04:26:10,000 let's go inside of it 8352 04:26:11,340 --> 04:26:12,340 and over here first thing we need is the 8353 04:26:13,080 --> 04:26:14,080 visual so let's pick up from the assets 8354 04:26:15,060 --> 04:26:16,060 The Cutting countervision so here it is 8355 04:26:18,420 --> 04:26:19,420 then we need the selected so let's 8356 04:26:20,159 --> 04:26:21,159 duplicate this one let's rename this one 8357 04:26:22,140 --> 04:26:23,140 to seal lectin and on the animator let's 8358 04:26:24,899 --> 04:26:25,899 get rid of it and instead at the 8359 04:26:26,760 --> 04:26:27,760 component the selected counter visual 8360 04:26:28,680 --> 04:26:29,680 okay great now let's write divisions for 8361 04:26:31,380 --> 04:26:32,380 the visual game object array and by the 8362 04:26:33,960 --> 04:26:34,960 way here's a quick tip on the right side 8363 04:26:36,120 --> 04:26:37,120 on the inspector you can see this nice 8364 04:26:37,800 --> 04:26:38,800 little lock icon 8365 04:26:39,420 --> 04:26:40,420 so if you click on it then that means 8366 04:26:41,399 --> 04:26:42,399 this inspector will not change as you 8367 04:26:43,439 --> 04:26:44,439 select other objects 8368 04:26:45,180 --> 04:26:46,180 so I can click on and select something 8369 04:26:46,979 --> 04:26:47,979 different and this one does not change 8370 04:26:48,300 --> 04:26:49,300 it is still showing the selected object 8371 04:26:50,100 --> 04:26:51,100 now this is this one when you want for 8372 04:26:51,960 --> 04:26:52,960 example to drag multiple things so you 8373 04:26:53,699 --> 04:26:54,699 can unlock the inspector then the 8374 04:26:55,560 --> 04:26:56,560 hierarchy you can use shift click to 8375 04:26:57,239 --> 04:26:58,239 select multiple objects and then just 8376 04:26:58,859 --> 04:26:59,859 drag them all directly inside the array 8377 04:27:01,080 --> 04:27:02,080 that's it just a nice quick tip so 8378 04:27:03,300 --> 04:27:04,300 everything is done let's unlock it there 8379 04:27:05,220 --> 04:27:06,220 it is okay so that said let's just 8380 04:27:07,500 --> 04:27:08,500 assign the selected material so the 8381 04:27:10,620 --> 04:27:11,620 counter select material let's make it 8382 04:27:12,479 --> 04:27:13,479 just one percent bigger so let's select 8383 04:27:15,000 --> 04:27:16,000 them all 1.01 okay and let's start with 8384 04:27:18,300 --> 04:27:19,300 all of them disabled okay 8385 04:27:20,460 --> 04:27:21,460 so the basic setup is done 8386 04:27:22,439 --> 04:27:23,439 now let's make our script to run this so 8387 04:27:24,359 --> 04:27:25,359 let's go down let's create a brand new 8388 04:27:26,040 --> 04:27:27,040 c-sharp script for The Cutting counter 8389 04:27:29,520 --> 04:27:30,520 let's select the apparent game object 8390 04:27:31,260 --> 04:27:32,260 and attach a cutting counter and let's 8391 04:27:33,180 --> 04:27:34,180 open 8392 04:27:34,920 --> 04:27:35,920 now here as usual instead of all this 8393 04:27:36,840 --> 04:27:37,840 let's start off by extending the base 8394 04:27:39,180 --> 04:27:40,180 counter okay 8395 04:27:41,340 --> 04:27:42,340 once again thanks to how we set things 8396 04:27:42,960 --> 04:27:43,960 up using such clean code this is pretty 8397 04:27:44,880 --> 04:27:45,880 much all we need to make a counter 8398 04:27:46,739 --> 04:27:47,739 with this the counter already works as a 8399 04:27:48,779 --> 04:27:49,779 counter then next thing we need is to 8400 04:27:50,580 --> 04:27:51,580 customize any logic specific to this 8401 04:27:52,319 --> 04:27:53,319 counter by just overriding the interact 8402 04:27:54,720 --> 04:27:55,720 function so that's it now over here we 8403 04:27:57,239 --> 04:27:58,239 can put whatever logic we want just for 8404 04:27:58,920 --> 04:27:59,920 the cutting counter and for this one for 8405 04:28:01,080 --> 04:28:02,080 star is actually going to be just like 8406 04:28:02,580 --> 04:28:03,580 the empty counter meaning we're going to 8407 04:28:04,140 --> 04:28:05,140 be able to drop objects on this 8408 04:28:06,180 --> 04:28:07,180 so let's just go directly into the clear 8409 04:28:08,399 --> 04:28:09,399 counter so here it is and let's just 8410 04:28:10,260 --> 04:28:11,260 copy all of this code go into the 8411 04:28:11,760 --> 04:28:12,760 cutting counter in Payson okay so the 8412 04:28:13,859 --> 04:28:14,859 exact same logic so checks if there is a 8413 04:28:15,600 --> 04:28:16,600 kitchen object or not checks if the 8414 04:28:17,159 --> 04:28:18,159 employer's carrying something or not and 8415 04:28:18,359 --> 04:28:19,359 picks up or drops in with this let's do 8416 04:28:20,580 --> 04:28:21,580 a quick test just to make sure this one 8417 04:28:21,899 --> 04:28:22,899 is working exactly like the clear 8418 04:28:23,279 --> 04:28:24,279 counter 8419 04:28:25,020 --> 04:28:26,020 so over here let's just make sure to 8420 04:28:26,399 --> 04:28:27,399 drag in less references so on The 8421 04:28:28,140 --> 04:28:29,140 Cutting counter let's make sure to drag 8422 04:28:29,460 --> 04:28:30,460 the countertop point so drag that 8423 04:28:31,140 --> 04:28:32,140 reference and then on the selected Drag 8424 04:28:33,420 --> 04:28:34,420 The Cutting counter reference okay 8425 04:28:35,340 --> 04:28:36,340 everything is good let's exit this 8426 04:28:37,080 --> 04:28:38,080 prefab make sure to save all the changes 8427 04:28:39,479 --> 04:28:40,479 and over here in the scene view let's 8428 04:28:41,220 --> 04:28:42,220 Place one of our cutting counter so 8429 04:28:42,840 --> 04:28:43,840 let's Basin right in there let's put it 8430 04:28:45,000 --> 04:28:46,000 on X of 4.5 0 and 3.5 8431 04:28:48,420 --> 04:28:49,420 okay so let's test 8432 04:28:50,340 --> 04:28:51,340 all right so here we are now if I 8433 04:28:51,899 --> 04:28:52,899 approach and I interact nope nothing 8434 04:28:53,159 --> 04:28:54,159 happens okay great pick up some cheese 8435 04:28:54,659 --> 04:28:55,659 and drop it on there any of there it is 8436 04:28:56,699 --> 04:28:57,699 I can pick it up I can pick up some 8437 04:28:58,620 --> 04:28:59,620 bread drop it and yep everything works 8438 04:29:01,199 --> 04:29:02,199 okay so far so good 8439 04:29:03,300 --> 04:29:04,300 now the next goal is to use the knife 8440 04:29:05,460 --> 04:29:06,460 and actually slice the object that is on 8441 04:29:07,140 --> 04:29:08,140 there and for that the first thing that 8442 04:29:09,180 --> 04:29:10,180 we need is we're going to need a 8443 04:29:10,680 --> 04:29:11,680 different input right now we only have 8444 04:29:12,720 --> 04:29:13,720 the movement and the interaction so 8445 04:29:14,279 --> 04:29:15,279 let's add another alt interaction 8446 04:29:16,560 --> 04:29:17,560 for that let's go into our input action 8447 04:29:19,140 --> 04:29:20,140 so let's open it up 8448 04:29:21,540 --> 04:29:22,540 let's make another action so create a 8449 04:29:24,060 --> 04:29:25,060 new action call it interact alternate 8450 04:29:28,199 --> 04:29:29,199 and for The Binding let's put it on 8451 04:29:30,000 --> 04:29:31,000 another key so let's listen and I think 8452 04:29:31,800 --> 04:29:32,800 on F makes sense 8453 04:29:33,720 --> 04:29:34,720 so let's go ahead select this one 8454 04:29:35,880 --> 04:29:36,880 then as usual let's make sure to save 8455 04:29:37,560 --> 04:29:38,560 the asset which in turn is going to 8456 04:29:39,120 --> 04:29:40,120 generate C sharp plus and compound the 8457 04:29:40,680 --> 04:29:41,680 code okay great 8458 04:29:42,000 --> 04:29:43,000 now we can go here into our game input 8459 04:29:43,859 --> 04:29:44,859 class and let's do the exact same thing 8460 04:29:45,359 --> 04:29:46,359 with it for the interact action so first 8461 04:29:47,880 --> 04:29:48,880 of all let's listen to it so let's go 8462 04:29:49,500 --> 04:29:50,500 inside the player input actions inside 8463 04:29:51,060 --> 04:29:52,060 the player action map so this one is the 8464 04:29:53,040 --> 04:29:54,040 interact alternate and let's listen to 8465 04:29:55,260 --> 04:29:56,260 the performed event 8466 04:29:56,760 --> 04:29:57,760 okay and when we have that let's fire 8467 04:29:58,439 --> 04:29:59,439 off an event pretty much the same thing 8468 04:29:59,939 --> 04:30:00,939 so interact alternate action 8469 04:30:05,460 --> 04:30:06,460 and down here let's just fire off this 8470 04:30:07,199 --> 04:30:08,199 event so 8471 04:30:08,880 --> 04:30:09,880 let's invoke using this and even RX dot 8472 04:30:11,819 --> 04:30:12,819 empty 8473 04:30:13,859 --> 04:30:14,859 okay so we have the input for the 8474 04:30:15,720 --> 04:30:16,720 interact alternate 8475 04:30:17,100 --> 04:30:18,100 now let's go on the player to listen the 8476 04:30:19,319 --> 04:30:20,319 same way we're listening to the regular 8477 04:30:20,819 --> 04:30:21,819 interact action 8478 04:30:22,920 --> 04:30:23,920 so over here on the player script let's 8479 04:30:25,080 --> 04:30:26,080 see how we're doing things so we go into 8480 04:30:26,640 --> 04:30:27,640 game input and listen to that so it's 8481 04:30:28,500 --> 04:30:29,500 the same thing game input and on 8482 04:30:30,659 --> 04:30:31,659 interact alternate action let's listen 8483 04:30:32,580 --> 04:30:33,580 to this one and when this one happens 8484 04:30:34,319 --> 04:30:35,319 lets you pretty much exactly the same 8485 04:30:36,120 --> 04:30:37,120 thing except we're just going to call a 8486 04:30:37,739 --> 04:30:38,739 different function 8487 04:30:39,239 --> 04:30:40,239 so instead of interacting let's call 8488 04:30:41,100 --> 04:30:42,100 interact Alternate which in turn 8489 04:30:43,260 --> 04:30:44,260 obviously means we need to Define this 8490 04:30:44,760 --> 04:30:45,760 function 8491 04:30:45,840 --> 04:30:46,840 so let's go into our base counter 8492 04:30:48,779 --> 04:30:49,779 so here we are on the base counter we've 8493 04:30:50,640 --> 04:30:51,640 got the interact and let's make another 8494 04:30:52,319 --> 04:30:53,319 one exactly the same just different name 8495 04:30:54,060 --> 04:30:55,060 interact alternate 8496 04:30:57,779 --> 04:30:58,779 okay that's it and now we are only going 8497 04:30:59,939 --> 04:31:00,939 to implement this in the ones that need 8498 04:31:01,620 --> 04:31:02,620 implementation 8499 04:31:03,359 --> 04:31:04,359 so for example on The Cutting counter 8500 04:31:05,159 --> 04:31:06,159 over here let's write down so public 8501 04:31:07,260 --> 04:31:08,260 override 8502 04:31:08,939 --> 04:31:09,939 and let's override the interact 8503 04:31:10,739 --> 04:31:11,739 alternate 8504 04:31:12,180 --> 04:31:13,180 and now here let's check check if 8505 04:31:14,460 --> 04:31:15,460 there's something placed on here so if 8506 04:31:16,620 --> 04:31:17,620 there's a kitchen object placed on this 8507 04:31:18,479 --> 04:31:19,479 counter 8508 04:31:19,439 --> 04:31:20,439 if so then let's basically cut it 8509 04:31:29,279 --> 04:31:30,279 and for cutting it the simplest way is 8510 04:31:31,260 --> 04:31:32,260 really to destroy whatever object is on 8511 04:31:33,540 --> 04:31:34,540 there and just spawn the slice object 8512 04:31:35,939 --> 04:31:36,939 so let's handle destroying a kitchen 8513 04:31:37,859 --> 04:31:38,859 object 8514 04:31:39,000 --> 04:31:40,000 for handling that let's go over here on 8515 04:31:40,680 --> 04:31:41,680 the kitchen object script 8516 04:31:42,180 --> 04:31:43,180 and let's make a simple function for 8517 04:31:44,040 --> 04:31:45,040 this object to destroy itself so let's 8518 04:31:46,080 --> 04:31:47,080 go up here make it public return void 8519 04:31:48,239 --> 04:31:49,239 and for name I like to use the name 8520 04:31:49,979 --> 04:31:50,979 destroy itself to make it destroy this 8521 04:31:52,260 --> 04:31:53,260 object 8522 04:31:53,760 --> 04:31:54,760 and really all we need to do is just 8523 04:31:55,380 --> 04:31:56,380 destroy and call destroy on this game 8524 04:31:57,120 --> 04:31:58,120 object 8525 04:31:58,020 --> 04:31:59,020 however before we do let's make sure to 8526 04:32:00,000 --> 04:32:01,000 clear the parent so let's go into the 8527 04:32:01,800 --> 04:32:02,800 kitchen object parent clear it and then 8528 04:32:03,540 --> 04:32:04,540 destroy the game object okay that's 8529 04:32:05,279 --> 04:32:06,279 great it's really this simple 8530 04:32:07,140 --> 04:32:08,140 and then on the cutting counter let's 8531 04:32:09,420 --> 04:32:10,420 get the kitchen object that is on here 8532 04:32:11,040 --> 04:32:12,040 and tell it to destroy itself okay so 8533 04:32:13,080 --> 04:32:14,080 let's raise the object 8534 04:32:14,640 --> 04:32:15,640 and after we do let's just spawn the 8535 04:32:16,680 --> 04:32:17,680 slices object so for now just keep 8536 04:32:19,020 --> 04:32:20,020 things simple let's make a direct 8537 04:32:20,460 --> 04:32:21,460 reference up here let's make a 8538 04:32:22,439 --> 04:32:23,439 serialized film 8539 04:32:24,540 --> 04:32:25,540 let's make it a type kitchen object so 8540 04:32:26,640 --> 04:32:27,640 and for the cut kitchen object the cell 8541 04:32:29,939 --> 04:32:30,939 okay so we have this then here in the 8542 04:32:32,460 --> 04:32:33,460 editor and let's make sure to drag the 8543 04:32:33,720 --> 04:32:34,720 reference so let's go inside the cutting 8544 04:32:36,060 --> 04:32:37,060 counter and let's open up the prefab and 8545 04:32:38,100 --> 04:32:39,100 inside let's assign this one that means 8546 04:32:40,439 --> 04:32:41,439 we need to create the object so let's 8547 04:32:41,760 --> 04:32:42,760 actually do that first 8548 04:32:44,040 --> 04:32:45,040 so let's create a brand new kitchen 8549 04:32:45,720 --> 04:32:46,720 object to sell let's come out for the 8550 04:32:48,180 --> 04:32:49,180 tomato slices 8551 04:32:50,220 --> 04:32:51,220 then if we do this we need to create the 8552 04:32:51,960 --> 04:32:52,960 prefab so let's once again do the same 8553 04:32:53,760 --> 04:32:54,760 thing tomato slices make the prefab 8554 04:32:56,279 --> 04:32:57,279 let's go inside this prefab let's modify 8555 04:32:58,979 --> 04:32:59,979 the visual so use the tomato slices 8556 04:33:00,779 --> 04:33:01,779 visual okay and drag the reference for 8557 04:33:03,479 --> 04:33:04,479 the other kitchen object for the tomato 8558 04:33:05,340 --> 04:33:06,340 slices okay 8559 04:33:06,959 --> 04:33:07,959 so the visual prefab is good and let's 8560 04:33:09,299 --> 04:33:10,299 just go into the kitchen object let's 8561 04:33:11,820 --> 04:33:12,820 just make sure to drag the prefab 8562 04:33:13,740 --> 04:33:14,740 reference then let's assign the tomato 8563 04:33:15,959 --> 04:33:16,959 slices icon and just come with tomato 8564 04:33:18,600 --> 04:33:19,600 slices 8565 04:33:20,459 --> 04:33:21,459 okay so we have the kitchen object so 8566 04:33:22,379 --> 04:33:23,379 now we can go into the kitchen counting 8567 04:33:24,660 --> 04:33:25,660 counter and over here let's open up and 8568 04:33:27,420 --> 04:33:28,420 set this one to the tomato slices 8569 04:33:29,699 --> 04:33:30,699 okay so we have all the references let's 8570 04:33:31,799 --> 04:33:32,799 go back outside save it 8571 04:33:33,719 --> 04:33:34,719 and back over here in our code so we 8572 04:33:35,459 --> 04:33:36,459 have this now we just need to spawn this 8573 04:33:37,141 --> 04:33:38,141 object 8574 04:33:38,219 --> 04:33:39,219 so we're really just going to spawn it 8575 04:33:39,719 --> 04:33:40,719 pretty much exactly like we did over 8576 04:33:40,980 --> 04:33:41,980 here on the container so we just go into 8577 04:33:43,080 --> 04:33:44,080 the description object spawn the prefab 8578 04:33:44,699 --> 04:33:45,699 and set the appearance so let's do 8579 04:33:46,080 --> 04:33:47,080 exactly that 8580 04:33:47,459 --> 04:33:48,459 over here we destroy the object then we 8581 04:33:50,400 --> 04:33:51,400 instantiate the cut kitchen object and 8582 04:33:53,039 --> 04:33:54,039 instead of getting into the player let's 8583 04:33:54,779 --> 04:33:55,779 put it on this 8584 04:33:56,459 --> 04:33:57,459 okay so that's it we should be able to 8585 04:33:58,799 --> 04:33:59,799 place a tomato directly on top of the 8586 04:34:00,900 --> 04:34:01,900 cutting counter and it should be able to 8587 04:34:02,459 --> 04:34:03,459 transform from a tomato into a tomato 8588 04:34:04,379 --> 04:34:05,379 slices 8589 04:34:05,939 --> 04:34:06,939 okay so here we are let me pick up a 8590 04:34:07,859 --> 04:34:08,859 tomato go up there drop it and okay that 8591 04:34:09,959 --> 04:34:10,959 works now if I press the onton track key 8592 04:34:12,420 --> 04:34:13,420 press it and if there go it did work the 8593 04:34:15,119 --> 04:34:16,119 Tomato was destroyed and the tomato 8594 04:34:16,561 --> 04:34:17,561 slices were spawn and I can pick them up 8595 04:34:18,660 --> 04:34:19,660 place them anywhere and yep everything 8596 04:34:19,980 --> 04:34:20,980 works alright awesome so with this the 8597 04:34:23,039 --> 04:34:24,039 basics are fully working let's just 8598 04:34:25,320 --> 04:34:26,320 briefly clean up this code 8599 04:34:27,299 --> 04:34:28,299 we already saw a little bit of code 8600 04:34:29,039 --> 04:34:30,039 duplication so the cutting counter is 8601 04:34:31,320 --> 04:34:32,320 going to spawn an object and the 8602 04:34:32,760 --> 04:34:33,760 container counter is also spawning an 8603 04:34:34,260 --> 04:34:35,260 object so we're copy pasting these two 8604 04:34:36,299 --> 04:34:37,299 lines of code in multiple places so 8605 04:34:38,219 --> 04:34:39,219 instead of doing that let's put it in 8606 04:34:39,539 --> 04:34:40,539 just one place 8607 04:34:41,039 --> 04:34:42,039 and actually a good place to put this is 8608 04:34:43,141 --> 04:34:44,141 on the kitchen object list itself so it 8609 04:34:45,180 --> 04:34:46,180 makes sense that this one is responsible 8610 04:34:46,740 --> 04:34:47,740 for spawning more objects 8611 04:34:48,660 --> 04:34:49,660 so let's put it over here however let us 8612 04:34:51,180 --> 04:34:52,180 not make it a regular function instead 8613 04:34:53,580 --> 04:34:54,580 let us make it a static function again 8614 04:34:55,980 --> 04:34:56,980 just like we saw for The Singletons by 8615 04:34:57,900 --> 04:34:58,900 making it static it means that the 8616 04:34:59,340 --> 04:35:00,340 function is going to belong to the class 8617 04:35:00,840 --> 04:35:01,840 itself as opposed to any instance so 8618 04:35:03,420 --> 04:35:04,420 let's go all the way down to the bottom 8619 04:35:05,039 --> 04:35:06,039 of the file personally I like to put 8620 04:35:06,480 --> 04:35:07,480 settings at the end and over here let's 8621 04:35:08,699 --> 04:35:09,699 make public make it static we're going 8622 04:35:10,799 --> 04:35:11,799 to return a kitchen object and let's 8623 04:35:13,020 --> 04:35:14,020 call it just spawn kitchen object 8624 04:35:16,561 --> 04:35:17,561 and for our parameters let's receive the 8625 04:35:19,141 --> 04:35:20,141 kitchen object that so 8626 04:35:21,240 --> 04:35:22,240 and let's also receive the kitchen 8627 04:35:22,799 --> 04:35:23,799 object parent 8628 04:35:25,020 --> 04:35:26,020 okay so that's it and we're going to do 8629 04:35:26,580 --> 04:35:27,580 the exact same thing so let's go into 8630 04:35:28,080 --> 04:35:29,080 the cutting counter and copy the code 8631 04:35:29,760 --> 04:35:30,760 that we're using and over here just 8632 04:35:31,859 --> 04:35:32,859 paste it in there so we go inside here 8633 04:35:34,080 --> 04:35:35,080 spawn the prefab and set it on this 8634 04:35:35,641 --> 04:35:36,641 parent 8635 04:35:36,600 --> 04:35:37,600 and finally let's return it 8636 04:35:40,020 --> 04:35:41,020 so let's return the kitchen object over 8637 04:35:42,000 --> 04:35:43,000 here let's pick it up so the kitchen 8638 04:35:43,920 --> 04:35:44,920 object 8639 04:35:45,900 --> 04:35:46,900 we get it and then we do kitchen object 8640 04:35:49,379 --> 04:35:50,379 set the parent and finally we return the 8641 04:35:51,959 --> 04:35:52,959 kitchen object 8642 04:35:54,480 --> 04:35:55,480 all right so that's it here we have a 8643 04:35:56,340 --> 04:35:57,340 super simple function that we can call 8644 04:35:57,900 --> 04:35:58,900 very easily it won't automatically spawn 8645 04:36:00,480 --> 04:36:01,480 an object and set to parents so now 8646 04:36:02,279 --> 04:36:03,279 let's just call this from somewhere so 8647 04:36:04,020 --> 04:36:05,020 over here on the cutting counter instead 8648 04:36:05,459 --> 04:36:06,459 of doing all this let's just go into the 8649 04:36:07,020 --> 04:36:08,020 kitchen object again remember let's go 8650 04:36:09,240 --> 04:36:10,240 through the class name itself and not 8651 04:36:11,039 --> 04:36:12,039 any instance and over here let's call 8652 04:36:13,320 --> 04:36:14,320 the function pass in the cut kitchen 8653 04:36:15,119 --> 04:36:16,119 object the cell and for the parent it's 8654 04:36:17,279 --> 04:36:18,279 going to be this 8655 04:36:18,480 --> 04:36:19,480 all right so that is now much much 8656 04:36:20,219 --> 04:36:21,219 simpler and let's do the same thing over 8657 04:36:22,020 --> 04:36:23,020 here on the container counter so if the 8658 04:36:24,299 --> 04:36:25,299 player is not carrying anything 8659 04:36:26,641 --> 04:36:27,641 let's give the player this object and 8660 04:36:29,219 --> 04:36:30,219 give it to the player just like this 8661 04:36:32,580 --> 04:36:33,580 as usual when we do some kind of 8662 04:36:34,080 --> 04:36:35,080 refactoring let's do a quick test make 8663 04:36:35,699 --> 04:36:36,699 sure everything still works exactly the 8664 04:36:37,260 --> 04:36:38,260 same 8665 04:36:38,039 --> 04:36:39,039 okay so here we are and if I go to the 8666 04:36:39,900 --> 04:36:40,900 counter and pick it up yep it does work 8667 04:36:41,340 --> 04:36:42,340 to spawn the object now I can drop it in 8668 04:36:43,080 --> 04:36:44,080 there I can cut it and yep there you go 8669 04:36:44,699 --> 04:36:45,699 everything does work all right so far so 8670 04:36:46,799 --> 04:36:47,799 good 8671 04:36:47,760 --> 04:36:48,760 so with all this basically we have 8672 04:36:49,379 --> 04:36:50,379 created a brand new counter where we can 8673 04:36:51,299 --> 04:36:52,299 cut objects however right now there's 8674 04:36:53,820 --> 04:36:54,820 obviously one huge layering funnel if I 8675 04:36:56,459 --> 04:36:57,459 now pick up a cabbage and I drop it on 8676 04:36:58,260 --> 04:36:59,260 the cutting counter and I interact with 8677 04:36:59,641 --> 04:37:00,641 it that cabbage has suddenly magically 8678 04:37:01,439 --> 04:37:02,439 turned into tomato slices now that is 8679 04:37:04,199 --> 04:37:05,199 obviously not intended so for that let's 8680 04:37:06,660 --> 04:37:07,660 define a proper cutting recipe and let's 8681 04:37:08,641 --> 04:37:09,641 do that in the next lecture 8682 04:37:11,039 --> 04:37:12,039 hello and welcome I'm your code monkey 8683 04:37:12,840 --> 04:37:13,840 in this lecture we're going to create 8684 04:37:14,760 --> 04:37:15,760 another scriptable object type this one 8685 04:37:16,980 --> 04:37:17,980 is going to be for handling our cutting 8686 04:37:18,840 --> 04:37:19,840 recipes 8687 04:37:19,859 --> 04:37:20,859 so here's our game I can pick up a 8688 04:37:21,840 --> 04:37:22,840 tomato drop it on the cutting counter 8689 04:37:23,520 --> 04:37:24,520 cut it there you go slice Tomatoes 8690 04:37:25,379 --> 04:37:26,379 however if I could pick up a cabbage go 8691 04:37:27,840 --> 04:37:28,840 there cut it and there you go cabbage 8692 04:37:29,400 --> 04:37:30,400 turns into tomatoes so we have an 8693 04:37:31,740 --> 04:37:32,740 obvious issue The Cutting object is 8694 04:37:33,420 --> 04:37:34,420 currently hard-coded instead of being 8695 04:37:34,920 --> 04:37:35,920 based on the object we put on top of it 8696 04:37:37,080 --> 04:37:38,080 so to solve that let's make another 8697 04:37:38,820 --> 04:37:39,820 scribble object type like I mentioned 8698 04:37:40,980 --> 04:37:41,980 scribble objects are excellent for 8699 04:37:42,719 --> 04:37:43,719 storing and organizing data so it's 8700 04:37:44,760 --> 04:37:45,760 perfect for this use case basically we 8701 04:37:46,980 --> 04:37:47,980 want a script mode object to hold a 8702 04:37:48,539 --> 04:37:49,539 reference to the regular object and the 8703 04:37:50,340 --> 04:37:51,340 cut object so we can then identify the 8704 04:37:52,920 --> 04:37:53,920 input in order to spawn the output okay 8705 04:37:55,199 --> 04:37:56,199 so let's build that let's create a brand 8706 04:37:57,420 --> 04:37:58,420 new c-sharp script 8707 04:37:58,799 --> 04:37:59,799 call it the cutting recipe so 8708 04:38:01,619 --> 04:38:02,619 and let's open it 8709 04:38:03,420 --> 04:38:04,420 okay so now here on let's do exactly 8710 04:38:05,279 --> 04:38:06,279 that so something extremely simple so 8711 04:38:06,959 --> 04:38:07,959 instead of modern behavior this one is a 8712 04:38:08,520 --> 04:38:09,520 script mode object let's add the create 8713 04:38:10,619 --> 04:38:11,619 asset menu and finally for the fields 8714 04:38:13,080 --> 04:38:14,080 let's do just an input and output so 8715 04:38:15,299 --> 04:38:16,299 we've got of type kitchen object so 8716 04:38:17,160 --> 04:38:18,160 let's go for the input and another one 8717 04:38:19,379 --> 04:38:20,379 for the output 8718 04:38:21,000 --> 04:38:22,000 okay so that's really it super simple 8719 04:38:23,580 --> 04:38:24,580 now here in the editor before we create 8720 04:38:25,320 --> 04:38:26,320 and let's keep things organized so let's 8721 04:38:26,939 --> 04:38:27,939 make another folder 8722 04:38:28,680 --> 04:38:29,680 let's make it for the cutting recipe so 8723 04:38:32,100 --> 04:38:33,100 and inside let's frequently create a new 8724 04:38:34,199 --> 04:38:35,199 cutting recipe 8725 04:38:35,279 --> 04:38:36,279 let's call it tomato two tomato slices 8726 04:38:40,799 --> 04:38:41,799 and over here let's select the reference 8727 04:38:42,299 --> 04:38:43,299 so the input is going to be our tomato 8728 04:38:43,980 --> 04:38:44,980 and the output the tomato slices 8729 04:38:46,680 --> 04:38:47,680 okay so this is how we're going to 8730 04:38:48,180 --> 04:38:49,180 handle things 8731 04:38:49,260 --> 04:38:50,260 so let's go ahead and make actually the 8732 04:38:51,061 --> 04:38:52,061 final kitchen object that sews 8733 04:38:53,219 --> 04:38:54,219 so let's make yet another one a kitchen 8734 04:38:55,740 --> 04:38:56,740 object to sell 8735 04:38:57,180 --> 04:38:58,180 let's make it for the Cabbage slices 8736 04:39:00,420 --> 04:39:01,420 and then let's have another one for the 8737 04:39:02,459 --> 04:39:03,459 cheese slices 8738 04:39:04,260 --> 04:39:05,260 okay so now let's make these so as usual 8739 04:39:06,299 --> 04:39:07,299 let's if we get tomato make the cheese 8740 04:39:08,459 --> 04:39:09,459 slices and another one for the Cabbage 8741 04:39:10,980 --> 04:39:11,980 slices 8742 04:39:12,420 --> 04:39:13,420 let's go inside of it and first of all 8743 04:39:14,879 --> 04:39:15,879 drag the kitchen object as so so this 8744 04:39:16,740 --> 04:39:17,740 one is the Cabbage slices 8745 04:39:18,660 --> 04:39:19,660 and let's go modify the visual so 8746 04:39:21,240 --> 04:39:22,240 instead of this one the Cabbage slices 8747 04:39:23,039 --> 04:39:24,039 okay 8748 04:39:24,719 --> 04:39:25,719 so we have this let's save the prefab go 8749 04:39:26,879 --> 04:39:27,879 outside then the other one we made the 8750 04:39:29,279 --> 04:39:30,279 cheese slices so let's swap this out 8751 04:39:31,379 --> 04:39:32,379 let's find the cheese slices 8752 04:39:34,740 --> 04:39:35,740 and modify the kitchen object as well 8753 04:39:37,320 --> 04:39:38,320 okay 8754 04:39:39,060 --> 04:39:40,060 so finally just assign the references so 8755 04:39:42,240 --> 04:39:43,240 on the cheese slices drag the cheese 8756 04:39:44,340 --> 04:39:45,340 slices prefab let's assign the icon and 8757 04:39:48,180 --> 04:39:49,180 call it cheese slices 8758 04:39:51,000 --> 04:39:52,000 okay so finally on the Cabbage slices so 8759 04:39:53,878 --> 04:39:54,878 these are the Cabbage slices 8760 04:39:56,520 --> 04:39:57,520 let's pick up the icon and let's drag 8761 04:39:59,760 --> 04:40:00,760 the prefab reference okay so far so good 8762 04:40:02,280 --> 04:40:03,280 we have created our new icons 8763 04:40:04,740 --> 04:40:05,740 and over here let's just make all of the 8764 04:40:06,840 --> 04:40:07,840 other cutting recipes so we've got two 8765 04:40:08,640 --> 04:40:09,640 more so one is going to be the cheese 8766 04:40:10,740 --> 04:40:11,740 block onto cheese slices and the other 8767 04:40:13,980 --> 04:40:14,980 one is going to be cabbage onto cabbage 8768 04:40:15,900 --> 04:40:16,900 slices 8769 04:40:17,280 --> 04:40:18,280 so we need is just to drag drop the 8770 04:40:19,620 --> 04:40:20,620 scriptable objects so for this one 8771 04:40:21,840 --> 04:40:22,840 cabbage let's drop the cabbage on the 8772 04:40:23,700 --> 04:40:24,700 input cabbage slices on the output for 8773 04:40:26,160 --> 04:40:27,160 cheese mug that's the cheese Wok on the 8774 04:40:28,680 --> 04:40:29,680 input and the cheese slices on the 8775 04:40:30,360 --> 04:40:31,360 output 8776 04:40:31,378 --> 04:40:32,378 okay great all of our data is now stored 8777 04:40:34,080 --> 04:40:35,080 in some really nice script mode objects 8778 04:40:36,180 --> 04:40:37,180 so now let's go here into our cutting 8779 04:40:38,218 --> 04:40:39,218 counter 8780 04:40:39,180 --> 04:40:40,180 instead of having a hard-coded kitchen 8781 04:40:41,100 --> 04:40:42,100 object let's receive a field of type 8782 04:40:43,798 --> 04:40:44,798 cutting rest BSO except we're going to 8783 04:40:46,378 --> 04:40:47,378 have multiple so let's actually make an 8784 04:40:48,000 --> 04:40:49,000 array of this 8785 04:40:49,440 --> 04:40:50,440 call it the cutting recipe so array 8786 04:40:53,520 --> 04:40:54,520 now for the interaction this is picking 8787 04:40:55,320 --> 04:40:56,320 up and dropping things so let's leave 8788 04:40:56,520 --> 04:40:57,520 that the same for now and over here on 8789 04:40:58,140 --> 04:40:59,140 the alternate 8790 04:40:59,280 --> 04:41:00,280 basically we need to find out which 8791 04:41:01,020 --> 04:41:02,020 recipe we should apply to this 8792 04:41:03,298 --> 04:41:04,298 so how I didn't find that is pretty 8793 04:41:05,160 --> 04:41:06,160 simple so we've got the kitchen object 8794 04:41:06,958 --> 04:41:07,958 that is placed on this object and we've 8795 04:41:08,820 --> 04:41:09,820 got a list of cutting recipes which in 8796 04:41:10,378 --> 04:41:11,378 turn has the input so we just need to 8797 04:41:12,298 --> 04:41:13,298 cycle through all the recipes in order 8798 04:41:13,860 --> 04:41:14,860 to find the one where the input matches 8799 04:41:15,480 --> 04:41:16,480 okay so let's go down here make a 8800 04:41:17,520 --> 04:41:18,520 function to do just that let's make it 8801 04:41:19,260 --> 04:41:20,260 private we're going to return a kitchen 8802 04:41:20,760 --> 04:41:21,760 object as so let's come with get output 8803 04:41:23,340 --> 04:41:24,340 for input so we give it a certain input 8804 04:41:25,798 --> 04:41:26,798 and Returns the one that matches that 8805 04:41:27,298 --> 04:41:28,298 one 8806 04:41:28,138 --> 04:41:29,138 so it turns a kitchen object as so for 8807 04:41:31,020 --> 04:41:32,020 the input kitchen object as well 8808 04:41:34,798 --> 04:41:35,798 here on let's cycle so do a for each 8809 04:41:36,780 --> 04:41:37,780 cutting recipe so in the cutting recipe 8810 04:41:39,360 --> 04:41:40,360 so right so let's cycle through all 8811 04:41:41,340 --> 04:41:42,340 these and just check if the cutting 8812 04:41:43,798 --> 04:41:44,798 recipe so if this one dot input matches 8813 04:41:46,798 --> 04:41:47,798 the input that we received 8814 04:41:48,718 --> 04:41:49,718 if so then this is the one we want so 8815 04:41:50,940 --> 04:41:51,940 let's return the cutting recipe 8816 04:41:53,420 --> 04:41:54,420 so.output and to make sure that the 8817 04:41:55,920 --> 04:41:56,920 function Works down here let's return no 8818 04:41:59,160 --> 04:42:00,160 okay so that's it we give it an input 8819 04:42:01,560 --> 04:42:02,560 and we get back the output 8820 04:42:03,600 --> 04:42:04,600 so now here we just need to make sure to 8821 04:42:05,520 --> 04:42:06,520 do it before we destroy the current 8822 04:42:07,020 --> 04:42:08,020 kitchen object 8823 04:42:09,000 --> 04:42:10,000 so let's store a kitchen object as so 8824 04:42:11,160 --> 04:42:12,160 for the output kitchen object SL and we 8825 04:42:14,638 --> 04:42:15,638 just get the output from the input and 8826 04:42:16,620 --> 04:42:17,620 for the input pass in the get kitchen 8827 04:42:18,240 --> 04:42:19,240 object so that's the one inside of this 8828 04:42:20,458 --> 04:42:21,458 cutting counter and let's get the 8829 04:42:22,260 --> 04:42:23,260 kitchen object this out so that gives us 8830 04:42:24,480 --> 04:42:25,480 the output and then we just spawn that 8831 04:42:26,638 --> 04:42:27,638 output 8832 04:42:27,540 --> 04:42:28,540 okay so that's it let's test 8833 04:42:30,120 --> 04:42:31,120 finally back in the scene let's just go 8834 04:42:32,280 --> 04:42:33,280 inside the prefab and over here on 8835 04:42:33,958 --> 04:42:34,958 cutting counter we need to make sure to 8836 04:42:35,340 --> 04:42:36,340 add all the recipes 8837 04:42:36,900 --> 04:42:37,900 so let's add so the cabbage 8838 04:42:39,480 --> 04:42:40,480 then a second one for cheese Mock and 8839 04:42:41,878 --> 04:42:42,878 finally for the Tomato okay so there are 8840 04:42:44,040 --> 04:42:45,040 of our recipes let's go outside save the 8841 04:42:46,200 --> 04:42:47,200 changes and let's test okay so over here 8842 04:42:48,600 --> 04:42:49,600 let's pick up a tomato go up there slice 8843 04:42:50,700 --> 04:42:51,700 it there you go got some tomato slices 8844 04:42:52,320 --> 04:42:53,320 now pick up some cheese go here slice it 8845 04:42:54,540 --> 04:42:55,540 and there you go got some cheese slices 8846 04:42:55,980 --> 04:42:56,980 and finally the Cabbage go up there 8847 04:42:58,200 --> 04:42:59,200 slice it and there you go some cabbage 8848 04:42:59,878 --> 04:43:00,878 slices all right awesome 8849 04:43:02,458 --> 04:43:03,458 so everything is working perfectly 8850 04:43:04,100 --> 04:43:05,100 however now let's say that I want to 8851 04:43:06,480 --> 04:43:07,480 pick up some bread and bread should not 8852 04:43:08,458 --> 04:43:09,458 really be able to be cut so if I go 8853 04:43:10,920 --> 04:43:11,920 ahead and I cut it and there you go 8854 04:43:12,840 --> 04:43:13,840 there's our air we have no recipe that 8855 04:43:15,120 --> 04:43:16,120 takes bread as an input So that 8856 04:43:16,740 --> 04:43:17,740 obviously leads to a known reference 8857 04:43:18,480 --> 04:43:19,480 exception 8858 04:43:19,560 --> 04:43:20,560 now here we have two options for solving 8859 04:43:22,020 --> 04:43:23,020 this problem 8860 04:43:23,100 --> 04:43:24,100 one option is simply over here when we 8861 04:43:25,500 --> 04:43:26,500 do the interact alternate 8862 04:43:27,298 --> 04:43:28,298 we get the output for the input and if 8863 04:43:29,280 --> 04:43:30,280 this one returns null then we just don't 8864 04:43:31,500 --> 04:43:32,500 cut it 8865 04:43:32,458 --> 04:43:33,458 so we don't destroy it and we don't 8866 04:43:34,138 --> 04:43:35,138 spawn it or alternatively we can 8867 04:43:36,000 --> 04:43:37,000 actually add some Foundation over here 8868 04:43:37,500 --> 04:43:38,500 when dropping objects so we can make 8869 04:43:39,420 --> 04:43:40,420 sure that we only drop valid cutable 8870 04:43:41,160 --> 04:43:42,160 objects now both approaches are valid 8871 04:43:43,500 --> 04:43:44,500 and actually we do need to implement 8872 04:43:44,940 --> 04:43:45,940 both them we'll see why in a bit 8873 04:43:46,920 --> 04:43:47,920 so let's do both starting off with the 8874 04:43:48,958 --> 04:43:49,958 validating the drop 8875 04:43:50,580 --> 04:43:51,580 so first we check if there is no kitchen 8876 04:43:52,200 --> 04:43:53,200 object on this cutting counter then we 8877 04:43:54,480 --> 04:43:55,480 check if the player is carrying 8878 04:43:55,620 --> 04:43:56,620 something and then we drop it from the 8879 04:43:57,240 --> 04:43:58,240 player on this 8880 04:43:58,440 --> 04:43:59,440 so over here let's just check if there's 8881 04:44:00,660 --> 04:44:01,660 any recipe that has whatever the player 8882 04:44:02,940 --> 04:44:03,940 has as an input 8883 04:44:04,560 --> 04:44:05,560 so let's go down here make a function to 8884 04:44:06,718 --> 04:44:07,718 do that private let's return a bone and 8885 04:44:08,940 --> 04:44:09,940 call it has recipe with input 8886 04:44:12,420 --> 04:44:13,420 and we're going to receive a kitchen 8887 04:44:14,580 --> 04:44:15,580 object episode for the input kitchen 8888 04:44:17,280 --> 04:44:18,280 object lesson 8889 04:44:19,200 --> 04:44:20,200 and over here lets you pretty much 8890 04:44:20,638 --> 04:44:21,638 literally the same logic so we have this 8891 04:44:22,980 --> 04:44:23,980 and if we find a match then let's return 8892 04:44:24,840 --> 04:44:25,840 true so there is a recipe with that 8893 04:44:26,940 --> 04:44:27,940 input if not return false so now up here 8894 04:44:30,060 --> 04:44:31,060 when the player is carrying something 8895 04:44:31,620 --> 04:44:32,620 let's check 8896 04:44:33,600 --> 04:44:34,600 if has recipe with input and give it the 8897 04:44:37,440 --> 04:44:38,440 player get the kitchen object the player 8898 04:44:39,298 --> 04:44:40,298 is holding and get the kitchen object as 8899 04:44:41,340 --> 04:44:42,340 so 8900 04:44:42,420 --> 04:44:43,420 so if there's any recipe that takes 8901 04:44:44,280 --> 04:44:45,280 whatever the player is carrying as an 8902 04:44:45,958 --> 04:44:46,958 input 8903 04:44:47,580 --> 04:44:48,580 if so then we drop it 8904 04:44:55,560 --> 04:44:56,560 okay so like this let's test and see if 8905 04:44:57,480 --> 04:44:58,480 we can drop the bread 8906 04:44:59,280 --> 04:45:00,280 okay so let's pick up some bread go 8907 04:45:01,378 --> 04:45:02,378 ahead drop it and nope does not work 8908 04:45:03,120 --> 04:45:04,120 pick up some cheese and yep that one 8909 04:45:04,740 --> 04:45:05,740 does work 8910 04:45:06,060 --> 04:45:07,060 however now we actually also need the 8911 04:45:08,160 --> 04:45:09,160 other validation that I mentioned the 8912 04:45:10,260 --> 04:45:11,260 reason is because if we place a valid 8913 04:45:11,878 --> 04:45:12,878 option like for example the cheese there 8914 04:45:13,860 --> 04:45:14,860 so that works and I can cut it and yep 8915 04:45:16,080 --> 04:45:17,080 that does work however Now the recipe 8916 04:45:18,780 --> 04:45:19,780 the cheese moth became cheese slices and 8917 04:45:21,060 --> 04:45:22,060 now cheese slice is no longer an input 8918 04:45:22,620 --> 04:45:23,620 to any cutting recipe so now if I try 8919 04:45:24,718 --> 04:45:25,718 cutting again 8920 04:45:25,980 --> 04:45:26,980 I've got another no reference exception 8921 04:45:28,740 --> 04:45:29,740 so we need to validate putting objects 8922 04:45:30,660 --> 04:45:31,660 on top of it and also actually cutting 8923 04:45:32,340 --> 04:45:33,340 them Technologic is also pretty simple 8924 04:45:34,260 --> 04:45:35,260 so let's go down to the interact 8925 04:45:36,000 --> 04:45:37,000 alternate so we just check if there's a 8926 04:45:38,280 --> 04:45:39,280 kitchen object on The Cutting counter 8927 04:45:40,500 --> 04:45:41,500 and has recipe input 8928 04:45:43,560 --> 04:45:44,560 and let's get this kitchen object get 8929 04:45:46,080 --> 04:45:47,080 kitchen object as so just like this 8930 04:45:48,540 --> 04:45:49,540 so we're only going to cut if there is a 8931 04:45:50,878 --> 04:45:51,878 kitchen object here and it can be cut 8932 04:45:55,440 --> 04:45:56,440 okay so let's test 8933 04:45:57,480 --> 04:45:58,480 so first of all the other one let's pick 8934 04:45:59,218 --> 04:46:00,218 up bread and nope cannot travel okay 8935 04:46:00,840 --> 04:46:01,840 great now pick up some cheese and I can 8936 04:46:02,580 --> 04:46:03,580 drop now interact cut now cut again and 8937 04:46:05,340 --> 04:46:06,340 yep there you go no more errors all 8938 04:46:07,798 --> 04:46:08,798 right awesome okay so here we have 8939 04:46:10,200 --> 04:46:11,200 everything working perfectly I can pick 8940 04:46:12,298 --> 04:46:13,298 up a cabbage go up there cut it into 8941 04:46:14,218 --> 04:46:15,218 slices I can slice some cheese and I can 8942 04:46:16,798 --> 04:46:17,798 even slice some Tomatoes everything 8943 04:46:18,180 --> 04:46:19,180 works perfectly now the one thing 8944 04:46:20,340 --> 04:46:21,340 missing from our design is we don't 8945 04:46:21,958 --> 04:46:22,958 actually want this action to be instant 8946 04:46:23,520 --> 04:46:24,520 we don't want to just press a button 8947 04:46:25,378 --> 04:46:26,378 everything slices instantly instead we 8948 04:46:27,600 --> 04:46:28,600 want to have the player press the button 8949 04:46:29,218 --> 04:46:30,218 a few times in order to actually cut so 8950 04:46:31,440 --> 04:46:32,440 let's do all that in the next lecture 8951 04:46:34,080 --> 04:46:35,080 hello and welcome I'm your code monkey 8952 04:46:36,060 --> 04:46:37,060 in this lecture we're going to add the 8953 04:46:38,400 --> 04:46:39,400 mechanic for the player to be able to 8954 04:46:40,020 --> 04:46:41,020 cut multiple times in order to actually 8955 04:46:41,820 --> 04:46:42,820 cut an object 8956 04:46:43,320 --> 04:46:44,320 okay so we have our cutting counter I 8957 04:46:45,240 --> 04:46:46,240 can drop a tomato and press button there 8958 04:46:47,100 --> 04:46:48,100 you go it cuts it straight away now we 8959 04:46:49,080 --> 04:46:50,080 want the exact same logic but we want it 8960 04:46:50,940 --> 04:46:51,940 to take a few Cuts before the cut object 8961 04:46:52,860 --> 04:46:53,860 is spawned 8962 04:46:54,000 --> 04:46:55,000 so let's start off by going here onto 8963 04:46:55,860 --> 04:46:56,860 the cutting counter and basically let's 8964 04:46:57,900 --> 04:46:58,900 keep track of some kind of progress 8965 04:47:00,180 --> 04:47:01,180 basically the way we do that is pretty 8966 04:47:01,860 --> 04:47:02,860 arbitrary it's up to you to decide for 8967 04:47:03,958 --> 04:47:04,958 example you could use a normalized float 8968 04:47:05,820 --> 04:47:06,820 however for cutting since this is going 8969 04:47:08,100 --> 04:47:09,100 to be a discrete action let's actually 8970 04:47:09,540 --> 04:47:10,540 count the numbers with an end so let's 8971 04:47:11,878 --> 04:47:12,878 store a private end just call it cutting 8972 04:47:13,740 --> 04:47:14,740 progress 8973 04:47:15,660 --> 04:47:16,660 okay so now let's begin by actually 8974 04:47:17,760 --> 04:47:18,760 initializing this progress so when the 8975 04:47:19,500 --> 04:47:20,500 player drops something on there let's 8976 04:47:21,060 --> 04:47:22,060 set this one to zero 8977 04:47:23,160 --> 04:47:24,160 and then down here when we have the 8978 04:47:25,020 --> 04:47:26,020 interact alternate we do our logic and 8979 04:47:27,660 --> 04:47:28,660 when we do let's just increase this by 8980 04:47:29,638 --> 04:47:30,638 one 8981 04:47:30,840 --> 04:47:31,840 and now we need to know if the object 8982 04:47:32,520 --> 04:47:33,520 has been cut so we need somewhere to 8983 04:47:34,138 --> 04:47:35,138 Define some kind of maximum 8984 04:47:36,600 --> 04:47:37,600 and for that we can actually do it 8985 04:47:38,400 --> 04:47:39,400 directly on the recipe so so inside the 8986 04:47:41,040 --> 04:47:42,040 cutting rest PSO over here we've got the 8987 04:47:43,740 --> 04:47:44,740 input we've got the output and let's 8988 04:47:45,180 --> 04:47:46,180 also Define an end 8989 04:47:46,980 --> 04:47:47,980 for The Cutting progress Max 8990 04:47:50,040 --> 04:47:51,040 okay that's it 8991 04:47:51,660 --> 04:47:52,660 and back here in the editor let's go 8992 04:47:54,060 --> 04:47:55,060 into the Tomato to tomato slices let's 8993 04:47:55,980 --> 04:47:56,980 say this one takes just three Cuts then 8994 04:47:58,260 --> 04:47:59,260 for the cheese let's also take three 8995 04:47:59,878 --> 04:48:00,878 cuts and for the Cabbage let's say it's 8996 04:48:01,620 --> 04:48:02,620 a bit thicker so let's say it takes five 8997 04:48:03,120 --> 04:48:04,120 cuts 8998 04:48:04,320 --> 04:48:05,320 okay so back in the cutting counter here 8999 04:48:07,320 --> 04:48:08,320 down here we are adding to our cutting 9000 04:48:09,420 --> 04:48:10,420 progress 9001 04:48:10,500 --> 04:48:11,500 so then we just need the recipe so in 9002 04:48:12,480 --> 04:48:13,480 order to grab the maximum so on 9003 04:48:14,638 --> 04:48:15,638 sectionally go down here and actually 9004 04:48:15,958 --> 04:48:16,958 make a different function so this one 9005 04:48:17,638 --> 04:48:18,638 just returns a Boolean this one a 9006 04:48:19,860 --> 04:48:20,860 kitchen object or so let's make another 9007 04:48:21,480 --> 04:48:22,480 one this one is going to return a 9008 04:48:23,760 --> 04:48:24,760 cutting recipe so 9009 04:48:25,798 --> 04:48:26,798 so get the cutting recipe so with input 9010 04:48:31,620 --> 04:48:32,620 and we're going to receive as usual the 9011 04:48:33,360 --> 04:48:34,360 kitchen objects so for the input 9012 04:48:37,740 --> 04:48:38,740 I'm really going to do the exact same 9013 04:48:39,540 --> 04:48:40,540 thing that we did up here next time 9014 04:48:41,458 --> 04:48:42,458 instead of returning the output let's 9015 04:48:42,780 --> 04:48:43,780 return the recipe itself 9016 04:48:44,700 --> 04:48:45,700 okay so now that we have this more 9017 04:48:46,440 --> 04:48:47,440 logical one we can actually get rid of 9018 04:48:48,240 --> 04:48:49,240 all this copy paste code 9019 04:48:50,100 --> 04:48:51,100 so over here we just get the cutting 9020 04:48:52,378 --> 04:48:53,378 recipe so 9021 04:48:55,138 --> 04:48:56,138 and we just get it and pass in the input 9022 04:48:59,638 --> 04:49:00,638 so we have this one over here if this 9023 04:49:02,280 --> 04:49:03,280 one is not no then we're going to return 9024 04:49:04,500 --> 04:49:05,500 this on the output 9025 04:49:06,120 --> 04:49:07,120 and if not we're just going to return 9026 04:49:07,798 --> 04:49:08,798 null 9027 04:49:09,120 --> 04:49:10,120 okay so we're doing the exact same logic 9028 04:49:11,160 --> 04:49:12,160 just a bit similar okay and up here 9029 04:49:13,500 --> 04:49:14,500 pretty much the same thing 9030 04:49:15,780 --> 04:49:16,780 so has recipe with input let's get the 9031 04:49:18,718 --> 04:49:19,718 cutting recipe a cell 9032 04:49:20,520 --> 04:49:21,520 and basically just return if this one is 9033 04:49:22,378 --> 04:49:23,378 not known 9034 04:49:24,660 --> 04:49:25,660 okay so we have our three nice sample 9035 04:49:26,638 --> 04:49:27,638 functions so let's just use this one to 9036 04:49:28,860 --> 04:49:29,860 get the cutting rest BSO so let's 9037 04:49:30,718 --> 04:49:31,718 actually copy this and go up here so we 9038 04:49:33,120 --> 04:49:34,120 do the cutting progress then let's pick 9039 04:49:35,218 --> 04:49:36,218 it up the one for this input so the 9040 04:49:37,200 --> 04:49:38,200 input is going to be this one the object 9041 04:49:39,240 --> 04:49:40,240 currently on the cutting counter and 9042 04:49:41,580 --> 04:49:42,580 over here we already know that there's 9043 04:49:42,958 --> 04:49:43,958 going to be a recipe with this input 9044 04:49:44,400 --> 04:49:45,400 since we've gone through this if 9045 04:49:46,620 --> 04:49:47,620 so then we can just check if the cutting 9046 04:49:48,718 --> 04:49:49,718 progress is bigger or equal to The 9047 04:49:51,420 --> 04:49:52,420 Cutting recipe so and let's grab the 9048 04:49:54,480 --> 04:49:55,480 maximum 9049 04:49:57,240 --> 04:49:58,240 if so then yep we do spawn it 9050 04:50:00,180 --> 04:50:01,180 okay so that's it some very simple logic 9051 04:50:02,340 --> 04:50:03,340 Let's test 9052 04:50:03,780 --> 04:50:04,780 so here we are let's pick up a tomato go 9053 04:50:05,940 --> 04:50:06,940 up there and okay now I'm going to press 9054 04:50:07,500 --> 04:50:08,500 enter direct okay press once and yep 9055 04:50:10,080 --> 04:50:11,080 okay so far so good nothing now two 9056 04:50:12,480 --> 04:50:13,480 times and Alpha press a third time boom 9057 04:50:15,298 --> 04:50:16,298 any up there you go got the nice slices 9058 04:50:16,860 --> 04:50:17,860 now for cheese same thing one two three 9059 04:50:19,440 --> 04:50:20,440 yep it works and finally for the 9060 04:50:21,420 --> 04:50:22,420 Cambridge this one should be five so one 9061 04:50:23,878 --> 04:50:24,878 two three four and five any up there you 9062 04:50:26,940 --> 04:50:27,940 go everything does work perfectly all 9063 04:50:29,100 --> 04:50:30,100 right awesome 9064 04:50:30,480 --> 04:50:31,480 so with this we now have progress in our 9065 04:50:32,520 --> 04:50:33,520 cutting logic although of course just 9066 04:50:34,440 --> 04:50:35,440 like this it's not very good for the 9067 04:50:35,820 --> 04:50:36,820 player the player has no way of knowing 9068 04:50:37,798 --> 04:50:38,798 what exactly is going on so we need some 9069 04:50:39,840 --> 04:50:40,840 kind of visual feedback so for that 9070 04:50:41,638 --> 04:50:42,638 let's add a really nice visual progress 9071 04:50:43,378 --> 04:50:44,378 bar and for doing this we're also going 9072 04:50:45,060 --> 04:50:46,060 to learn about a really awesome Unity 9073 04:50:46,680 --> 04:50:47,680 feature these are World canvases 9074 04:50:49,260 --> 04:50:50,260 so before we make the world canvas on 9075 04:50:51,298 --> 04:50:52,298 The Cutting counter let's actually set 9076 04:50:52,860 --> 04:50:53,860 something up over here on the scene 9077 04:50:54,180 --> 04:50:55,180 itself 9078 04:50:55,138 --> 04:50:56,138 let's first create a regular canvas 9079 04:50:57,180 --> 04:50:58,180 we're only going to use this in a couple 9080 04:50:58,860 --> 04:50:59,860 of lectures but let's first do that one 9081 04:51:00,540 --> 04:51:01,540 just for now 9082 04:51:02,160 --> 04:51:03,160 so let's go on the plus button go into 9083 04:51:04,920 --> 04:51:05,920 UI and let's create a brand new canvas 9084 04:51:07,920 --> 04:51:08,920 okay so there you go that creates a 9085 04:51:09,540 --> 04:51:10,540 canvas and an event system 9086 04:51:11,400 --> 04:51:12,400 like I said we're only going to worry 9087 04:51:12,780 --> 04:51:13,780 about this in a little bit but for now 9088 04:51:14,340 --> 04:51:15,340 let's just leave those as is 9089 04:51:16,200 --> 04:51:17,200 and also since we're here creating some 9090 04:51:17,760 --> 04:51:18,760 objects let's also take some time to 9091 04:51:19,680 --> 04:51:20,680 organize our hurricane 9092 04:51:21,360 --> 04:51:22,360 Unity suddenly doesn't really have any 9093 04:51:23,218 --> 04:51:24,218 folder objects so you can't organize the 9094 04:51:25,560 --> 04:51:26,560 hierarchy in any folders however you can 9095 04:51:28,080 --> 04:51:29,080 use empty game objects essentially as 9096 04:51:29,820 --> 04:51:30,820 folders 9097 04:51:31,020 --> 04:51:32,020 so let's make a brand new empty game 9098 04:51:32,940 --> 04:51:33,940 object let's call it counters 9099 04:51:35,520 --> 04:51:36,520 and now very importantly for empty 9100 04:51:37,320 --> 04:51:38,320 folder objects make sure you put them on 9101 04:51:38,820 --> 04:51:39,820 zero zero zero so nothing breaks 9102 04:51:41,218 --> 04:51:42,218 so make sure you put it on there before 9103 04:51:43,080 --> 04:51:44,080 you drag the counters 9104 04:51:44,760 --> 04:51:45,760 and now let's just drag on the counters 9105 04:51:46,500 --> 04:51:47,500 inside so all the clear counters put 9106 04:51:48,000 --> 04:51:49,000 them outside this one also drag it 9107 04:51:50,340 --> 04:51:51,340 inside and all of these counters put 9108 04:51:52,560 --> 04:51:53,560 them all inside so there you go now 9109 04:51:54,298 --> 04:51:55,298 hierarchy is quite a bit more clean 9110 04:51:56,458 --> 04:51:57,458 okay so now let's make the cutting 9111 04:51:58,200 --> 04:51:59,200 progress so let's click on the cutting 9112 04:52:00,000 --> 04:52:01,000 counter 9113 04:52:01,138 --> 04:52:02,138 and let's go inside our prefab so let's 9114 04:52:03,718 --> 04:52:04,718 go inside of it 9115 04:52:05,520 --> 04:52:06,520 now over here let's right click on the 9116 04:52:07,440 --> 04:52:08,440 hierarchy and we're going to create a UI 9117 04:52:09,480 --> 04:52:10,480 let's create another canvas 9118 04:52:11,218 --> 04:52:12,218 now for this one let's give it a name 9119 04:52:12,780 --> 04:52:13,780 let's name it the progress bar UI and 9120 04:52:15,480 --> 04:52:16,480 for this one over here on the inspector 9121 04:52:16,860 --> 04:52:17,860 for the settings instead of being screen 9122 04:52:18,540 --> 04:52:19,540 space overlay let's make this one a 9123 04:52:20,700 --> 04:52:21,700 world space canvas 9124 04:52:22,320 --> 04:52:23,320 basically screen space means that it 9125 04:52:24,060 --> 04:52:25,060 would occupy the entire screen whereas 9126 04:52:25,740 --> 04:52:26,740 World space means that this exists in 9127 04:52:27,480 --> 04:52:28,480 the world in whatever position it is 9128 04:52:29,760 --> 04:52:30,760 so let's make it World space and over 9129 04:52:31,620 --> 04:52:32,620 here the fields actually unlock so let's 9130 04:52:34,260 --> 04:52:35,260 put the positions on zero and for the 9131 04:52:36,718 --> 04:52:37,718 width and height let's also put it on 9132 04:52:38,218 --> 04:52:39,218 zero 9133 04:52:39,900 --> 04:52:40,900 so basically the canvas is going to be 9134 04:52:41,760 --> 04:52:42,760 exactly over here by the way the 9135 04:52:43,740 --> 04:52:44,740 shortcut that I just used was the F in 9136 04:52:45,600 --> 04:52:46,600 order to focus on the object 9137 04:52:47,280 --> 04:52:48,280 so this useful if you're zoomed out or 9138 04:52:49,620 --> 04:52:50,620 zoomed in way too much okay 9139 04:52:51,718 --> 04:52:52,718 so we have this and we want the bar to 9140 04:52:53,400 --> 04:52:54,400 be a little bit above so let's actually 9141 04:52:54,600 --> 04:52:55,600 lift it up on the Y by a little bit so 9142 04:52:56,820 --> 04:52:57,820 over here let's put it on y of 2.5 okay 9143 04:53:00,000 --> 04:53:01,000 now I said the going with this is to 9144 04:53:01,560 --> 04:53:02,560 make a progress bar so inside the 9145 04:53:03,420 --> 04:53:04,420 progress bar UI let's create a new UI 9146 04:53:05,458 --> 04:53:06,458 image let's name this one our bar 9147 04:53:09,540 --> 04:53:10,540 let's put it with a width of one and a 9148 04:53:12,180 --> 04:53:13,180 height maybe of 0.2 9149 04:53:14,458 --> 04:53:15,458 so there you go just a really thin bar 9150 04:53:16,440 --> 04:53:17,440 and for the color you can play round 9151 04:53:18,180 --> 04:53:19,180 tinted with any color you want now for 9152 04:53:20,700 --> 04:53:21,700 progress I think maybe a blue or a 9153 04:53:22,500 --> 04:53:23,500 yellow something like that makes sense 9154 04:53:23,878 --> 04:53:24,878 so let's go with the yellow kind of like 9155 04:53:26,100 --> 04:53:27,100 this 9156 04:53:27,360 --> 04:53:28,360 okay so there's our really nice progress 9157 04:53:29,400 --> 04:53:30,400 bar 9158 04:53:30,420 --> 04:53:31,420 and for this let's actually use one 9159 04:53:32,520 --> 04:53:33,520 really nice trick for making a super 9160 04:53:33,958 --> 04:53:34,958 easy progress bar the image component 9161 04:53:36,360 --> 04:53:37,360 has a really easy way of making a slider 9162 04:53:38,580 --> 04:53:39,580 image however it only actually works if 9163 04:53:41,040 --> 04:53:42,040 you assign an image over here 9164 04:53:42,958 --> 04:53:43,958 so let's assign one in order to be able 9165 04:53:44,458 --> 04:53:45,458 to see those options 9166 04:53:45,900 --> 04:53:46,900 and for that in the project files 9167 04:53:48,000 --> 04:53:49,000 there's a texture white one by one this 9168 04:53:50,458 --> 04:53:51,458 is literally just a one by one white 9169 04:53:52,138 --> 04:53:53,138 pixel 9170 04:53:53,520 --> 04:53:54,520 so here it is just a one by one image if 9171 04:53:55,620 --> 04:53:56,620 only white 9172 04:53:56,878 --> 04:53:57,878 and as soon as we assign it we do see 9173 04:53:58,680 --> 04:53:59,680 over here the image type so we see a 9174 04:54:00,420 --> 04:54:01,420 bunch more options and the one that we 9175 04:54:02,400 --> 04:54:03,400 want is to set the Sprite as filled this 9176 04:54:04,860 --> 04:54:05,860 one lets you do some really cool really 9177 04:54:06,420 --> 04:54:07,420 easy effects for example you can make it 9178 04:54:08,820 --> 04:54:09,820 radial and look at what happens in there 9179 04:54:10,560 --> 04:54:11,560 as I modify over here on the film Mount 9180 04:54:12,360 --> 04:54:13,360 so as I go down look at that it's 9181 04:54:14,280 --> 04:54:15,280 radiantly filling so for some kind of 9182 04:54:16,500 --> 04:54:17,500 circular progress bar this would be 9183 04:54:17,940 --> 04:54:18,940 excellent but in our case what we really 9184 04:54:20,218 --> 04:54:21,218 want is just a horizontal bar so we're 9185 04:54:22,620 --> 04:54:23,620 here for the film method instead of 9186 04:54:24,000 --> 04:54:25,000 Radion let's go with horizontal 9187 04:54:25,980 --> 04:54:26,980 and if there you go now by playing 9188 04:54:27,360 --> 04:54:28,360 around this we have a really nice 9189 04:54:28,920 --> 04:54:29,920 progress bar 9190 04:54:30,480 --> 04:54:31,480 then if you want you can modify on left 9191 04:54:31,860 --> 04:54:32,860 to right right and left but yep like 9192 04:54:33,240 --> 04:54:34,240 this it looks great 9193 04:54:34,920 --> 04:54:35,920 now in order to modify this visual 9194 04:54:36,540 --> 04:54:37,540 really only we're going to need is 9195 04:54:37,620 --> 04:54:38,620 modify over here the film Mount this one 9196 04:54:39,840 --> 04:54:40,840 is a normalized value so between 0 and 1 9197 04:54:41,940 --> 04:54:42,940 so 0 is commonly empty one is commonly 9198 04:54:43,740 --> 04:54:44,740 full however one issue with this is when 9199 04:54:46,320 --> 04:54:47,320 the bar is empty then we can pretty much 9200 04:54:48,240 --> 04:54:49,240 not see so we can see the actual size of 9201 04:54:50,820 --> 04:54:51,820 the bar we can see what size it should 9202 04:54:52,440 --> 04:54:53,440 be 9203 04:54:53,160 --> 04:54:54,160 so with this it's pretty difficult to 9204 04:54:54,780 --> 04:54:55,780 see how far along we are but something 9205 04:54:57,120 --> 04:54:58,120 that is pretty simple we can really just 9206 04:54:58,798 --> 04:54:59,798 add some kind of background 9207 04:55:00,420 --> 04:55:01,420 so let's duplicate the bar let's name 9208 04:55:02,760 --> 04:55:03,760 this one the background 9209 04:55:04,798 --> 04:55:05,798 for this one for the image type we don't 9210 04:55:06,600 --> 04:55:07,600 want anything so let's leave it on 9211 04:55:07,860 --> 04:55:08,860 SIMPLE and for the color let's put it on 9212 04:55:09,958 --> 04:55:10,958 kind of a dark gray okay great and now 9213 04:55:12,958 --> 04:55:13,958 here's one very very important thing is 9214 04:55:15,060 --> 04:55:16,060 over here on the hierarchy let's click 9215 04:55:16,860 --> 04:55:17,860 and drag and place it above the bar 9216 04:55:19,260 --> 04:55:20,260 the reason why that is super important 9217 04:55:20,878 --> 04:55:21,878 is because the Sorting order and how it 9218 04:55:22,860 --> 04:55:23,860 works in unity basically when it comes 9219 04:55:24,840 --> 04:55:25,840 to UI elements inside a canvas the 9220 04:55:27,180 --> 04:55:28,180 Sorting order is based on The Horde in 9221 04:55:29,100 --> 04:55:30,100 the hierarchy basically it renders from 9222 04:55:31,200 --> 04:55:32,200 top to bottom 9223 04:55:32,520 --> 04:55:33,520 so the bar on top the background this is 9224 04:55:34,440 --> 04:55:35,440 going to render first and then the one 9225 04:55:36,240 --> 04:55:37,240 below it the bar is going to render 9226 04:55:37,620 --> 04:55:38,620 afterwards which means it's going to 9227 04:55:39,120 --> 04:55:40,120 render on top 9228 04:55:40,500 --> 04:55:41,500 so for the background we want to be 9229 04:55:42,060 --> 04:55:43,060 behind so place it above on the 9230 04:55:43,680 --> 04:55:44,680 hierarchy and that way it renders the 9231 04:55:45,600 --> 04:55:46,600 background and then renders the bar also 9232 04:55:47,878 --> 04:55:48,878 by the way for 2D Sprites Unity has 9233 04:55:49,860 --> 04:55:50,860 another different sorting method it's 9234 04:55:51,718 --> 04:55:52,718 all based on sorting layers and sorting 9235 04:55:53,458 --> 04:55:54,458 orders 9236 04:55:54,360 --> 04:55:55,360 I have video on that topic if you're 9237 04:55:56,040 --> 04:55:57,040 interested in 2D games 9238 04:55:57,540 --> 04:55:58,540 okay so with this we have the background 9239 04:55:59,580 --> 04:56:00,580 and then we have our film bar this way 9240 04:56:01,500 --> 04:56:02,500 we can see if the progress is being 9241 04:56:02,700 --> 04:56:03,700 filmed or not 9242 04:56:04,020 --> 04:56:05,020 also one more tiny thing that I like to 9243 04:56:05,878 --> 04:56:06,878 add is Unity has some really nice really 9244 04:56:08,040 --> 04:56:09,040 easy to add effects 9245 04:56:09,780 --> 04:56:10,780 so you can go into that component and 9246 04:56:11,638 --> 04:56:12,638 let's search for a shadow 9247 04:56:13,920 --> 04:56:14,920 this one does exactly what you expected 9248 04:56:15,540 --> 04:56:16,540 as a nice drop shadow over here on the 9249 04:56:17,458 --> 04:56:18,458 effect distance let's put it on 0.1.1 in 9250 04:56:19,798 --> 04:56:20,798 order to see 9251 04:56:21,298 --> 04:56:22,298 next one let's not do it on this one 9252 04:56:23,040 --> 04:56:24,040 we'll do it on the background so let's 9253 04:56:24,600 --> 04:56:25,600 get rid of this instead of going to the 9254 04:56:26,340 --> 04:56:27,340 background over here let's add the same 9255 04:56:27,780 --> 04:56:28,780 shadow 9256 04:56:28,560 --> 04:56:29,560 so if you put it on point one and minus 9257 04:56:30,600 --> 04:56:31,600 point one you better go a nice simple 9258 04:56:32,280 --> 04:56:33,280 and drop shadow or the other one that I 9259 04:56:34,740 --> 04:56:35,740 prefer so instead of the Shadow let's 9260 04:56:36,600 --> 04:56:37,600 add a really nice outline once again for 9261 04:56:39,360 --> 04:56:40,360 the effect distance 0.1.1 or maybe 9262 04:56:41,820 --> 04:56:42,820 actually 0.05 just to be just a tiny bit 9263 04:56:44,940 --> 04:56:45,940 and let's raise it on the alpha so there 9264 04:56:46,920 --> 04:56:47,920 you go nice little outline tour bar this 9265 04:56:49,680 --> 04:56:50,680 is just a visual thing so you don't have 9266 04:56:51,060 --> 04:56:52,060 to add this but personally I find that 9267 04:56:52,500 --> 04:56:53,500 it looks pretty good 9268 04:56:54,120 --> 04:56:55,120 so with all of this we have our Visual 9269 04:56:55,740 --> 04:56:56,740 and perfectly set up we've got our nice 9270 04:56:57,660 --> 04:56:58,660 bar all we need to do is play around the 9271 04:56:59,458 --> 04:57:00,458 filament in order to fill it 9272 04:57:01,200 --> 04:57:02,200 so now all we need to do is to connect 9273 04:57:03,060 --> 04:57:04,060 this to the logic but as usual let's 9274 04:57:04,798 --> 04:57:05,798 make sure to write some good clean code 9275 04:57:06,420 --> 04:57:07,420 so we do not want the cutting counter to 9276 04:57:08,878 --> 04:57:09,878 directly touch on this image 9277 04:57:10,980 --> 04:57:11,980 instead let's make a script to handle on 9278 04:57:12,958 --> 04:57:13,958 that so let's right click create a new 9279 04:57:14,400 --> 04:57:15,400 c-sharp script call it the progress bar 9280 04:57:16,980 --> 04:57:17,980 UI 9281 04:57:18,840 --> 04:57:19,840 and just personally as a rule I like to 9282 04:57:20,940 --> 04:57:21,940 open the UI to any UI script 9283 04:57:23,700 --> 04:57:24,700 you don't have to do that it's just a 9284 04:57:25,500 --> 04:57:26,500 rule that I personally find helpful to 9285 04:57:27,060 --> 04:57:28,060 follow that way just by looking at these 9286 04:57:29,040 --> 04:57:30,040 scripts I can immediately see this one 9287 04:57:30,480 --> 04:57:31,480 is a UI this one is script and logic and 9288 04:57:32,400 --> 04:57:33,400 so on 9289 04:57:33,600 --> 04:57:34,600 so on the progress bar UI on the main 9290 04:57:35,878 --> 04:57:36,878 game object let's attach the script and 9291 04:57:38,100 --> 04:57:39,100 let's open it 9292 04:57:39,420 --> 04:57:40,420 okay so now here we're going to need a 9293 04:57:41,940 --> 04:57:42,940 reference to our image 9294 04:57:44,218 --> 04:57:45,218 so let's add a serialized field private 9295 04:57:47,040 --> 04:57:48,040 and we're going to need the image type 9296 04:57:49,080 --> 04:57:50,080 and importantly this is inside using 9297 04:57:51,120 --> 04:57:52,120 Unity engine.ui so let's go up here 9298 04:57:52,920 --> 04:57:53,920 using Unity engine dot UI so we have our 9299 04:57:56,760 --> 04:57:57,760 image component okay great let's call it 9300 04:57:59,100 --> 04:58:00,100 the bar image 9301 04:58:01,378 --> 04:58:02,378 so we have a reference and now with this 9302 04:58:04,020 --> 04:58:05,020 obviously we need to have some kind of 9303 04:58:05,700 --> 04:58:06,700 reference to the counter so we know when 9304 04:58:07,260 --> 04:58:08,260 the progress changes so it's really the 9305 04:58:09,298 --> 04:58:10,298 same thing that we've already done so 9306 04:58:10,798 --> 04:58:11,798 many times throughout this course so 9307 04:58:12,600 --> 04:58:13,600 let's set a film up here serialize film 9308 04:58:14,540 --> 04:58:15,540 private cutting counter for our cutting 9309 04:58:18,000 --> 04:58:19,000 counter 9310 04:58:19,740 --> 04:58:20,740 then over here in the editor let's write 9311 04:58:21,420 --> 04:58:22,420 new references so drag the reference to 9312 04:58:23,040 --> 04:58:24,040 The Cutting counter and another one to 9313 04:58:24,958 --> 04:58:25,958 the bar image okay great 9314 04:58:26,940 --> 04:58:27,940 now we just need some kind of event to 9315 04:58:28,798 --> 04:58:29,798 update the bar image 9316 04:58:30,718 --> 04:58:31,718 so let's go over here into our cutting 9317 04:58:32,520 --> 04:58:33,520 count script let's make an event to 9318 04:58:34,500 --> 04:58:35,500 spawn that so public event let's use the 9319 04:58:37,260 --> 04:58:38,260 event handler the default standard 9320 04:58:39,660 --> 04:58:40,660 let's go with on progress change 9321 04:58:43,798 --> 04:58:44,798 and let's also make a nice event artist 9322 04:58:45,540 --> 04:58:46,540 to be able to send the current progress 9323 04:58:47,100 --> 04:58:48,100 amount 9324 04:58:48,298 --> 04:58:49,298 so let's make a public class on progress 9325 04:58:51,180 --> 04:58:52,180 changed event arcs and let's extend 9326 04:58:53,820 --> 04:58:54,820 event arcs 9327 04:58:55,500 --> 04:58:56,500 and then inside and let's put the 9328 04:58:57,298 --> 04:58:58,298 current progress 9329 04:58:58,680 --> 04:58:59,680 however let's also pass in the progress 9330 04:59:00,958 --> 04:59:01,958 as normalized since that's the what the 9331 04:59:02,760 --> 04:59:03,760 bar will use 9332 04:59:04,560 --> 04:59:05,560 so public Cloud progress normalized 9333 04:59:08,160 --> 04:59:09,160 and we're going to make this event of 9334 04:59:10,138 --> 04:59:11,138 this type 9335 04:59:11,340 --> 04:59:12,340 okay great so we have our event 9336 04:59:13,980 --> 04:59:14,980 now whenever we modify the progress we 9337 04:59:16,020 --> 04:59:17,020 just need to fire this event so over 9338 04:59:17,218 --> 04:59:18,218 here when resetting the progress let's 9339 04:59:19,138 --> 04:59:20,138 fire it so let's invoke pass in this 9340 04:59:21,718 --> 04:59:22,718 instantiate our event args and pass in 9341 04:59:24,718 --> 04:59:25,718 the progress normalized and to get the 9342 04:59:27,120 --> 04:59:28,120 normalized progress sectionally very 9343 04:59:28,680 --> 04:59:29,680 simple basically we just need to divide 9344 04:59:30,480 --> 04:59:31,480 the current progress by the maximum so 9345 04:59:32,458 --> 04:59:33,458 cutting progress divided by cutting 9346 04:59:34,500 --> 04:59:35,500 progress Max which is actually inside 9347 04:59:36,540 --> 04:59:37,540 the rest BSO so we need to pick that one 9348 04:59:38,700 --> 04:59:39,700 up 9349 04:59:39,718 --> 04:59:40,718 so let's go down there to pick up the 9350 04:59:42,000 --> 04:59:43,000 cutting progress recipe 9351 04:59:44,760 --> 04:59:45,760 so we picked this one up and we go in 9352 04:59:47,160 --> 04:59:48,160 there and get the maximum 9353 04:59:49,020 --> 04:59:50,020 however over here we also need to be 9354 04:59:51,000 --> 04:59:52,000 very careful because there is one sneaky 9355 04:59:52,980 --> 04:59:53,980 issue here this has to do with how 9356 04:59:55,020 --> 04:59:56,020 c-sharp works and how instar divided 9357 04:59:57,240 --> 04:59:58,240 with other ends 9358 04:59:58,798 --> 04:59:59,798 for example if we had a cutting progress 9359 05:00:00,718 --> 05:00:01,718 of one and cutting progress Max of five 9360 05:00:02,700 --> 05:00:03,700 you would think one divided by 5 would 9361 05:00:04,860 --> 05:00:05,860 equal 0.2 however if we actually did 9362 05:00:07,440 --> 05:00:08,440 that over here we would actually get a 9363 05:00:09,240 --> 05:00:10,240 zero and the reason for that is because 9364 05:00:11,458 --> 05:00:12,458 we are dividing two ends cutting 9365 05:00:13,200 --> 05:00:14,200 progress is an end cutting progress Max 9366 05:00:14,638 --> 05:00:15,638 is also an INT and if you divide an end 9367 05:00:17,100 --> 05:00:18,100 by an end then the end result will also 9368 05:00:19,378 --> 05:00:20,378 be an end 9369 05:00:20,458 --> 05:00:21,458 since you cannot Define 0.2 in an end 9370 05:00:22,798 --> 05:00:23,798 the decimal gets cut down and you end up 9371 05:00:24,958 --> 05:00:25,958 with just zero so that would not be 9372 05:00:27,180 --> 05:00:28,180 correct in order to get the right value 9373 05:00:29,218 --> 05:00:30,218 from this calculation we need to make 9374 05:00:30,780 --> 05:00:31,780 sure to convert one of these values onto 9375 05:00:32,400 --> 05:00:33,400 a float so that's really simple we just 9376 05:00:34,620 --> 05:00:35,620 cast one of them so just cast this one 9377 05:00:36,298 --> 05:00:37,298 to the float just like that 9378 05:00:38,700 --> 05:00:39,700 basically now this one will first be 9379 05:00:40,260 --> 05:00:41,260 cast to a float and then we're going to 9380 05:00:42,060 --> 05:00:43,060 have a float divided by an end and the 9381 05:00:43,740 --> 05:00:44,740 end result won't be afloat so if you 9382 05:00:46,320 --> 05:00:47,320 ever do some math and you get some weird 9383 05:00:47,760 --> 05:00:48,760 results always make sure to check the 9384 05:00:49,440 --> 05:00:50,440 type of your numbers 9385 05:00:50,700 --> 05:00:51,700 okay so here we are correctly firing the 9386 05:00:53,280 --> 05:00:54,280 event and then down here when adding our 9387 05:00:55,080 --> 05:00:56,080 progress let's do the same thing let's 9388 05:00:57,718 --> 05:00:58,718 also fire on the event 9389 05:01:00,298 --> 05:01:01,298 so now we can go back into our progress 9390 05:01:02,218 --> 05:01:03,218 bar UI 9391 05:01:03,718 --> 05:01:04,718 and over here let's listen to the event 9392 05:01:05,340 --> 05:01:06,340 and again remember that if we're 9393 05:01:07,440 --> 05:01:08,440 accessing an external reference let's do 9394 05:01:09,540 --> 05:01:10,540 that around start and not an awake 9395 05:01:12,000 --> 05:01:13,000 so cutting counter listen to the on 9396 05:01:14,340 --> 05:01:15,340 progress changed event 9397 05:01:16,980 --> 05:01:17,980 when that happens let's just go bar 9398 05:01:18,718 --> 05:01:19,718 image and set the fill amount to what we 9399 05:01:20,520 --> 05:01:21,520 received from the event so the progress 9400 05:01:22,080 --> 05:01:23,080 normalized 9401 05:01:23,218 --> 05:01:24,218 okay so that's really it and also appear 9402 05:01:25,920 --> 05:01:26,920 on start let's initialize it as 0f so 9403 05:01:28,740 --> 05:01:29,740 the bar is nice and empty 9404 05:01:30,718 --> 05:01:31,718 okay so let's test 9405 05:01:32,520 --> 05:01:33,520 back in the editor let's just go back 9406 05:01:34,138 --> 05:01:35,138 into the scenes make sure the prefab has 9407 05:01:35,760 --> 05:01:36,760 been saved and let's head on play 9408 05:01:37,680 --> 05:01:38,680 and right away yep we do see the bar yep 9409 05:01:39,780 --> 05:01:40,780 it is empty now pick up some cheese drop 9410 05:01:41,760 --> 05:01:42,760 it and if I cut and if there go add a 9411 05:01:44,280 --> 05:01:45,280 little bit of progress now a bit more 9412 05:01:45,540 --> 05:01:46,540 and there you go there's our cheese 9413 05:01:48,240 --> 05:01:49,240 okay great everything does work now 9414 05:01:51,120 --> 05:01:52,120 let's add just one more tiny bonus thing 9415 05:01:53,040 --> 05:01:54,040 we can add some extra logic in order to 9416 05:01:55,320 --> 05:01:56,320 hide this visual if the bar is either 9417 05:01:56,820 --> 05:01:57,820 completely empty or completely full that 9418 05:01:58,798 --> 05:01:59,798 is actually pretty simple 9419 05:02:00,420 --> 05:02:01,420 over here on the progress bar UI script 9420 05:02:03,060 --> 05:02:04,060 let's just make some basic show and 9421 05:02:04,798 --> 05:02:05,798 height functions 9422 05:02:05,878 --> 05:02:06,878 so private void show and then we're 9423 05:02:08,940 --> 05:02:09,940 going to have 9424 05:02:11,878 --> 05:02:12,878 a private void Hind 9425 05:02:14,940 --> 05:02:15,940 on these one just game objects that 9426 05:02:16,740 --> 05:02:17,740 active this one set it to true and this 9427 05:02:19,020 --> 05:02:20,020 one set it to false 9428 05:02:20,638 --> 05:02:21,638 now on start we subscribe to the event 9429 05:02:22,560 --> 05:02:23,560 and then let's hide it okay 9430 05:02:26,040 --> 05:02:27,040 also here it's very important make sure 9431 05:02:27,900 --> 05:02:28,900 you hide it after you listen to the 9432 05:02:29,580 --> 05:02:30,580 event if for example You Can't Hide on 9433 05:02:31,798 --> 05:02:32,798 awake that would disable the game object 9434 05:02:33,540 --> 05:02:34,540 and the start would never run so it 9435 05:02:34,980 --> 05:02:35,980 would never listen to the event 9436 05:02:36,480 --> 05:02:37,480 so if you have reset the game object as 9437 05:02:38,700 --> 05:02:39,700 inactive make sure you do it only after 9438 05:02:41,040 --> 05:02:42,040 you're listening to whatever events you 9439 05:02:42,900 --> 05:02:43,900 want so we have this that's great and 9440 05:02:45,120 --> 05:02:46,120 then when the progress changes 9441 05:02:47,040 --> 05:02:48,040 let's just do a basic test so if e dot 9442 05:02:49,740 --> 05:02:50,740 progress normalized equals zero f or if 9443 05:02:53,218 --> 05:02:54,218 the progress normalized equals one F so 9444 05:02:55,138 --> 05:02:56,138 if the bar is similarly empty or 9445 05:02:56,340 --> 05:02:57,340 completely full 9446 05:02:57,780 --> 05:02:58,780 if so then let's hide it and if not then 9447 05:03:01,260 --> 05:03:02,260 let's show it 9448 05:03:04,440 --> 05:03:05,440 okay that's it let's test 9449 05:03:06,780 --> 05:03:07,780 okay and yep by default starts off 9450 05:03:08,638 --> 05:03:09,638 hidden let's pick up the Tomato go up 9451 05:03:10,440 --> 05:03:11,440 there and yep still hidden now I cut and 9452 05:03:12,660 --> 05:03:13,660 there you go there it is cut again and 9453 05:03:14,280 --> 05:03:15,280 yep there you go it hides itself okay 9454 05:03:16,260 --> 05:03:17,260 great so we've got a nice little visual 9455 05:03:18,718 --> 05:03:19,718 let's do just one more final thing let's 9456 05:03:20,878 --> 05:03:21,878 add a really nice animation 9457 05:03:23,040 --> 05:03:24,040 if we go inside the cutting counter and 9458 05:03:25,440 --> 05:03:26,440 we'll look at the cutting counter visual 9459 05:03:27,000 --> 05:03:28,000 over here note how it already has an 9460 05:03:28,620 --> 05:03:29,620 animator 9461 05:03:29,520 --> 05:03:30,520 just like we did for the container 9462 05:03:31,440 --> 05:03:32,440 counter it's all very simple 9463 05:03:33,120 --> 05:03:34,120 so basically just has a cut parameter 9464 05:03:35,400 --> 05:03:36,400 when that happens it just cuts the 9465 05:03:37,080 --> 05:03:38,080 counter so just plays a simple animation 9466 05:03:39,540 --> 05:03:40,540 since it's going to be pretty much 9467 05:03:41,040 --> 05:03:42,040 exactly like the container counter and 9468 05:03:42,660 --> 05:03:43,660 let's actually duplicate that script so 9469 05:03:45,000 --> 05:03:46,000 let's go down find that script so the 9470 05:03:47,040 --> 05:03:48,040 container comes to visual let's 9471 05:03:48,240 --> 05:03:49,240 duplicate this so Ctrl d 9472 05:03:50,520 --> 05:03:51,520 let's rename this to The Cutting counter 9473 05:03:53,218 --> 05:03:54,218 visual 9474 05:03:54,600 --> 05:03:55,600 okay let's open 9475 05:03:56,100 --> 05:03:57,100 and over here let's rename the script so 9476 05:03:57,840 --> 05:03:58,840 the cutting countervision okay great 9477 05:04:00,060 --> 05:04:01,060 then for the parameter let's rename this 9478 05:04:02,280 --> 05:04:03,280 instead of open close is going to be 9479 05:04:03,900 --> 05:04:04,900 called cut 9480 05:04:05,160 --> 05:04:06,160 and for the string it's cut again make 9481 05:04:08,040 --> 05:04:09,040 sure you write it case sensitive make 9482 05:04:09,780 --> 05:04:10,780 sure it's all correct 9483 05:04:11,218 --> 05:04:12,218 then instead of having a container come 9484 05:04:12,958 --> 05:04:13,958 through we've got a cutting counter and 9485 05:04:14,940 --> 05:04:15,940 a cutting counter 9486 05:04:17,040 --> 05:04:18,040 and finally we just need to listen to 9487 05:04:18,900 --> 05:04:19,900 the correct event so technically we 9488 05:04:21,120 --> 05:04:22,120 couldn't listen to the unprogressed 9489 05:04:22,560 --> 05:04:23,560 changed however that one also gets fired 9490 05:04:24,540 --> 05:04:25,540 over here when the cutting progress is 9491 05:04:25,740 --> 05:04:26,740 zero we don't want the current mission 9492 05:04:27,480 --> 05:04:28,480 to play when this happens so let's just 9493 05:04:29,700 --> 05:04:30,700 make another simple event so a public 9494 05:04:31,980 --> 05:04:32,980 event event handler 9495 05:04:34,080 --> 05:04:35,080 let's call this just on cut 9496 05:04:36,900 --> 05:04:37,900 okay and then down here when we have our 9497 05:04:39,180 --> 05:04:40,180 cutting progress so we cut and let's 9498 05:04:41,218 --> 05:04:42,218 just invoke this event 9499 05:04:44,638 --> 05:04:45,638 okay that's it super simple 9500 05:04:47,040 --> 05:04:48,040 so now on The Cutting counter visual 9501 05:04:48,780 --> 05:04:49,780 let's go into the cutting counter and 9502 05:04:50,700 --> 05:04:51,700 into the uncut event let's listen to 9503 05:04:52,620 --> 05:04:53,620 this and we're going to set the trigger 9504 05:04:54,958 --> 05:04:55,958 example like this so get rid of the 9505 05:04:57,180 --> 05:04:58,180 container counter like this 9506 05:05:00,060 --> 05:05:01,060 okay there you go a very simple script 9507 05:05:02,760 --> 05:05:03,760 so now here back in the scene view 9508 05:05:04,378 --> 05:05:05,378 inside the container counter prefab 9509 05:05:07,200 --> 05:05:08,200 let's just go inside the visual let's 9510 05:05:09,000 --> 05:05:10,000 attach The Cutting counter visual just 9511 05:05:10,680 --> 05:05:11,680 need to drag The Cutting counter 9512 05:05:12,000 --> 05:05:13,000 reference and that's it let's exit the 9513 05:05:14,218 --> 05:05:15,218 prefab save it and let's play okay so 9514 05:05:16,980 --> 05:05:17,980 now let's pick up a cabbage go up there 9515 05:05:18,840 --> 05:05:19,840 drop it and aren't interact and if there 9516 05:05:21,060 --> 05:05:22,060 you go we've got a nice little animation 9517 05:05:23,340 --> 05:05:24,340 all right awesome so I can drop things I 9518 05:05:26,160 --> 05:05:27,160 can cut them and everything works 9519 05:05:27,958 --> 05:05:28,958 perfectly 9520 05:05:28,980 --> 05:05:29,980 all right 9521 05:05:30,540 --> 05:05:31,540 so here we added a cutting progress to 9522 05:05:32,820 --> 05:05:33,820 our cutting counter and we also learned 9523 05:05:35,040 --> 05:05:36,040 about yet another very useful ENT 9524 05:05:36,540 --> 05:05:37,540 feature called World canvases 9525 05:05:39,240 --> 05:05:40,240 and at the same time you might have also 9526 05:05:40,860 --> 05:05:41,860 noticed that the canvas is looking at 9527 05:05:42,540 --> 05:05:43,540 the camera in kind of a weird way 9528 05:05:43,798 --> 05:05:44,798 basically just pointing straight forward 9529 05:05:45,860 --> 05:05:46,860 this can sometimes make it difficult to 9530 05:05:48,360 --> 05:05:49,360 see so let's work on that in the next 9531 05:05:50,160 --> 05:05:51,160 lecture 9532 05:05:51,600 --> 05:05:52,600 hello and welcome I'm your code monkey 9533 05:05:53,520 --> 05:05:54,520 in this lecture we're going to build a 9534 05:05:55,798 --> 05:05:56,798 very simple but very useful script to 9535 05:05:57,900 --> 05:05:58,900 make an object look straight at the 9536 05:05:59,280 --> 05:06:00,280 camera with various options 9537 05:06:01,320 --> 05:06:02,320 okay so we previously made the cutting 9538 05:06:03,420 --> 05:06:04,420 counter and when I placed something yep 9539 05:06:05,040 --> 05:06:06,040 there's a nice progress bar 9540 05:06:07,020 --> 05:06:08,020 so now that this is working let's do one 9541 05:06:09,298 --> 05:06:10,298 more thing right now look at how the bar 9542 05:06:11,700 --> 05:06:12,700 is oriented it's looking quite a bit 9543 05:06:13,620 --> 05:06:14,620 slanted that's because we have a 9544 05:06:15,298 --> 05:06:16,298 perspective camera and it's looking from 9545 05:06:16,798 --> 05:06:17,798 top down 9546 05:06:17,940 --> 05:06:18,940 now this is one of those things that is 9547 05:06:19,440 --> 05:06:20,440 kind of personal preference so maybe you 9548 05:06:20,878 --> 05:06:21,878 don't like it just like this 9549 05:06:22,620 --> 05:06:23,620 but a lot of the times you want these 9550 05:06:24,240 --> 05:06:25,240 World UI elements to face the camera 9551 05:06:26,040 --> 05:06:27,040 just like a regular UI 9552 05:06:28,020 --> 05:06:29,020 one example of this problem is for 9553 05:06:29,820 --> 05:06:30,820 example let me pick up the cutting 9554 05:06:31,500 --> 05:06:32,500 counter duplicated and let's put one 9555 05:06:33,600 --> 05:06:34,600 down here so rotate it upwards 9556 05:06:37,740 --> 05:06:38,740 okay let's put it on 4.50 and minus 5. 9557 05:06:41,820 --> 05:06:42,820 now if I place something on there and I 9558 05:06:43,860 --> 05:06:44,860 cut it yep like that the bar is Now 9559 05:06:45,480 --> 05:06:46,480 inverted so let's make a simple script 9560 05:06:47,940 --> 05:06:48,940 to solve this problem 9561 05:06:49,860 --> 05:06:50,860 let's go into our scripts create a new 9562 05:06:51,958 --> 05:06:52,958 c-sharp script call it look at camera 9563 05:06:55,620 --> 05:06:56,620 let's go on to The Cutting counter 9564 05:06:57,600 --> 05:06:58,600 prefab let's open it up go inside on the 9565 05:06:59,878 --> 05:07:00,878 progress bar let's attach the script so 9566 05:07:01,798 --> 05:07:02,798 the unlocked camera okay now let's open 9567 05:07:03,600 --> 05:07:04,600 so from here let's use an interesting 9568 05:07:06,360 --> 05:07:07,360 function so let's use a private void 9569 05:07:08,940 --> 05:07:09,940 late update so not update we have the 9570 05:07:11,520 --> 05:07:12,520 late update so if this is the first time 9571 05:07:14,100 --> 05:07:15,100 you're hearing about this like the name 9572 05:07:15,900 --> 05:07:16,900 flies this one is going to run after the 9573 05:07:17,638 --> 05:07:18,638 regular update so every single update 9574 05:07:20,340 --> 05:07:21,340 and all the objects is going to run and 9575 05:07:22,138 --> 05:07:23,138 then on the late updates so kind of like 9576 05:07:24,240 --> 05:07:25,240 you've got awake and start you have 9577 05:07:25,860 --> 05:07:26,860 update and late update why this is 9578 05:07:27,958 --> 05:07:28,958 useful specifically for this script is 9579 05:07:30,420 --> 05:07:31,420 because for this element you really want 9580 05:07:32,040 --> 05:07:33,040 us to run the orienting logic you want 9581 05:07:34,200 --> 05:07:35,200 that to be done after whatever that 9582 05:07:35,940 --> 05:07:36,940 object does in the update in this case 9583 05:07:38,040 --> 05:07:39,040 this object will never move so it's not 9584 05:07:39,660 --> 05:07:40,660 really an issue 9585 05:07:40,798 --> 05:07:41,798 but for example if you had some kind of 9586 05:07:42,718 --> 05:07:43,718 moving vehicle with a warm cameras on 9587 05:07:44,638 --> 05:07:45,638 top if you have that you would want to 9588 05:07:46,440 --> 05:07:47,440 set the Warren canvas and location to 9589 05:07:47,940 --> 05:07:48,940 unlock the camera after the vehicle had 9590 05:07:49,980 --> 05:07:50,980 moved otherwise the canvas would not 9591 05:07:52,138 --> 05:07:53,138 look perfect so anyways because that 9592 05:07:54,298 --> 05:07:55,298 here we're doing on late update and now 9593 05:07:56,940 --> 05:07:57,940 we can just look straight the camera so 9594 05:07:58,740 --> 05:07:59,740 we can just do transform dot lookup 9595 05:08:03,540 --> 05:08:04,540 and for the Target passing the camera 9596 05:08:05,218 --> 05:08:06,218 Dot main.transform 9597 05:08:07,500 --> 05:08:08,500 this function makes this transform look 9598 05:08:09,540 --> 05:08:10,540 at another transform or another point so 9599 05:08:11,280 --> 05:08:12,280 this will make it look straight at the 9600 05:08:12,480 --> 05:08:13,480 camera 9601 05:08:13,200 --> 05:08:14,200 also by the way one quick note here in 9602 05:08:15,600 --> 05:08:16,600 some other tutorials you might see 9603 05:08:17,160 --> 05:08:18,160 people telling you not to use 9604 05:08:18,780 --> 05:08:19,780 camera.main the reason for that is 9605 05:08:21,120 --> 05:08:22,120 because this field did not used to be 9606 05:08:22,920 --> 05:08:23,920 cached so every time you use this it 9607 05:08:25,138 --> 05:08:26,138 would cycle through every single game 9608 05:08:26,580 --> 05:08:27,580 object in the scene until it found the 9609 05:08:28,260 --> 05:08:29,260 main camera so that was obviously really 9610 05:08:30,298 --> 05:08:31,298 bad for performance but nowadays this 9611 05:08:32,340 --> 05:08:33,340 field is now cached by default on the 9612 05:08:33,958 --> 05:08:34,958 ENT backend so you no longer need to 9613 05:08:35,878 --> 05:08:36,878 Cache it yourself accessing it directly 9614 05:08:37,740 --> 05:08:38,740 just like this is now fine 9615 05:08:39,540 --> 05:08:40,540 okay so with this let's test 9616 05:08:41,940 --> 05:08:42,940 just make sure to save the prefab and 9617 05:08:44,160 --> 05:08:45,160 let's hit on play 9618 05:08:45,780 --> 05:08:46,780 let's go ahead pick up a cabbage put it 9619 05:08:47,878 --> 05:08:48,878 up there and if they're young look at 9620 05:08:49,440 --> 05:08:50,440 that how it's looking straight at the 9621 05:08:50,760 --> 05:08:51,760 camera and for this one down here same 9622 05:08:52,860 --> 05:08:53,860 thing cut it any up there you go both of 9623 05:08:54,600 --> 05:08:55,600 them are looking straight at the camera 9624 05:08:56,580 --> 05:08:57,580 okay so that's great 9625 05:08:58,920 --> 05:08:59,920 you can also see exactly what it's doing 9626 05:09:00,540 --> 05:09:01,540 if we try to move the camera again we're 9627 05:09:02,580 --> 05:09:03,580 using cinemachine so let's move the 9628 05:09:04,020 --> 05:09:05,020 virtual camera 9629 05:09:05,458 --> 05:09:06,458 so over here if I just play around with 9630 05:09:07,320 --> 05:09:08,320 the position.x look at that look how as 9631 05:09:09,958 --> 05:09:10,958 I move the camera yep the objects are 9632 05:09:11,940 --> 05:09:12,940 perfectly looking straight at the camera 9633 05:09:13,740 --> 05:09:14,740 so that's great that's what we want but 9634 05:09:16,020 --> 05:09:17,020 also you might notice one thing notice 9635 05:09:18,120 --> 05:09:19,120 under the bars are actually inverted 9636 05:09:20,520 --> 05:09:21,520 instead of going left to right they're 9637 05:09:22,080 --> 05:09:23,080 actually going right and left basically 9638 05:09:23,700 --> 05:09:24,700 this has to do with how the canvas by 9639 05:09:25,440 --> 05:09:26,440 default assumes you are essentially 9640 05:09:26,820 --> 05:09:27,820 going to look at it from behind instead 9641 05:09:28,500 --> 05:09:29,500 of looking forward so that is why when 9642 05:09:30,900 --> 05:09:31,900 this game object is pointing straight at 9643 05:09:32,400 --> 05:09:33,400 the camera it's essentially inverted 9644 05:09:34,500 --> 05:09:35,500 so to sum this is actually quite simple 9645 05:09:36,120 --> 05:09:37,120 we basically just need to look in the 9646 05:09:37,920 --> 05:09:38,920 exact opposite direction 9647 05:09:39,660 --> 05:09:40,660 but at the same time sometimes we might 9648 05:09:41,520 --> 05:09:42,520 want this exact Behavior having 9649 05:09:43,080 --> 05:09:44,080 something looks right at the camera 9650 05:09:44,280 --> 05:09:45,280 maybe we do want it to be inverted 9651 05:09:46,020 --> 05:09:47,020 sometimes so for that let's make a nice 9652 05:09:48,540 --> 05:09:49,540 complete script with all of our possible 9653 05:09:50,340 --> 05:09:51,340 options and for the finding options it's 9654 05:09:52,680 --> 05:09:53,680 also an excellent way to learn about one 9655 05:09:54,600 --> 05:09:55,600 more thing which are c-sharp enums enums 9656 05:09:57,660 --> 05:09:58,660 are an enumeration meaning a fixed set 9657 05:09:59,700 --> 05:10:00,700 of options that you can have of 9658 05:10:01,020 --> 05:10:02,020 something 9659 05:10:01,980 --> 05:10:02,980 so these are really useful when you have 9660 05:10:03,660 --> 05:10:04,660 a fixed set of something like for 9661 05:10:05,760 --> 05:10:06,760 example maybe a fixed number of options 9662 05:10:07,560 --> 05:10:08,560 so for example up here let's make it 9663 05:10:10,020 --> 05:10:11,020 private make it an enum and let's call 9664 05:10:12,540 --> 05:10:13,540 it mode and then inside we can Define 9665 05:10:14,878 --> 05:10:15,878 all of our options so let's say we have 9666 05:10:17,340 --> 05:10:18,340 the regular look at it and then look at 9667 05:10:19,260 --> 05:10:20,260 inverted 9668 05:10:20,638 --> 05:10:21,638 okay so we have these two options in our 9669 05:10:22,980 --> 05:10:23,980 enum now let's do a field of this type 9670 05:10:25,138 --> 05:10:26,138 and expose it in the editor 9671 05:10:26,878 --> 05:10:27,878 so let's make a serialized film private 9672 05:10:29,218 --> 05:10:30,218 of type mode and call it mode 9673 05:10:31,980 --> 05:10:32,980 okay let's save this and look what this 9674 05:10:34,020 --> 05:10:35,020 looks like in the editor and if we go 9675 05:10:36,420 --> 05:10:37,420 inside the cutting counter and we'll 9676 05:10:38,340 --> 05:10:39,340 look at the progress bar 9677 05:10:39,840 --> 05:10:40,840 even look at that the mode shows up and 9678 05:10:41,638 --> 05:10:42,638 it shows up as a really nice drop down 9679 05:10:43,500 --> 05:10:44,500 menu so since we have a limited number 9680 05:10:45,958 --> 05:10:46,958 of options we've got a really nice menu 9681 05:10:47,580 --> 05:10:48,580 where we can choose each round if you 9682 05:10:49,260 --> 05:10:50,260 want 9683 05:10:50,100 --> 05:10:51,100 so that's really awesome that's one of 9684 05:10:51,780 --> 05:10:52,780 the benefits of enums they are really 9685 05:10:53,638 --> 05:10:54,638 easy to use over here in the editor 9686 05:10:55,980 --> 05:10:56,980 now back in the code here and let's 9687 05:10:57,600 --> 05:10:58,600 decide which one to use 9688 05:10:59,160 --> 05:11:00,160 so on The Late update let me just do a 9689 05:11:01,260 --> 05:11:02,260 switch on our mode in case we are on the 9690 05:11:04,320 --> 05:11:05,320 regular look at mode then let's see 9691 05:11:06,120 --> 05:11:07,120 exactly this let's simply look in in 9692 05:11:08,400 --> 05:11:09,400 case we are on the look at invertent 9693 05:11:11,458 --> 05:11:12,458 for this we just want to look at the 9694 05:11:12,958 --> 05:11:13,958 inverse position so that's actually 9695 05:11:14,218 --> 05:11:15,218 pretty easy we just calculate the 9696 05:11:16,440 --> 05:11:17,440 direction Vector from the camera to this 9697 05:11:18,360 --> 05:11:19,360 object 9698 05:11:19,200 --> 05:11:20,200 so a vector 3 call it deer from camera 9699 05:11:23,218 --> 05:11:24,218 and to get direction from the camera we 9700 05:11:25,200 --> 05:11:26,200 start from this object so this 9701 05:11:26,458 --> 05:11:27,458 transformed that position subtract the 9702 05:11:28,560 --> 05:11:29,560 camera dot main transform position 9703 05:11:31,560 --> 05:11:32,560 so this gives us the direction pointing 9704 05:11:33,900 --> 05:11:34,900 from the camera and then just to 9705 05:11:35,878 --> 05:11:36,878 transform down look at 9706 05:11:38,100 --> 05:11:39,100 and instead of looking at the camera 9707 05:11:39,480 --> 05:11:40,480 let's look at the opposite position so 9708 05:11:41,160 --> 05:11:42,160 let's look at transform that position so 9709 05:11:42,958 --> 05:11:43,958 our current position points the 9710 05:11:44,820 --> 05:11:45,820 direction from the camera so we're going 9711 05:11:46,138 --> 05:11:47,138 to be looking at the exact opposite 9712 05:11:47,638 --> 05:11:48,638 point 9713 05:11:48,540 --> 05:11:49,540 okay so that's it let's test 9714 05:11:50,940 --> 05:11:51,940 and right now by default we have the 9715 05:11:52,740 --> 05:11:53,740 regular look at so let's just see it 9716 05:11:55,320 --> 05:11:56,320 let's just play some objects okay so 9717 05:11:57,480 --> 05:11:58,480 right now it's still inverting 9718 05:11:59,638 --> 05:12:00,638 and something real nice is you can play 9719 05:12:01,440 --> 05:12:02,440 around the enums even as the game is 9720 05:12:03,180 --> 05:12:04,180 running so let's go inside the cutting 9721 05:12:04,798 --> 05:12:05,798 counter on the progress bar UI for this 9722 05:12:06,900 --> 05:12:07,900 one let's swap from Lookout to unlock 9723 05:12:08,218 --> 05:12:09,218 inverten anything like that that one is 9724 05:12:10,320 --> 05:12:11,320 now looking perfectly 9725 05:12:11,760 --> 05:12:12,760 so this one is using Lookout and this 9726 05:12:13,740 --> 05:12:14,740 one using look at inverted 9727 05:12:15,600 --> 05:12:16,600 okay great it's all working 9728 05:12:17,760 --> 05:12:18,760 however yet another thing that is all 9729 05:12:19,320 --> 05:12:20,320 about personal preference 9730 05:12:21,060 --> 05:12:22,060 note how the visual has a slight slant 9731 05:12:23,760 --> 05:12:24,760 this is due to how the visual section 9732 05:12:25,980 --> 05:12:26,980 looking directly at the center of the 9733 05:12:27,718 --> 05:12:28,718 camera 9734 05:12:28,920 --> 05:12:29,920 so you can really see it if I move the 9735 05:12:30,540 --> 05:12:31,540 camera left and right how it Slants 9736 05:12:32,760 --> 05:12:33,760 going left or going right 9737 05:12:34,920 --> 05:12:35,920 again the Zone personal preference it's 9738 05:12:36,718 --> 05:12:37,718 just a visual so maybe you do want this 9739 05:12:38,458 --> 05:12:39,458 look but let's see another method so 9740 05:12:40,980 --> 05:12:41,980 over here in our modes let's add two 9741 05:12:42,420 --> 05:12:43,420 more let's add camera forward and Camera 9742 05:12:44,878 --> 05:12:45,878 forward inverted 9743 05:12:47,100 --> 05:12:48,100 and then down here on our late update 9744 05:12:49,378 --> 05:12:50,378 let's add those so the camera forward 9745 05:12:51,240 --> 05:12:52,240 and then we have the camera forward 9746 05:12:53,400 --> 05:12:54,400 inversion 9747 05:12:54,900 --> 05:12:55,900 so for this one for the camera forward 9748 05:12:56,458 --> 05:12:57,458 super simple let's just take this 9749 05:12:57,840 --> 05:12:58,840 transform use the forward which again 9750 05:12:59,638 --> 05:13:00,638 you can get or you can set it and let's 9751 05:13:01,798 --> 05:13:02,798 set it to the exact same one as the 9752 05:13:03,420 --> 05:13:04,420 camera Dot main.transform.4 9753 05:13:06,480 --> 05:13:07,480 and for the inverting example the same 9754 05:13:08,520 --> 05:13:09,520 thing X7 set of four do we do minus four 9755 05:13:11,760 --> 05:13:12,760 okay so let's see what this looks like 9756 05:13:14,160 --> 05:13:15,160 okay so here's the game with both 9757 05:13:15,958 --> 05:13:16,958 counters they're both currently using 9758 05:13:17,940 --> 05:13:18,940 the unlockit mode now if we put a look 9759 05:13:19,980 --> 05:13:20,980 at inverting yep that one goes left to 9760 05:13:21,480 --> 05:13:22,480 right okay great now if I put camera 4 9761 05:13:23,280 --> 05:13:24,280 in give a look at that now that one is 9762 05:13:25,260 --> 05:13:26,260 perfectly straight 9763 05:13:26,458 --> 05:13:27,458 so even as I move the virtual camera on 9764 05:13:28,560 --> 05:13:29,560 left and right look how that one is 9765 05:13:30,298 --> 05:13:31,298 always perfectly facing the camera as if 9766 05:13:32,160 --> 05:13:33,160 it was a regular UI owned 9767 05:13:34,860 --> 05:13:35,860 and for the inverter does the exact same 9768 05:13:36,480 --> 05:13:37,480 thing but invert and so just like that 9769 05:13:38,820 --> 05:13:39,820 so that's it these are the four modes 9770 05:13:40,798 --> 05:13:41,798 again these are all just visual elements 9771 05:13:42,600 --> 05:13:43,600 so pick whatever you prefer for me I'm 9772 05:13:44,820 --> 05:13:45,820 going to be using this one the camera.4 9773 05:13:46,440 --> 05:13:47,440 so that everything is perfectly 9774 05:13:47,638 --> 05:13:48,638 horizontal so I'm just going to make 9775 05:13:49,920 --> 05:13:50,920 sure to go inside the prefab and on the 9776 05:13:52,138 --> 05:13:53,138 prefab itself modified and set it as 9777 05:13:53,878 --> 05:13:54,878 camera.4 9778 05:13:55,560 --> 05:13:56,560 and now if I add the cheese there yep 9779 05:13:57,660 --> 05:13:58,660 looks great and if I had a cabbage here 9780 05:13:59,520 --> 05:14:00,520 and yep it also looks right 9781 05:14:01,680 --> 05:14:02,680 all right so here we created a really 9782 05:14:03,958 --> 05:14:04,958 nice useful generic script to make an 9783 05:14:05,940 --> 05:14:06,940 object look straight at the camera in 9784 05:14:07,500 --> 05:14:08,500 various ways note how this one has 9785 05:14:09,718 --> 05:14:10,718 nothing to do with canvas or a progress 9786 05:14:11,638 --> 05:14:12,638 bar or anything it's really a generic 9787 05:14:13,920 --> 05:14:14,920 script to look at the camera so you can 9788 05:14:15,360 --> 05:14:16,360 apply this to anything where you want it 9789 05:14:17,160 --> 05:14:18,160 to look at the camera 9790 05:14:18,360 --> 05:14:19,360 okay so with that the cutting counter is 9791 05:14:20,520 --> 05:14:21,520 fully done 9792 05:14:21,660 --> 05:14:22,660 now let's handle the trash counter in 9793 05:14:23,700 --> 05:14:24,700 the next lecture 9794 05:14:25,320 --> 05:14:26,320 hello and welcome I'm your code monkey 9795 05:14:27,900 --> 05:14:28,900 in this lecture let's create the trash 9796 05:14:29,820 --> 05:14:30,820 counter this one is actually pretty 9797 05:14:31,680 --> 05:14:32,680 simple it's how we're going to drop 9798 05:14:33,240 --> 05:14:34,240 something and just destroy it okay so 9799 05:14:35,580 --> 05:14:36,580 making the trash counter is going to be 9800 05:14:37,138 --> 05:14:38,138 super super easy once again going to be 9801 05:14:39,718 --> 05:14:40,718 another great practical example of the 9802 05:14:41,458 --> 05:14:42,458 power of writing good clean code and 9803 05:14:43,020 --> 05:14:44,020 having good organization in your project 9804 05:14:44,700 --> 05:14:45,700 so let's do the same thing that we've 9805 05:14:46,980 --> 05:14:47,980 already done a bunch of times so first 9806 05:14:48,780 --> 05:14:49,780 of all let's make the prefab variant so 9807 05:14:51,000 --> 05:14:52,000 let's right click on the base counter 9808 05:14:52,620 --> 05:14:53,620 and create a brand new prefab variant 9809 05:14:54,600 --> 05:14:55,600 come with the trash counter 9810 05:14:58,080 --> 05:14:59,080 okay let's go inside and first of all 9811 05:15:00,958 --> 05:15:01,958 let's drag the visual so find the visual 9812 05:15:03,000 --> 05:15:04,000 prefab on the trash counter okay then 9813 05:15:05,820 --> 05:15:06,820 let's duplicate it to make the selecting 9814 05:15:07,980 --> 05:15:08,980 so let's rename this to selected 9815 05:15:10,920 --> 05:15:11,920 let's add the selected counter visual 9816 05:15:13,740 --> 05:15:14,740 let's add the visual inside of it and on 9817 05:15:17,580 --> 05:15:18,580 the visual let's select the other 9818 05:15:20,360 --> 05:15:21,360 material so the counter selected and 9819 05:15:23,040 --> 05:15:24,040 finally on the selected put it one 9820 05:15:25,620 --> 05:15:26,620 percent bigger 1.01 9821 05:15:28,560 --> 05:15:29,560 and start off with visual disabled okay 9822 05:15:31,740 --> 05:15:32,740 so that's the basics just like we've 9823 05:15:33,600 --> 05:15:34,600 already done so many times now let's 9824 05:15:35,638 --> 05:15:36,638 make this script to run this so let's 9825 05:15:37,680 --> 05:15:38,680 frequently create a new c-sharp script 9826 05:15:39,360 --> 05:15:40,360 call it the trash counter 9827 05:15:42,000 --> 05:15:43,000 and by the way here we're already 9828 05:15:43,378 --> 05:15:44,378 starting to have quite a bunch of 9829 05:15:44,940 --> 05:15:45,940 scripts so we should probably organize 9830 05:15:46,500 --> 05:15:47,500 the scripts folder so let's make a new 9831 05:15:49,320 --> 05:15:50,320 folder let's come with counters 9832 05:15:52,680 --> 05:15:53,680 and let's make another one and call it 9833 05:15:55,320 --> 05:15:56,320 scriptable objects 9834 05:15:57,840 --> 05:15:58,840 so on the counters let's drag the base 9835 05:15:59,580 --> 05:16:00,580 counter clear counter the container the 9836 05:16:01,920 --> 05:16:02,920 container visual The Cutting The Cutting 9837 05:16:03,540 --> 05:16:04,540 visual then down here the trash counter 9838 05:16:06,180 --> 05:16:07,180 okay let's drag them all onto the 9839 05:16:08,100 --> 05:16:09,100 counters folder and on these critical 9840 05:16:10,138 --> 05:16:11,138 objects let's put the cutting recipe and 9841 05:16:12,060 --> 05:16:13,060 the kitchen object as so okay now our 9842 05:16:14,400 --> 05:16:15,400 phone there is a bit more organized so 9843 05:16:16,260 --> 05:16:17,260 let's open up the trash counter 9844 05:16:18,298 --> 05:16:19,298 and over here as usual let's begin by 9845 05:16:20,820 --> 05:16:21,820 extending the base counter okay great 9846 05:16:24,298 --> 05:16:25,298 then let's implement the regular 9847 05:16:25,920 --> 05:16:26,920 interaction so override the interact 9848 05:16:29,700 --> 05:16:30,700 and on this one again it's going to be 9849 05:16:31,378 --> 05:16:32,378 super simple we just check if the player 9850 05:16:33,540 --> 05:16:34,540 is holding something and if so we 9851 05:16:34,980 --> 05:16:35,980 destroy it so just check if player that 9852 05:16:37,560 --> 05:16:38,560 has kitchen object so if the player is 9853 05:16:39,900 --> 05:16:40,900 holding something go into the player get 9854 05:16:41,820 --> 05:16:42,820 the kitchen object the player is holding 9855 05:16:43,500 --> 05:16:44,500 and simply call destroy itself 9856 05:16:46,980 --> 05:16:47,980 and that's it it's this simple back in 9857 05:16:49,440 --> 05:16:50,440 the editorial let's just attach a script 9858 05:16:51,180 --> 05:16:52,180 let's make sure to drag the countertop 9859 05:16:53,340 --> 05:16:54,340 Point reference and on the selected drag 9860 05:16:55,500 --> 05:16:56,500 the base counter reference 9861 05:16:57,360 --> 05:16:58,360 okay with this it should be working so 9862 05:16:59,340 --> 05:17:00,340 let's exit the scene let's save the 9863 05:17:01,020 --> 05:17:02,020 prefab and let's drag it over here onto 9864 05:17:03,298 --> 05:17:04,298 our scene so let's drag the trash 9865 05:17:05,100 --> 05:17:06,100 counter and put it maybe somewhere over 9866 05:17:07,560 --> 05:17:08,560 here on the corner 9867 05:17:08,940 --> 05:17:09,940 so let's put it here on an X of 7 y 0 9868 05:17:11,820 --> 05:17:12,820 and -3.5 9869 05:17:14,700 --> 05:17:15,700 then let's also fill out these spots 9870 05:17:16,440 --> 05:17:17,440 down here so let's duplicate the clear 9871 05:17:18,718 --> 05:17:19,718 counter put one in there put another one 9872 05:17:21,180 --> 05:17:22,180 in there 9873 05:17:22,620 --> 05:17:23,620 let's put another one on the side and 9874 05:17:24,660 --> 05:17:25,660 for the crash counter and let's align it 9875 05:17:26,218 --> 05:17:27,218 so let's put it a bit more to the side 9876 05:17:28,378 --> 05:17:29,378 so on 7.5 okay great and let's put it 9877 05:17:31,378 --> 05:17:32,378 inside the counters and now we can test 9878 05:17:33,780 --> 05:17:34,780 okay so let's see if we can interact 9879 05:17:35,580 --> 05:17:36,580 with it and yep as I approach yep I do 9880 05:17:37,440 --> 05:17:38,440 see it highlighted okay great and if I 9881 05:17:39,180 --> 05:17:40,180 interact obviously nothing happens since 9882 05:17:40,680 --> 05:17:41,680 the player isn't holding anything now if 9883 05:17:42,900 --> 05:17:43,900 I pick something up let's say a tomato 9884 05:17:44,280 --> 05:17:45,280 and I don't want this tomato so I want 9885 05:17:46,200 --> 05:17:47,200 to trash it and if there you go it does 9886 05:17:47,878 --> 05:17:48,878 get trashed all right awesome so this is 9887 05:17:50,520 --> 05:17:51,520 literally it like I said this is once 9888 05:17:52,920 --> 05:17:53,920 again another excellent example of the 9889 05:17:54,600 --> 05:17:55,600 power of writing good clean code this 9890 05:17:56,638 --> 05:17:57,638 was super simple to implement because we 9891 05:17:58,500 --> 05:17:59,500 have a really nice structure for how all 9892 05:18:00,298 --> 05:18:01,298 of our Counters work also because our 9893 05:18:02,700 --> 05:18:03,700 interaction system is very well built 9894 05:18:04,560 --> 05:18:05,560 also because the kitchen object system 9895 05:18:06,660 --> 05:18:07,660 is very well made it's because of all of 9896 05:18:09,000 --> 05:18:10,000 that great very clean code that we were 9897 05:18:10,920 --> 05:18:11,920 able to implement a brand new counter in 9898 05:18:12,780 --> 05:18:13,780 literally about 60 seconds 9899 05:18:14,820 --> 05:18:15,820 so once again I hope that by following 9900 05:18:16,798 --> 05:18:17,798 this course you know understand why I'm 9901 05:18:18,360 --> 05:18:19,360 always talking about the importance of 9902 05:18:19,560 --> 05:18:20,560 writing good clean code it's exactly 9903 05:18:21,600 --> 05:18:22,600 because this if you write your code 9904 05:18:23,400 --> 05:18:24,400 correctly it makes developing the game 9905 05:18:25,138 --> 05:18:26,138 so much easier at first it might seem 9906 05:18:27,600 --> 05:18:28,600 like the quick and dirty approach is 9907 05:18:29,040 --> 05:18:30,040 faster and usually in the beginning it 9908 05:18:30,718 --> 05:18:31,718 is faster but as soon as you add some 9909 05:18:32,700 --> 05:18:33,700 complexity the quick and dirty approach 9910 05:18:34,440 --> 05:18:35,440 suddenly won't scale whereas the 9911 05:18:36,660 --> 05:18:37,660 well-built clean code approach this one 9912 05:18:38,340 --> 05:18:39,340 will continue scaling very well so here 9913 05:18:40,620 --> 05:18:41,620 we have a fully functional trash bin so 9914 05:18:42,718 --> 05:18:43,718 we can dispose of unwanted objects next 9915 05:18:45,240 --> 05:18:46,240 let's build a much much more complex 9916 05:18:47,400 --> 05:18:48,400 Hunter let's build a stove counter which 9917 05:18:49,798 --> 05:18:50,798 also requires building a really nice 9918 05:18:51,298 --> 05:18:52,298 State machine so let's do that in the 9919 05:18:53,700 --> 05:18:54,700 next lecture 9920 05:18:55,080 --> 05:18:56,080 hey again another quick intermission 9921 05:18:56,878 --> 05:18:57,878 you're past the halfway point so 9922 05:18:58,798 --> 05:18:59,798 congrats again by now I really hope 9923 05:19:01,138 --> 05:19:02,138 you've already learned a ton from the 9924 05:19:02,580 --> 05:19:03,580 course we've already covered lots of 9925 05:19:04,200 --> 05:19:05,200 topics and built a ton of systems I hope 9926 05:19:06,420 --> 05:19:07,420 you've been following the website as you 9927 05:19:07,740 --> 05:19:08,740 go through the lectures and I hope 9928 05:19:08,940 --> 05:19:09,940 reading the frequently asked questions 9929 05:19:10,320 --> 05:19:11,320 that I sent you in some way let me know 9930 05:19:12,600 --> 05:19:13,600 in the comments how you've used the 9931 05:19:13,740 --> 05:19:14,740 course website did you just read the FAQ 9932 05:19:16,620 --> 05:19:17,620 or did you also download some project 9933 05:19:18,120 --> 05:19:19,120 files let me know I'm curious to know if 9934 05:19:20,520 --> 05:19:21,520 you enjoy my teaching song also look at 9935 05:19:22,440 --> 05:19:23,440 my other courses after finishing this 9936 05:19:23,940 --> 05:19:24,940 one especially the turn-based strategy 9937 05:19:25,980 --> 05:19:26,980 course that one is an excellent 9938 05:19:27,360 --> 05:19:28,360 follow-up for this one okay there's 9939 05:19:29,280 --> 05:19:30,280 still quite a bit more for us to build 9940 05:19:30,718 --> 05:19:31,718 and learn so let's continue in the next 9941 05:19:32,638 --> 05:19:33,638 lecture 9942 05:19:33,958 --> 05:19:34,958 hello and welcome I'm your code monkey 9943 05:19:36,060 --> 05:19:37,060 in this lecture we're going to build the 9944 05:19:38,100 --> 05:19:39,100 stove counter so we want to place some 9945 05:19:40,500 --> 05:19:41,500 uncooked meat then we wait for a bit for 9946 05:19:42,540 --> 05:19:43,540 it to be cooked however if we weigh too 9947 05:19:44,580 --> 05:19:45,580 much it's going to get burnt so let's 9948 05:19:46,200 --> 05:19:47,200 Implement that alright so as usual let's 9949 05:19:48,180 --> 05:19:49,180 first begin by making our counter so 9950 05:19:49,920 --> 05:19:50,920 let's go inside the prefabs the counters 9951 05:19:51,600 --> 05:19:52,600 let's right click on the base counter 9952 05:19:53,160 --> 05:19:54,160 and create new prefab variant call this 9953 05:19:55,500 --> 05:19:56,500 the stove counter and as usual let's go 9954 05:19:58,020 --> 05:19:59,020 inside of it let's find the visual so 9955 05:20:00,780 --> 05:20:01,780 inside the prefab visuals it counters 9956 05:20:02,580 --> 05:20:03,580 visuals here is the stove counter so 9957 05:20:04,680 --> 05:20:05,680 let's drag it then let's duplicate this 9958 05:20:07,020 --> 05:20:08,020 rename this one the selecton let's set 9959 05:20:09,900 --> 05:20:10,900 the component the selected counter 9960 05:20:11,458 --> 05:20:12,458 visual 9961 05:20:12,540 --> 05:20:13,540 then let's go inside on all of these and 9962 05:20:15,600 --> 05:20:16,600 by the way this visual actually has some 9963 05:20:17,280 --> 05:20:18,280 nice visuals that we're going to 9964 05:20:18,360 --> 05:20:19,360 implement in a little bit but for the 9965 05:20:19,798 --> 05:20:20,798 selected we really just want the static 9966 05:20:21,660 --> 05:20:22,660 objects so let's pick up all of these 9967 05:20:23,400 --> 05:20:24,400 and let's select the counter slide 9968 05:20:24,900 --> 05:20:25,900 visual okay nice and white then let's 9969 05:20:27,298 --> 05:20:28,298 lock over here the parents so I can 9970 05:20:28,980 --> 05:20:29,980 select all of these and drag all of them 9971 05:20:30,718 --> 05:20:31,718 okay great and start off with all of 9972 05:20:32,520 --> 05:20:33,520 them disabled okay so that's the basic 9973 05:20:34,680 --> 05:20:35,680 setup as usual 9974 05:20:36,060 --> 05:20:37,060 just for the Counterpoint 9975 05:20:38,340 --> 05:20:39,340 since this one has a nice little sub on 9976 05:20:40,560 --> 05:20:41,560 top let's lift it up by a little bit so 9977 05:20:42,840 --> 05:20:43,840 put it on a y of 1.456 9978 05:20:45,600 --> 05:20:46,600 okay that looks pretty good just move it 9979 05:20:48,298 --> 05:20:49,298 a little bit to the center okay great 9980 05:20:50,700 --> 05:20:51,700 so now let's make our script so let's go 9981 05:20:52,920 --> 05:20:53,920 inside our scripts folder we've got our 9982 05:20:54,718 --> 05:20:55,718 counters so in here let's create the 9983 05:20:56,400 --> 05:20:57,400 brand new c-sharp script for the stove 9984 05:20:58,260 --> 05:20:59,260 counter let's wait for it to compile 9985 05:21:01,200 --> 05:21:02,200 let's attach the script and open okay so 9986 05:21:04,080 --> 05:21:05,080 here as usual let's extend the base 9987 05:21:06,120 --> 05:21:07,120 counter 9988 05:21:07,440 --> 05:21:08,440 now like I said the going for this one 9989 05:21:09,298 --> 05:21:10,298 is to be able to cook our meat and for 9990 05:21:11,280 --> 05:21:12,280 that it's going to be based on a timer 9991 05:21:13,500 --> 05:21:14,500 and to actually cook the meat we're 9992 05:21:15,180 --> 05:21:16,180 going to need to know which one is the 9993 05:21:16,798 --> 05:21:17,798 uncooked meat type and which one is the 9994 05:21:18,420 --> 05:21:19,420 cook me type 9995 05:21:19,740 --> 05:21:20,740 so for that we really want the exact 9996 05:21:21,480 --> 05:21:22,480 same logic that we did for the cutting 9997 05:21:22,920 --> 05:21:23,920 action we want some kind of place where 9998 05:21:25,138 --> 05:21:26,138 we can store an input and output as well 9999 05:21:27,120 --> 05:21:28,120 as a cook timer so for that let's 10000 05:21:29,218 --> 05:21:30,218 actually just duplicate so let's go 10001 05:21:30,660 --> 05:21:31,660 inside our scribble objects for The 10002 05:21:32,100 --> 05:21:33,100 Cutting recipe and let's duplicate this 10003 05:21:33,718 --> 05:21:34,718 one so Ctrl D and let's name this one 10004 05:21:36,298 --> 05:21:37,298 the frying recipe so 10005 05:21:38,638 --> 05:21:39,638 okay let's go inside 10006 05:21:40,378 --> 05:21:41,378 and over here let's rename the object 10007 05:21:42,240 --> 05:21:43,240 then we have an input we have an output 10008 05:21:44,340 --> 05:21:45,340 and then a set of progress let's have 10009 05:21:46,440 --> 05:21:47,440 the frying timer Max and since this one 10010 05:21:49,080 --> 05:21:50,080 is a timer instead of an in let's make 10011 05:21:51,000 --> 05:21:52,000 it a float okay so that's it pretty 10012 05:21:53,340 --> 05:21:54,340 simple then back here in the editor 10013 05:21:55,680 --> 05:21:56,680 let's create our script mode object so 10014 05:21:57,180 --> 05:21:58,180 let's go inside let's make a nice folder 10015 05:21:58,920 --> 05:21:59,920 so a folder for the frying recipe so 10016 05:22:06,420 --> 05:22:07,420 and inside let's create one so let's 10017 05:22:08,218 --> 05:22:09,218 create a brand new frying recipe so for 10018 05:22:10,560 --> 05:22:11,560 this one let's call it meat Patty 10019 05:22:12,298 --> 05:22:13,298 uncooked into meat Patty cooked 10020 05:22:16,138 --> 05:22:17,138 then for the inputs let's choose the 10021 05:22:18,298 --> 05:22:19,298 meat Patty uncooked now we have to make 10022 05:22:20,218 --> 05:22:21,218 the other one so let's go ahead and make 10023 05:22:22,378 --> 05:22:23,378 that one let's duplicate this one rename 10024 05:22:24,958 --> 05:22:25,958 it to the meat Patty cooked 10025 05:22:27,480 --> 05:22:28,480 and the object name meat Patty cooked 10026 05:22:30,060 --> 05:22:31,060 let's select the different Sprites so 10027 05:22:32,878 --> 05:22:33,878 this one is going to be the meat Patty 10028 05:22:34,680 --> 05:22:35,680 cooked okay 10029 05:22:35,760 --> 05:22:36,760 and finally for the prefab let's also 10030 05:22:37,798 --> 05:22:38,798 make it so for the meat Patty cooked 10031 05:22:41,040 --> 05:22:42,040 let's go inside of it and also make sure 10032 05:22:43,440 --> 05:22:44,440 to save changes on our stove counter 10033 05:22:45,180 --> 05:22:46,180 it's okay now in here let's get rid of 10034 05:22:47,218 --> 05:22:48,218 this Visual and use the other visual so 10035 05:22:49,680 --> 05:22:50,680 we want to meet Patty cooked and let's 10036 05:22:51,840 --> 05:22:52,840 make sure to drag the script monk object 10037 05:22:54,660 --> 05:22:55,660 okay so it's all good here and let's go 10038 05:22:56,280 --> 05:22:57,280 back outside save it and finally over 10039 05:22:58,560 --> 05:22:59,560 here on meat Patty cooked let's just 10040 05:23:00,540 --> 05:23:01,540 grab the prefab reference so there you 10041 05:23:02,580 --> 05:23:03,580 go that one okay so this one is working 10042 05:23:04,200 --> 05:23:05,200 and since we're here and let's actually 10043 05:23:05,218 --> 05:23:06,218 make the other one right away 10044 05:23:07,080 --> 05:23:08,080 so let's make the meat Patty burned so 10045 05:23:10,798 --> 05:23:11,798 the prefab and let's also duplicate this 10046 05:23:13,020 --> 05:23:14,020 to make the meat Patty burned then on 10047 05:23:16,378 --> 05:23:17,378 the text let's rename this to Burnt 10048 05:23:18,540 --> 05:23:19,540 let's choose the burn icon 10049 05:23:21,600 --> 05:23:22,600 and for the prefab let's go into our 10050 05:23:23,760 --> 05:23:24,760 meat Patty burned and swap it out for 10051 05:23:26,040 --> 05:23:27,040 the burned one so there you go nice and 10052 05:23:28,200 --> 05:23:29,200 charred and over here swap it for the 10053 05:23:30,480 --> 05:23:31,480 meat Patty burned okay let's save it and 10054 05:23:33,480 --> 05:23:34,480 finally down here just make sure 10055 05:23:34,980 --> 05:23:35,980 everything is correct 10056 05:23:38,360 --> 05:23:39,360 object the transform prefab just like 10057 05:23:41,638 --> 05:23:42,638 that okay so all of our burn references 10058 05:23:44,160 --> 05:23:45,160 over here all of our cooked and over 10059 05:23:46,020 --> 05:23:47,020 here all of our uncut and again when 10060 05:23:48,180 --> 05:23:49,180 going through this process always make 10061 05:23:49,620 --> 05:23:50,620 sure that you match all the references 10062 05:23:51,000 --> 05:23:52,000 on the certain objects and also over 10063 05:23:52,798 --> 05:23:53,798 here on the kitchen objects so meet 10064 05:23:55,020 --> 05:23:56,020 Patty burn yep meet Patty burn for the 10065 05:23:57,180 --> 05:23:58,180 uncooked the uncooked and for the coke 10066 05:23:58,980 --> 05:23:59,980 there it is okay everything is good 10067 05:24:00,540 --> 05:24:01,540 great so now we can go back over here 10068 05:24:02,638 --> 05:24:03,638 into our frying recipe so and for the 10069 05:24:04,440 --> 05:24:05,440 output let's output the meat Patty 10070 05:24:06,480 --> 05:24:07,480 cooked and for the frying timer let's 10071 05:24:08,400 --> 05:24:09,400 put it on three seconds 10072 05:24:09,840 --> 05:24:10,840 okay so that's it great now back in the 10073 05:24:12,780 --> 05:24:13,780 code here on the stove counter let's add 10074 05:24:15,000 --> 05:24:16,000 an array of our frying recipes so a 10075 05:24:17,100 --> 05:24:18,100 serialized field private it's going to 10076 05:24:19,260 --> 05:24:20,260 be an array of frying recipe so frying 10077 05:24:21,360 --> 05:24:22,360 recipe so array make omelette frying 10078 05:24:23,400 --> 05:24:24,400 recipe so a ring okay great then back 10079 05:24:26,700 --> 05:24:27,700 here in the editor let's go inside the 10080 05:24:28,500 --> 05:24:29,500 stove counter let's make sure to drag 10081 05:24:31,200 --> 05:24:32,200 that so let's drag the mid Patty from 10082 05:24:33,900 --> 05:24:34,900 uncooked into cut okay let's also drag 10083 05:24:36,000 --> 05:24:37,000 the counter top point and finally since 10084 05:24:38,340 --> 05:24:39,340 we already made the script over here on 10085 05:24:39,718 --> 05:24:40,718 the selected we can also drag the 10086 05:24:41,218 --> 05:24:42,218 selector okay so our stove prefab should 10087 05:24:43,740 --> 05:24:44,740 be working okay let's go outside make 10088 05:24:45,780 --> 05:24:46,780 sure to save the prefab okay now let's 10089 05:24:47,760 --> 05:24:48,760 continue with the rest of the script 10090 05:24:49,860 --> 05:24:50,860 so let's make our override so override 10091 05:24:53,218 --> 05:24:54,218 the interact action 10092 05:24:54,958 --> 05:24:55,958 and when we interact with it let's 10093 05:24:57,480 --> 05:24:58,480 validate dropping the object just like 10094 05:24:59,100 --> 05:25:00,100 we did on the cutting counter 10095 05:25:02,340 --> 05:25:03,340 so let's go over here into our cutting 10096 05:25:04,138 --> 05:25:05,138 count script and let's just copy pretty 10097 05:25:06,120 --> 05:25:07,120 much the exact same thing so let's copy 10098 05:25:07,798 --> 05:25:08,798 all of this interact code let's go over 10099 05:25:10,020 --> 05:25:11,020 here in the stove counter and just paste 10100 05:25:11,700 --> 05:25:12,700 it now we also need to copy in our 10101 05:25:14,280 --> 05:25:15,280 recipe 10102 05:25:15,120 --> 05:25:16,120 so over here on the cutting counter 10103 05:25:17,160 --> 05:25:18,160 let's copy paste those functions so 10104 05:25:19,200 --> 05:25:20,200 these functions go into the cell counter 10105 05:25:21,180 --> 05:25:22,180 and over here on let's face them they're 10106 05:25:22,740 --> 05:25:23,740 going to work pretty much the same thing 10107 05:25:24,840 --> 05:25:25,840 so we get an input except instead of 10108 05:25:26,700 --> 05:25:27,700 being a cutting recipe so we're going to 10109 05:25:28,920 --> 05:25:29,920 have a frying recipe so so let's replace 10110 05:25:31,320 --> 05:25:32,320 all the cutting recipe references with 10111 05:25:33,298 --> 05:25:34,298 frying recipe reference 10112 05:25:35,218 --> 05:25:36,218 then for the array this one is the 10113 05:25:37,138 --> 05:25:38,138 frying rasps array and obviously let's 10114 05:25:39,000 --> 05:25:40,000 rename these so Ctrl R to rename all of 10115 05:25:41,940 --> 05:25:42,940 them into frying recipe so 10116 05:25:44,638 --> 05:25:45,638 let's also rename the function instead 10117 05:25:46,320 --> 05:25:47,320 of get cutting rest BSO it's the frying 10118 05:25:48,240 --> 05:25:49,240 recipe so okay so there's no more 10119 05:25:50,340 --> 05:25:51,340 mentions of cutting over here so let's 10120 05:25:52,378 --> 05:25:53,378 use this function up here and up here 10121 05:25:54,120 --> 05:25:55,120 and just make sure to rename these the 10122 05:25:56,580 --> 05:25:57,580 frying recipe as so 10123 05:26:00,540 --> 05:26:01,540 and down here on same thing so the 10124 05:26:02,638 --> 05:26:03,638 frying recipe so okay so down here we 10125 05:26:05,820 --> 05:26:06,820 have no more mentions of any cutting 10126 05:26:07,440 --> 05:26:08,440 let's just go up here and solve all 10127 05:26:09,298 --> 05:26:10,298 these problems so first we check if 10128 05:26:11,580 --> 05:26:12,580 there's no kitchen object here and if 10129 05:26:13,080 --> 05:26:14,080 the player is carrying something then we 10130 05:26:14,638 --> 05:26:15,638 see if what the pointer is carrying 10131 05:26:16,080 --> 05:26:17,080 matches any kind of frying recipe if so 10132 05:26:18,958 --> 05:26:19,958 then the player is carrying something 10133 05:26:20,160 --> 05:26:21,160 that can be primed then we set the 10134 05:26:22,798 --> 05:26:23,798 parent and for now let's not worry about 10135 05:26:24,718 --> 05:26:25,718 the progress 10136 05:26:26,040 --> 05:26:27,040 so let's just get rid of all this just 10137 05:26:28,200 --> 05:26:29,200 like this okay so with this we should be 10138 05:26:30,540 --> 05:26:31,540 able to drop but only in uncooked meat 10139 05:26:32,638 --> 05:26:33,638 so back in the afternoon let's just set 10140 05:26:34,378 --> 05:26:35,378 up our scene so let's drag a stove 10141 05:26:36,298 --> 05:26:37,298 counter onto our scene let's put over 10142 05:26:38,340 --> 05:26:39,340 there on X of 6 y of 0 and 3.5 alright 10143 05:26:42,900 --> 05:26:43,900 so let's test okay so now if I pick up 10144 05:26:45,660 --> 05:26:46,660 some cheese I go up there and I drop it 10145 05:26:47,580 --> 05:26:48,580 and nope doesn't work okay great but if 10146 05:26:50,040 --> 05:26:51,040 I pick up some uncooked meat and I go 10147 05:26:51,780 --> 05:26:52,780 and I drop it and yep that does work 10148 05:26:53,340 --> 05:26:54,340 okay great so it works and I can only 10149 05:26:55,860 --> 05:26:56,860 drop the actual objects and matchy 10150 05:26:57,660 --> 05:26:58,660 recipe now unlike the cutting counter 10151 05:26:59,820 --> 05:27:00,820 this one will not be based on a player 10152 05:27:01,740 --> 05:27:02,740 alt interaction and actually over here 10153 05:27:04,138 --> 05:27:05,138 and let's fix this minor issue 10154 05:27:06,480 --> 05:27:07,480 basically we added this debug.log error 10155 05:27:09,000 --> 05:27:10,000 to the base interact because pretty much 10156 05:27:11,280 --> 05:27:12,280 every single counter is going to 10157 05:27:12,540 --> 05:27:13,540 implement this interact function but not 10158 05:27:14,760 --> 05:27:15,760 all encounters are going to have the 10159 05:27:16,138 --> 05:27:17,138 interact alternate action 10160 05:27:17,820 --> 05:27:18,820 so this one lets us do nothing let's not 10161 05:27:19,980 --> 05:27:20,980 spawn error okay just a quick fix 10162 05:27:22,320 --> 05:27:23,320 so like I said the stove counter this 10163 05:27:24,420 --> 05:27:25,420 one is going to be based on a simple 10164 05:27:26,218 --> 05:27:27,218 timer and for making some time based 10165 05:27:28,560 --> 05:27:29,560 logic basically we have two approaches 10166 05:27:30,240 --> 05:27:31,240 one approach is to use a simple foil 10167 05:27:32,878 --> 05:27:33,878 timer or you can also use a co-routine 10168 05:27:35,458 --> 05:27:36,458 now a lot of tutorials will teach you 10169 05:27:37,320 --> 05:27:38,320 how to use a co-routine and that's not 10170 05:27:39,360 --> 05:27:40,360 necessarily a bad practice it does work 10171 05:27:41,400 --> 05:27:42,400 it does achieve desired result so to do 10172 05:27:44,040 --> 05:27:45,040 that you would just make a function like 10173 05:27:45,660 --> 05:27:46,660 Freight timer 10174 05:27:47,400 --> 05:27:48,400 so you'd make a private you have to 10175 05:27:49,798 --> 05:27:50,798 return I in numerator 10176 05:27:52,138 --> 05:27:53,138 then call it something like handle fry 10177 05:27:54,420 --> 05:27:55,420 timer 10178 05:27:56,940 --> 05:27:57,940 then inside you can do a yield return 10179 05:28:00,420 --> 05:28:01,420 and return a new weight for seconds 10180 05:28:06,120 --> 05:28:07,120 and to start this co-routine you would 10181 05:28:08,400 --> 05:28:09,400 do maybe on start you would call start 10182 05:28:10,798 --> 05:28:11,798 Co routine 10183 05:28:14,520 --> 05:28:15,520 and start the handle for right hammer 10184 05:28:17,400 --> 05:28:18,400 so this one approach this is definitely 10185 05:28:19,200 --> 05:28:20,200 perfectly foundly timer code 10186 05:28:21,180 --> 05:28:22,180 however personally I am not a fan of 10187 05:28:23,280 --> 05:28:24,280 co-routines it's not because of 10188 05:28:25,080 --> 05:28:26,080 performance or anything it's simply 10189 05:28:27,180 --> 05:28:28,180 because I don't like the pattern that 10190 05:28:28,740 --> 05:28:29,740 they force you to use I don't like being 10191 05:28:31,020 --> 05:28:32,020 forced to make a function that returns I 10192 05:28:32,638 --> 05:28:33,638 numerator I don't like using yield 10193 05:28:35,100 --> 05:28:36,100 return I don't like having to use the 10194 05:28:37,920 --> 05:28:38,920 start core routine function I don't like 10195 05:28:39,958 --> 05:28:40,958 being forced to use this on a 10196 05:28:41,340 --> 05:28:42,340 monobehavior object those are all 10197 05:28:43,500 --> 05:28:44,500 requirements for making a CO routine 10198 05:28:45,120 --> 05:28:46,120 work and personally I find those are way 10199 05:28:47,760 --> 05:28:48,760 too many requirements that create a very 10200 05:28:49,620 --> 05:28:50,620 strange pattern that I really don't like 10201 05:28:51,240 --> 05:28:52,240 so that's really the only reason I don't 10202 05:28:53,940 --> 05:28:54,940 like Co routines because I find this 10203 05:28:55,560 --> 05:28:56,560 pattern to be quite a lot convoluted so 10204 05:28:57,840 --> 05:28:58,840 instead of core routines what I like to 10205 05:28:59,218 --> 05:29:00,218 use are simple basic flow timers so just 10206 05:29:02,700 --> 05:29:03,700 make a simple and private void update 10207 05:29:04,440 --> 05:29:05,440 then we just need to keep track of a 10208 05:29:06,660 --> 05:29:07,660 certain timer so for example a simple 10209 05:29:08,878 --> 05:29:09,878 private float frying timer 10210 05:29:11,700 --> 05:29:12,700 then on the update let's first check 10211 05:29:13,440 --> 05:29:14,440 that we have an object so it has a 10212 05:29:15,120 --> 05:29:16,120 kitchen object if we have a kitchen 10213 05:29:16,740 --> 05:29:17,740 object then let's increase the timer by 10214 05:29:19,378 --> 05:29:20,378 time dot of time by the way here when 10215 05:29:21,780 --> 05:29:22,780 working with a timer you can increase or 10216 05:29:23,580 --> 05:29:24,580 decrease it's pretty arbitrary both ways 10217 05:29:25,798 --> 05:29:26,798 work the obvious difference is only if 10218 05:29:27,840 --> 05:29:28,840 you test if it's above the max or if 10219 05:29:29,580 --> 05:29:30,580 it's under zero in here for frying it 10220 05:29:31,560 --> 05:29:32,560 does make sense to start at zero and 10221 05:29:33,000 --> 05:29:34,000 then the defraying timer Max 10222 05:29:35,100 --> 05:29:36,100 so either that and if the frying timer 10223 05:29:37,500 --> 05:29:38,500 if it is bigger than the maximum 10224 05:29:40,020 --> 05:29:41,020 so let's get the frying rest PSO frying 10225 05:29:42,180 --> 05:29:43,180 recipe so 10226 05:29:43,680 --> 05:29:44,680 let's get the frying recipe so with 10227 05:29:45,840 --> 05:29:46,840 input so let's get this kitchen object 10228 05:29:47,760 --> 05:29:48,760 and get the kitchen object itself okay 10229 05:29:50,160 --> 05:29:51,160 so we go into the frying rest BSO and we 10230 05:29:52,378 --> 05:29:53,378 get the frying timer Max okay so if it's 10231 05:29:54,958 --> 05:29:55,958 above the max then this one has been 10232 05:29:56,458 --> 05:29:57,458 fried so here I'll let you see what we 10233 05:29:58,500 --> 05:29:59,500 did on the cutting counter 10234 05:30:00,660 --> 05:30:01,660 so let's get this kitchen object and 10235 05:30:02,700 --> 05:30:03,700 tunnel to destroy itself 10236 05:30:04,560 --> 05:30:05,560 and then let's go into the kitchen 10237 05:30:06,180 --> 05:30:07,180 object class in order to spawn another 10238 05:30:07,740 --> 05:30:08,740 kitchen object let's go into the frying 10239 05:30:09,840 --> 05:30:10,840 recipe and spawn the output 10240 05:30:12,180 --> 05:30:13,180 and we're going to spawn it inside of 10241 05:30:13,980 --> 05:30:14,980 this counter 10242 05:30:16,260 --> 05:30:17,260 right so that's it this should already 10243 05:30:17,820 --> 05:30:18,820 be working we don't have a visual yet so 10244 05:30:20,160 --> 05:30:21,160 let's add a debug log 10245 05:30:21,780 --> 05:30:22,780 so here just say debug.log on the frying 10246 05:30:24,540 --> 05:30:25,540 timer 10247 05:30:25,680 --> 05:30:26,680 and up here let's also just reset the 10248 05:30:28,440 --> 05:30:29,440 timer so frying time now let's put it on 10249 05:30:30,060 --> 05:30:31,060 zero f and let's also do a debug.log and 10250 05:30:32,820 --> 05:30:33,820 say fried 10251 05:30:34,080 --> 05:30:35,080 however like this you might already be 10252 05:30:35,760 --> 05:30:36,760 guessing that we're going to have a 10253 05:30:37,138 --> 05:30:38,138 bunch of bugs but still let's just test 10254 05:30:38,940 --> 05:30:39,940 it just like this 10255 05:30:40,260 --> 05:30:41,260 okay so over here I can move around I 10256 05:30:42,600 --> 05:30:43,600 can pick up some uncooked meat I can 10257 05:30:44,218 --> 05:30:45,218 drop it there and after a little bit 10258 05:30:46,500 --> 05:30:47,500 there you go there's the timers and if 10259 05:30:48,718 --> 05:30:49,718 there you go it did work you can see the 10260 05:30:50,160 --> 05:30:51,160 timer increase until three then it was 10261 05:30:52,440 --> 05:30:53,440 fried then it was reset and then we've 10262 05:30:54,480 --> 05:30:55,480 got a known reference exception 10263 05:30:56,340 --> 05:30:57,340 basically this is the exact same problem 10264 05:30:58,200 --> 05:30:59,200 that we had on the cutting counter where 10265 05:31:00,360 --> 05:31:01,360 first we put an object like tomato and 10266 05:31:02,400 --> 05:31:03,400 that is indeed an input for a recipe so 10267 05:31:04,680 --> 05:31:05,680 we cut tomato into slices but then the 10268 05:31:06,540 --> 05:31:07,540 slices are not an input for any recipe 10269 05:31:08,400 --> 05:31:09,400 so over here we put some uncooked meat 10270 05:31:10,798 --> 05:31:11,798 so that's great we frying which means we 10271 05:31:12,780 --> 05:31:13,780 destroy the uncooked meat and we spawn 10272 05:31:14,340 --> 05:31:15,340 the cooked meat but then next time the 10273 05:31:16,378 --> 05:31:17,378 cooked meat is not an input for anything 10274 05:31:17,760 --> 05:31:18,760 so obviously this one is going to return 10275 05:31:19,500 --> 05:31:20,500 no one thing we can do to sort of solve 10276 05:31:22,320 --> 05:31:23,320 this problem which is also going to be 10277 05:31:24,298 --> 05:31:25,298 beneficial in terms of performance is 10278 05:31:25,920 --> 05:31:26,920 simply caching this field so let's go 10279 05:31:28,440 --> 05:31:29,440 here to find a frying recipe a cell 10280 05:31:30,660 --> 05:31:31,660 frying recipe so 10281 05:31:32,940 --> 05:31:33,940 instead of constantly getting it on 10282 05:31:34,680 --> 05:31:35,680 every single update which might be a bit 10283 05:31:36,360 --> 05:31:37,360 costly in terms of performance instead 10284 05:31:38,458 --> 05:31:39,458 of this let's just get it over here when 10285 05:31:40,080 --> 05:31:41,080 the player drops something so the player 10286 05:31:42,240 --> 05:31:43,240 drops something and we assign the Frank 10287 05:31:43,980 --> 05:31:44,980 rest BSO so we sign it cache the value 10288 05:31:45,958 --> 05:31:46,958 and then do this okay that should have 10289 05:31:48,000 --> 05:31:49,000 fixed the non-reference problem but we 10290 05:31:50,218 --> 05:31:51,218 still have a bunch more problems but 10291 05:31:51,600 --> 05:31:52,600 still let's test it out okay so here 10292 05:31:53,878 --> 05:31:54,878 let's pick up some meat put it there and 10293 05:31:56,280 --> 05:31:57,280 let's look at the timer and if there you 10294 05:31:57,718 --> 05:31:58,718 go everything is cooking great any of 10295 05:31:59,160 --> 05:32:00,160 their yo it finished it cooked and the 10296 05:32:01,020 --> 05:32:02,020 time was reset and now it's finishing 10297 05:32:02,638 --> 05:32:03,638 it's cooking and so on so this is 10298 05:32:04,920 --> 05:32:05,920 obviously another pretty serious problem 10299 05:32:06,540 --> 05:32:07,540 basically it's constantly frying the 10300 05:32:08,280 --> 05:32:09,280 meat and spawning more and more objects 10301 05:32:09,900 --> 05:32:10,900 instead of constantly spawning from the 10302 05:32:12,180 --> 05:32:13,180 same recipe what we want is for the 10303 05:32:14,580 --> 05:32:15,580 stove to First fry the object but then 10304 05:32:16,860 --> 05:32:17,860 if the object is fried then we want to 10305 05:32:18,780 --> 05:32:19,780 burn it so really that means that we 10306 05:32:21,000 --> 05:32:22,000 want the stove to have multiple States 10307 05:32:22,560 --> 05:32:23,560 meaning that we're going to need to make 10308 05:32:24,780 --> 05:32:25,780 a simple State machine so let's do just 10309 05:32:26,820 --> 05:32:27,820 that now if you're a beginner the 10310 05:32:28,680 --> 05:32:29,680 concept of a state machine might seem 10311 05:32:30,298 --> 05:32:31,298 daunting at first but it's actually 10312 05:32:31,560 --> 05:32:32,560 extremely simple at least to make a very 10313 05:32:33,780 --> 05:32:34,780 basic one all we need is really just a 10314 05:32:36,180 --> 05:32:37,180 bunch of saints so to define those 10315 05:32:37,980 --> 05:32:38,980 States let's go up here and make a 10316 05:32:39,540 --> 05:32:40,540 simple enum so let's make a private enum 10317 05:32:42,360 --> 05:32:43,360 call it state 10318 05:32:44,218 --> 05:32:45,218 and now let's put all the states for our 10319 05:32:46,138 --> 05:32:47,138 state machine now for the server let's 10320 05:32:47,940 --> 05:32:48,940 say we have idle when there's nothing on 10321 05:32:49,620 --> 05:32:50,620 top 10322 05:32:50,340 --> 05:32:51,340 then let's say we have a frying state 10323 05:32:52,200 --> 05:32:53,200 for when the ingredient is actually 10324 05:32:54,000 --> 05:32:55,000 being fried then we have fried for when 10325 05:32:56,580 --> 05:32:57,580 the ingredient has already been cooked 10326 05:32:58,138 --> 05:32:59,138 but it's still getting some heat and 10327 05:33:00,000 --> 05:33:01,000 finally if we leave it too long in that 10328 05:33:01,560 --> 05:33:02,560 state then everything ends up burned 10329 05:33:03,420 --> 05:33:04,420 okay so these are all of our states for 10330 05:33:05,700 --> 05:33:06,700 our state machine 10331 05:33:06,900 --> 05:33:07,900 and how to make the actual stick machine 10332 05:33:08,458 --> 05:33:09,458 it's actually quite simple first of all 10333 05:33:10,138 --> 05:33:11,138 we just need to store the current state 10334 05:33:11,700 --> 05:33:12,700 so here make a private of type State and 10335 05:33:14,400 --> 05:33:15,400 sort the current state 10336 05:33:15,840 --> 05:33:16,840 and then on update let's just do a 10337 05:33:17,878 --> 05:33:18,878 switch on the current state 10338 05:33:20,160 --> 05:33:21,160 okay now here basically we're going to 10339 05:33:21,540 --> 05:33:22,540 do different logic depending on the 10340 05:33:22,798 --> 05:33:23,798 state that we're at 10341 05:33:24,180 --> 05:33:25,180 so let's say if we're I don't we do 10342 05:33:26,100 --> 05:33:27,100 something then if we are frying we're 10343 05:33:28,560 --> 05:33:29,560 going to do something else then if we 10344 05:33:30,780 --> 05:33:31,780 are on the front also something else and 10345 05:33:33,660 --> 05:33:34,660 finally if we are on Burn do something 10346 05:33:35,458 --> 05:33:36,458 else 10347 05:33:36,480 --> 05:33:37,480 so here are all of our states and the 10348 05:33:39,180 --> 05:33:40,180 logic that we did down here this is the 10349 05:33:41,638 --> 05:33:42,638 frame logic so let's actually just copy 10350 05:33:43,620 --> 05:33:44,620 on this 10351 05:33:44,700 --> 05:33:45,700 and let's face it inside the frying 10352 05:33:46,560 --> 05:33:47,560 logic and for the seed machine we're 10353 05:33:49,500 --> 05:33:50,500 only going to run any of these states if 10354 05:33:51,240 --> 05:33:52,240 there's a kitchen object inside of it so 10355 05:33:52,980 --> 05:33:53,980 it's actually put that switch in there 10356 05:33:54,600 --> 05:33:55,600 just like this 10357 05:33:55,980 --> 05:33:56,980 okay so that's it so when I don't we're 10358 05:33:58,138 --> 05:33:59,138 not doing anything and when frying we're 10359 05:33:59,700 --> 05:34:00,700 going to run our frying timer we're 10360 05:34:01,320 --> 05:34:02,320 going to fry the object let's also get 10361 05:34:03,180 --> 05:34:04,180 rid of the low we no longer need this 10362 05:34:04,440 --> 05:34:05,440 then we destroy the current object and 10363 05:34:06,298 --> 05:34:07,298 we spawn a brand new object now what we 10364 05:34:08,520 --> 05:34:09,520 need is to handle over here the State 10365 05:34:10,080 --> 05:34:11,080 field we need to modify this winching in 10366 05:34:12,480 --> 05:34:13,480 Saints so first of all let's handle the 10367 05:34:14,340 --> 05:34:15,340 start so let's make a private void start 10368 05:34:17,760 --> 05:34:18,760 and on start let's begin with the state 10369 05:34:20,100 --> 05:34:21,100 on state DOT Idol okay great then down 10370 05:34:23,218 --> 05:34:24,218 here when we interact when the player 10371 05:34:24,718 --> 05:34:25,718 drops something when the player drops 10372 05:34:26,218 --> 05:34:27,218 something that can be fried 10373 05:34:27,780 --> 05:34:28,780 over here on let's set the state and put 10374 05:34:30,120 --> 05:34:31,120 it on state DOT frame 10375 05:34:32,340 --> 05:34:33,340 and over here we should also probably 10376 05:34:33,660 --> 05:34:34,660 reset the timer so let's set the frying 10377 05:34:35,638 --> 05:34:36,638 timer back into zero f okay we set the 10378 05:34:38,100 --> 05:34:39,100 timer and we reset the state finally up 10379 05:34:40,920 --> 05:34:41,920 here let's not reset the timer since 10380 05:34:43,020 --> 05:34:44,020 we're resetting the timer down there 10381 05:34:44,280 --> 05:34:45,280 since it makes more sense down there so 10382 05:34:46,440 --> 05:34:47,440 we do the frying the frying timer we end 10383 05:34:48,060 --> 05:34:49,060 the frying and then obviously we need to 10384 05:34:49,680 --> 05:34:50,680 modify the state so modify State and put 10385 05:34:51,600 --> 05:34:52,600 it on state DOT fright 10386 05:34:53,340 --> 05:34:54,340 okay so that's the basics of our state 10387 05:34:55,440 --> 05:34:56,440 machine with this everything should be 10388 05:34:57,540 --> 05:34:58,540 working just the same as previously 10389 05:34:58,920 --> 05:34:59,920 except we're only going to fry once so 10390 05:35:01,020 --> 05:35:02,020 let's actually just put them out here 10391 05:35:02,458 --> 05:35:03,458 debug the hog 10392 05:35:04,080 --> 05:35:05,080 object Pride 10393 05:35:06,958 --> 05:35:07,958 and let's put one down here outside of 10394 05:35:09,480 --> 05:35:10,480 the save machine just do a debug.log on 10395 05:35:12,180 --> 05:35:13,180 the state 10396 05:35:14,878 --> 05:35:15,878 okay like this let's test 10397 05:35:16,980 --> 05:35:17,980 okay so here we are let's pick up some 10398 05:35:19,138 --> 05:35:20,138 meat and drop it on there and there you 10399 05:35:21,240 --> 05:35:22,240 go it goes from idle directly into 10400 05:35:22,980 --> 05:35:23,980 frying and then it's fried and after you 10401 05:35:25,620 --> 05:35:26,620 go now it stays on fried so it no longer 10402 05:35:27,600 --> 05:35:28,600 goes on frying and it's no longer 10403 05:35:29,040 --> 05:35:30,040 spawning any more objects it went from 10404 05:35:30,660 --> 05:35:31,660 frying into fried and yep everything 10405 05:35:32,100 --> 05:35:33,100 worked alright awesome 10406 05:35:34,378 --> 05:35:35,378 so we have the Frank State working 10407 05:35:36,298 --> 05:35:37,298 perfectly now let's handle the burning 10408 05:35:38,340 --> 05:35:39,340 in terms of logic it's really going to 10409 05:35:39,958 --> 05:35:40,958 be the exact same thing 10410 05:35:41,340 --> 05:35:42,340 we're going to have a frying timer so 10411 05:35:43,620 --> 05:35:44,620 let's copy this code and paste it down 10412 05:35:45,600 --> 05:35:46,600 here now technically we could reuse the 10413 05:35:48,420 --> 05:35:49,420 exact same float timer but that would be 10414 05:35:50,760 --> 05:35:51,760 a bit confusing so let's keep our code 10415 05:35:52,798 --> 05:35:53,798 as clear as possible and really just 10416 05:35:54,600 --> 05:35:55,600 make a different timer with a more 10417 05:35:56,100 --> 05:35:57,100 descriptive name 10418 05:35:57,480 --> 05:35:58,480 so pure a private float called The 10419 05:36:00,000 --> 05:36:01,000 Burning timer 10420 05:36:01,740 --> 05:36:02,740 then let's initialize this timer so when 10421 05:36:03,900 --> 05:36:04,900 we go into the fried State let's set the 10422 05:36:06,298 --> 05:36:07,298 timer the burning timer into zero then 10423 05:36:08,820 --> 05:36:09,820 down here let's use this Burning timer 10424 05:36:10,740 --> 05:36:11,740 okay great when timers and lapse and the 10425 05:36:13,440 --> 05:36:14,440 object is spawn let's go into the 10426 05:36:15,060 --> 05:36:16,060 Burnside 10427 05:36:16,080 --> 05:36:17,080 and obviously we need another recipe 10428 05:36:18,420 --> 05:36:19,420 so let's make another scriptable object 10429 05:36:20,218 --> 05:36:21,218 back in the editor let's find the frying 10430 05:36:23,100 --> 05:36:24,100 recipe so let's duplicate this call it 10431 05:36:25,740 --> 05:36:26,740 the burning recipe so 10432 05:36:28,020 --> 05:36:29,020 then over here let's modify the name 10433 05:36:29,700 --> 05:36:30,700 instead of frying timer Max let's call 10434 05:36:31,440 --> 05:36:32,440 it burning timer Max okay great so now 10435 05:36:34,320 --> 05:36:35,320 over here on the stove let's use pretty 10436 05:36:36,060 --> 05:36:37,060 much the exact same thing and let's make 10437 05:36:38,218 --> 05:36:39,218 over here private of burning recipe so 10438 05:36:40,740 --> 05:36:41,740 the burning recipe so 10439 05:36:43,260 --> 05:36:44,260 then down here we just need a function 10440 05:36:45,600 --> 05:36:46,600 to get the burning recipe so so let's 10441 05:36:47,280 --> 05:36:48,280 copy this and paste it over here this 10442 05:36:50,280 --> 05:36:51,280 one's going to return a burning rest BSO 10443 05:36:52,378 --> 05:36:53,378 so let's replace this and this 10444 05:36:54,480 --> 05:36:55,480 rename this into burning recipe so we're 10445 05:36:58,500 --> 05:36:59,500 going to need an array and over here 10446 05:36:59,820 --> 05:37:00,820 let's just change the name instead of 10447 05:37:01,320 --> 05:37:02,320 frying recipe so the burning recipe so 10448 05:37:05,820 --> 05:37:06,820 let's just find a new array so let's go 10449 05:37:08,218 --> 05:37:09,218 all the way up here make another array 10450 05:37:09,718 --> 05:37:10,718 an array of burning recipe so and this 10451 05:37:12,900 --> 05:37:13,900 is the burning recipe SL ring and 10452 05:37:15,180 --> 05:37:16,180 finally if we go down here let's use 10453 05:37:16,798 --> 05:37:17,798 this array okay that's it so now let's 10454 05:37:19,260 --> 05:37:20,260 use this function to set our burning 10455 05:37:21,480 --> 05:37:22,480 rest BSL so when we set it to find let's 10456 05:37:24,660 --> 05:37:25,660 set the burning recipe so and let's get 10457 05:37:27,420 --> 05:37:28,420 it with the input and the input is going 10458 05:37:28,920 --> 05:37:29,920 to be the object that is on here so the 10459 05:37:31,020 --> 05:37:32,020 kitchen object dot get the kitchen 10460 05:37:32,700 --> 05:37:33,700 object.so 10461 05:37:36,660 --> 05:37:37,660 okay so we're initializing our fright 10462 05:37:39,120 --> 05:37:40,120 State and setting up the burning recipe 10463 05:37:40,440 --> 05:37:41,440 so and over here we use that one dot Max 10464 05:37:43,920 --> 05:37:44,920 and we get into that one and use the 10465 05:37:45,958 --> 05:37:46,958 output so over there object frying over 10466 05:37:48,060 --> 05:37:49,060 here object burned all right so that's 10467 05:37:50,580 --> 05:37:51,580 pretty much it we modified everything to 10468 05:37:52,320 --> 05:37:53,320 say burning timer over here we are 10469 05:37:54,240 --> 05:37:55,240 correctly initializing so we go through 10470 05:37:56,100 --> 05:37:57,100 the burning timer through the burning 10471 05:37:57,600 --> 05:37:58,600 rest PSO which we are grabbing up here 10472 05:37:59,280 --> 05:38:00,280 then we spawn the output on the burning 10473 05:38:01,500 --> 05:38:02,500 rest BSO and we go into state.burn okay 10474 05:38:04,200 --> 05:38:05,200 so all that's left is just filling in 10475 05:38:05,878 --> 05:38:06,878 this array so back in the editor over 10476 05:38:08,340 --> 05:38:09,340 here on let's make the object so let's 10477 05:38:10,080 --> 05:38:11,080 make a brand new folder for the burning 10478 05:38:13,138 --> 05:38:14,138 recipe and so and now inside let's 10479 05:38:15,780 --> 05:38:16,780 create a new Burning recipe so call this 10480 05:38:18,420 --> 05:38:19,420 one the meat Patty cooked into meat 10481 05:38:22,200 --> 05:38:23,200 Patty burned and over here let's set the 10482 05:38:24,840 --> 05:38:25,840 input so the meat Patty cooked onto the 10483 05:38:27,000 --> 05:38:28,000 meat Patty burned and for timer let's 10484 05:38:29,638 --> 05:38:30,638 make it take a bit longer to burn so 10485 05:38:31,138 --> 05:38:32,138 let's say five seconds okay that's great 10486 05:38:33,180 --> 05:38:34,180 let's just drag the reference so let's 10487 05:38:34,798 --> 05:38:35,798 go into the stove counter and let's make 10488 05:38:36,480 --> 05:38:37,480 sure to open up and go inside the prefab 10489 05:38:38,760 --> 05:38:39,760 and over here on the prefab just write 10490 05:38:40,680 --> 05:38:41,680 the burning recipe okay that's great 10491 05:38:42,780 --> 05:38:43,780 let's go outside save the prefab and 10492 05:38:44,940 --> 05:38:45,940 let's test alright so here we are let's 10493 05:38:47,280 --> 05:38:48,280 pick up some meat drop it on there and 10494 05:38:49,200 --> 05:38:50,200 look over there it's frying and after a 10495 05:38:51,000 --> 05:38:52,000 bit yep it's right there you would spawn 10496 05:38:52,980 --> 05:38:53,980 that one and now if we wait for five 10497 05:38:54,900 --> 05:38:55,900 seconds it should go from frying to burn 10498 05:38:56,820 --> 05:38:57,820 any up there you go that one is charred 10499 05:38:58,320 --> 05:38:59,320 everything is burned everything is great 10500 05:38:59,700 --> 05:39:00,700 all right awesome so everything worked 10501 05:39:02,160 --> 05:39:03,160 as intended with this song of our logic 10502 05:39:04,200 --> 05:39:05,200 is working now let's handle on picking 10503 05:39:05,878 --> 05:39:06,878 up objects from the stove now 10504 05:39:07,680 --> 05:39:08,680 technically it's already working so I 10505 05:39:09,600 --> 05:39:10,600 can approach yourself and pick it up the 10506 05:39:11,580 --> 05:39:12,580 object and there you go drop it in there 10507 05:39:12,900 --> 05:39:13,900 so that does work however if we look 10508 05:39:15,540 --> 05:39:16,540 over here in the log the state machine 10509 05:39:16,860 --> 05:39:17,860 is now in the wrong state so over here 10510 05:39:19,080 --> 05:39:20,080 let's do a quick fix let's go down into 10511 05:39:22,260 --> 05:39:23,260 the interact action okay so here it is 10512 05:39:24,120 --> 05:39:25,120 so if there's no kitchen object then the 10513 05:39:26,100 --> 05:39:27,100 player places it okay that's good but if 10514 05:39:28,320 --> 05:39:29,320 there is a kitchen object so if there's 10515 05:39:29,820 --> 05:39:30,820 something on the stove counter when the 10516 05:39:31,980 --> 05:39:32,980 player picks it up let's also manually 10517 05:39:33,660 --> 05:39:34,660 set the state 10518 05:39:34,920 --> 05:39:35,920 and put the state back into idle just 10519 05:39:38,040 --> 05:39:39,040 like this okay that's it so let's test 10520 05:39:41,040 --> 05:39:42,040 okay so over here let's pick up some 10521 05:39:42,840 --> 05:39:43,840 meat put it in there it's cooking and 10522 05:39:44,878 --> 05:39:45,878 let's wait until it gets finished yep 10523 05:39:46,798 --> 05:39:47,798 there you go it's done pick it up and 10524 05:39:48,000 --> 05:39:49,000 there you go out now if I want I can put 10525 05:39:50,100 --> 05:39:51,100 another one and if there you go the 10526 05:39:51,360 --> 05:39:52,360 logic is reset and everything is back to 10527 05:39:53,100 --> 05:39:54,100 normal okay great so often logic is 10528 05:39:55,500 --> 05:39:56,500 working perfectly now let's just get rid 10529 05:39:57,840 --> 05:39:58,840 of our logs so we don't need this so 10530 05:39:59,400 --> 05:40:00,400 let's get rid of that debugging log this 10531 05:40:01,680 --> 05:40:02,680 one and this one okay great everything 10532 05:40:03,420 --> 05:40:04,420 is nice and clean and now let's add some 10533 05:40:06,000 --> 05:40:07,000 nice fun visuals so if we go inside the 10534 05:40:08,820 --> 05:40:09,820 stove counter and over here is the 10535 05:40:10,798 --> 05:40:11,798 visual and I include these two prefabs 10536 05:40:13,440 --> 05:40:14,440 inside the visual so one of them this 10537 05:40:15,780 --> 05:40:16,780 one the stove on visual this one is just 10538 05:40:18,180 --> 05:40:19,180 a glowing red square now again there's a 10539 05:40:20,700 --> 05:40:21,700 weird bug on this specific empty version 10540 05:40:22,500 --> 05:40:23,500 so post processing isn't showing over 10541 05:40:24,360 --> 05:40:25,360 here on scene view but if I leave it 10542 05:40:26,400 --> 05:40:27,400 enabled and I go back outside 10543 05:40:28,680 --> 05:40:29,680 and now from work in the game view if 10544 05:40:30,718 --> 05:40:31,718 there you go there's a nice glowing red 10545 05:40:32,280 --> 05:40:33,280 square if you don't see glowing make 10546 05:40:34,138 --> 05:40:35,138 sure you add the balloon post Crossing 10547 05:40:35,700 --> 05:40:36,700 effect 10548 05:40:36,420 --> 05:40:37,420 so if you missed something you can go 10549 05:40:37,980 --> 05:40:38,980 back into the post-processing lecture 10550 05:40:39,480 --> 05:40:40,480 and make sure everything is set up 10551 05:40:40,680 --> 05:40:41,680 correctly so there's a nice glowing red 10552 05:40:43,020 --> 05:40:44,020 square and there's also a bunch of 10553 05:40:44,218 --> 05:40:45,218 particles so you can name on this one 10554 05:40:46,260 --> 05:40:47,260 press on restart and there you go just 10555 05:40:47,820 --> 05:40:48,820 some nice particles just jumping up this 10556 05:40:49,980 --> 05:40:50,980 was made with the unity particle system 10557 05:40:52,440 --> 05:40:53,440 so for example on the hierarchy you can 10558 05:40:54,180 --> 05:40:55,180 right click go up here into effects and 10559 05:40:56,280 --> 05:40:57,280 you can create a particle system 10560 05:40:58,440 --> 05:40:59,440 so that's what this is it has a particle 10561 05:41:00,780 --> 05:41:01,780 system over here you can see all of the 10562 05:41:02,638 --> 05:41:03,638 various settings for these particles 10563 05:41:04,560 --> 05:41:05,560 they just jump up and fall down so for 10564 05:41:07,260 --> 05:41:08,260 jumping up that is the emission you can 10565 05:41:09,180 --> 05:41:10,180 actually see a visual over there of the 10566 05:41:10,980 --> 05:41:11,980 cone that is the spawning cone which you 10567 05:41:12,900 --> 05:41:13,900 can find over here on the shape so in 10568 05:41:15,480 --> 05:41:16,480 the shape it has the shape of a cone 10569 05:41:17,100 --> 05:41:18,100 then you can see the radius radius 10570 05:41:19,138 --> 05:41:20,138 thickness and so on so that is from 10571 05:41:20,520 --> 05:41:21,520 where the objects are being spawned then 10572 05:41:22,560 --> 05:41:23,560 up here you can see the lifetime of each 10573 05:41:24,298 --> 05:41:25,298 object so each particle is going to last 10574 05:41:26,638 --> 05:41:27,638 for 0.7 seconds 10575 05:41:28,260 --> 05:41:29,260 you can all see the speed so that's 10576 05:41:29,820 --> 05:41:30,820 speed at which they come from there the 10577 05:41:31,980 --> 05:41:32,980 start size that's how big they are on 10578 05:41:33,600 --> 05:41:34,600 start 10579 05:41:34,378 --> 05:41:35,378 and note how the particles are spawning 10580 05:41:36,840 --> 05:41:37,840 jumping up and falling down 10581 05:41:39,120 --> 05:41:40,120 so that Falling Down is over here the 10582 05:41:40,680 --> 05:41:41,680 gravity modifier if you put it at zero 10583 05:41:43,200 --> 05:41:44,200 then they just keep going up and if you 10584 05:41:44,878 --> 05:41:45,878 put a two yep they go up and they fall 10585 05:41:46,920 --> 05:41:47,920 down 10586 05:41:47,820 --> 05:41:48,820 next down here on the emission this is 10587 05:41:49,560 --> 05:41:50,560 how many are being spawned so if I put 10588 05:41:51,480 --> 05:41:52,480 this on 200 there you go tons and tons 10589 05:41:53,340 --> 05:41:54,340 of particles next is over here the size 10590 05:41:56,040 --> 05:41:57,040 of our lifetime so this one has just a 10591 05:41:58,020 --> 05:41:59,020 basic curve so they started off on font 10592 05:42:00,180 --> 05:42:01,180 size and over the x-axis this one is in 10593 05:42:03,360 --> 05:42:04,360 a lifetime so as the particle goes from 10594 05:42:05,458 --> 05:42:06,458 the beginning until the end their life 10595 05:42:06,718 --> 05:42:07,718 they basically go down on size so that 10596 05:42:08,160 --> 05:42:09,160 is why they become quite a bit smaller 10597 05:42:09,540 --> 05:42:10,540 also by the way this one down here this 10598 05:42:11,458 --> 05:42:12,458 one is called an animation curve this is 10599 05:42:13,860 --> 05:42:14,860 another really useful ENT feature I have 10600 05:42:16,080 --> 05:42:17,080 a dedicated video on animation curves 10601 05:42:17,820 --> 05:42:18,820 and finally down here just have the 10602 05:42:19,620 --> 05:42:20,620 renderer so it's just using some basic 10603 05:42:21,540 --> 05:42:22,540 particles so we can inspect the material 10604 05:42:23,520 --> 05:42:24,520 simple in the assets and there you go 10605 05:42:25,620 --> 05:42:26,620 we're just using the default particle 10606 05:42:27,240 --> 05:42:28,240 material just with the alpha on half and 10607 05:42:29,638 --> 05:42:30,638 that's pretty much it so as you can see 10608 05:42:31,440 --> 05:42:32,440 just a very basic very simple particle 10609 05:42:33,540 --> 05:42:34,540 system now all we really want to do is 10610 05:42:36,060 --> 05:42:37,060 just for both of these we want to enable 10611 05:42:38,218 --> 05:42:39,218 or disable them depending on if the 10612 05:42:40,020 --> 05:42:41,020 stove is on or not so let's make a 10613 05:42:42,540 --> 05:42:43,540 script to handle the visuals so let's go 10614 05:42:44,160 --> 05:42:45,160 down and create a brand new c-sharp 10615 05:42:45,958 --> 05:42:46,958 script let's go with the stove counter 10616 05:42:48,420 --> 05:42:49,420 visual then let's go into the stove 10617 05:42:50,520 --> 05:42:51,520 counter Visual and let's attach the 10618 05:42:52,260 --> 05:42:53,260 script 10619 05:42:53,218 --> 05:42:54,218 so here it is attach it and open right 10620 05:42:55,740 --> 05:42:56,740 so now here we just need references to 10621 05:42:57,600 --> 05:42:58,600 those two objects so as usual let's make 10622 05:42:59,820 --> 05:43:00,820 a basic serialized film let's make it of 10623 05:43:02,218 --> 05:43:03,218 type game object 10624 05:43:04,020 --> 05:43:05,020 for the stove on game object and the 10625 05:43:07,020 --> 05:43:08,020 other one is the particles game object 10626 05:43:10,260 --> 05:43:11,260 okay let's save and back here in the 10627 05:43:12,718 --> 05:43:13,718 editor let's drag the references so the 10628 05:43:14,400 --> 05:43:15,400 stove on Visual and the sizzling 10629 05:43:16,138 --> 05:43:17,138 particles okay great so now all we 10630 05:43:18,540 --> 05:43:19,540 really need to know is know when to turn 10631 05:43:20,400 --> 05:43:21,400 these on or off and for that is really 10632 05:43:22,740 --> 05:43:23,740 going to be based on the state over here 10633 05:43:24,360 --> 05:43:25,360 on the stove counter so if it is on the 10634 05:43:26,638 --> 05:43:27,638 state frying or fried then we want to 10635 05:43:28,320 --> 05:43:29,320 show them if it is on idle or burned we 10636 05:43:30,240 --> 05:43:31,240 want to hide them but as usual we don't 10637 05:43:32,218 --> 05:43:33,218 want to mix the logic and Visions 10638 05:43:33,840 --> 05:43:34,840 directly so let's do that through a 10639 05:43:36,000 --> 05:43:37,000 really nice event 10640 05:43:37,200 --> 05:43:38,200 let's make a public event let's use a 10641 05:43:40,378 --> 05:43:41,378 standard event handler let's call it on 10642 05:43:43,138 --> 05:43:44,138 stay changed 10643 05:43:45,120 --> 05:43:46,120 and let's also include the state on the 10644 05:43:47,218 --> 05:43:48,218 event Arc so let's make a public class 10645 05:43:48,840 --> 05:43:49,840 call it on state change event args and 10646 05:43:53,040 --> 05:43:54,040 let's expand event arcs and then in here 10647 05:43:56,218 --> 05:43:57,218 let's just put a public state 10648 05:43:58,680 --> 05:43:59,680 for our state 10649 05:44:00,298 --> 05:44:01,298 however here we also have a really nice 10650 05:44:02,340 --> 05:44:03,340 error so this one is telling you there's 10651 05:44:04,378 --> 05:44:05,378 inconsistent accessibility basically 10652 05:44:06,660 --> 05:44:07,660 that's because we made this one public 10653 05:44:08,638 --> 05:44:09,638 so any class link for his Mr visual 10654 05:44:10,620 --> 05:44:11,620 class can indeed see this class however 10655 05:44:13,200 --> 05:44:14,200 from outside that class cannot see the 10656 05:44:15,180 --> 05:44:16,180 private state 10657 05:44:16,378 --> 05:44:17,378 so that is why we have inconsistent 10658 05:44:18,360 --> 05:44:19,360 accessibility we cannot have something 10659 05:44:20,400 --> 05:44:21,400 public which inside has something of a 10660 05:44:22,500 --> 05:44:23,500 specific type which is private 10661 05:44:24,420 --> 05:44:25,420 so in order to make this work we need to 10662 05:44:26,100 --> 05:44:27,100 modify this state and make it public so 10663 05:44:28,200 --> 05:44:29,200 that the other classes can see it okay 10664 05:44:30,298 --> 05:44:31,298 so that's great now let's just fire this 10665 05:44:31,860 --> 05:44:32,860 event whenever the state changes so over 10666 05:44:34,260 --> 05:44:35,260 here when you go into the frying State 10667 05:44:35,878 --> 05:44:36,878 let's go and invoke and as usual just 10668 05:44:38,760 --> 05:44:39,760 this 10669 05:44:40,378 --> 05:44:41,378 and I actually forgot to add that so 10670 05:44:42,420 --> 05:44:43,420 let's go up here let's use the one with 10671 05:44:44,700 --> 05:44:45,700 generics so the on state change event 10672 05:44:46,558 --> 05:44:47,558 arcs okay great so then down here we 10673 05:44:48,840 --> 05:44:49,840 invoke the event let's create of this 10674 05:44:51,360 --> 05:44:52,360 time 10675 05:44:52,260 --> 05:44:53,260 and inside passing the state equals this 10676 05:44:54,480 --> 05:44:55,480 state 10677 05:44:55,500 --> 05:44:56,500 okay so this one we need so then down 10678 05:44:57,958 --> 05:44:58,958 here go into the burn State let's fire 10679 05:44:59,820 --> 05:45:00,820 the event and down here frying fire the 10680 05:45:02,040 --> 05:45:03,040 vent and on idle fried event alright 10681 05:45:04,378 --> 05:45:05,378 that's it so we have all of our state 10682 05:45:06,058 --> 05:45:07,058 logic and over here on the stove counter 10683 05:45:08,638 --> 05:45:09,638 visual obviously we need a reference to 10684 05:45:10,860 --> 05:45:11,860 the counter so let's add that so a 10685 05:45:13,200 --> 05:45:14,200 serialized field private 10686 05:45:15,600 --> 05:45:16,600 maker of type stove counter for the 10687 05:45:18,058 --> 05:45:19,058 stove counter and then we can do an as 10688 05:45:20,940 --> 05:45:21,940 usual for accessing external references 10689 05:45:22,620 --> 05:45:23,620 let's do it on start go into the stove 10690 05:45:25,020 --> 05:45:26,020 counter and let's listen to the on say 10691 05:45:27,540 --> 05:45:28,540 change event 10692 05:45:29,218 --> 05:45:30,218 and over here it's going to be very 10693 05:45:30,958 --> 05:45:31,958 simple we just want to show if it's on 10694 05:45:32,940 --> 05:45:33,940 the state frying or fried and if not we 10695 05:45:35,580 --> 05:45:36,580 don't want to show so let's define a 10696 05:45:37,260 --> 05:45:38,260 bone called show visual 10697 05:45:39,180 --> 05:45:40,180 and this one is going to true if the E 10698 05:45:40,860 --> 05:45:41,860 dot State equals the state DOT frying or 10699 05:45:44,520 --> 05:45:45,520 E dot State equals 10700 05:45:46,740 --> 05:45:47,740 the state DOT fried 10701 05:45:49,440 --> 05:45:50,440 so if it's either of these then this is 10702 05:45:50,940 --> 05:45:51,940 going to be true if not it's going to be 10703 05:45:52,200 --> 05:45:53,200 false so then let's just go into the 10704 05:45:54,600 --> 05:45:55,600 stove on game object 10705 05:45:57,000 --> 05:45:58,000 and constant active and pass in this 10706 05:46:00,180 --> 05:46:01,180 and same thing for the other for the 10707 05:46:02,100 --> 05:46:03,100 particles game object okay that's it 10708 05:46:04,080 --> 05:46:05,080 super simple let's just drag this 10709 05:46:05,820 --> 05:46:06,820 reference so over here inside the prefab 10710 05:46:07,980 --> 05:46:08,980 just drag the reference let's leave the 10711 05:46:10,080 --> 05:46:11,080 prefab save the changes and let's hit on 10712 05:46:12,420 --> 05:46:13,420 play and all right so it starts off 10713 05:46:14,520 --> 05:46:15,520 disabled okay so there's no visuals now 10714 05:46:16,378 --> 05:46:17,378 if I pick it up and I drop it and there 10715 05:46:17,820 --> 05:46:18,820 you go a nice visual so the glowing red 10716 05:46:19,980 --> 05:46:20,980 hot and the particles and now it's 10717 05:46:21,660 --> 05:46:22,660 running and if I leave it until it burns 10718 05:46:23,340 --> 05:46:24,340 when it burns and it's going to turn it 10719 05:46:25,080 --> 05:46:26,080 off and if there go turns off 10720 05:46:26,940 --> 05:46:27,940 all right awesome so now if I pick it up 10721 05:46:29,040 --> 05:46:30,040 wait until it gets cooked so let's go 10722 05:46:32,100 --> 05:46:33,100 pick it up and the other you go turns it 10723 05:46:33,718 --> 05:46:34,718 off 10724 05:46:34,378 --> 05:46:35,378 all right awesome we've got a really 10725 05:46:36,180 --> 05:46:37,180 nice visual all that's left is to have a 10726 05:46:38,580 --> 05:46:39,580 proper visual progress bar and with this 10727 05:46:40,860 --> 05:46:41,860 we actually have another interesting 10728 05:46:42,120 --> 05:46:43,120 clean code question 10729 05:46:43,500 --> 05:46:44,500 right now the progress bar that we made 10730 05:46:45,360 --> 05:46:46,360 over here on the cutting counter that 10731 05:46:47,458 --> 05:46:48,458 one is great so we would like to reuse 10732 05:46:49,620 --> 05:46:50,620 that however if we look over here on the 10733 05:46:52,080 --> 05:46:53,080 progress bar UI we can see this is only 10734 05:46:54,540 --> 05:46:55,540 working with the specific type cutting 10735 05:46:56,340 --> 05:46:57,340 counter 10736 05:46:57,298 --> 05:46:58,298 so by default this will not work with a 10737 05:46:59,340 --> 05:47:00,340 stealth counter so as usual we have 10738 05:47:01,558 --> 05:47:02,558 multiple approaches to solving this 10739 05:47:03,298 --> 05:47:04,298 problem one option would be to Simply 10740 05:47:05,340 --> 05:47:06,340 commonly duplicate the script then we 10741 05:47:07,860 --> 05:47:08,860 would make a completely different 10742 05:47:09,000 --> 05:47:10,000 progress bar UI class that would work 10743 05:47:10,680 --> 05:47:11,680 only with the stealth counter so that's 10744 05:47:12,420 --> 05:47:13,420 one approach that would work and that 10745 05:47:14,638 --> 05:47:15,638 approach might be good if you want the 10746 05:47:16,378 --> 05:47:17,378 progress bar to behave very very 10747 05:47:18,000 --> 05:47:19,000 differently 10748 05:47:18,958 --> 05:47:19,958 but over here I want both of them to 10749 05:47:20,638 --> 05:47:21,638 behave exactly the same so instead of 10750 05:47:22,920 --> 05:47:23,920 having some code application we can 10751 05:47:25,080 --> 05:47:26,080 write some good clean code but doing 10752 05:47:26,820 --> 05:47:27,820 exactly what we did with regards to the 10753 05:47:28,680 --> 05:47:29,680 kitchen object parent meaning we can use 10754 05:47:31,020 --> 05:47:32,020 a nice interface we can then Implement 10755 05:47:32,760 --> 05:47:33,760 on anything that has some kind of 10756 05:47:34,500 --> 05:47:35,500 progress so let's do exactly that first 10757 05:47:37,320 --> 05:47:38,320 of all let's actually go inside the 10758 05:47:39,000 --> 05:47:40,000 cutting counter so let's go inside the 10759 05:47:40,620 --> 05:47:41,620 prefab then over here we've got the 10760 05:47:42,298 --> 05:47:43,298 progress bar and this one is just a 10761 05:47:43,740 --> 05:47:44,740 regular game object but since we're 10762 05:47:45,420 --> 05:47:46,420 going to reuse this let's make this a 10763 05:47:47,040 --> 05:47:48,040 proper prefab so let's find over here 10764 05:47:49,378 --> 05:47:50,378 all of our prefabs and just drag the 10765 05:47:51,180 --> 05:47:52,180 progress bar UI inside the prefabs 10766 05:47:52,980 --> 05:47:53,980 folder okay great so this is now a 10767 05:47:54,840 --> 05:47:55,840 proper prefab now let's define our 10768 05:47:57,120 --> 05:47:58,120 interface so let's create a brand new 10769 05:47:59,160 --> 05:48:00,160 c-sharp script as usual interface start 10770 05:48:01,378 --> 05:48:02,378 with I so let's go on I and for this one 10771 05:48:03,718 --> 05:48:04,718 we wanted to represent anything that has 10772 05:48:05,520 --> 05:48:06,520 progress so let's just call it literally 10773 05:48:07,200 --> 05:48:08,200 has progress 10774 05:48:09,120 --> 05:48:10,120 personally I like to use the word has to 10775 05:48:11,160 --> 05:48:12,160 indicate that a certain object has 10776 05:48:12,718 --> 05:48:13,718 certain Behavior so in this case objects 10777 05:48:15,180 --> 05:48:16,180 that implement this interface will have 10778 05:48:16,680 --> 05:48:17,680 some kind of progress Behavior so now 10779 05:48:18,718 --> 05:48:19,718 over here for the interface let's first 10780 05:48:20,400 --> 05:48:21,400 make it so this one does not extend 10781 05:48:22,020 --> 05:48:23,020 amount of behavior instead of a quest 10782 05:48:23,638 --> 05:48:24,638 this one is an interface okay great so 10783 05:48:26,458 --> 05:48:27,458 now for the functions that we're going 10784 05:48:27,958 --> 05:48:28,958 to need if we look in the progress bar 10785 05:48:30,180 --> 05:48:31,180 and we'll look at the cutting counter 10786 05:48:31,558 --> 05:48:32,558 references we can see the only one is 10787 05:48:33,058 --> 05:48:34,058 literally just this so we just have to 10788 05:48:35,580 --> 05:48:36,580 listen to the event and then the rest of 10789 05:48:37,500 --> 05:48:38,500 progress bar Works inside of it so real 10790 05:48:39,600 --> 05:48:40,600 and interface is the only thing we need 10791 05:48:41,100 --> 05:48:42,100 to Define so let's actually go inside 10792 05:48:42,900 --> 05:48:43,900 the cutting counter so here we have the 10793 05:48:44,940 --> 05:48:45,940 unprogress change event and then we have 10794 05:48:46,620 --> 05:48:47,620 this so we can literally just copy this 10795 05:48:48,360 --> 05:48:49,360 go into the I has progress and let's put 10796 05:48:50,940 --> 05:48:51,940 exactly this 10797 05:48:52,260 --> 05:48:53,260 okay that's it that is literally all we 10798 05:48:54,120 --> 05:48:55,120 need now if we wanted we can also make a 10799 05:48:56,520 --> 05:48:57,520 function to expose the progress amount 10800 05:48:57,958 --> 05:48:58,958 but since we included over here on the 10801 05:49:00,000 --> 05:49:01,000 event then we really don't need it just 10802 05:49:01,798 --> 05:49:02,798 this is enough now let's go over here on 10803 05:49:03,840 --> 05:49:04,840 the progress bar UI script instead of 10804 05:49:06,058 --> 05:49:07,058 working with the type cutting counter 10805 05:49:07,320 --> 05:49:08,320 instead let's work with a type that has 10806 05:49:09,420 --> 05:49:10,420 I has progress so let's rename this Q 10807 05:49:12,058 --> 05:49:13,058 has progress 10808 05:49:14,160 --> 05:49:15,160 and it's going to have the exact same 10809 05:49:15,660 --> 05:49:16,660 event the only difference is over here 10810 05:49:18,058 --> 05:49:19,058 instead of the event RX being the one 10811 05:49:19,860 --> 05:49:20,860 inside the cutting counter is the one 10812 05:49:21,360 --> 05:49:22,360 inside the eye has progress so let's 10813 05:49:22,740 --> 05:49:23,740 make sure to change this I has progress 10814 05:49:25,080 --> 05:49:26,080 okay so the signature matches let's just 10815 05:49:27,420 --> 05:49:28,420 obviously rename this 10816 05:49:29,160 --> 05:49:30,160 so let's rename instead of cutting 10817 05:49:30,780 --> 05:49:31,780 counter let's rename has progress on 10818 05:49:33,718 --> 05:49:34,718 progress change and that's pretty much 10819 05:49:35,700 --> 05:49:36,700 it we don't have any more errors so 10820 05:49:37,620 --> 05:49:38,620 everything over here is now working 10821 05:49:39,000 --> 05:49:40,000 nicely with our interface and back here 10822 05:49:41,700 --> 05:49:42,700 in the editor once we're still inside 10823 05:49:43,138 --> 05:49:44,138 the cutting counter 10824 05:49:44,700 --> 05:49:45,700 suddenly interfaces do have one downside 10825 05:49:46,920 --> 05:49:47,920 when it comes to Unity 10826 05:49:48,480 --> 05:49:49,480 if we look in the progress bar UI down 10827 05:49:50,638 --> 05:49:51,638 there we can see the progress bar UI and 10828 05:49:52,798 --> 05:49:53,798 previously we had the counter field 10829 05:49:54,120 --> 05:49:55,120 exposed in the editor however now by 10830 05:49:56,760 --> 05:49:57,760 changing into an interface there we have 10831 05:49:58,680 --> 05:49:59,680 the issue the film does not show up here 10832 05:50:00,500 --> 05:50:01,500 interfaces do not show up in the editor 10833 05:50:02,760 --> 05:50:03,760 because Unity basically has no way of 10834 05:50:04,680 --> 05:50:05,680 knowing that the interface won't be 10835 05:50:05,940 --> 05:50:06,940 implemented by some kind of game object 10836 05:50:07,680 --> 05:50:08,680 so sadly this is the one thing that 10837 05:50:09,780 --> 05:50:10,780 doesn't work very well with unity the 10838 05:50:12,000 --> 05:50:13,000 solution that I normally do is actually 10839 05:50:13,260 --> 05:50:14,260 pretty simple instead of exposing the 10840 05:50:15,660 --> 05:50:16,660 interface which does not work and said 10841 05:50:17,458 --> 05:50:18,458 let's just make this a regular private 10842 05:50:19,200 --> 05:50:20,200 field 10843 05:50:19,860 --> 05:50:20,860 and then let's make a serialized film 10844 05:50:21,660 --> 05:50:22,660 and for this one let's make it a type 10845 05:50:23,160 --> 05:50:24,160 game object and let's call it has 10846 05:50:25,200 --> 05:50:26,200 progress game object 10847 05:50:27,718 --> 05:50:28,718 okay so like this we have a regular 10848 05:50:29,520 --> 05:50:30,520 serialized field with a regular game 10849 05:50:31,080 --> 05:50:32,080 object so if you look here yep we do 10850 05:50:33,240 --> 05:50:34,240 have that field so now we can indeed 10851 05:50:35,580 --> 05:50:36,580 Drag The Cutting counter reference and 10852 05:50:37,798 --> 05:50:38,798 then over here in the code in order to 10853 05:50:39,180 --> 05:50:40,180 get the has progress that is super 10854 05:50:40,680 --> 05:50:41,680 simple has progress we just go into the 10855 05:50:43,200 --> 05:50:44,200 hash progress game object and get 10856 05:50:44,820 --> 05:50:45,820 component of type I has progress 10857 05:50:47,520 --> 05:50:48,520 okay so that's it now our code does work 10858 05:50:50,040 --> 05:50:51,040 however of course one big potential 10859 05:50:52,080 --> 05:50:53,080 issue with this is that over here we 10860 05:50:53,940 --> 05:50:54,940 have a field of type game object meaning 10861 05:50:56,218 --> 05:50:57,218 that we have no guarantee that this 10862 05:50:58,138 --> 05:50:59,138 field does have a component that 10863 05:50:59,638 --> 05:51:00,638 implements the interface so we cannot 10864 05:51:01,680 --> 05:51:02,680 make sure that we drag the correct 10865 05:51:03,120 --> 05:51:04,120 reference we can drag any reference 10866 05:51:04,920 --> 05:51:05,920 doesn't have to have our progress 10867 05:51:06,600 --> 05:51:07,600 interface so in order to keep our sound 10868 05:51:08,820 --> 05:51:09,820 safe let's add a nice safety warning so 10869 05:51:10,920 --> 05:51:11,920 over here if has progress equals no so 10870 05:51:14,160 --> 05:51:15,160 if this one is known that means that 10871 05:51:15,600 --> 05:51:16,600 that game object does not have any 10872 05:51:17,100 --> 05:51:18,100 progress interface if so let's do a 10873 05:51:19,260 --> 05:51:20,260 debug download error 10874 05:51:22,020 --> 05:51:23,020 and let's say the game object and let's 10875 05:51:25,080 --> 05:51:26,080 pass in this game object 10876 05:51:29,280 --> 05:51:30,280 does not have a component that 10877 05:51:31,740 --> 05:51:32,740 implements I has progress 10878 05:51:35,458 --> 05:51:36,458 so this way if we make a mistake we 10879 05:51:37,260 --> 05:51:38,260 won't have a nice error message 10880 05:51:38,580 --> 05:51:39,580 basically this is the one workaround 10881 05:51:40,798 --> 05:51:41,798 that you need to use since Unity does 10882 05:51:42,480 --> 05:51:43,480 not support dragging references in the 10883 05:51:44,940 --> 05:51:45,940 editor if they are interface references 10884 05:51:46,920 --> 05:51:47,920 okay so with that everything is good so 10885 05:51:49,320 --> 05:51:50,320 all of our progress bar UI this should 10886 05:51:51,360 --> 05:51:52,360 all be working perfectly we just need to 10887 05:51:53,580 --> 05:51:54,580 go over here into our cutting count 10888 05:51:55,320 --> 05:51:56,320 script and let's make it so that we 10889 05:51:57,540 --> 05:51:58,540 Implement our interface so I has 10890 05:51:59,280 --> 05:52:00,280 progress and we got an error just 10891 05:52:01,200 --> 05:52:02,200 because even though we did Define that 10892 05:52:03,540 --> 05:52:04,540 interface remember the on progress 10893 05:52:04,798 --> 05:52:05,798 change again keep in mind that the types 10894 05:52:07,138 --> 05:52:08,138 depend on not just their name but where 10895 05:52:09,420 --> 05:52:10,420 they're at so this type that we have 10896 05:52:11,280 --> 05:52:12,280 here is the one that we Define here 10897 05:52:12,718 --> 05:52:13,718 which is not the same one that we have 10898 05:52:14,700 --> 05:52:15,700 here so even though they have the exact 10899 05:52:16,260 --> 05:52:17,260 same name because they are in different 10900 05:52:17,700 --> 05:52:18,700 places they are actually different types 10901 05:52:19,440 --> 05:52:20,440 so we need to make sure to use the type 10902 05:52:21,180 --> 05:52:22,180 in the interface over here let's just go 10903 05:52:22,920 --> 05:52:23,920 into the I has progress and use that 10904 05:52:25,020 --> 05:52:26,020 exact type and get rid of this one okay 10905 05:52:27,000 --> 05:52:28,000 so that's it that's the change we need 10906 05:52:28,378 --> 05:52:29,378 and down here when firing let's just 10907 05:52:30,540 --> 05:52:31,540 fire with that type and down here the 10908 05:52:32,638 --> 05:52:33,638 same thing with that type okay great so 10909 05:52:35,100 --> 05:52:36,100 like the this The Cutting counter should 10910 05:52:37,320 --> 05:52:38,320 still be working exactly the same as 10911 05:52:38,820 --> 05:52:39,820 previously again when refactoring any 10912 05:52:40,980 --> 05:52:41,980 code always do a quick test and let's do 10913 05:52:42,718 --> 05:52:43,718 that let's make sure to save our counter 10914 05:52:44,878 --> 05:52:45,878 save the prefab go back outside head on 10915 05:52:46,740 --> 05:52:47,740 play now let's pick up some cheese put 10916 05:52:48,900 --> 05:52:49,900 it there cut and there you go the 10917 05:52:50,218 --> 05:52:51,218 progress bar still does work okay great 10918 05:52:52,500 --> 05:52:53,500 now let's apply it to the stove and that 10919 05:52:54,480 --> 05:52:55,480 is actually going to be very simple 10920 05:52:55,620 --> 05:52:56,620 first let's go inside the stove so let's 10921 05:52:57,900 --> 05:52:58,900 find the stove counter let's open it up 10922 05:52:59,700 --> 05:53:00,700 go inside the prefab and over here let's 10923 05:53:01,798 --> 05:53:02,798 drag the progress bar UI prefab so let's 10924 05:53:04,080 --> 05:53:05,080 drag that then down here we already have 10925 05:53:06,180 --> 05:53:07,180 the has progress game object so let's 10926 05:53:07,680 --> 05:53:08,680 drag the stove counter and that's it 10927 05:53:09,360 --> 05:53:10,360 there's nothing else we need to touch 10928 05:53:10,980 --> 05:53:11,980 here we just need to go over here into 10929 05:53:13,680 --> 05:53:14,680 the stove counter and as usual let's 10930 05:53:15,240 --> 05:53:16,240 implement the interface so the eye has 10931 05:53:17,458 --> 05:53:18,458 progress 10932 05:53:18,540 --> 05:53:19,540 and now let's implement it pretty much 10933 05:53:19,980 --> 05:53:20,980 just like we did on the cutting counter 10934 05:53:21,480 --> 05:53:22,480 so we can actually just copy this so we 10935 05:53:23,878 --> 05:53:24,878 just need to implement the event so 10936 05:53:25,260 --> 05:53:26,260 that's it and now for firing the event 10937 05:53:27,480 --> 05:53:28,480 let's go down and see where we are 10938 05:53:29,878 --> 05:53:30,878 modifying all of our timers so let's go 10939 05:53:32,760 --> 05:53:33,760 down to when the player drops something 10940 05:53:34,200 --> 05:53:35,200 so we do the on say change and now let's 10941 05:53:36,900 --> 05:53:37,900 invoke this event so this and for the 10942 05:53:40,200 --> 05:53:41,200 progress bar for the progress normalize 10943 05:53:42,540 --> 05:53:43,540 this one is very simple so just frying 10944 05:53:44,160 --> 05:53:45,160 timer divided by the frying recipe so 10945 05:53:47,520 --> 05:53:48,520 dot frying timer Max 10946 05:53:49,798 --> 05:53:50,798 okay that's it we are modifying the 10947 05:53:51,420 --> 05:53:52,420 progress now let's go up here when we 10948 05:53:53,580 --> 05:53:54,580 are in the Frank State and when we do 10949 05:53:55,920 --> 05:53:56,920 let's fire off the on progress change 10950 05:53:57,958 --> 05:53:58,958 event okay great and finally down here 10951 05:54:00,660 --> 05:54:01,660 when we have defined over here let's 10952 05:54:02,878 --> 05:54:03,878 also fire except obviously we have the 10953 05:54:05,280 --> 05:54:06,280 burning timer and the burning timer Max 10954 05:54:08,218 --> 05:54:09,218 and then just to make sure that the bar 10955 05:54:10,620 --> 05:54:11,620 actually hides itself when we go into 10956 05:54:12,120 --> 05:54:13,120 burned let's also find an event this one 10957 05:54:14,218 --> 05:54:15,218 doesn't have a timer so let's just put 10958 05:54:15,540 --> 05:54:16,540 it on xeraf okay that's really it 10959 05:54:18,240 --> 05:54:19,240 we don't need to touch the progress bar 10960 05:54:20,400 --> 05:54:21,400 UI at all Let's test this just make sure 10961 05:54:22,920 --> 05:54:23,920 to save the prefab let's go back outside 10962 05:54:25,020 --> 05:54:26,020 and hit on point and right away yep the 10963 05:54:27,600 --> 05:54:28,600 bar is indeed hidden now if I pick up 10964 05:54:29,400 --> 05:54:30,400 some meat and I drop it and there you go 10965 05:54:31,200 --> 05:54:32,200 got a really nice bar going up any up 10966 05:54:34,020 --> 05:54:35,020 going up on the burning site and let's 10967 05:54:35,700 --> 05:54:36,700 get to the end let's see if the bar 10968 05:54:36,900 --> 05:54:37,900 hides so it gets to the end and you have 10969 05:54:38,878 --> 05:54:39,878 to go the bar that's high all right 10970 05:54:40,860 --> 05:54:41,860 awesome and if I pick up something 10971 05:54:43,080 --> 05:54:44,080 actually this was the one event that we 10972 05:54:44,878 --> 05:54:45,878 forgot so let's fix that so let's just 10973 05:54:47,340 --> 05:54:48,340 copy the one where we set the progress 10974 05:54:48,600 --> 05:54:49,600 normalized to zero and over here if the 10975 05:54:50,160 --> 05:54:51,160 player picks up something let's add the 10976 05:54:52,260 --> 05:54:53,260 progress back into zero 10977 05:54:54,180 --> 05:54:55,180 so here we are let's pick up some meat 10978 05:54:56,280 --> 05:54:57,280 drop it on there okay let's wait for it 10979 05:54:58,620 --> 05:54:59,620 to be cooked okay it's cooked now before 10980 05:55:00,600 --> 05:55:01,600 it burns pick it up and there you go the 10981 05:55:02,458 --> 05:55:03,458 bar is gone all right awesome okay so 10982 05:55:05,700 --> 05:55:06,700 here we have again another example of 10983 05:55:07,980 --> 05:55:08,980 the power of writing good clean code we 10984 05:55:10,200 --> 05:55:11,200 made a nice generic progress bar and we 10985 05:55:12,298 --> 05:55:13,298 very easily made it work with a 10986 05:55:13,680 --> 05:55:14,680 completely different counter which of 10987 05:55:15,540 --> 05:55:16,540 course would also work with literally 10988 05:55:16,798 --> 05:55:17,798 anything that implements that interface 10989 05:55:18,360 --> 05:55:19,360 doesn't have to be a counter now let me 10990 05:55:20,458 --> 05:55:21,458 make one note here basically I showed 10991 05:55:22,558 --> 05:55:23,558 you how to make a generic progress bar 10992 05:55:24,120 --> 05:55:25,120 and reuse it but let's say you want to 10993 05:55:26,340 --> 05:55:27,340 do something specific just for the solve 10994 05:55:28,260 --> 05:55:29,260 well one approach like I mentioned is to 10995 05:55:30,480 --> 05:55:31,480 duplicate the code and make a progress 10996 05:55:32,160 --> 05:55:33,160 bar that works only with the solve but 10997 05:55:34,620 --> 05:55:35,620 another approach is to Simply add more 10998 05:55:36,298 --> 05:55:37,298 elements on top 10999 05:55:37,798 --> 05:55:38,798 for example during the Polish stage 11000 05:55:39,900 --> 05:55:40,900 we're going to do exactly that 11001 05:55:41,878 --> 05:55:42,878 we're going to add an extra UI element 11002 05:55:43,860 --> 05:55:44,860 that won't show up to one of the player 11003 05:55:45,360 --> 05:55:46,360 when the food is about to burn so I just 11004 05:55:47,400 --> 05:55:48,400 want to point out how you can mix and 11005 05:55:48,900 --> 05:55:49,900 match both them you can have both 11006 05:55:50,700 --> 05:55:51,700 generic components coupled with specific 11007 05:55:52,620 --> 05:55:53,620 components 11008 05:55:53,638 --> 05:55:54,638 but for now our progress bar everything 11009 05:55:55,320 --> 05:55:56,320 is looking pretty good so let's leave 11010 05:55:57,480 --> 05:55:58,480 that burn warning just for the police 11011 05:55:58,860 --> 05:55:59,860 age now the next very important thing we 11012 05:56:01,320 --> 05:56:02,320 need is some points so let's do that in 11013 05:56:03,120 --> 05:56:04,120 the next lecture 11014 05:56:04,620 --> 05:56:05,620 hello and welcome I'm your kudmaki in 11015 05:56:07,558 --> 05:56:08,558 this lecture we're going to create the 11016 05:56:09,000 --> 05:56:10,000 plates counter this one is just going to 11017 05:56:10,920 --> 05:56:11,920 spawn some points which we can then pick 11018 05:56:12,718 --> 05:56:13,718 up to grab some objects okay so let's 11019 05:56:15,360 --> 05:56:16,360 begin making the counter as usual so 11020 05:56:17,400 --> 05:56:18,400 let's go inside our prefabs inside our 11021 05:56:19,378 --> 05:56:20,378 counters right click the base counter 11022 05:56:21,058 --> 05:56:22,058 make a new prefab variant 11023 05:56:23,700 --> 05:56:24,700 called the plates counter 11024 05:56:26,218 --> 05:56:27,218 let's go inside and let's drag the 11025 05:56:29,160 --> 05:56:30,160 visual for the plates counter let's go 11026 05:56:31,020 --> 05:56:32,020 into scene view so we can see it okay 11027 05:56:32,580 --> 05:56:33,580 let's duplicate this make this the 11028 05:56:34,740 --> 05:56:35,740 selected let's go inside and we can 11029 05:56:37,680 --> 05:56:38,680 actually hide the Eternal Sprite we only 11030 05:56:39,240 --> 05:56:40,240 need this one so on this one let's 11031 05:56:40,620 --> 05:56:41,620 modify it for the counter selected on 11032 05:56:42,900 --> 05:56:43,900 the selected let's make it just one 11033 05:56:44,878 --> 05:56:45,878 percent bigger and let's add the 11034 05:56:47,280 --> 05:56:48,280 selected counter Vision okay then inside 11035 05:56:49,500 --> 05:56:50,500 obviously drag the reference for the 11036 05:56:51,180 --> 05:56:52,180 kitchen counter okay that's our basic 11037 05:56:53,520 --> 05:56:54,520 setup now let's make our script to run 11038 05:56:55,260 --> 05:56:56,260 this so let's create a brand new c-sharp 11039 05:56:57,480 --> 05:56:58,480 script for the plates counter let's 11040 05:57:00,718 --> 05:57:01,718 attach the scrub to the plates counter 11041 05:57:02,878 --> 05:57:03,878 and open okay now here as usual let's 11042 05:57:05,700 --> 05:57:06,700 extend our base counter and then first 11043 05:57:08,458 --> 05:57:09,458 let's handle the spawn timer logic so 11044 05:57:11,100 --> 05:57:12,100 basically we want to spawn some plates 11045 05:57:12,780 --> 05:57:13,780 every once amount of time 11046 05:57:14,760 --> 05:57:15,760 somewhat sorry simple float for the 11047 05:57:17,458 --> 05:57:18,458 spawn plate timer then let's make a 11048 05:57:20,400 --> 05:57:21,400 simple update on timer let's increase 11049 05:57:22,200 --> 05:57:23,200 the spawn point timer by time dot of 11050 05:57:24,480 --> 05:57:25,480 time 11051 05:57:27,240 --> 05:57:28,240 and then just check if it's above a 11052 05:57:29,280 --> 05:57:30,280 certain maximum 11053 05:57:31,860 --> 05:57:32,860 so if it is above something in this case 11054 05:57:34,138 --> 05:57:35,138 we're going to have a fixed value 11055 05:57:36,180 --> 05:57:37,180 but still like I mentioned in the very 11056 05:57:37,860 --> 05:57:38,860 beginning of this course let us not use 11057 05:57:39,840 --> 05:57:40,840 magic numbers here you should never use 11058 05:57:41,400 --> 05:57:42,400 magic numbers 11059 05:57:42,718 --> 05:57:43,718 instead if you wanted to make it edible 11060 05:57:44,580 --> 05:57:45,580 you could also make it up here as the 11061 05:57:46,200 --> 05:57:47,200 serialized field but in my case for 11062 05:57:48,120 --> 05:57:49,120 design that I'm going for I'm perfectly 11063 05:57:49,440 --> 05:57:50,440 content with having a fixed value so 11064 05:57:51,058 --> 05:57:52,058 just appear pretty simple the spawn 11065 05:57:53,940 --> 05:57:54,940 complete timer Max and let's define it 11066 05:57:56,940 --> 05:57:57,940 to 4f 11067 05:57:58,440 --> 05:57:59,440 and let's use it over here okay great so 11068 05:58:01,500 --> 05:58:02,500 this is what we want 11069 05:58:02,820 --> 05:58:03,820 however for spawning it's actually going 11070 05:58:04,680 --> 05:58:05,680 to be a bit tricky the plate is supposed 11071 05:58:07,320 --> 05:58:08,320 to be a kitchen object the player should 11072 05:58:09,780 --> 05:58:10,780 be able to carry the plate and right now 11073 05:58:12,180 --> 05:58:13,180 for design that we Define is that each 11074 05:58:13,980 --> 05:58:14,980 kitchen object can only have one parent 11075 05:58:15,900 --> 05:58:16,900 and each parent can only have one object 11076 05:58:18,240 --> 05:58:19,240 but over here we want to spawn multiple 11077 05:58:20,218 --> 05:58:21,218 objects now let's quickly see what 11078 05:58:22,260 --> 05:58:23,260 happens if we try spawning multiple as 11079 05:58:23,820 --> 05:58:24,820 usual so let's just go into the kitchen 11080 05:58:25,798 --> 05:58:26,798 object spawn a kitchen object which 11081 05:58:28,320 --> 05:58:29,320 means we need the plate so so let's do 11082 05:58:30,660 --> 05:58:31,660 it up here as usual a serialized film 11083 05:58:33,180 --> 05:58:34,180 private kitchen object so for the Plate 11084 05:58:36,180 --> 05:58:37,180 Kitchen object SL 11085 05:58:40,440 --> 05:58:41,440 so we're going to need to make this and 11086 05:58:42,120 --> 05:58:43,120 then we're just going to spawn this 11087 05:58:43,558 --> 05:58:44,558 object on this 11088 05:58:46,020 --> 05:58:47,020 okay so this is going to throw an error 11089 05:58:47,940 --> 05:58:48,940 but so let's see let's first create the 11090 05:58:49,920 --> 05:58:50,920 object 11091 05:58:50,760 --> 05:58:51,760 over here let's go inside our objects 11092 05:58:53,458 --> 05:58:54,458 our kitchen objects let's create a brand 11093 05:58:55,080 --> 05:58:56,080 new kitchen object call it just the 11094 05:58:57,298 --> 05:58:58,298 plate for the object name this one is a 11095 05:58:59,580 --> 05:59:00,580 plate for the Sprite let's go with the 11096 05:59:02,280 --> 05:59:03,280 plate Sprite and for the prefab let's 11097 05:59:04,500 --> 05:59:05,500 make it so let's duplicate one of these 11098 05:59:06,958 --> 05:59:07,958 called the plate 11099 05:59:09,120 --> 05:59:10,120 let's go inside it and obviously make 11100 05:59:11,760 --> 05:59:12,760 sure to change say the changes then over 11101 05:59:14,340 --> 05:59:15,340 here let's drag the plate visual get rid 11102 05:59:16,860 --> 05:59:17,860 of the tomato and on the plate let's 11103 05:59:19,320 --> 05:59:20,320 make sure to assign the plate and 11104 05:59:21,840 --> 05:59:22,840 finally let's exit this let's make sure 11105 05:59:23,820 --> 05:59:24,820 to save it and on the plate let's drag 11106 05:59:25,620 --> 05:59:26,620 the plate prefab okay so we have the 11107 05:59:28,200 --> 05:59:29,200 kitchen object so now let's just go 11108 05:59:30,180 --> 05:59:31,180 inside our plates counter and over here 11109 05:59:32,940 --> 05:59:33,940 let's drag the reference so the 11110 05:59:35,160 --> 05:59:36,160 reference to the play kitchen object 11111 05:59:36,900 --> 05:59:37,900 let's also drag the reference to the 11112 05:59:38,580 --> 05:59:39,580 counter top point then on the selected 11113 05:59:40,440 --> 05:59:41,440 drag the reference to our base counter 11114 05:59:42,298 --> 05:59:43,298 and finally start off with a selected 11115 05:59:44,160 --> 05:59:45,160 disabled okay so this should be working 11116 05:59:46,138 --> 05:59:47,138 let's just add a plate counter over here 11117 05:59:48,000 --> 05:59:49,000 onto our scene so let's pick up a police 11118 05:59:50,340 --> 05:59:51,340 counter and put it somewhere in here 11119 05:59:51,660 --> 05:59:52,660 over there on the side so on an X of 7.5 11120 05:59:54,540 --> 05:59:55,540 then 0 and let's say on zero Maybe 11121 05:59:58,620 --> 05:59:59,620 let's make sure we have space for one 11122 06:00:00,360 --> 06:00:01,360 more counter over there so let's 11123 06:00:02,100 --> 06:00:03,100 duplicate this empty counter and let's 11124 06:00:04,260 --> 06:00:05,260 put it over there pointing to the side 11125 06:00:05,700 --> 06:00:06,700 so this one is on 7.50 and -2 11126 06:00:10,260 --> 06:00:11,260 okay so now let's just make sure that 11127 06:00:11,878 --> 06:00:12,878 they perfectly match so let's put this 11128 06:00:14,160 --> 06:00:15,160 one on a set of minus 0.5 okay so let's 11129 06:00:17,218 --> 06:00:18,218 test all right so here we are and look 11130 06:00:19,260 --> 06:00:20,260 at that and after four seconds if there 11131 06:00:22,020 --> 06:00:23,020 go it spawns the object and then it 11132 06:00:24,240 --> 06:00:25,240 immediately tried to spawn another one 11133 06:00:25,740 --> 06:00:26,740 and there you go we have the error 11134 06:00:27,180 --> 06:00:28,180 kitchen object parent only has a kitchen 11135 06:00:29,280 --> 06:00:30,280 object basically the way we designed our 11136 06:00:31,680 --> 06:00:32,680 game and set up the code assumes that a 11137 06:00:33,298 --> 06:00:34,298 single encounter will only hold a single 11138 06:00:35,400 --> 06:00:36,400 kitchen object so we cannot have 11139 06:00:37,620 --> 06:00:38,620 multiple plates on the same counter now 11140 06:00:40,138 --> 06:00:41,138 when solution for this problem is 11141 06:00:41,340 --> 06:00:42,340 actually quite simple when we spawn the 11142 06:00:43,558 --> 06:00:44,558 plates instead let's not spawn a kitchen 11143 06:00:46,138 --> 06:00:47,138 object instead we're just going to spawn 11144 06:00:48,360 --> 06:00:49,360 a dumb visual then when the player 11145 06:00:50,638 --> 06:00:51,638 interacts with the counter that is when 11146 06:00:52,378 --> 06:00:53,378 we're going to spawn the proper kitchen 11147 06:00:53,820 --> 06:00:54,820 object so let's do that although again 11148 06:00:56,458 --> 06:00:57,458 let's keep the logic and division 11149 06:00:57,840 --> 06:00:58,840 separate so over here let's first just 11150 06:01:00,058 --> 06:01:01,058 handle the logic so we just need to keep 11151 06:01:02,040 --> 06:01:03,040 track of how many points respond so for 11152 06:01:04,620 --> 06:01:05,620 that let's start up here you private end 11153 06:01:06,240 --> 06:01:07,240 for the plates spawn amount and let's 11154 06:01:09,718 --> 06:01:10,718 also do another private end for the 11155 06:01:11,520 --> 06:01:12,520 plates Pawn amount Max 11156 06:01:17,100 --> 06:01:18,100 and let's say we can spawn at most four 11157 06:01:18,900 --> 06:01:19,900 plates 11158 06:01:19,920 --> 06:01:20,920 okay so over here instead of spawning 11159 06:01:21,600 --> 06:01:22,600 the object let's first of all actually 11160 06:01:23,340 --> 06:01:24,340 reset the timer 11161 06:01:25,200 --> 06:01:26,200 so let's put it back to zero zero and on 11162 06:01:27,718 --> 06:01:28,718 the plate spawn the mount let's check if 11163 06:01:30,240 --> 06:01:31,240 this one is under the plate spawn Max 11164 06:01:34,680 --> 06:01:35,680 and if so 11165 06:01:37,260 --> 06:01:38,260 let's go into the plate spawn amount and 11166 06:01:39,600 --> 06:01:40,600 increase it by one okay so that's logic 11167 06:01:41,940 --> 06:01:42,940 super simple now let's send the visual 11168 06:01:43,680 --> 06:01:44,680 so let's first make our script so let's 11169 06:01:46,558 --> 06:01:47,558 create a brand new c-sharp script for 11170 06:01:48,840 --> 06:01:49,840 the plates counter visual 11171 06:01:51,780 --> 06:01:52,780 now let's make sure that the visual so 11172 06:01:53,760 --> 06:01:54,760 let's go inside the prefab and over here 11173 06:01:56,040 --> 06:01:57,040 we've got the visual let's attach it 11174 06:01:57,480 --> 06:01:58,480 okay open now here basically the first 11175 06:01:59,760 --> 06:02:00,760 thing we need is we need to know where 11176 06:02:01,440 --> 06:02:02,440 to spawn the visuals 11177 06:02:02,940 --> 06:02:03,940 so let's actually add a reference to our 11178 06:02:04,680 --> 06:02:05,680 counter top point 11179 06:02:06,240 --> 06:02:07,240 so let's add a serialized film for 11180 06:02:08,638 --> 06:02:09,638 private transform for the counter top 11181 06:02:11,340 --> 06:02:12,340 point then let's also add a reference 11182 06:02:13,860 --> 06:02:14,860 for the prefab we're going to spawn so 11183 06:02:15,480 --> 06:02:16,480 let's call it the plate visual prefab 11184 06:02:17,280 --> 06:02:18,280 then here in the editor let's drag the 11185 06:02:19,500 --> 06:02:20,500 references so the countertop Point Place 11186 06:02:21,360 --> 06:02:22,360 it in there and for the plate vision 11187 06:02:23,160 --> 06:02:24,160 prefab let's go a pair and find the 11188 06:02:26,160 --> 06:02:27,160 visuals for the kitchen object so these 11189 06:02:28,138 --> 06:02:29,138 are just the visuals and let's write the 11190 06:02:29,760 --> 06:02:30,760 plate visual so the plate visual not the 11191 06:02:31,860 --> 06:02:32,860 Plate Kitchen object okay now back in 11192 06:02:33,958 --> 06:02:34,958 the code here we obviously need to know 11193 06:02:35,520 --> 06:02:36,520 when I play this Bond so let's go into 11194 06:02:37,740 --> 06:02:38,740 the plates counter and make a nice event 11195 06:02:39,718 --> 06:02:40,718 so fun week event event handler as usual 11196 06:02:42,660 --> 06:02:43,660 on plate spawned 11197 06:02:45,660 --> 06:02:46,660 and down here let's just find the event 11198 06:02:47,700 --> 06:02:48,700 so we just invoke 11199 06:02:51,120 --> 06:02:52,120 with this and eventar is not empty 11200 06:02:55,798 --> 06:02:56,798 okay that's it very simple and then on 11201 06:02:58,138 --> 06:02:59,138 the other script over here let's just 11202 06:02:59,400 --> 06:03:00,400 listen to it which also means that we 11203 06:03:01,378 --> 06:03:02,378 need a reference to our counter so let's 11204 06:03:03,120 --> 06:03:04,120 add up here the plates counter for the 11205 06:03:05,878 --> 06:03:06,878 plates counter so we're going to need to 11206 06:03:07,920 --> 06:03:08,920 drag the reference and then on start 11207 06:03:09,958 --> 06:03:10,958 let's listen to the on plate spawned 11208 06:03:12,000 --> 06:03:13,000 event 11209 06:03:12,840 --> 06:03:13,840 and when that happens then let's spawn 11210 06:03:14,520 --> 06:03:15,520 so let's call instantiate on the plate 11211 06:03:17,400 --> 06:03:18,400 visual prefab 11212 06:03:19,080 --> 06:03:20,080 let's put it inside the counter top 11213 06:03:21,000 --> 06:03:22,000 point so this is the transform for the 11214 06:03:23,160 --> 06:03:24,160 plate visual transform and that's pretty 11215 06:03:26,580 --> 06:03:27,580 much it okay so unlike this it should be 11216 06:03:28,798 --> 06:03:29,798 working 11217 06:03:29,700 --> 06:03:30,700 when the plate is spawned we should be 11218 06:03:31,320 --> 06:03:32,320 spawning a brand new visual back in the 11219 06:03:33,298 --> 06:03:34,298 editor we just need to drag the plates 11220 06:03:34,860 --> 06:03:35,860 counter reference like that let's exit 11221 06:03:37,080 --> 06:03:38,080 save the prefab and let's test okay so 11222 06:03:39,840 --> 06:03:40,840 here we are and if we wait for four 11223 06:03:41,760 --> 06:03:42,760 seconds we should be able to see a play 11224 06:03:43,200 --> 06:03:44,200 spawn yep there you go and if we wait 11225 06:03:45,180 --> 06:03:46,180 for a little bit more we should also be 11226 06:03:47,400 --> 06:03:48,400 able to see some more play Swing spawn 11227 06:03:49,100 --> 06:03:50,100 except we can't really see them that's 11228 06:03:51,420 --> 06:03:52,420 because we're spawning them on the exact 11229 06:03:52,920 --> 06:03:53,920 same spot every time but if we pause the 11230 06:03:55,320 --> 06:03:56,320 game and over here I'm looking the 11231 06:03:57,120 --> 06:03:58,120 hierarchy and find the plate counter and 11232 06:03:59,340 --> 06:04:00,340 inside the counter top Point yep we do 11233 06:04:01,260 --> 06:04:02,260 have four visions and if we wait for 11234 06:04:03,600 --> 06:04:04,600 longer then nope it's not going to spawn 11235 06:04:05,400 --> 06:04:06,400 anymore it's only going to spawn four 11236 06:04:07,020 --> 06:04:08,020 plates okay great 11237 06:04:08,820 --> 06:04:09,820 so some of the visual let yourself set 11238 06:04:10,680 --> 06:04:11,680 them by a tiny bit to know how much we 11239 06:04:13,260 --> 06:04:14,260 shouldn't offset let's keep track of how 11240 06:04:14,878 --> 06:04:15,878 many plates haven't spawned 11241 06:04:16,740 --> 06:04:17,740 so let's store up here on the visual 11242 06:04:18,540 --> 06:04:19,540 script in list of Game object 11243 06:04:21,360 --> 06:04:22,360 call it the plate visual game object 11244 06:04:23,820 --> 06:04:24,820 list 11245 06:04:25,500 --> 06:04:26,500 let's also make sure that you initialize 11246 06:04:27,240 --> 06:04:28,240 this so it lets you on awake let's 11247 06:04:29,520 --> 06:04:30,520 initialize this list 11248 06:04:31,440 --> 06:04:32,440 and then when we spawn them okay so here 11249 06:04:33,600 --> 06:04:34,600 we have the object that we spawned now 11250 06:04:35,878 --> 06:04:36,878 basically we just need to modify the low 11251 06:04:37,680 --> 06:04:38,680 composition 11252 06:04:39,120 --> 06:04:40,120 and let's put it on new Vector 3 on the 11253 06:04:41,280 --> 06:04:42,280 X so let's put it on zero then on the Z 11254 06:04:43,860 --> 06:04:44,860 we're also going to have zero and then 11255 06:04:45,660 --> 06:04:46,660 over here on the one let's offset it by 11256 06:04:47,218 --> 06:04:48,218 a certain amount and basically it's 11257 06:04:48,900 --> 06:04:49,900 going to be based on how many plates 11258 06:04:50,400 --> 06:04:51,400 have been spawned 11259 06:04:51,840 --> 06:04:52,840 so let's define up here a float for the 11260 06:04:53,878 --> 06:04:54,878 plate offset y let's put it at save 0.1 11261 06:04:56,580 --> 06:04:57,580 f 11262 06:04:58,080 --> 06:04:59,080 and over here we're going to offset it 11263 06:04:59,700 --> 06:05:00,700 by this much multiplied by how many 11264 06:05:01,680 --> 06:05:02,680 plates have been spawned so we can go 11265 06:05:03,240 --> 06:05:04,240 into our visual list account so you can 11266 06:05:05,400 --> 06:05:06,400 delete this and then we just need to add 11267 06:05:07,080 --> 06:05:08,080 it to the list so let's add this plate 11268 06:05:09,660 --> 06:05:10,660 visual transform.game object okay so now 11269 06:05:12,718 --> 06:05:13,718 each game object should respond at a 11270 06:05:14,580 --> 06:05:15,580 different height so let's see so here we 11271 06:05:16,680 --> 06:05:17,680 are and if we wait for four seconds we 11272 06:05:18,420 --> 06:05:19,420 should be able to see a plate and there 11273 06:05:20,040 --> 06:05:21,040 you go and now after four seconds we 11274 06:05:22,080 --> 06:05:23,080 should be able to see another one placed 11275 06:05:23,700 --> 06:05:24,700 slightly above and yep there it is okay 11276 06:05:25,620 --> 06:05:26,620 great 11277 06:05:26,580 --> 06:05:27,580 so everything is spawning perfectly both 11278 06:05:29,160 --> 06:05:30,160 in the logic as well as the visual now 11279 06:05:30,840 --> 06:05:31,840 let's actually pick up a plate so on the 11280 06:05:33,058 --> 06:05:34,058 plates counter as usual let's implement 11281 06:05:34,680 --> 06:05:35,680 the interact 11282 06:05:35,940 --> 06:05:36,940 so let's do a public let's override the 11283 06:05:38,820 --> 06:05:39,820 interact function 11284 06:05:40,320 --> 06:05:41,320 and now for picking up let's first see 11285 06:05:42,718 --> 06:05:43,718 if the player is actually empty-handed 11286 06:05:45,480 --> 06:05:46,480 so if and we check the player has 11287 06:05:48,360 --> 06:05:49,360 kitchen object so if the player does not 11288 06:05:50,400 --> 06:05:51,400 have a kitchen object 11289 06:05:52,860 --> 06:05:53,860 then the player is empty-handed okay 11290 06:05:55,500 --> 06:05:56,500 great then let's see if we have a plate 11291 06:05:58,020 --> 06:05:59,020 that we can give them so if the plate 11292 06:06:00,660 --> 06:06:01,660 spawned the mount if it is bigger than 11293 06:06:02,760 --> 06:06:03,760 zero 11294 06:06:04,860 --> 06:06:05,860 then there's at least one plate here and 11295 06:06:08,218 --> 06:06:09,218 if so let's give it to the player so how 11296 06:06:10,558 --> 06:06:11,558 we do that is one over here for logic 11297 06:06:12,780 --> 06:06:13,780 let's just increase it by one then let's 11298 06:06:15,420 --> 06:06:16,420 actually spawn the object so on the 11299 06:06:17,218 --> 06:06:18,218 kitchen object let's spawn the Plate 11300 06:06:19,680 --> 06:06:20,680 Kitchen object so and spawn it on the 11301 06:06:22,138 --> 06:06:23,138 player 11302 06:06:23,100 --> 06:06:24,100 and finally we just need to update the 11303 06:06:24,900 --> 06:06:25,900 visuals so let's make another event 11304 06:06:27,540 --> 06:06:28,540 so up here on plane spawn and on plate 11305 06:06:30,540 --> 06:06:31,540 removed 11306 06:06:32,040 --> 06:06:33,040 okay we have this event and then down 11307 06:06:34,500 --> 06:06:35,500 here on let's just whenever the player 11308 06:06:36,058 --> 06:06:37,058 picks it up let's invoke this with this 11309 06:06:38,340 --> 06:06:39,340 an event RX dot empty 11310 06:06:41,580 --> 06:06:42,580 okay great so now the visual let's 11311 06:06:43,378 --> 06:06:44,378 listen to this so we're here on start 11312 06:06:45,420 --> 06:06:46,420 for the plates counter listen to this 11313 06:06:47,940 --> 06:06:48,940 event 11314 06:06:48,840 --> 06:06:49,840 and when this event happens we just want 11315 06:06:50,820 --> 06:06:51,820 to destroy the very last plate 11316 06:06:52,798 --> 06:06:53,798 so let's grab the game object for the 11317 06:06:54,660 --> 06:06:55,660 played game object and recently just 11318 06:06:56,878 --> 06:06:57,878 going to go into our list so the plate 11319 06:06:59,218 --> 06:07:00,218 visual game object list 11320 06:07:01,080 --> 06:07:02,080 and let's pick up the very last one 11321 06:07:03,660 --> 06:07:04,660 so let's go into the list.count minus 11322 06:07:05,878 --> 06:07:06,878 one so this is going to be the very last 11323 06:07:07,378 --> 06:07:08,378 element of the list then let's remove 11324 06:07:09,420 --> 06:07:10,420 this one from the list so Point dot 11325 06:07:11,458 --> 06:07:12,458 remove this one that we just grabbed and 11326 06:07:14,280 --> 06:07:15,280 then we simply call destroy on this one 11327 06:07:17,100 --> 06:07:18,100 all right so that's it super simple 11328 06:07:19,500 --> 06:07:20,500 so we're here on the plates counter we 11329 06:07:21,120 --> 06:07:22,120 do all of our checks we cut it down by 11330 06:07:23,040 --> 06:07:24,040 one 11331 06:07:23,820 --> 06:07:24,820 we spawn the actual kitchen object then 11332 06:07:25,740 --> 06:07:26,740 we fire the event and over here the 11333 06:07:27,420 --> 06:07:28,420 event listens and updates a visual okay 11334 06:07:29,400 --> 06:07:30,400 let's test 11335 06:07:30,540 --> 06:07:31,540 so here we are let's wait for a play to 11336 06:07:32,638 --> 06:07:33,638 be spawned and when this phone there it 11337 06:07:34,558 --> 06:07:35,558 is I'm going to pick it up and if there 11338 06:07:36,000 --> 06:07:37,000 go the player is now carrying a plate 11339 06:07:37,558 --> 06:07:38,558 let's drop it here and there you go 11340 06:07:39,000 --> 06:07:40,000 there's another one now let's wait for a 11341 06:07:40,440 --> 06:07:41,440 bunch more to be spawned okay so the 11342 06:07:42,360 --> 06:07:43,360 plates counter is full now if I pick up 11343 06:07:43,980 --> 06:07:44,980 it should only eliminate the last visual 11344 06:07:45,840 --> 06:07:46,840 pick it up any of there you go it'll 11345 06:07:47,580 --> 06:07:48,580 eliminate that one now I can drop it in 11346 06:07:49,440 --> 06:07:50,440 there any other ones one all right 11347 06:07:51,480 --> 06:07:52,480 awesome okay so that's really it for the 11348 06:07:54,120 --> 06:07:55,120 basics of the play counter it 11349 06:07:56,040 --> 06:07:57,040 periodically spawns some points which 11350 06:07:57,718 --> 06:07:58,718 the player can then pick up 11351 06:07:59,340 --> 06:08:00,340 now in the next lecture we're going to 11352 06:08:01,200 --> 06:08:02,200 add the ability for the player to be 11353 06:08:02,760 --> 06:08:03,760 holding a plate and pick up another 11354 06:08:04,320 --> 06:08:05,320 object onto the plate 11355 06:08:06,600 --> 06:08:07,600 hello and welcome I'm your code monkey 11356 06:08:08,520 --> 06:08:09,520 in this lecture we're going to add the 11357 06:08:10,620 --> 06:08:11,620 ability for the player to be carrying a 11358 06:08:12,480 --> 06:08:13,480 plate and pick up objects onto that 11359 06:08:14,218 --> 06:08:15,218 plate okay so here we already have the 11360 06:08:16,798 --> 06:08:17,798 plate counter working it has some basic 11361 06:08:18,840 --> 06:08:19,840 logic after a bunch of time it spawns a 11362 06:08:21,120 --> 06:08:22,120 plate it spawns up to a certain maximum 11363 06:08:23,458 --> 06:08:24,458 and I can pick up a plate and if the 11364 06:08:26,100 --> 06:08:27,100 player is carrying a plate so I can put 11365 06:08:27,360 --> 06:08:28,360 it anywhere 11366 06:08:28,320 --> 06:08:29,320 then I can for example pick up some 11367 06:08:30,120 --> 06:08:31,120 Tomatoes slice them and pick them up 11368 06:08:32,760 --> 06:08:33,760 however now I am not able to place the 11369 06:08:34,860 --> 06:08:35,860 tomatoes on the plate so let's add that 11370 06:08:36,780 --> 06:08:37,780 logic let's begin over here on the clear 11371 06:08:39,240 --> 06:08:40,240 counter script first we're testing if 11372 06:08:41,340 --> 06:08:42,340 there is no catch an object here and the 11373 06:08:43,138 --> 06:08:44,138 player is carrying something that the 11374 06:08:44,218 --> 06:08:45,218 player drops something in there but then 11375 06:08:46,080 --> 06:08:47,080 we're testing if there is a kitchen 11376 06:08:47,400 --> 06:08:48,400 object here and if the player is 11377 06:08:48,958 --> 06:08:49,958 carrying something so it's over here 11378 06:08:50,760 --> 06:08:51,760 that we want to check if there's 11379 06:08:52,020 --> 06:08:53,020 something that the player is carrying if 11380 06:08:53,340 --> 06:08:54,340 it is a plate now our plate is also 11381 06:08:55,500 --> 06:08:56,500 going to have a bit of custom logic so 11382 06:08:58,138 --> 06:08:59,138 to help both identify and hold that 11383 06:09:00,058 --> 06:09:01,058 custom logic let's make a proper script 11384 06:09:01,980 --> 06:09:02,980 to handle it 11385 06:09:03,120 --> 06:09:04,120 so back in India let's create a brand 11386 06:09:05,280 --> 06:09:06,280 new script currently the Plate Kitchen 11387 06:09:07,860 --> 06:09:08,860 object 11388 06:09:09,058 --> 06:09:10,058 and let's open this now over here on 11389 06:09:11,638 --> 06:09:12,638 this one instead of extending Model 11390 06:09:13,138 --> 06:09:14,138 Behavior we're going to extend kitchen 11391 06:09:15,240 --> 06:09:16,240 object 11392 06:09:16,620 --> 06:09:17,620 so the plate is really just a more 11393 06:09:18,360 --> 06:09:19,360 specific type of a kitchen object 11394 06:09:20,700 --> 06:09:21,700 again like I mentioned quite a while ago 11395 06:09:22,558 --> 06:09:23,558 you want to be very careful with 11396 06:09:23,820 --> 06:09:24,820 inheritance you need to have a very good 11397 06:09:25,860 --> 06:09:26,860 reason to do it here we want the play to 11398 06:09:28,260 --> 06:09:29,260 behave exactly like a kitchen object 11399 06:09:29,940 --> 06:09:30,940 just with a tiny bit of extra logic so 11400 06:09:32,040 --> 06:09:33,040 in this case it makes perfect sense 11401 06:09:33,420 --> 06:09:34,420 let's just go ahead and save this and 11402 06:09:36,058 --> 06:09:37,058 wait for ENT to compile and over here 11403 06:09:38,458 --> 06:09:39,458 let's find our kitchen object with the 11404 06:09:40,860 --> 06:09:41,860 plate so here it is the prefab as you 11405 06:09:42,900 --> 06:09:43,900 can see we have a kitchen object now 11406 06:09:44,280 --> 06:09:45,280 instead of having that one let's replace 11407 06:09:45,780 --> 06:09:46,780 that with the play kitchen object and 11408 06:09:48,058 --> 06:09:49,058 since we are extending kitchen object we 11409 06:09:49,798 --> 06:09:50,798 have the same Fields so let's make sure 11410 06:09:51,240 --> 06:09:52,240 to add the kitchen object as so and get 11411 06:09:53,638 --> 06:09:54,638 rid of the other one okay great so now 11412 06:09:56,040 --> 06:09:57,040 back here on the on your counter when 11413 06:09:58,080 --> 06:09:59,080 there is a kitchen object here and the 11414 06:09:59,638 --> 06:10:00,638 player is carrying something we can 11415 06:10:01,680 --> 06:10:02,680 check if the player is holding a plate 11416 06:10:03,480 --> 06:10:04,480 and for that we can check the type 11417 06:10:05,820 --> 06:10:06,820 so if let's go into the player and let's 11418 06:10:08,580 --> 06:10:09,580 get the kitchen object the player is 11419 06:10:10,200 --> 06:10:11,200 holding and we test if this object is of 11420 06:10:12,660 --> 06:10:13,660 type Plate Kitchen object 11421 06:10:15,298 --> 06:10:16,298 if so then that means player is holding 11422 06:10:17,638 --> 06:10:18,638 a plate and if that is the case then we 11423 06:10:19,740 --> 06:10:20,740 basically want to give the player 11424 06:10:21,240 --> 06:10:22,240 whatever object is over here we want to 11425 06:10:23,520 --> 06:10:24,520 add it to the plate so let's go into the 11426 06:10:25,320 --> 06:10:26,320 plate script to add that function so 11427 06:10:27,298 --> 06:10:28,298 over here let's make a public Point 11428 06:10:29,280 --> 06:10:30,280 let's call it add ingredient 11429 06:10:35,100 --> 06:10:36,100 as a parameter we're going to receive a 11430 06:10:37,138 --> 06:10:38,138 kitchen object as so we really only care 11431 06:10:39,420 --> 06:10:40,420 about the type we're going to destroy 11432 06:10:40,860 --> 06:10:41,860 the actual kitchen object like we've 11433 06:10:42,420 --> 06:10:43,420 been doing when creating different types 11434 06:10:43,980 --> 06:10:44,980 so the plate is really just going to 11435 06:10:45,660 --> 06:10:46,660 store in list of types so here let's 11436 06:10:47,940 --> 06:10:48,940 store a list of kitchen object a cell 11437 06:10:50,160 --> 06:10:51,160 for the kitchen object that sell list 11438 06:10:54,240 --> 06:10:55,240 then when we add the ingredient let's 11439 06:10:56,400 --> 06:10:57,400 just add it to the list so this kitchen 11440 06:10:58,020 --> 06:10:59,020 object is so let's also make sure to 11441 06:10:59,878 --> 06:11:00,878 initialize the list so let's see what 11442 06:11:01,320 --> 06:11:02,320 I'm awake let's initialize our list and 11443 06:11:04,500 --> 06:11:05,500 now from the other side we just need to 11444 06:11:06,058 --> 06:11:07,058 call this so over here on the clear 11445 06:11:07,798 --> 06:11:08,798 counter if the player is holding a plate 11446 06:11:09,420 --> 06:11:10,420 let's first get the type of plate so 11447 06:11:11,580 --> 06:11:12,580 play kitchen object or the Plate Kitchen 11448 06:11:13,860 --> 06:11:14,860 object we go into the player to get the 11449 06:11:16,500 --> 06:11:17,500 kitchen object and we cast this as a 11450 06:11:19,320 --> 06:11:20,320 plate kitchen object 11451 06:11:21,058 --> 06:11:22,058 okay so we have this and then over here 11452 06:11:22,860 --> 06:11:23,860 let's call add ingredient 11453 06:11:24,660 --> 06:11:25,660 and let's add whatever is currently on 11454 06:11:26,700 --> 06:11:27,700 this counter so let's get the kitchen 11455 06:11:28,440 --> 06:11:29,440 object and get the kitchen object itself 11456 06:11:30,718 --> 06:11:31,718 okay so we're adding it to the plate and 11457 06:11:32,940 --> 06:11:33,940 then let's destroy what is here so get 11458 06:11:34,740 --> 06:11:35,740 kitchen object and destroy itself 11459 06:11:37,080 --> 06:11:38,080 okay so that's it so if there is 11460 06:11:38,700 --> 06:11:39,700 something here and if the player is 11461 06:11:40,260 --> 06:11:41,260 holding something and that's something 11462 06:11:41,458 --> 06:11:42,458 the player is holding as a plate if so 11463 06:11:43,500 --> 06:11:44,500 we're going to add that ingredient to 11464 06:11:44,760 --> 06:11:45,760 the plate and then destroy the object in 11465 06:11:46,500 --> 06:11:47,500 here so let's test okay so here let's 11466 06:11:48,958 --> 06:11:49,958 pick up a tomato let's slice it let's 11467 06:11:51,240 --> 06:11:52,240 put it on a clear kitchen counter 11468 06:11:52,740 --> 06:11:53,740 because that's the only one where we 11469 06:11:53,940 --> 06:11:54,940 added logic so on this one let's pick up 11470 06:11:56,218 --> 06:11:57,218 a plate and now whilst I'm carrying the 11471 06:11:58,440 --> 06:11:59,440 plate and if I approach and I interact 11472 06:12:00,058 --> 06:12:01,058 with it and if there you go it does work 11473 06:12:01,680 --> 06:12:02,680 the object vanished from the counter and 11474 06:12:03,660 --> 06:12:04,660 supposedly was added to the plate again 11475 06:12:05,638 --> 06:12:06,638 we can use a really nice debug inspector 11476 06:12:07,500 --> 06:12:08,500 to see it so let's pause the game Let's 11477 06:12:09,900 --> 06:12:10,900 select the plate let's see the play 11478 06:12:12,120 --> 06:12:13,120 kitchen object so here it is this one 11479 06:12:13,860 --> 06:12:14,860 and let's change the inspector into 11480 06:12:16,680 --> 06:12:17,680 debug mode and down here yep we do see 11481 06:12:19,200 --> 06:12:20,200 the kitchen object that's on list and it 11482 06:12:20,700 --> 06:12:21,700 does have some tomato slices okay 11483 06:12:22,558 --> 06:12:23,558 awesome so with this here we have our 11484 06:12:24,780 --> 06:12:25,780 basics 11485 06:12:25,860 --> 06:12:26,860 we can have some ingredients and we can 11486 06:12:27,840 --> 06:12:28,840 basically pick it up from a plate now 11487 06:12:29,878 --> 06:12:30,878 one thing about our plate this is where 11488 06:12:31,680 --> 06:12:32,680 we're basically going to carry the final 11489 06:12:33,240 --> 06:12:34,240 recipe that we're going to deliver to 11490 06:12:34,740 --> 06:12:35,740 the customers and based on the design 11491 06:12:36,718 --> 06:12:37,718 that I defined I want something pretty 11492 06:12:38,400 --> 06:12:39,400 simple meaning for the design that I'm 11493 06:12:40,440 --> 06:12:41,440 going for there won't be any kind of 11494 06:12:41,878 --> 06:12:42,878 double burgers or double cheese so each 11495 06:12:44,580 --> 06:12:45,580 final recipe will only have at most one 11496 06:12:46,920 --> 06:12:47,920 of each ingredient 11497 06:12:48,298 --> 06:12:49,298 so let's add some basic logic just to 11498 06:12:50,100 --> 06:12:51,100 prevent adding duplicates over here on 11499 06:12:52,440 --> 06:12:53,440 the Plate Kitchen object when we add an 11500 06:12:54,180 --> 06:12:55,180 ingredient 11501 06:12:55,200 --> 06:12:56,200 since the function will now not 11502 06:12:57,120 --> 06:12:58,120 necessarily succeed every time let's 11503 06:12:59,040 --> 06:13:00,040 actually rename this and again use a 11504 06:13:01,320 --> 06:13:02,320 very useful Visual Studio shortcut so 11505 06:13:03,360 --> 06:13:04,360 you can press Ctrl RR or right click and 11506 06:13:05,520 --> 06:13:06,520 let's rename 11507 06:13:06,718 --> 06:13:07,718 since this function will no longer 11508 06:13:08,400 --> 06:13:09,400 succeed we're just going to try to add 11509 06:13:10,378 --> 06:13:11,378 an ingredient so try add ingredient and 11510 06:13:12,958 --> 06:13:13,958 then let's also make it return a buoying 11511 06:13:14,820 --> 06:13:15,820 basically for any function where you're 11512 06:13:16,740 --> 06:13:17,740 not sure if it won't succeed I like to 11513 06:13:18,420 --> 06:13:19,420 add try and make it return ball so this 11514 06:13:20,638 --> 06:13:21,638 way it works pretty much exactly like 11515 06:13:21,900 --> 06:13:22,900 the try again component that we've 11516 06:13:23,458 --> 06:13:24,458 already seen so many times so it tries 11517 06:13:25,920 --> 06:13:26,920 to do something and returns whether it 11518 06:13:27,420 --> 06:13:28,420 succeeds or not so over here instead of 11519 06:13:29,340 --> 06:13:30,340 always adding the ingredient let's see 11520 06:13:31,138 --> 06:13:32,138 if this one is a duplicate so let's do 11521 06:13:33,360 --> 06:13:34,360 an if and let's go into the list and 11522 06:13:35,400 --> 06:13:36,400 check if the contains and if the list 11523 06:13:37,558 --> 06:13:38,558 summary contains this kitchen object as 11524 06:13:39,298 --> 06:13:40,298 well 11525 06:13:40,200 --> 06:13:41,200 if though then already has this type so 11526 06:13:43,440 --> 06:13:44,440 let's return false and if not 11527 06:13:46,740 --> 06:13:47,740 then that means it's a brand new 11528 06:13:48,420 --> 06:13:49,420 ingredient 11529 06:13:49,378 --> 06:13:50,378 so let's add it and return true okay so 11530 06:13:52,020 --> 06:13:53,020 that's it now let's go over here onto 11531 06:13:54,240 --> 06:13:55,240 the clear counter so we try to add the 11532 06:13:56,760 --> 06:13:57,760 ingredient but then we only want to 11533 06:13:58,558 --> 06:13:59,558 destroy if this one succeeds so let's 11534 06:14:00,058 --> 06:14:01,058 put this one inside an if so if we do 11535 06:14:02,700 --> 06:14:03,700 manage to add the ingredients 11536 06:14:04,440 --> 06:14:05,440 then yes let's destroy itself if not 11537 06:14:06,958 --> 06:14:07,958 then we don't destroy anything okay so 11538 06:14:09,058 --> 06:14:10,058 let's test 11539 06:14:10,020 --> 06:14:11,020 so let's go ahead and slice two tomatoes 11540 06:14:12,240 --> 06:14:13,240 so one slice it put it here then another 11541 06:14:14,878 --> 06:14:15,878 one slice it and put it here now let's 11542 06:14:17,760 --> 06:14:18,760 pick up a plate go up here try to pick 11543 06:14:19,500 --> 06:14:20,500 up this one and yep it does work now for 11544 06:14:21,180 --> 06:14:22,180 this one and I hope it doesn't work okay 11545 06:14:23,040 --> 06:14:24,040 great now one more thing in our logic we 11546 06:14:25,980 --> 06:14:26,980 only want to pick up certain things like 11547 06:14:28,200 --> 06:14:29,200 I said only things that won't be used in 11548 06:14:29,820 --> 06:14:30,820 the final recipe 11549 06:14:31,080 --> 06:14:32,080 for example no customer is ever going to 11550 06:14:33,298 --> 06:14:34,298 request a full entire tomato the recipes 11551 06:14:35,638 --> 06:14:36,638 only have sliced tomatoes so we should 11552 06:14:37,860 --> 06:14:38,860 not be able to drop a foam tomato 11553 06:14:39,240 --> 06:14:40,240 directly on top of a plate so let's 11554 06:14:41,100 --> 06:14:42,100 change that so over here on the plate 11555 06:14:43,080 --> 06:14:44,080 script let's basically just create a 11556 06:14:44,700 --> 06:14:45,700 list of our valid ingredients 11557 06:14:47,340 --> 06:14:48,340 so let's make a serialized film private 11558 06:14:50,160 --> 06:14:51,160 make it a list of kitchen object SL 11559 06:14:53,280 --> 06:14:54,280 ope and call it the valid kitchen object 11560 06:14:55,500 --> 06:14:56,500 SL list okay so we have this list and 11561 06:14:58,620 --> 06:14:59,620 over here in the editor let's just write 11562 06:15:00,058 --> 06:15:01,058 the ones that we want so let's first of 11563 06:15:01,920 --> 06:15:02,920 all select the plate object okay here is 11564 06:15:04,680 --> 06:15:05,680 the flight prefab and over here we've 11565 06:15:06,660 --> 06:15:07,660 got all of our kitchen objects so let's 11566 06:15:08,820 --> 06:15:09,820 just write the ones that we want to add 11567 06:15:10,138 --> 06:15:11,138 to the point 11568 06:15:11,280 --> 06:15:12,280 so the final recipes will have some 11569 06:15:13,080 --> 06:15:14,080 bread yep but they will not have entire 11570 06:15:15,298 --> 06:15:16,298 cabbages they will only have cabbage 11571 06:15:16,798 --> 06:15:17,798 slices same thing no cheese only slices 11572 06:15:19,980 --> 06:15:20,980 for the meat we're only going to be able 11573 06:15:22,138 --> 06:15:23,138 to add meat cooked but also meat burned 11574 06:15:24,540 --> 06:15:25,540 then we're not going to be able to add a 11575 06:15:27,000 --> 06:15:28,000 plate onto a plate of course not and 11576 06:15:28,740 --> 06:15:29,740 finally inside of a tomato just tomato 11577 06:15:30,298 --> 06:15:31,298 slices okay that's our Vellum list and 11578 06:15:33,120 --> 06:15:34,120 over here again it's very simple 11579 06:15:34,860 --> 06:15:35,860 so we can just go if the evaluate 11580 06:15:36,780 --> 06:15:37,780 kitchen object that's on list if this 11581 06:15:39,000 --> 06:15:40,000 one contains the one that we want to add 11582 06:15:41,580 --> 06:15:42,580 then we can add it but if not then let's 11583 06:15:44,340 --> 06:15:45,340 return phones 11584 06:15:45,780 --> 06:15:46,780 not a valid ingredient 11585 06:15:48,240 --> 06:15:49,240 okay so let's test alright so let's pick 11586 06:15:51,058 --> 06:15:52,058 up a tomato and also some tomato slices 11587 06:15:53,280 --> 06:15:54,280 and now if I pick up a plate and I go 11588 06:15:55,620 --> 06:15:56,620 into the Tomato nope doesn't work but 11589 06:15:57,298 --> 06:15:58,298 the slices yep it does work okay great 11590 06:15:59,280 --> 06:16:00,280 so here we have all of our basic plate 11591 06:16:01,860 --> 06:16:02,860 rooms everything is working perfectly 11592 06:16:03,900 --> 06:16:04,900 but it's only working over here with the 11593 06:16:05,458 --> 06:16:06,458 clear counter so let's do a little bit 11594 06:16:07,378 --> 06:16:08,378 of code cleanup and then let's add this 11595 06:16:09,120 --> 06:16:10,120 logic to all the other counters so first 11596 06:16:11,280 --> 06:16:12,280 to clean up this cone over here we are 11597 06:16:13,558 --> 06:16:14,558 testing if this is a plain kitchen 11598 06:16:15,058 --> 06:16:16,058 object then we cast to an object and 11599 06:16:17,638 --> 06:16:18,638 then we count the function so let's 11600 06:16:19,200 --> 06:16:20,200 simplify all this 11601 06:16:20,820 --> 06:16:21,820 and let's do it just like yinty does 11602 06:16:22,620 --> 06:16:23,620 with their try and get the component 11603 06:16:23,760 --> 06:16:24,760 function so let's make a custom function 11604 06:16:26,160 --> 06:16:27,160 that takes an output parameter the best 11605 06:16:28,378 --> 06:16:29,378 place to put it is on the kitchen object 11606 06:16:30,180 --> 06:16:31,180 so here we've got the kitchen object 11607 06:16:32,160 --> 06:16:33,160 script okay great let's scroll down and 11608 06:16:34,680 --> 06:16:35,680 make a nice function here so let's make 11609 06:16:37,080 --> 06:16:38,080 it public we're going to return Boolean 11610 06:16:39,298 --> 06:16:40,298 in case this succeeds or not let's 11611 06:16:40,920 --> 06:16:41,920 currently try get plate and over here 11612 06:16:43,500 --> 06:16:44,500 let's make an out parameter so don't 11613 06:16:45,718 --> 06:16:46,718 forget the out keyword let's return of 11614 06:16:47,878 --> 06:16:48,878 type Plate Kitchen object for the play 11615 06:16:50,280 --> 06:16:51,280 kitchen object then over here we do 11616 06:16:52,620 --> 06:16:53,620 examine what we did so we test if this 11617 06:16:54,660 --> 06:16:55,660 object is a plate kitchen object 11618 06:16:57,660 --> 06:16:58,660 if so then let's set the play kitchen 11619 06:16:59,458 --> 06:17:00,458 object equals this as a play kitchen 11620 06:17:01,920 --> 06:17:02,920 object and we return true but if not 11621 06:17:04,920 --> 06:17:05,920 then this is not a plate so let's return 11622 06:17:06,780 --> 06:17:07,780 false and one thing when working with 11623 06:17:09,180 --> 06:17:10,180 output parameters you always need to 11624 06:17:10,980 --> 06:17:11,980 make sure to set the output before you 11625 06:17:13,020 --> 06:17:14,020 exit the function 11626 06:17:14,458 --> 06:17:15,458 so over here that's the error that it's 11627 06:17:16,080 --> 06:17:17,080 telling us 11628 06:17:17,040 --> 06:17:18,040 we must assign it to something when we 11629 06:17:19,200 --> 06:17:20,200 return so over here we don't have a play 11630 06:17:21,298 --> 06:17:22,298 kitchen object so to solve this we just 11631 06:17:23,520 --> 06:17:24,520 set this to no okay great now over here 11632 06:17:26,340 --> 06:17:27,340 on the clear counter instead of doing 11633 06:17:27,780 --> 06:17:28,780 all this basically let's ask the player 11634 06:17:30,240 --> 06:17:31,240 if this is a kitchen object 11635 06:17:32,400 --> 06:17:33,400 so let's try to get the plate 11636 06:17:35,820 --> 06:17:36,820 out Plate Kitchen object for the Plate 11637 06:17:38,160 --> 06:17:39,160 Kitchen object 11638 06:17:40,200 --> 06:17:41,200 so you try to get it then we try to add 11639 06:17:41,820 --> 06:17:42,820 the ingredient and so on now obviously 11640 06:17:43,860 --> 06:17:44,860 we could further simplify things by 11641 06:17:45,360 --> 06:17:46,360 making a function that would try to get 11642 06:17:46,860 --> 06:17:47,860 the plate and try to add the ingredient 11643 06:17:48,120 --> 06:17:49,120 that could work but since some counters 11644 06:17:50,520 --> 06:17:51,520 are going to have a bit more custom 11645 06:17:51,718 --> 06:17:52,718 logic I think keeping them separate like 11646 06:17:53,820 --> 06:17:54,820 this makes more sense so first we try to 11647 06:17:55,740 --> 06:17:56,740 get the plate then we try to add the 11648 06:17:57,240 --> 06:17:58,240 ingredients so let's apply the same 11649 06:17:59,218 --> 06:18:00,218 logic to The Cutting counter 11650 06:18:01,260 --> 06:18:02,260 so over here on the cutting counter 11651 06:18:03,000 --> 06:18:04,000 let's scroll down to where there is a 11652 06:18:05,218 --> 06:18:06,218 kitchen object here and the point is 11653 06:18:06,420 --> 06:18:07,420 carrying something so on the earlier 11654 06:18:08,040 --> 06:18:09,040 counter we just want to copy all of this 11655 06:18:10,200 --> 06:18:11,200 so let's go over here and we do the 11656 06:18:12,240 --> 06:18:13,240 exact same thing okay that's it and the 11657 06:18:14,700 --> 06:18:15,700 other counter from where we can pick up 11658 06:18:16,260 --> 06:18:17,260 things is from the stove counter 11659 06:18:19,020 --> 06:18:20,020 so here we are on the stove let's scroll 11660 06:18:21,298 --> 06:18:22,298 down until we find the interaction okay 11661 06:18:23,100 --> 06:18:24,100 there's something here The Player's 11662 06:18:24,298 --> 06:18:25,298 carrying something so it's over here 11663 06:18:25,798 --> 06:18:26,798 let's do that and do the exact same 11664 06:18:27,360 --> 06:18:28,360 thing except on the stove again let's 11665 06:18:29,280 --> 06:18:30,280 remember that this is using a save 11666 06:18:30,600 --> 06:18:31,600 machine so when we pick up something 11667 06:18:32,340 --> 06:18:33,340 let's do pretty much the same thing that 11668 06:18:33,600 --> 06:18:34,600 we did here so let's make sure to reset 11669 06:18:36,298 --> 06:18:37,298 the State Fire the events and so on okay 11670 06:18:39,298 --> 06:18:40,298 so those are the only counters that we 11671 06:18:40,920 --> 06:18:41,920 need to implement we cannot drop things 11672 06:18:42,840 --> 06:18:43,840 on top of a container we cannot drop 11673 06:18:44,700 --> 06:18:45,700 things on top of the plate counter or 11674 06:18:46,558 --> 06:18:47,558 the trash so these are the only three 11675 06:18:48,180 --> 06:18:49,180 types that we need to implement so with 11676 06:18:49,980 --> 06:18:50,980 this let's test okay so let's begin with 11677 06:18:52,200 --> 06:18:53,200 some meat so let's pick up some meat put 11678 06:18:53,700 --> 06:18:54,700 it on the stove let's pick up a plate 11679 06:18:55,680 --> 06:18:56,680 wait for it to cook pick it up any up 11680 06:18:57,540 --> 06:18:58,540 there you go it does work now it says 11681 06:18:59,520 --> 06:19:00,520 the cut encounters and let's pick up 11682 06:19:00,900 --> 06:19:01,900 some cheese and let's slice it pick up 11683 06:19:02,878 --> 06:19:03,878 some plate and go any up there you go it 11684 06:19:04,920 --> 06:19:05,920 does work and again if we inspect we can 11685 06:19:07,138 --> 06:19:08,138 make sure that it is indeed working so 11686 06:19:08,580 --> 06:19:09,580 let's get into the plate and let's put 11687 06:19:10,740 --> 06:19:11,740 this on debug inspector and if there we 11688 06:19:12,840 --> 06:19:13,840 do see this one has a meat Patty cooked 11689 06:19:14,580 --> 06:19:15,580 and some cheese slices okay great now 11690 06:19:17,458 --> 06:19:18,458 the last piece of logic that we need is 11691 06:19:19,138 --> 06:19:20,138 pretty much the opposite so right now it 11692 06:19:21,180 --> 06:19:22,180 works if there's a sliced object on the 11693 06:19:23,040 --> 06:19:24,040 plate and the player is holding a plate 11694 06:19:24,840 --> 06:19:25,840 object but now we want the opposite so 11695 06:19:27,180 --> 06:19:28,180 let's say there's a plate in here and we 11696 06:19:29,580 --> 06:19:30,580 slice some cheese and now I want to drop 11697 06:19:31,320 --> 06:19:32,320 the cheese on the plate so let's do that 11698 06:19:33,180 --> 06:19:34,180 and basically for this one this one is 11699 06:19:35,100 --> 06:19:36,100 only going to happen on the clear 11700 06:19:36,120 --> 06:19:37,120 counter that's the only counter type 11701 06:19:38,458 --> 06:19:39,458 that can have a plate on top of it so 11702 06:19:40,740 --> 06:19:41,740 over here on the clear counter then we 11703 06:19:43,020 --> 06:19:44,020 check if there is no object there but 11704 06:19:44,700 --> 06:19:45,700 that's not what we want we want if 11705 06:19:46,020 --> 06:19:47,020 there's a plate on the counter so if 11706 06:19:47,580 --> 06:19:48,580 there is an object there and if the 11707 06:19:49,440 --> 06:19:50,440 player is carrying something 11708 06:19:50,940 --> 06:19:51,940 then we check if the player is holding a 11709 06:19:52,558 --> 06:19:53,558 plate but if not so if the player is not 11710 06:19:55,378 --> 06:19:56,378 holding a plate 11711 06:19:56,940 --> 06:19:57,940 so player is not carrying plate but 11712 06:20:00,240 --> 06:20:01,240 something else over here we need pretty 11713 06:20:02,700 --> 06:20:03,700 much exact same logic except just 11714 06:20:04,200 --> 06:20:05,200 testing for the object on this counter 11715 06:20:05,820 --> 06:20:06,820 so let's do if let's get the kitchen 11716 06:20:07,920 --> 06:20:08,920 object on this counter this one try to 11717 06:20:10,378 --> 06:20:11,378 get the plate so out play kitchen 11718 06:20:12,718 --> 06:20:13,718 objects for the Plate Kitchen object so 11719 06:20:15,120 --> 06:20:16,120 if so if so there's a plate over here 11720 06:20:19,260 --> 06:20:20,260 that means the counter is holding a 11721 06:20:21,958 --> 06:20:22,958 plate 11722 06:20:23,638 --> 06:20:24,638 so then let's go into this play kitchen 11723 06:20:25,680 --> 06:20:26,680 object let's add the ingredient 11724 06:20:27,958 --> 06:20:28,958 and we're going to try to add whatever 11725 06:20:29,520 --> 06:20:30,520 the player is currently carrying so the 11726 06:20:31,740 --> 06:20:32,740 player dot get kitchen object 11727 06:20:34,740 --> 06:20:35,740 and get the kitchen object as so 11728 06:20:39,540 --> 06:20:40,540 so we're going to try to add this 11729 06:20:42,600 --> 06:20:43,600 and if we can add then we're just going 11730 06:20:44,458 --> 06:20:45,458 to destroy whatever is on the player 11731 06:20:47,638 --> 06:20:48,638 okay that's it and over here we've got a 11732 06:20:49,860 --> 06:20:50,860 nice error just because we've defined it 11733 06:20:51,240 --> 06:20:52,240 with the same name appear so up here 11734 06:20:53,340 --> 06:20:54,340 we're already defining the variable and 11735 06:20:55,260 --> 06:20:56,260 over here we're defining the same 11736 06:20:56,940 --> 06:20:57,940 variable with the same name 11737 06:20:58,620 --> 06:20:59,620 so we can either give this a different 11738 06:21:00,058 --> 06:21:01,058 name or just not Define a brand new 11739 06:21:01,680 --> 06:21:02,680 variable here so just it's a fine up 11740 06:21:03,480 --> 06:21:04,480 here and we're using it here okay so 11741 06:21:05,638 --> 06:21:06,638 while logic is working now here make 11742 06:21:07,440 --> 06:21:08,440 very sure that you're not mixing 11743 06:21:08,878 --> 06:21:09,878 references keep in mind when you're 11744 06:21:10,740 --> 06:21:11,740 referencing the kitchen object on this 11745 06:21:12,298 --> 06:21:13,298 counter and the one on the player those 11746 06:21:14,100 --> 06:21:15,100 are two different things so over here if 11747 06:21:16,138 --> 06:21:17,138 the player is not carrying a plate but 11748 06:21:17,580 --> 06:21:18,580 something else then you check the 11749 06:21:19,558 --> 06:21:20,558 kitchen counter so over here you're not 11750 06:21:21,660 --> 06:21:22,660 checking the player but checking the 11751 06:21:22,860 --> 06:21:23,860 counter then you go into that point and 11752 06:21:24,958 --> 06:21:25,958 try to add the ingredient and you try to 11753 06:21:26,520 --> 06:21:27,520 add the one that the player is carrying 11754 06:21:27,900 --> 06:21:28,900 and then you destroy the one the player 11755 06:21:29,458 --> 06:21:30,458 is carrying so again be very careful 11756 06:21:31,200 --> 06:21:32,200 here make sure you don't mix references 11757 06:21:33,058 --> 06:21:34,058 so with this it should work so let's 11758 06:21:35,040 --> 06:21:36,040 make sure to save our script and let's 11759 06:21:36,900 --> 06:21:37,900 test okay so here we are let's first 11760 06:21:39,298 --> 06:21:40,298 pick up a nice plate let's drop the 11761 06:21:41,218 --> 06:21:42,218 plate in there pick up some bread drop 11762 06:21:42,900 --> 06:21:43,900 the bread any of there you go it does 11763 06:21:44,400 --> 06:21:45,400 work alright so now we can do a bit more 11764 06:21:46,798 --> 06:21:47,798 natural interactions so for example 11765 06:21:48,480 --> 06:21:49,480 let's pick up some meat and put it on 11766 06:21:49,980 --> 06:21:50,980 cooking and there you go the meat is 11767 06:21:52,200 --> 06:21:53,200 fried so now I'm currently carrying just 11768 06:21:53,580 --> 06:21:54,580 some meat so I place it there then I 11769 06:21:55,378 --> 06:21:56,378 pick up some bread and put some bread on 11770 06:21:56,820 --> 06:21:57,820 top of the meat and yep everything does 11771 06:21:58,440 --> 06:21:59,440 work policy okay so here we created the 11772 06:22:00,958 --> 06:22:01,958 plate and we created some custom logic 11773 06:22:02,878 --> 06:22:03,878 to Define what the plate can and cannot 11774 06:22:04,920 --> 06:22:05,920 account no that's left is actually being 11775 06:22:07,138 --> 06:22:08,138 able to see what is on the plane so 11776 06:22:08,878 --> 06:22:09,878 let's do that in the next lecture 11777 06:22:11,580 --> 06:22:12,580 hello and welcome I'm your code monkey 11778 06:22:13,378 --> 06:22:14,378 in this lecture we're going to add a 11779 06:22:15,600 --> 06:22:16,600 nice visual to our plate okay so right 11780 06:22:17,760 --> 06:22:18,760 now we can already pick up ingredients 11781 06:22:19,138 --> 06:22:20,138 under the plate so if I pick up the 11782 06:22:20,760 --> 06:22:21,760 plate and I pick up some cheese there 11783 06:22:22,440 --> 06:22:23,440 you go there's some cheese on the plate 11784 06:22:23,638 --> 06:22:24,638 but we cannot see it so let's solve that 11785 06:22:25,920 --> 06:22:26,920 and we were going to do that it's 11786 06:22:27,420 --> 06:22:28,420 actually in a very simple way 11787 06:22:29,458 --> 06:22:30,458 if you look in the included assets 11788 06:22:31,378 --> 06:22:32,378 inside the prefab visuals there's this 11789 06:22:33,600 --> 06:22:34,600 nice plate complete visual that I built 11790 06:22:35,340 --> 06:22:36,340 basically it's a foam burger that 11791 06:22:37,500 --> 06:22:38,500 contains all the ingredients what we're 11792 06:22:39,298 --> 06:22:40,298 going to do is actually very simple 11793 06:22:40,558 --> 06:22:41,558 we're just going to enable or disable 11794 06:22:42,480 --> 06:22:43,480 these game objects that's it so let's do 11795 06:22:44,820 --> 06:22:45,820 example that let's make a new c-sharp 11796 06:22:47,400 --> 06:22:48,400 script quality plate complete visual 11797 06:22:50,700 --> 06:22:51,700 let's attach a script over here and 11798 06:22:53,458 --> 06:22:54,458 let's also make sure to put this one 11799 06:22:54,780 --> 06:22:55,780 inside the plate so let's save this 11800 06:22:57,000 --> 06:22:58,000 prefab let's go inside the play prefab 11801 06:22:59,638 --> 06:23:00,638 so inside the prefabs here the kitchen 11802 06:23:02,218 --> 06:23:03,218 objects we've got the plate so inside of 11803 06:23:04,558 --> 06:23:05,558 the point let's drag that let's drag the 11804 06:23:06,298 --> 06:23:07,298 plate complete visual okay great so now 11805 06:23:08,820 --> 06:23:09,820 let's open up this script over here on 11806 06:23:11,040 --> 06:23:12,040 let's first have the reference to our 11807 06:23:12,420 --> 06:23:13,420 Plate Kitchen object 11808 06:23:14,480 --> 06:23:15,480 film private for the Plate Kitchen 11809 06:23:17,040 --> 06:23:18,040 object for the Plate Kitchen object 11810 06:23:19,320 --> 06:23:20,320 back in the editor let's drag the 11811 06:23:21,240 --> 06:23:22,240 reference okay great so now here 11812 06:23:23,218 --> 06:23:24,218 basically we need to update this visual 11813 06:23:24,958 --> 06:23:25,958 whenever the plate gets any ingredient 11814 06:23:26,700 --> 06:23:27,700 added to it 11815 06:23:28,020 --> 06:23:29,020 so let's go over here into the point 11816 06:23:29,580 --> 06:23:30,580 script and basically just need to fire 11817 06:23:30,958 --> 06:23:31,958 off an event when that happens 11818 06:23:32,940 --> 06:23:33,940 so let's make a public event event 11819 06:23:35,160 --> 06:23:36,160 handler and let's call it on ingredient 11820 06:23:37,740 --> 06:23:38,740 added 11821 06:23:41,160 --> 06:23:42,160 okay and for this one let's also make an 11822 06:23:42,900 --> 06:23:43,900 event RX to contain the data of what 11823 06:23:45,120 --> 06:23:46,120 object we added so let's make a public 11824 06:23:47,100 --> 06:23:48,100 class on ingredient added event args 11825 06:23:51,540 --> 06:23:52,540 let's extend event args and inside let's 11826 06:23:55,138 --> 06:23:56,138 make just a kitchen object a cell 11827 06:23:57,480 --> 06:23:58,480 kitchen object as well 11828 06:24:00,420 --> 06:24:01,420 okay great and let's make the event of 11829 06:24:02,760 --> 06:24:03,760 this time 11830 06:24:04,020 --> 06:24:05,020 all right so now let's just fire off 11831 06:24:05,820 --> 06:24:06,820 this event so down here when we try to 11832 06:24:07,620 --> 06:24:08,620 add an ingredient if we do add the 11833 06:24:09,540 --> 06:24:10,540 ingredient let's fire off this event so 11834 06:24:11,580 --> 06:24:12,580 let's invoke with this and let's create 11835 06:24:14,100 --> 06:24:15,100 a brand new one passing the kitchen 11836 06:24:15,718 --> 06:24:16,718 object as so as this kitchen I'll take 11837 06:24:17,520 --> 06:24:18,520 this off okay so we have our event 11838 06:24:19,920 --> 06:24:20,920 correctly being sent now we're here on 11839 06:24:22,020 --> 06:24:23,020 the play complete visual let's listen to 11840 06:24:23,580 --> 06:24:24,580 it again as always let's make sure to do 11841 06:24:25,740 --> 06:24:26,740 it only on start so the play kitchen 11842 06:24:27,360 --> 06:24:28,360 object on ingredient added let's listen 11843 06:24:29,820 --> 06:24:30,820 to this event and over here we just need 11844 06:24:32,340 --> 06:24:33,340 to either enable or disable the visuals 11845 06:24:34,200 --> 06:24:35,200 that relate to the kitchen object inside 11846 06:24:36,180 --> 06:24:37,180 over here the event arcs however of 11847 06:24:38,280 --> 06:24:39,280 course the question is how exactly do we 11848 06:24:40,200 --> 06:24:41,200 find them the point complete visual has 11849 06:24:42,540 --> 06:24:43,540 all these game objects how do we know 11850 06:24:44,760 --> 06:24:45,760 which one belongs to that kitchen object 11851 06:24:46,740 --> 06:24:47,740 now technically one way would be to do a 11852 06:24:49,320 --> 06:24:50,320 simple transform find and find the 11853 06:24:51,120 --> 06:24:52,120 channel objects by name technically that 11854 06:24:53,400 --> 06:24:54,400 would work but like I mentioned in the 11855 06:24:55,320 --> 06:24:56,320 beginning of the course strings are a 11856 06:24:57,058 --> 06:24:58,058 horrible way to identify things they are 11857 06:24:58,920 --> 06:24:59,920 very air prone so let's not do that 11858 06:25:01,378 --> 06:25:02,378 instead let's use a proper approach 11859 06:25:03,540 --> 06:25:04,540 where we can Define some kind of link 11860 06:25:05,280 --> 06:25:06,280 between a kitchen object a so and a game 11861 06:25:07,620 --> 06:25:08,620 object and we can do this very easily by 11862 06:25:09,780 --> 06:25:10,780 justifying a struct so here in our 11863 06:25:12,058 --> 06:25:13,058 script let's do exactly that let's 11864 06:25:14,100 --> 06:25:15,100 define a public 11865 06:25:16,138 --> 06:25:17,138 make it a struct 11866 06:25:18,420 --> 06:25:19,420 and name it kitchen object so underscore 11867 06:25:21,718 --> 06:25:22,718 game object 11868 06:25:25,138 --> 06:25:26,138 then inside it's very simple we just 11869 06:25:27,000 --> 06:25:28,000 have a kitchen object so field 11870 06:25:31,378 --> 06:25:32,378 and then also a game object field 11871 06:25:37,798 --> 06:25:38,798 that's it super simple by the way if you 11872 06:25:40,200 --> 06:25:41,200 don't know what is a struct basically 11873 06:25:41,940 --> 06:25:42,940 it's very similar to a class except it's 11874 06:25:44,580 --> 06:25:45,580 stored in different places in memory and 11875 06:25:46,320 --> 06:25:47,320 behaves somewhat differently 11876 06:25:48,298 --> 06:25:49,298 I have a very very important video on 11877 06:25:50,280 --> 06:25:51,280 that subject what is the difference 11878 06:25:51,480 --> 06:25:52,480 between value types and reference types 11879 06:25:53,480 --> 06:25:54,480 classes are reference types so when you 11880 06:25:56,100 --> 06:25:57,100 pass in a class into a parameter you are 11881 06:25:57,958 --> 06:25:58,958 passing in a reference to that object 11882 06:25:59,600 --> 06:26:00,600 whereas struts are value types so when 11883 06:26:02,280 --> 06:26:03,280 you pass in a struct onto a parameter 11884 06:26:03,958 --> 06:26:04,958 you are passing in a copy it's a bit of 11885 06:26:06,480 --> 06:26:07,480 a tricky thing so definitely make sure 11886 06:26:08,040 --> 06:26:09,040 you go watch that video for more details 11887 06:26:09,660 --> 06:26:10,660 so you don't get confused in the future 11888 06:26:11,040 --> 06:26:12,040 here I Define that as a struct simply as 11889 06:26:13,320 --> 06:26:14,320 kind of a teaching moment but also 11890 06:26:15,120 --> 06:26:16,120 because it just makes sense that if I 11891 06:26:16,798 --> 06:26:17,798 just want to store some data without any 11892 06:26:18,660 --> 06:26:19,660 logic then it should probably be a 11893 06:26:20,520 --> 06:26:21,520 struct and not a class although in this 11894 06:26:22,378 --> 06:26:23,378 case the class would work just as well 11895 06:26:24,360 --> 06:26:25,360 anyway so here we have a struct inside 11896 06:26:26,760 --> 06:26:27,760 the struct we have a field of type 11897 06:26:28,260 --> 06:26:29,260 kitchen object so another one of type 11898 06:26:30,058 --> 06:26:31,058 game object so now let's just make a 11899 06:26:32,280 --> 06:26:33,280 list of this type that we can expose in 11900 06:26:33,958 --> 06:26:34,958 the editor so here a serialized film 11901 06:26:36,058 --> 06:26:37,058 private let's make it a list of kitchen 11902 06:26:38,340 --> 06:26:39,340 objects so game object and call it 11903 06:26:41,100 --> 06:26:42,100 kitchen object so game object list 11904 06:26:44,340 --> 06:26:45,340 okay that's it super simple so let's 11905 06:26:46,860 --> 06:26:47,860 save and make sure this compounds so 11906 06:26:48,180 --> 06:26:49,180 actually let's just comment this out 11907 06:26:49,680 --> 06:26:50,680 just make sure our code compounds okay 11908 06:26:51,840 --> 06:26:52,840 and over here in the editor we see the 11909 06:26:53,760 --> 06:26:54,760 tricky thing when it comes to using 11910 06:26:55,020 --> 06:26:56,020 fields of custom types if we look in the 11911 06:26:57,718 --> 06:26:58,718 inspector no we don't see anything so we 11912 06:26:59,820 --> 06:27:00,820 cannot see our custom type in the 11913 06:27:01,200 --> 06:27:02,200 inspector if you make a custom time like 11914 06:27:03,600 --> 06:27:04,600 this front and you want to show it in 11915 06:27:05,520 --> 06:27:06,520 the inspector then you need to add the 11916 06:27:07,440 --> 06:27:08,440 attribute serializable which exists 11917 06:27:09,958 --> 06:27:10,958 inside system so let's go up here using 11918 06:27:12,780 --> 06:27:13,780 system 11919 06:27:15,480 --> 06:27:16,480 and let's say the attribute serializable 11920 06:27:17,580 --> 06:27:18,580 just like this okay so do this save and 11921 06:27:20,760 --> 06:27:21,760 let's look and if there you go now we do 11922 06:27:23,160 --> 06:27:24,160 see our custom struct so we've got a 11923 06:27:25,138 --> 06:27:26,138 list then we can click on the pause icon 11924 06:27:26,700 --> 06:27:27,700 and there you go we've got an element 11925 06:27:27,718 --> 06:27:28,718 and it does have a film for a kitchen 11926 06:27:29,280 --> 06:27:30,280 object so and one for a game object so 11927 06:27:32,218 --> 06:27:33,218 that's great with this now we have a 11928 06:27:34,020 --> 06:27:35,020 really nice place where we can link one 11929 06:27:35,940 --> 06:27:36,940 object to another so let's just do 11930 06:27:37,740 --> 06:27:38,740 exactly that so for example let's put 11931 06:27:39,420 --> 06:27:40,420 the bread over there and let's assign 11932 06:27:41,458 --> 06:27:42,458 the kitchen object as so for the one 11933 06:27:42,780 --> 06:27:43,780 with bread let's do the same thing for 11934 06:27:44,940 --> 06:27:45,940 all of the others so let's add a whole 11935 06:27:47,400 --> 06:27:48,400 bunch more Okay so we've got the bread 11936 06:27:49,500 --> 06:27:50,500 then we're going to have the meat Patty 11937 06:27:51,120 --> 06:27:52,120 cooked then the tomato slices then we 11938 06:27:54,298 --> 06:27:55,298 have the cheese slices the Cabbage 11939 06:27:56,700 --> 06:27:57,700 sliced and finally the meat Patty burned 11940 06:27:58,680 --> 06:27:59,680 so I've got number zero through five so 11941 06:28:00,540 --> 06:28:01,540 you have six elements and over here yep 11942 06:28:02,100 --> 06:28:03,100 we do got six so we have all of them we 11943 06:28:04,020 --> 06:28:05,020 can get rid of these last two okay great 11944 06:28:06,298 --> 06:28:07,298 and now let's assign the proper objects 11945 06:28:08,520 --> 06:28:09,520 so this one for the meat Patty cooked 11946 06:28:10,378 --> 06:28:11,378 then we've got the tomato slices then we 11947 06:28:13,860 --> 06:28:14,860 have the cheese slices then the Cabbage 11948 06:28:17,218 --> 06:28:18,218 slices and finally the meat Patty burned 11949 06:28:19,860 --> 06:28:20,860 okay great so all of the references 11950 06:28:21,840 --> 06:28:22,840 match now back in the code here so we 11951 06:28:24,480 --> 06:28:25,480 have this List fully filmed out and when 11952 06:28:26,878 --> 06:28:27,878 we have this really very simple we just 11953 06:28:29,400 --> 06:28:30,400 cycle through the list to find the right 11954 06:28:30,718 --> 06:28:31,718 game object it's similar to a 40 inch of 11955 06:28:33,240 --> 06:28:34,240 type kitchen object so game object 11956 06:28:36,120 --> 06:28:37,120 in our kitchen object so game object 11957 06:28:38,820 --> 06:28:39,820 list and we check if this kitchen object 11958 06:28:41,820 --> 06:28:42,820 is so dot kitchen object matches the one 11959 06:28:43,980 --> 06:28:44,980 that we received in the event 11960 06:28:45,780 --> 06:28:46,780 if they do match then go into this one 11961 06:28:47,760 --> 06:28:48,760 grab the game object and set active into 11962 06:28:49,980 --> 06:28:50,980 true 11963 06:28:51,600 --> 06:28:52,600 okay so that's it some very simple logic 11964 06:28:53,638 --> 06:28:54,638 and also we can start with them disable 11965 06:28:55,680 --> 06:28:56,680 them by default in the editor or just 11966 06:28:58,020 --> 06:28:59,020 over here just use something very simple 11967 06:28:59,520 --> 06:29:00,520 just do a for each second through every 11968 06:29:02,520 --> 06:29:03,520 single one of them and set every single 11969 06:29:04,980 --> 06:29:05,980 one of them to false so that they are 11970 06:29:07,200 --> 06:29:08,200 hidden okay so with this on the 11971 06:29:09,120 --> 06:29:10,120 ingredients on the plate should be 11972 06:29:10,378 --> 06:29:11,378 visible so here in the editor let's just 11973 06:29:12,718 --> 06:29:13,718 make sure all the references have been 11974 06:29:14,340 --> 06:29:15,340 set let's go back save the prefab and 11975 06:29:16,620 --> 06:29:17,620 let's set on play okay so here we are 11976 06:29:18,660 --> 06:29:19,660 and by default like that an empty plate 11977 06:29:20,400 --> 06:29:21,400 and yep it is empty and now let's slice 11978 06:29:22,558 --> 06:29:23,558 some cheese now let's Place some cheese 11979 06:29:24,180 --> 06:29:25,180 on there and there you go we've got some 11980 06:29:25,620 --> 06:29:26,620 cheese now let's pick up some bread drop 11981 06:29:28,020 --> 06:29:29,020 some bread and there you go got some 11982 06:29:29,638 --> 06:29:30,638 cheese and some bread 11983 06:29:31,378 --> 06:29:32,378 then let's cook some meat so let's cook 11984 06:29:34,260 --> 06:29:35,260 it and let's pick it up with a plate and 11985 06:29:36,180 --> 06:29:37,180 as soon as I go boom there you go I've 11986 06:29:37,740 --> 06:29:38,740 got a nice cheese butter 11987 06:29:39,240 --> 06:29:40,240 all right awesome so wait a second I'll 11988 06:29:41,700 --> 06:29:42,700 do a complete Burger so let's finish it 11989 06:29:43,440 --> 06:29:44,440 let's just add some more tomatoes so 11990 06:29:45,900 --> 06:29:46,900 slice them and add the tomatoes and 11991 06:29:48,298 --> 06:29:49,298 finally some sliced cabbages slice them 11992 06:29:50,340 --> 06:29:51,340 put them there and there you go here we 11993 06:29:52,260 --> 06:29:53,260 have a fully complete Burger okay so 11994 06:29:54,780 --> 06:29:55,780 that's great all of our vision logic is 11995 06:29:56,520 --> 06:29:57,520 indeed working however this visual is a 11996 06:29:59,160 --> 06:30:00,160 bit hard to see it's not very clear to 11997 06:30:00,958 --> 06:30:01,958 the player so just looking at it from 11998 06:30:03,120 --> 06:30:04,120 this distance does that have a tomato or 11999 06:30:05,760 --> 06:30:06,760 not 12000 06:30:06,480 --> 06:30:07,480 there's a tiny sliver of red in there 12001 06:30:08,580 --> 06:30:09,580 but you can't really see it 12002 06:30:10,260 --> 06:30:11,260 so we should probably add some nice 12003 06:30:11,878 --> 06:30:12,878 clear icons on top to clearly indicate 12004 06:30:14,100 --> 06:30:15,100 what exactly is on this plate so that's 12005 06:30:16,500 --> 06:30:17,500 exactly what we're going to do in the 12006 06:30:18,058 --> 06:30:19,058 next lecture 12007 06:30:19,860 --> 06:30:20,860 hello and welcome I'm your code monkey 12008 06:30:21,718 --> 06:30:22,718 in this lecture we're going to add some 12009 06:30:24,058 --> 06:30:25,058 really nice icons on top of our plate so 12010 06:30:25,920 --> 06:30:26,920 we can easily see what is on there okay 12011 06:30:28,020 --> 06:30:29,020 so for the icons let's do the exact same 12012 06:30:30,360 --> 06:30:31,360 thing that we did for the progress bar 12013 06:30:31,798 --> 06:30:32,798 meaning let's use a warm space canvas so 12014 06:30:34,680 --> 06:30:35,680 let's go inside our play kitchen after 12015 06:30:36,540 --> 06:30:37,540 prefab and over here on let's right 12016 06:30:38,458 --> 06:30:39,458 click let's create a brand new canvas 12017 06:30:40,920 --> 06:30:41,920 let's name this the plate icons UI then 12018 06:30:44,700 --> 06:30:45,700 for the settings let's make it World 12019 06:30:46,320 --> 06:30:47,320 space put it on zero zero everything 12020 06:30:48,420 --> 06:30:49,420 width and height also on zero then let's 12021 06:30:51,540 --> 06:30:52,540 lift it up a little bit so put it on a y 12022 06:30:53,580 --> 06:30:54,580 of one okay like that now inside let's 12023 06:30:56,160 --> 06:30:57,160 define an icon 12024 06:30:57,780 --> 06:30:58,780 so let's start by making an empty game 12025 06:30:59,580 --> 06:31:00,580 object call this just the icon template 12026 06:31:03,058 --> 06:31:04,058 let's put it with a size of 0.3.3 it's 12027 06:31:06,240 --> 06:31:07,240 okay something like that then inside 12028 06:31:08,458 --> 06:31:09,458 let's add a new UI image name this the 12029 06:31:11,458 --> 06:31:12,458 background 12030 06:31:12,540 --> 06:31:13,540 and make it stretch to film The 12031 06:31:14,700 --> 06:31:15,700 appearance so put 0 on everything okay 12032 06:31:17,280 --> 06:31:18,280 there's our background 12033 06:31:18,840 --> 06:31:19,840 for the background image instead of a 12034 06:31:20,820 --> 06:31:21,820 square and let's actually go with a 12035 06:31:22,138 --> 06:31:23,138 circle for that Unity actually has a 12036 06:31:24,660 --> 06:31:25,660 bunch of built-in Sprites that are 12037 06:31:26,040 --> 06:31:27,040 tatted in the last versions however it's 12038 06:31:28,558 --> 06:31:29,558 not actually over here by default 12039 06:31:30,660 --> 06:31:31,660 in order to see those default Sprites we 12040 06:31:32,580 --> 06:31:33,580 need to install the 2D Sprite package so 12041 06:31:34,860 --> 06:31:35,860 let's quickly just go into window 12042 06:31:36,420 --> 06:31:37,420 package manager let's make sure we are 12043 06:31:38,878 --> 06:31:39,878 in the UNT registry make sure we aren't 12044 06:31:40,680 --> 06:31:41,680 looking at all and over here let's find 12045 06:31:42,780 --> 06:31:43,780 the 2D Sprite package okay so let's 12046 06:31:44,700 --> 06:31:45,700 install this 12047 06:31:45,840 --> 06:31:46,840 okay there's the package so now if we go 12048 06:31:48,420 --> 06:31:49,420 into the background and we search for a 12049 06:31:49,920 --> 06:31:50,920 Sprite and over here make sure you click 12050 06:31:52,138 --> 06:31:53,138 to actually show the assets from the 12051 06:31:54,360 --> 06:31:55,360 packages and now we see a bunch of 12052 06:31:56,160 --> 06:31:57,160 default hexagons a bunch of isometric 12053 06:31:58,320 --> 06:31:59,320 tiles the square so on and if we search 12054 06:32:01,200 --> 06:32:02,200 for Circle yep here we've got a bunch of 12055 06:32:03,120 --> 06:32:04,120 circle so let's use this one over here 12056 06:32:05,100 --> 06:32:06,100 on this path so let's use it there you 12057 06:32:07,138 --> 06:32:08,138 go we have a nice circle now let's 12058 06:32:09,360 --> 06:32:10,360 duplicate this image and for the second 12059 06:32:11,160 --> 06:32:12,160 one let's name it icon 12060 06:32:13,138 --> 06:32:14,138 then for this one let's assign just a 12061 06:32:15,420 --> 06:32:16,420 random Sprite so let's say the bread 12062 06:32:17,340 --> 06:32:18,340 and again remember how the Sorting order 12063 06:32:19,200 --> 06:32:20,200 on the UI this one is based on the 12064 06:32:20,820 --> 06:32:21,820 ordering the hierarchy 12065 06:32:22,378 --> 06:32:23,378 so make sure that the icon is underneath 12066 06:32:25,020 --> 06:32:26,020 the background the hierarchy that way it 12067 06:32:26,940 --> 06:32:27,940 shows up on top okay so we have our icon 12068 06:32:29,520 --> 06:32:30,520 template that's great of course we're 12069 06:32:31,260 --> 06:32:32,260 going to dynamically generate all of 12070 06:32:33,058 --> 06:32:34,058 this through code we're going to have 12071 06:32:34,740 --> 06:32:35,740 multiple icons and for positioning them 12072 06:32:36,840 --> 06:32:37,840 Unity actually has some really useful 12073 06:32:38,520 --> 06:32:39,520 components let's select the plate icons 12074 06:32:41,040 --> 06:32:42,040 UI and over here now let's add a 12075 06:32:42,718 --> 06:32:43,718 component now for example a built-in 12076 06:32:45,058 --> 06:32:46,058 component is the grid layout group this 12077 06:32:47,878 --> 06:32:48,878 basically helps you position all the 12078 06:32:49,558 --> 06:32:50,558 charm objects so let's put the size of 12079 06:32:51,780 --> 06:32:52,780 the canvas over here on 0.9.9 okay so 12080 06:32:54,600 --> 06:32:55,600 there you go a nice Square window then 12081 06:32:56,580 --> 06:32:57,580 over here on the settings for this for 12082 06:32:58,260 --> 06:32:59,260 the cell size let's put it at 0.3.3 and 12083 06:33:01,020 --> 06:33:02,020 if there you go already shows up over 12084 06:33:02,400 --> 06:33:03,400 there on the corner 12085 06:33:03,900 --> 06:33:04,900 and we can see what it will look like if 12086 06:33:05,878 --> 06:33:06,878 we just duplicate this object so let's 12087 06:33:07,378 --> 06:33:08,378 make a bunch more templates and if there 12088 06:33:09,480 --> 06:33:10,480 you go that's what it looks like so as 12089 06:33:11,340 --> 06:33:12,340 you can see this component is super 12090 06:33:12,540 --> 06:33:13,540 useful for automatically positioning all 12091 06:33:14,400 --> 06:33:15,400 of the challenge objects now if we want 12092 06:33:16,378 --> 06:33:17,378 we can play around all of these we can 12093 06:33:17,820 --> 06:33:18,820 add a little bit of spacing on the XR on 12094 06:33:19,680 --> 06:33:20,680 the Y but let's actually leave both 12095 06:33:21,780 --> 06:33:22,780 those with zero let's leave everything 12096 06:33:23,820 --> 06:33:24,820 on defaults just over here on the 12097 06:33:25,378 --> 06:33:26,378 channel alignment let's put it on middle 12098 06:33:26,940 --> 06:33:27,940 Center okay so there you go that looks 12099 06:33:29,280 --> 06:33:30,280 pretty nice so you can see how this 12100 06:33:31,020 --> 06:33:32,020 built-in component is super useful 12101 06:33:32,638 --> 06:33:33,638 there's actually two more so this one 12102 06:33:34,980 --> 06:33:35,980 for the grid layout this is great when 12103 06:33:36,780 --> 06:33:37,780 you want to put things horizontally and 12104 06:33:38,458 --> 06:33:39,458 vertically 12105 06:33:39,540 --> 06:33:40,540 but if you just want horizontally then 12106 06:33:41,580 --> 06:33:42,580 there is the horizontal layout group and 12107 06:33:43,798 --> 06:33:44,798 if you just want vertically there's the 12108 06:33:45,180 --> 06:33:46,180 vertical layout group so all of these 12109 06:33:47,218 --> 06:33:48,218 components are really awesome really 12110 06:33:48,540 --> 06:33:49,540 useful okay so with this our objects are 12111 06:33:51,180 --> 06:33:52,180 placed and note how I named this an icon 12112 06:33:53,940 --> 06:33:54,940 template basically a template is just 12113 06:33:56,340 --> 06:33:57,340 what I call something that is kind of 12114 06:33:58,020 --> 06:33:59,020 like a prefab but not really a prefab 12115 06:33:59,820 --> 06:34:00,820 through code we're going to duplicate 12116 06:34:02,218 --> 06:34:03,218 this template and dynamically modify the 12117 06:34:04,020 --> 06:34:05,020 icon so we're going to use it very much 12118 06:34:06,000 --> 06:34:07,000 like a prefab 12119 06:34:07,200 --> 06:34:08,200 we could actually make this into a 12120 06:34:09,360 --> 06:34:10,360 proper prefab so I could just drag it 12121 06:34:11,100 --> 06:34:12,100 over here onto the project files and 12122 06:34:12,600 --> 06:34:13,600 make a regular prefab that could work 12123 06:34:14,940 --> 06:34:15,940 and the only reason why I prefer this 12124 06:34:17,040 --> 06:34:18,040 method of not using a prefab 12125 06:34:19,320 --> 06:34:20,320 he's just because this object this 12126 06:34:21,480 --> 06:34:22,480 template stays here on the object as 12127 06:34:23,280 --> 06:34:24,280 opposed to cluttering over here your 12128 06:34:24,600 --> 06:34:25,600 project files if you have tons of 12129 06:34:26,820 --> 06:34:27,820 single-use UI elements with tons of 12130 06:34:28,620 --> 06:34:29,620 objects you need to spawn you can end up 12131 06:34:30,298 --> 06:34:31,298 with tons and tons of prefabs and you 12132 06:34:32,218 --> 06:34:33,218 might not even know where each of those 12133 06:34:33,540 --> 06:34:34,540 is used whereas with this method the 12134 06:34:35,700 --> 06:34:36,700 template says exactly where it's used 12135 06:34:37,320 --> 06:34:38,320 and does not take an asset slot over 12136 06:34:39,420 --> 06:34:40,420 here on the project files so personally 12137 06:34:41,340 --> 06:34:42,340 this is just approach that I prefer for 12138 06:34:43,320 --> 06:34:44,320 spawning UI elements but like I said 12139 06:34:45,540 --> 06:34:46,540 prefabs work as well so if you prefer 12140 06:34:47,458 --> 06:34:48,458 using prefabs go ahead and make it okay 12141 06:34:49,798 --> 06:34:50,798 so let's make our script to run the 12142 06:34:51,660 --> 06:34:52,660 plate icons UI so let's go into our 12143 06:34:54,360 --> 06:34:55,360 scripts and on the scripts folder let's 12144 06:34:56,638 --> 06:34:57,638 create a brand new c-sharp script for 12145 06:34:58,138 --> 06:34:59,138 the plate icons UI over here let's 12146 06:35:00,480 --> 06:35:01,480 attach a script and open it okay so now 12147 06:35:02,940 --> 06:35:03,940 the first thing we need is a reference 12148 06:35:04,620 --> 06:35:05,620 to our plate 12149 06:35:06,000 --> 06:35:07,000 so let's begin by making a serialized 12150 06:35:07,980 --> 06:35:08,980 film private for the played kitchen 12151 06:35:09,718 --> 06:35:10,718 object for our play kitchen object 12152 06:35:13,138 --> 06:35:14,138 okay let's save it and drag the 12153 06:35:14,760 --> 06:35:15,760 reference so over here there's the point 12154 06:35:16,620 --> 06:35:17,620 icons let's just drag the plate 12155 06:35:18,180 --> 06:35:19,180 reference okay great now on the plate we 12156 06:35:20,400 --> 06:35:21,400 already made this event when an 12157 06:35:22,080 --> 06:35:23,080 ingredient is added so basically we just 12158 06:35:24,420 --> 06:35:25,420 need to listen to this in order to add 12159 06:35:25,920 --> 06:35:26,920 the new icon so over here on the UI 12160 06:35:28,080 --> 06:35:29,080 let's do as usual private void start and 12161 06:35:30,360 --> 06:35:31,360 on start let's go into the Plate Kitchen 12162 06:35:31,920 --> 06:35:32,920 object and listen to that event 12163 06:35:34,260 --> 06:35:35,260 and when that happens let's spawn an 12164 06:35:36,058 --> 06:35:37,058 icon although here let's actually use a 12165 06:35:38,160 --> 06:35:39,160 different method from the one we used on 12166 06:35:39,780 --> 06:35:40,780 the plaint visual over here on the plate 12167 06:35:42,058 --> 06:35:43,058 visual whenever we had the event we 12168 06:35:44,458 --> 06:35:45,458 really just modified the object that was 12169 06:35:46,260 --> 06:35:47,260 added so over here the equivalent would 12170 06:35:48,360 --> 06:35:49,360 be to spawn a new icon whenever that one 12171 06:35:50,580 --> 06:35:51,580 was added but instead of doing that 12172 06:35:52,620 --> 06:35:53,620 right now let's listen to this event and 12173 06:35:54,660 --> 06:35:55,660 when this happens let's update all the 12174 06:35:56,458 --> 06:35:57,458 icons in this display basically this 12175 06:35:58,558 --> 06:35:59,558 other method is useful when the contents 12176 06:36:00,360 --> 06:36:01,360 can be added as well as removed now in 12177 06:36:02,580 --> 06:36:03,580 this case they are never going to be 12178 06:36:03,718 --> 06:36:04,718 removed so in this case both methods 12179 06:36:05,458 --> 06:36:06,458 were fine but still I want to show you 12180 06:36:07,200 --> 06:36:08,200 the second method just so you can use it 12181 06:36:08,878 --> 06:36:09,878 when you need it so for that method we 12182 06:36:10,798 --> 06:36:11,798 just need to know exactly what is on the 12183 06:36:12,298 --> 06:36:13,298 plate so over here on the Plate Kitchen 12184 06:36:14,340 --> 06:36:15,340 object we just need to expose the 12185 06:36:16,080 --> 06:36:17,080 kitchen object as some list so let's do 12186 06:36:18,000 --> 06:36:19,000 example that so fun week we're going to 12187 06:36:19,860 --> 06:36:20,860 return a list of kitchen object SL 12188 06:36:23,160 --> 06:36:24,160 let's go and look get the kitchen object 12189 06:36:24,958 --> 06:36:25,958 the sewn list and we just return the 12190 06:36:27,480 --> 06:36:28,480 kitchen object that's always okay very 12191 06:36:29,160 --> 06:36:30,160 soon then over here on the planet icons 12192 06:36:31,200 --> 06:36:32,200 UI let's just make a function to update 12193 06:36:33,240 --> 06:36:34,240 the visuals so private Droid let's call 12194 06:36:35,700 --> 06:36:36,700 it update visual 12195 06:36:38,940 --> 06:36:39,940 and when we have the event let's call 12196 06:36:41,100 --> 06:36:42,100 our update visual okay 12197 06:36:43,740 --> 06:36:44,740 so now here let's basically just cycle 12198 06:36:46,500 --> 06:36:47,500 through all the ingredients so let's do 12199 06:36:48,240 --> 06:36:49,240 a 40 inch kitchen object so in the plate 12200 06:36:52,320 --> 06:36:53,320 and get the kitchen object the sewn list 12201 06:36:54,780 --> 06:36:55,780 okay so we're cycling through all the 12202 06:36:57,000 --> 06:36:58,000 ingredients on the plate and then we 12203 06:36:59,340 --> 06:37:00,340 want to duplicate our template so that 12204 06:37:01,138 --> 06:37:02,138 means we need a reference up here so 12205 06:37:02,520 --> 06:37:03,520 let's add a serialized film private type 12206 06:37:04,980 --> 06:37:05,980 transform complete the icon template 12207 06:37:07,260 --> 06:37:08,260 okay and let's save the code 12208 06:37:09,600 --> 06:37:10,600 and over here in the editor let's drag 12209 06:37:11,400 --> 06:37:12,400 the reference so let's drag the icon 12210 06:37:13,020 --> 06:37:14,020 template by the way I'll have the others 12211 06:37:14,760 --> 06:37:15,760 over here that's not a problem since 12212 06:37:16,500 --> 06:37:17,500 these are going to be destroyed those 12213 06:37:17,700 --> 06:37:18,700 we're going to see in a little bit the 12214 06:37:19,620 --> 06:37:20,620 only one that matters is the first one 12215 06:37:20,940 --> 06:37:21,940 okay so here we have the icon template 12216 06:37:23,218 --> 06:37:24,218 so to spawn it we do it just like we do 12217 06:37:25,500 --> 06:37:26,500 with any preform so we just call 12218 06:37:27,480 --> 06:37:28,480 instantiate pass in the icon template 12219 06:37:30,840 --> 06:37:31,840 and then transform parents so let's put 12220 06:37:32,638 --> 06:37:33,638 it as a child of this object this part 12221 06:37:34,920 --> 06:37:35,920 is important we need to make sure the 12222 06:37:37,080 --> 06:37:38,080 object is spawned as a child of this 12223 06:37:38,638 --> 06:37:39,638 object if over here you put something 12224 06:37:40,440 --> 06:37:41,440 like no then the template won't be 12225 06:37:42,480 --> 06:37:43,480 spawned as a mobile object so it won't 12226 06:37:44,340 --> 06:37:45,340 be somewhere in the world so in order to 12227 06:37:46,558 --> 06:37:47,558 make it positioned properly let's make 12228 06:37:48,058 --> 06:37:49,058 sure to use transform to become a child 12229 06:37:49,798 --> 06:37:50,798 of this object okay and then since we're 12230 06:37:52,200 --> 06:37:53,200 using the other script the green layout 12231 06:37:55,080 --> 06:37:56,080 group this is already going to be 12232 06:37:56,820 --> 06:37:57,820 automatically positioned so just like 12233 06:37:58,920 --> 06:37:59,920 this it should be spawning the icon and 12234 06:38:01,320 --> 06:38:02,320 with the icon spawned all that's left is 12235 06:38:03,000 --> 06:38:04,000 really just setting the image and now 12236 06:38:04,980 --> 06:38:05,980 again the quick and dirty approach would 12237 06:38:06,600 --> 06:38:07,600 be over here when we spawn let's say we 12238 06:38:08,820 --> 06:38:09,820 pick up the item transform 12239 06:38:11,520 --> 06:38:12,520 and over here we could go inside and do 12240 06:38:13,680 --> 06:38:14,680 a find in order to find the image in 12241 06:38:16,680 --> 06:38:17,680 order to get the component of Type image 12242 06:38:18,420 --> 06:38:19,420 and so on so that is one approach that 12243 06:38:20,940 --> 06:38:21,940 would be the quick and dairy approach 12244 06:38:22,440 --> 06:38:23,440 but again we want to do things properly 12245 06:38:24,298 --> 06:38:25,298 so let's do it the proper way instead so 12246 06:38:26,340 --> 06:38:27,340 instead of this 12247 06:38:27,600 --> 06:38:28,600 let's make a proper script that we're 12248 06:38:29,280 --> 06:38:30,280 going to run on the icon template so 12249 06:38:31,378 --> 06:38:32,378 let's create a new script so a new 12250 06:38:33,120 --> 06:38:34,120 c-sharp script come with the plate icon 12251 06:38:35,760 --> 06:38:36,760 single UI so this one represents just a 12252 06:38:38,820 --> 06:38:39,820 single icon let's go ahead and attach it 12253 06:38:41,580 --> 06:38:42,580 to the template so over here let's drag 12254 06:38:43,740 --> 06:38:44,740 it and now when using this template 12255 06:38:45,540 --> 06:38:46,540 method really the only one we need to 12256 06:38:47,638 --> 06:38:48,638 worry about is this one the other 12257 06:38:49,260 --> 06:38:50,260 duplicates we can just leave them they 12258 06:38:51,000 --> 06:38:52,000 don't really matter but don't just 12259 06:38:52,740 --> 06:38:53,740 avoiding confusion I'm actually going to 12260 06:38:54,480 --> 06:38:55,480 delete them it's okay we just have one 12261 06:38:56,638 --> 06:38:57,638 icon template okay and it has our script 12262 06:38:58,500 --> 06:38:59,500 okay let's open now over here let's 12263 06:39:00,600 --> 06:39:01,600 basically just make a function to set a 12264 06:39:02,458 --> 06:39:03,458 kitchen object or so so public void 12265 06:39:04,558 --> 06:39:05,558 let's go on set kitchen object so 12266 06:39:10,260 --> 06:39:11,260 we receive parameter of type kitchen 12267 06:39:12,360 --> 06:39:13,360 object that so okay great so then we 12268 06:39:14,878 --> 06:39:15,878 need to set the image so let's just go 12269 06:39:17,160 --> 06:39:18,160 into a serialized film private of Type 12270 06:39:19,378 --> 06:39:20,378 image which is inside the unity 12271 06:39:21,058 --> 06:39:22,058 engine.ui 12272 06:39:22,680 --> 06:39:23,680 so for this one for the image we have a 12273 06:39:24,780 --> 06:39:25,780 reference and then we set the 12274 06:39:26,218 --> 06:39:27,218 image.sprite go into the kitchen object 12275 06:39:28,558 --> 06:39:29,558 and grab the Sprites 12276 06:39:30,718 --> 06:39:31,718 okay so we need to do is drag this 12277 06:39:32,580 --> 06:39:33,580 reference so over here in our template 12278 06:39:34,620 --> 06:39:35,620 let's drag the icon image okay great so 12279 06:39:37,378 --> 06:39:38,378 now back here on the plate icon Ty so we 12280 06:39:39,480 --> 06:39:40,480 spawn it that's great then let's we get 12281 06:39:41,638 --> 06:39:42,638 component in order to get our script 12282 06:39:44,458 --> 06:39:45,458 so the plate icon signal UI okay and 12283 06:39:47,700 --> 06:39:48,700 then we just call set kitchen object so 12284 06:39:49,680 --> 06:39:50,680 and pass in this okay that's great this 12285 06:39:52,860 --> 06:39:53,860 is much better now again you might be 12286 06:39:55,020 --> 06:39:56,020 thinking that this method is a lot more 12287 06:39:56,580 --> 06:39:57,580 verbose than just setting the image 12288 06:39:58,020 --> 06:39:59,020 Sprite here we had to create another 12289 06:40:00,420 --> 06:40:01,420 completely new script we had to write 12290 06:40:02,820 --> 06:40:03,820 this logic and over here get it and use 12291 06:40:04,558 --> 06:40:05,558 it the quick and dirty approach would 12292 06:40:06,540 --> 06:40:07,540 indeed be quicker but remember that 12293 06:40:08,580 --> 06:40:09,580 while the equationary approach might be 12294 06:40:10,440 --> 06:40:11,440 faster at first it will mess you up over 12295 06:40:12,298 --> 06:40:13,298 time so just take a few extra seconds to 12296 06:40:14,878 --> 06:40:15,878 do things properly this approach is much 12297 06:40:16,980 --> 06:40:17,980 more scalable let's say for example on 12298 06:40:19,378 --> 06:40:20,378 this function you want to change not 12299 06:40:20,940 --> 06:40:21,940 just Sprite but also trigger some kind 12300 06:40:22,680 --> 06:40:23,680 of Spawn effect or animation with this 12301 06:40:24,718 --> 06:40:25,718 it's very simple we've got this function 12302 06:40:26,400 --> 06:40:27,400 right here we receive the kitchen object 12303 06:40:27,958 --> 06:40:28,958 of so and we can do whatever we want 12304 06:40:29,638 --> 06:40:30,638 with it so like this we have this grip 12305 06:40:31,798 --> 06:40:32,798 that is responsible for anything related 12306 06:40:33,900 --> 06:40:34,900 to the single template and if you've got 12307 06:40:36,420 --> 06:40:37,420 the general one which just spawns him 12308 06:40:38,100 --> 06:40:39,100 and just gives them the kitchen object 12309 06:40:39,540 --> 06:40:40,540 so so all of our logic is nicely 12310 06:40:41,760 --> 06:40:42,760 separate okay so just like this it 12311 06:40:44,100 --> 06:40:45,100 should already work however like this 12312 06:40:46,138 --> 06:40:47,138 you might already be thinking want to 12313 06:40:47,700 --> 06:40:48,700 spawn way too many icons and yep it will 12314 06:40:50,040 --> 06:40:51,040 basically every time we add an 12315 06:40:51,660 --> 06:40:52,660 ingredient we're updating the visual 12316 06:40:53,160 --> 06:40:54,160 where we're cycling through every single 12317 06:40:54,900 --> 06:40:55,900 one and spawning all of them so with 12318 06:40:57,120 --> 06:40:58,120 this we're constantly going to spawn 12319 06:40:58,378 --> 06:40:59,378 more and more items this is not what we 12320 06:41:00,840 --> 06:41:01,840 want over here on the update visual we 12321 06:41:02,580 --> 06:41:03,580 do want to update and spawn all of the 12322 06:41:04,260 --> 06:41:05,260 icons but before we do that we actually 12323 06:41:06,298 --> 06:41:07,298 need to clean it up we need to clean up 12324 06:41:08,458 --> 06:41:09,458 the icons from the previous event 12325 06:41:10,378 --> 06:41:11,378 so before we do that let's just cycle 12326 06:41:12,360 --> 06:41:13,360 through all the children on this 12327 06:41:13,798 --> 06:41:14,798 transform so that's pretty simple you 12328 06:41:15,660 --> 06:41:16,660 can just do a for each transformed child 12329 06:41:17,580 --> 06:41:18,580 in the transform 12330 06:41:19,798 --> 06:41:20,798 so this way Cycles through all the 12331 06:41:22,200 --> 06:41:23,200 children and then just call destroy on 12332 06:41:24,900 --> 06:41:25,900 this channel that game object so that 12333 06:41:27,058 --> 06:41:28,058 won't work that won't destroy all of the 12334 06:41:28,620 --> 06:41:29,620 previous children however of course we 12335 06:41:30,718 --> 06:41:31,718 also have one issue the icon template 12336 06:41:33,298 --> 06:41:34,298 itself is also a child 12337 06:41:35,340 --> 06:41:36,340 so if we do this we're going to destroy 12338 06:41:37,080 --> 06:41:38,080 the icon template which then over here 12339 06:41:38,820 --> 06:41:39,820 we're going to have an error because 12340 06:41:40,020 --> 06:41:41,020 we're going to instantiate no so we want 12341 06:41:42,298 --> 06:41:43,298 to destroy all the children except for 12342 06:41:44,520 --> 06:41:45,520 the template so over here that's pretty 12343 06:41:46,620 --> 06:41:47,620 simple we just check if the child equals 12344 06:41:49,080 --> 06:41:50,080 the icon template if so then let's just 12345 06:41:51,600 --> 06:41:52,600 skip it so we can just call continue and 12346 06:41:53,940 --> 06:41:54,940 there you go it skips 12347 06:41:55,440 --> 06:41:56,440 okay great so just one more final thing 12348 06:41:59,458 --> 06:42:00,458 if we leave the template like this 12349 06:42:01,260 --> 06:42:02,260 meaning the game object is enabled like 12350 06:42:03,780 --> 06:42:04,780 this the template will always be visible 12351 06:42:05,580 --> 06:42:06,580 plus whatever ingredients we have we 12352 06:42:07,920 --> 06:42:08,920 don't really want the template to be 12353 06:42:09,420 --> 06:42:10,420 visible this is just meant to be a 12354 06:42:11,280 --> 06:42:12,280 template that we can instantiate so 12355 06:42:13,200 --> 06:42:14,200 that's pretty simple to fix let's make a 12356 06:42:15,240 --> 06:42:16,240 private void awake and on a week let's 12357 06:42:17,100 --> 06:42:18,100 grab the icon template grab the game 12358 06:42:19,200 --> 06:42:20,200 object set active into false okay so now 12359 06:42:22,558 --> 06:42:23,558 the icon template won't be disabled so 12360 06:42:24,240 --> 06:42:25,240 it won't be visible and then over here 12361 06:42:26,458 --> 06:42:27,458 when we are instantiating the 12362 06:42:27,840 --> 06:42:28,840 instantiated ones will also be disabled 12363 06:42:29,700 --> 06:42:30,700 so let's make sure we go in there and 12364 06:42:32,218 --> 06:42:33,218 enable these all right that should do it 12365 06:42:34,558 --> 06:42:35,558 so all of our logic should be working 12366 06:42:36,420 --> 06:42:37,420 there's only one more tiny thing we need 12367 06:42:38,638 --> 06:42:39,638 to take care of this one is a world 12368 06:42:40,860 --> 06:42:41,860 canvas so like we saw with the progress 12369 06:42:42,900 --> 06:42:43,900 bar we need extra logic to make it look 12370 06:42:45,058 --> 06:42:46,058 towards the camera and thankfully we 12371 06:42:47,100 --> 06:42:48,100 already wrote an excellent generic 12372 06:42:48,600 --> 06:42:49,600 script to do just that so let's go into 12373 06:42:50,700 --> 06:42:51,700 the point icons UI and let's add a 12374 06:42:53,040 --> 06:42:54,040 component and let's add our very nice 12375 06:42:54,900 --> 06:42:55,900 look at camera something like this and 12376 06:42:57,240 --> 06:42:58,240 let's set the mode the same that we use 12377 06:42:58,798 --> 06:42:59,798 so let's put it camera.org okay so 12378 06:43:00,780 --> 06:43:01,780 everything is great everything should be 12379 06:43:02,160 --> 06:43:03,160 perfect so let's finally test let's 12380 06:43:03,840 --> 06:43:04,840 leave the scene save the prefab and hit 12381 06:43:05,760 --> 06:43:06,760 on play all right so let's go pick up a 12382 06:43:08,340 --> 06:43:09,340 plate and there you go there are no 12383 06:43:09,718 --> 06:43:10,718 icons visible okay that's great now I'm 12384 06:43:11,520 --> 06:43:12,520 going to place a bread on top of the 12385 06:43:13,320 --> 06:43:14,320 plate and there you go I've got a nice 12386 06:43:14,940 --> 06:43:15,940 bright icon okay great now let's make 12387 06:43:17,280 --> 06:43:18,280 some meat cook it and as soon as it's 12388 06:43:19,680 --> 06:43:20,680 done going to pick it up and there you 12389 06:43:21,240 --> 06:43:22,240 go I've got a bread and some meat now 12390 06:43:23,638 --> 06:43:24,638 let's put some cheese slice it put it 12391 06:43:25,440 --> 06:43:26,440 there and there you go now I can easily 12392 06:43:27,058 --> 06:43:28,058 see that plate has some bread some meat 12393 06:43:29,100 --> 06:43:30,100 and some cheese now let's just add the 12394 06:43:31,020 --> 06:43:32,020 rest of the ingredients to make a foam 12395 06:43:32,760 --> 06:43:33,760 Mega Burger so let's add some tomatoes 12396 06:43:34,740 --> 06:43:35,740 and add some nice cabbage slices any of 12397 06:43:38,160 --> 06:43:39,160 there you go it works perfectly so here 12398 06:43:40,558 --> 06:43:41,558 we have a complete burger with 12399 06:43:42,000 --> 06:43:43,000 everything and we can easily see on the 12400 06:43:43,680 --> 06:43:44,680 icons everything this contains alright 12401 06:43:46,080 --> 06:43:47,080 awesome 12402 06:43:47,280 --> 06:43:48,280 okay so here you'll learn how to make 12403 06:43:49,378 --> 06:43:50,378 yet another Super useful element that 12404 06:43:51,240 --> 06:43:52,240 you can easily add to all of your games 12405 06:43:52,798 --> 06:43:53,798 personally I use this kind of logica ton 12406 06:43:55,260 --> 06:43:56,260 in all kinds of UI things for example in 12407 06:43:58,260 --> 06:43:59,260 my upcoming steam game total warm 12408 06:44:00,058 --> 06:44:01,058 Liberation the items in the inventory 12409 06:44:02,218 --> 06:44:03,218 they're all added using this method so 12410 06:44:04,740 --> 06:44:05,740 there's a template and I duplicate that 12411 06:44:06,480 --> 06:44:07,480 template same thing for all of the 12412 06:44:08,280 --> 06:44:09,280 action buttons all of those are based on 12413 06:44:10,320 --> 06:44:11,320 having a template and duplicating it 12414 06:44:12,120 --> 06:44:13,120 it's a really easy way to do this kind 12415 06:44:14,040 --> 06:44:15,040 of thing with all that here we have a 12416 06:44:16,080 --> 06:44:17,080 phone plate and we can easily see what 12417 06:44:17,820 --> 06:44:18,820 is on there so with this the next 12418 06:44:20,100 --> 06:44:21,100 obvious step is to actually deliver some 12419 06:44:21,840 --> 06:44:22,840 orders so let's do that in the next 12420 06:44:23,638 --> 06:44:24,638 lecture 12421 06:44:25,200 --> 06:44:26,200 hello and welcome I'm your code monkey 12422 06:44:27,058 --> 06:44:28,058 in this lecture we're going to build the 12423 06:44:28,980 --> 06:44:29,980 delivery counter this is where we're 12424 06:44:30,660 --> 06:44:31,660 going to drop some items that the 12425 06:44:32,160 --> 06:44:33,160 customers have requested in order to 12426 06:44:33,540 --> 06:44:34,540 complete the orders also just for fun 12427 06:44:35,878 --> 06:44:36,878 we're going to learn how to use Shader 12428 06:44:37,378 --> 06:44:38,378 graph to make a simple custom Shader 12429 06:44:39,180 --> 06:44:40,180 okay so let's begin by making our 12430 06:44:41,280 --> 06:44:42,280 counter so let's go into our base 12431 06:44:43,558 --> 06:44:44,558 counter let's create a new prefab 12432 06:44:45,180 --> 06:44:46,180 variant for the delivery counter let's 12433 06:44:48,480 --> 06:44:49,480 go inside and now let's find the visual 12434 06:44:50,940 --> 06:44:51,940 the visual for delivery counter let's 12435 06:44:53,638 --> 06:44:54,638 duplicate it to make the selecting let's 12436 06:44:56,458 --> 06:44:57,458 go inside modify the material then on 12437 06:45:00,000 --> 06:45:01,000 the selected make it one percent bigger 12438 06:45:01,920 --> 06:45:02,920 one zero one add the component the 12439 06:45:04,378 --> 06:45:05,378 selected counter visual let's drag the 12440 06:45:06,420 --> 06:45:07,420 kitchen counter like that okay that's 12441 06:45:08,520 --> 06:45:09,520 our basic setup and also start with the 12442 06:45:10,980 --> 06:45:11,980 kitchen count disable okay great now 12443 06:45:13,378 --> 06:45:14,378 let's make a script to run this so let's 12444 06:45:15,298 --> 06:45:16,298 go into our counters folder and let's 12445 06:45:16,980 --> 06:45:17,980 create a brand new c-sharp script for 12446 06:45:19,320 --> 06:45:20,320 the delivery counter let's attach it and 12447 06:45:22,138 --> 06:45:23,138 open okay so now here as usual let's 12448 06:45:24,660 --> 06:45:25,660 begin by extending our base counter 12449 06:45:27,180 --> 06:45:28,180 class all right now let's override the 12450 06:45:30,540 --> 06:45:31,540 interact function 12451 06:45:32,400 --> 06:45:33,400 and for now let's actually do it it's 12452 06:45:33,958 --> 06:45:34,958 not like the trash counter meaning let's 12453 06:45:35,638 --> 06:45:36,638 just destroy the object so we just check 12454 06:45:38,040 --> 06:45:39,040 if the player is holding something so if 12455 06:45:40,138 --> 06:45:41,138 the player has a catch an object let's 12456 06:45:42,718 --> 06:45:43,718 go into the player the kitchen object 12457 06:45:44,280 --> 06:45:45,280 then let's destroy it 12458 06:45:45,780 --> 06:45:46,780 however another room over here for an 12459 06:45:47,700 --> 06:45:48,700 Oliver counter is this is only going to 12460 06:45:49,320 --> 06:45:50,320 accept plates so let's see if the player 12461 06:45:51,600 --> 06:45:52,600 is carrying a plate object so player get 12462 06:45:54,298 --> 06:45:55,298 kitchen object and test try to get the 12463 06:45:57,120 --> 06:45:58,120 plate so out played kitchen object for 12464 06:45:59,940 --> 06:46:00,940 the Plate Kitchen object 12465 06:46:02,040 --> 06:46:03,040 we try to get this and if it is a point 12466 06:46:04,200 --> 06:46:05,200 then we destroy it 12467 06:46:08,100 --> 06:46:09,100 okay that's it here in the editor let's 12468 06:46:10,920 --> 06:46:11,920 just compound the script and drag the 12469 06:46:12,360 --> 06:46:13,360 references so the countertop point and 12470 06:46:14,520 --> 06:46:15,520 on the selected let's drag the counter 12471 06:46:16,740 --> 06:46:17,740 reference and let's exit this save the 12472 06:46:18,900 --> 06:46:19,900 prefab and let's drop it over here on 12473 06:46:21,058 --> 06:46:22,058 the corner so let's find over here the 12474 06:46:23,458 --> 06:46:24,458 delivery counter and let's put it over 12475 06:46:24,958 --> 06:46:25,958 there hang on it on this side put it 12476 06:46:27,660 --> 06:46:28,660 like this let's also just quickly 12477 06:46:29,760 --> 06:46:30,760 reposition all of our counters since we 12478 06:46:31,680 --> 06:46:32,680 already have all the types that we're 12479 06:46:33,120 --> 06:46:34,120 going to use so on the lever counter 12480 06:46:34,978 --> 06:46:35,978 let's put it over here on this corner so 12481 06:46:36,540 --> 06:46:37,540 x 7.5 0 and Z of two then next to it 12482 06:46:40,320 --> 06:46:41,320 let's put the plates counter so over 12483 06:46:42,058 --> 06:46:43,058 there okay 12484 06:46:43,138 --> 06:46:44,138 then next week let's put a clear counter 12485 06:46:45,298 --> 06:46:46,298 after that let's put the trash counter 12486 06:46:48,000 --> 06:46:49,000 and then let's also put another empty 12487 06:46:49,620 --> 06:46:50,620 one there so let's duplicate this one 12488 06:46:51,840 --> 06:46:52,840 move it up to about this and put it like 12489 06:46:54,120 --> 06:46:55,120 that now we just need to move all of 12490 06:46:55,978 --> 06:46:56,978 these down here so just select all of 12491 06:46:58,320 --> 06:46:59,320 these counters and let's move them down 12492 06:47:00,740 --> 06:47:01,740 by about this okay so on minus 5.5 like 12493 06:47:04,740 --> 06:47:05,740 this okay so everything is nicely 12494 06:47:06,840 --> 06:47:07,840 positioned just over there right now we 12495 06:47:09,058 --> 06:47:10,058 cannot access that container so let's 12496 06:47:10,558 --> 06:47:11,558 actually modify those as well which by 12497 06:47:12,780 --> 06:47:13,780 the way over here there's the canvas in 12498 06:47:14,638 --> 06:47:15,638 front so as I click I'm actually 12499 06:47:15,900 --> 06:47:16,900 selecting the canvas in the hierarchy so 12500 06:47:18,120 --> 06:47:19,120 here's a quick empty tab on the 12501 06:47:19,798 --> 06:47:20,798 hierarchy on the left side you've got 12502 06:47:21,120 --> 06:47:22,120 these two buttons so one of them hides 12503 06:47:22,978 --> 06:47:23,978 the object and the other one simply 12504 06:47:24,240 --> 06:47:25,240 makes it unselectable so if I click on 12505 06:47:26,400 --> 06:47:27,400 this and I click through any of the 12506 06:47:27,840 --> 06:47:28,840 click goes through the canvas so that 12507 06:47:29,400 --> 06:47:30,400 makes it much easier to select over here 12508 06:47:31,200 --> 06:47:32,200 on the items in our scene so let you 12509 06:47:33,840 --> 06:47:34,840 select all of these okay all of these 12510 06:47:36,420 --> 06:47:37,420 now just push them all to the side and 12511 06:47:39,360 --> 06:47:40,360 make another empty one and put it over 12512 06:47:40,978 --> 06:47:41,978 here okay that's a nice layout now let's 12513 06:47:43,080 --> 06:47:44,080 just finish the rest so over here let's 12514 06:47:45,120 --> 06:47:46,120 just duplicate our empty counters and 12515 06:47:47,218 --> 06:47:48,218 place a bunch more let's put one more to 12516 06:47:49,978 --> 06:47:50,978 the side 12517 06:47:50,878 --> 06:47:51,878 and now these ones over here so let's 12518 06:47:52,500 --> 06:47:53,500 put it over there and rotate it here 12519 06:47:54,958 --> 06:47:55,958 and duplicate another one and another 12520 06:47:57,120 --> 06:47:58,120 one 12521 06:47:58,080 --> 06:47:59,080 and another one and just one more and 12522 06:48:01,378 --> 06:48:02,378 get rid of this one okay great so here 12523 06:48:03,420 --> 06:48:04,420 we have pretty much our complete map 12524 06:48:04,978 --> 06:48:05,978 let's also just move the camera tiny 12525 06:48:07,320 --> 06:48:08,320 tiny bit just make sure that it is 12526 06:48:08,820 --> 06:48:09,820 nicely organized so put it over there 12527 06:48:11,160 --> 06:48:12,160 just so everything is nice and centered 12528 06:48:12,718 --> 06:48:13,718 okay so there's our map now let's get 12529 06:48:15,058 --> 06:48:16,058 back to working on our delivery counter 12530 06:48:16,740 --> 06:48:17,740 we already added this code so let's just 12531 06:48:18,900 --> 06:48:19,900 quickly test so here we are and if I 12532 06:48:21,058 --> 06:48:22,058 pick up something like for example some 12533 06:48:22,260 --> 06:48:23,260 cheese go into the delivery counter and 12534 06:48:23,700 --> 06:48:24,700 interact and nope nothing happens 12535 06:48:25,080 --> 06:48:26,080 because that one only accepts plates now 12536 06:48:27,120 --> 06:48:28,120 if I pick up a plate go there don't wait 12537 06:48:28,860 --> 06:48:29,860 for any of there you go it does work 12538 06:48:30,000 --> 06:48:31,000 okay great so this is the basic logic 12539 06:48:32,700 --> 06:48:33,700 that we want 12540 06:48:33,660 --> 06:48:34,660 for defining the actual recipe and logic 12541 06:48:35,638 --> 06:48:36,638 we're actually only going to do that in 12542 06:48:36,900 --> 06:48:37,900 the next lecture but for now let's add 12543 06:48:38,700 --> 06:48:39,700 one more nice thing let's add a simple 12544 06:48:40,620 --> 06:48:41,620 custom visual over here using Shader 12545 06:48:42,840 --> 06:48:43,840 graph this is a great way for you to 12546 06:48:44,520 --> 06:48:45,520 learn the pottery of Shader graph and 12547 06:48:45,958 --> 06:48:46,958 just how easy it is to use this is a 12548 06:48:48,000 --> 06:48:49,000 visual tool for making shaders it's 12549 06:48:49,620 --> 06:48:50,620 really very easy personally I don't know 12550 06:48:52,200 --> 06:48:53,200 how to write shaders with code but I can 12551 06:48:53,878 --> 06:48:54,878 build some pretty nice things using 12552 06:48:55,200 --> 06:48:56,200 Shadow graph as usual I have a dedicated 12553 06:48:57,660 --> 06:48:58,660 video on it I also have an entire 12554 06:48:59,638 --> 06:49:00,638 playlist showcasing how to make all 12555 06:49:01,260 --> 06:49:02,260 kinds of interesting effects and even 12556 06:49:03,180 --> 06:49:04,180 one special video covering some changes 12557 06:49:05,040 --> 06:49:06,040 in recent shareware versions so over 12558 06:49:07,138 --> 06:49:08,138 here let's learn the basics how to use 12559 06:49:08,638 --> 06:49:09,638 it so first here in our project window 12560 06:49:10,740 --> 06:49:11,740 let's create a brand new folder let's 12561 06:49:12,840 --> 06:49:13,840 name it just shaders and now inside 12562 06:49:15,120 --> 06:49:16,120 let's create one so let's create then go 12563 06:49:17,878 --> 06:49:18,878 up here into sheet graph then we're 12564 06:49:19,860 --> 06:49:20,860 using urp so let's go inside there and 12565 06:49:22,138 --> 06:49:23,138 here we've got a bunch of options now 12566 06:49:24,298 --> 06:49:25,298 don't worry about picking the quote 12567 06:49:25,798 --> 06:49:26,798 unquote wrong option all this does is 12568 06:49:27,718 --> 06:49:28,718 just create a template so for example if 12569 06:49:29,820 --> 06:49:30,820 you accidentally create an unlit Shader 12570 06:49:31,500 --> 06:49:32,500 you can then easily swap it out from it 12571 06:49:33,058 --> 06:49:34,058 so right right now let's go with the 12572 06:49:34,860 --> 06:49:35,860 English hitter and for the name let's 12573 06:49:36,420 --> 06:49:37,420 name it moving visual 12574 06:49:38,160 --> 06:49:39,160 okay there's our shade Rafael now now 12575 06:49:40,620 --> 06:49:41,620 let's just double click to open it and 12576 06:49:42,660 --> 06:49:43,660 up here we have the nice shade graph 12577 06:49:44,218 --> 06:49:45,218 window by the way you can make this 12578 06:49:45,718 --> 06:49:46,718 phone screen so you can either right 12579 06:49:47,700 --> 06:49:48,700 click over there on the tab and maximize 12580 06:49:49,500 --> 06:49:50,500 or alternatively you can just click on 12581 06:49:51,660 --> 06:49:52,660 this window and then use the hotkey 12582 06:49:53,400 --> 06:49:54,400 shift space and if there you go it does 12583 06:49:55,798 --> 06:49:56,798 maximize okay great now by default we 12584 06:49:58,558 --> 06:49:59,558 have this down the center this is called 12585 06:49:59,940 --> 06:50:00,940 the master stack these are the actual 12586 06:50:02,218 --> 06:50:03,218 properties that we're going to need to 12587 06:50:03,478 --> 06:50:04,478 use then on the left side we have the 12588 06:50:06,000 --> 06:50:07,000 properties Blackboard on the right side 12589 06:50:08,280 --> 06:50:09,280 we've got the graph inspector and 12590 06:50:10,680 --> 06:50:11,680 finally down here we've got the main 12591 06:50:12,180 --> 06:50:13,180 preview all of these windows can be 12592 06:50:13,920 --> 06:50:14,920 scaled and also if you don't see these 12593 06:50:15,780 --> 06:50:16,780 windows or if you accidentally hide them 12594 06:50:17,820 --> 06:50:18,820 they're all appear on these three 12595 06:50:19,378 --> 06:50:20,378 buttons so the Blackboard that's on the 12596 06:50:21,000 --> 06:50:22,000 left the graph inspector and the main 12597 06:50:22,378 --> 06:50:23,378 preview okay so now here we've got a 12598 06:50:24,420 --> 06:50:25,420 nice empty board so we can add whatever 12599 06:50:25,978 --> 06:50:26,978 nodes we want so we can right click and 12600 06:50:28,500 --> 06:50:29,500 go into create node and then we can 12601 06:50:30,240 --> 06:50:31,240 write something or just click anywhere 12602 06:50:31,620 --> 06:50:32,620 and press on space and there you go now 12603 06:50:33,840 --> 06:50:34,840 we can cycle through and browse all of 12604 06:50:35,700 --> 06:50:36,700 these menus to see all of the nodes that 12605 06:50:37,440 --> 06:50:38,440 exist there's tons and tons of them or 12606 06:50:39,660 --> 06:50:40,660 alternatively just go up here and use 12607 06:50:41,218 --> 06:50:42,218 the search bar so for example let's find 12608 06:50:43,680 --> 06:50:44,680 the sample texture 2D node so here it is 12609 06:50:45,840 --> 06:50:46,840 this one okay we've got this node what 12610 06:50:48,540 --> 06:50:49,540 this one does is it takes a texture and 12611 06:50:51,120 --> 06:50:52,120 grabs the color from it so on the left 12612 06:50:53,218 --> 06:50:54,218 side of the node are the inputs and on 12613 06:50:54,780 --> 06:50:55,780 the right side are the outputs within 12614 06:50:57,298 --> 06:50:58,298 the parentheses you can actually see the 12615 06:50:58,798 --> 06:50:59,798 types so for the input texture this one 12616 06:51:00,840 --> 06:51:01,840 is of type T2 so that means it's a 12617 06:51:02,820 --> 06:51:03,820 textured 2D then on the output you can 12618 06:51:04,920 --> 06:51:05,920 see there's a 4 meaning it contains four 12619 06:51:06,780 --> 06:51:07,780 floats which in this case refers to the 12620 06:51:08,760 --> 06:51:09,760 four colors so that's red green blue and 12621 06:51:11,280 --> 06:51:12,280 Alpha so for an input we want a texture 12622 06:51:13,798 --> 06:51:14,798 so let's set it over here as a property 12623 06:51:15,478 --> 06:51:16,478 let's click on the plus icon and we've 12624 06:51:17,700 --> 06:51:18,700 got a whole bunch of types for texture 12625 06:51:20,218 --> 06:51:21,218 we want a textured 2D so let's go with 12626 06:51:21,900 --> 06:51:22,900 that and then for the name now usually 12627 06:51:24,058 --> 06:51:25,058 there are two standard names there's one 12628 06:51:26,160 --> 06:51:27,160 called main text or base map main tags 12629 06:51:29,280 --> 06:51:30,280 used to be the more common name but when 12630 06:51:31,378 --> 06:51:32,378 working with urp for some reason they 12631 06:51:33,180 --> 06:51:34,180 decided to name the main texture as base 12632 06:51:34,740 --> 06:51:35,740 map so we're here let's stick within the 12633 06:51:36,718 --> 06:51:37,718 urp standard and just call this basement 12634 06:51:38,520 --> 06:51:39,520 okay there's our property and if we 12635 06:51:40,680 --> 06:51:41,680 click the select it and on the right 12636 06:51:42,058 --> 06:51:43,058 side we can see the graph inspector and 12637 06:51:44,040 --> 06:51:45,040 we can see all the properties for this 12638 06:51:45,840 --> 06:51:46,840 Actron property so we see a name 12639 06:51:47,760 --> 06:51:48,760 reference and a bunch more things now 12640 06:51:49,378 --> 06:51:50,378 the really important one is over here 12641 06:51:51,120 --> 06:51:52,120 the reference this is the actual name 12642 06:51:53,218 --> 06:51:54,218 that you're going to use if you want to 12643 06:51:54,718 --> 06:51:55,718 interact with this Shader through code 12644 06:51:56,160 --> 06:51:57,160 the name on the property this one is 12645 06:51:58,080 --> 06:51:59,080 just a text ring so this can be whatever 12646 06:51:59,700 --> 06:52:00,700 you want you can even have spaces and so 12647 06:52:01,620 --> 06:52:02,620 on whereas the reference name this is 12648 06:52:03,718 --> 06:52:04,718 the really important one and by default 12649 06:52:05,638 --> 06:52:06,638 when you set up a name it should already 12650 06:52:07,558 --> 06:52:08,558 accept the correct reference usually the 12651 06:52:09,840 --> 06:52:10,840 standard is to name it just like the 12652 06:52:11,280 --> 06:52:12,280 name both without any spaces and with an 12653 06:52:13,500 --> 06:52:14,500 underscore in the beginning so just like 12654 06:52:15,000 --> 06:52:16,000 this okay then we can give it a default 12655 06:52:17,280 --> 06:52:18,280 texture so let's go ahead and select 12656 06:52:19,320 --> 06:52:20,320 something for example over here the 12657 06:52:20,700 --> 06:52:21,700 bread texture remember this is just the 12658 06:52:22,920 --> 06:52:23,920 default this will not be hard-coded 12659 06:52:25,558 --> 06:52:26,558 directly into the Shader we can then 12660 06:52:26,940 --> 06:52:27,940 modify this okay so we we have our nice 12661 06:52:29,100 --> 06:52:30,100 base map property definition now we can 12662 06:52:31,260 --> 06:52:32,260 just drag it over here on the board and 12663 06:52:32,760 --> 06:52:33,760 yep there it is and now we can just 12664 06:52:34,320 --> 06:52:35,320 click on the server icon in order to 12665 06:52:35,820 --> 06:52:36,820 drag a connection and let's connect it 12666 06:52:37,378 --> 06:52:38,378 over here onto the sample textures to 12667 06:52:39,120 --> 06:52:40,120 the input and yep right away we do see 12668 06:52:41,100 --> 06:52:42,100 it does work so we are correctly 12669 06:52:42,660 --> 06:52:43,660 sampling the texture however if you look 12670 06:52:45,058 --> 06:52:46,058 on the main preview over here there's 12671 06:52:46,620 --> 06:52:47,620 still nothing that's because we don't 12672 06:52:48,360 --> 06:52:49,360 have this node connect to anything we 12673 06:52:50,700 --> 06:52:51,700 need to connect it to the final Master 12674 06:52:52,260 --> 06:52:53,260 sack in order to render something so 12675 06:52:54,420 --> 06:52:55,420 again on the output over here we can see 12676 06:52:55,978 --> 06:52:56,978 a four so these are all of our colors 12677 06:52:57,958 --> 06:52:58,958 and actually one very useful node is the 12678 06:53:00,360 --> 06:53:01,360 preview since so many things in Shader 12679 06:53:02,400 --> 06:53:03,400 graph can be hard to visualize so we can 12680 06:53:05,160 --> 06:53:06,160 move these nodes around and let's add 12681 06:53:07,020 --> 06:53:08,020 the preview node 12682 06:53:08,520 --> 06:53:09,520 and this does examine that so you can 12683 06:53:10,260 --> 06:53:11,260 fit it an input and you can see down 12684 06:53:11,878 --> 06:53:12,878 here what that input contains so for 12685 06:53:14,280 --> 06:53:15,280 example let's drag just the red Channel 12686 06:53:16,080 --> 06:53:17,080 and if they go over there we can see the 12687 06:53:18,000 --> 06:53:19,000 red channel for this texture we can drag 12688 06:53:20,160 --> 06:53:21,160 the green channel the blue Channel or 12689 06:53:22,260 --> 06:53:23,260 look at the alpha Channel yep there you 12690 06:53:24,478 --> 06:53:25,478 go it does work so this preview node is 12691 06:53:26,580 --> 06:53:27,580 super useful for being able to see what 12692 06:53:28,500 --> 06:53:29,500 your Shader is actually doing over here 12693 06:53:30,900 --> 06:53:31,900 we have the colors so let's get rid of 12694 06:53:32,520 --> 06:53:33,520 the preview right now in order to make 12695 06:53:34,620 --> 06:53:35,620 it work we really just need to connect 12696 06:53:35,940 --> 06:53:36,940 the rgba and go up here into the base 12697 06:53:38,400 --> 06:53:39,400 color and right away it should work but 12698 06:53:41,100 --> 06:53:42,100 you might not be able to see anything 12699 06:53:42,600 --> 06:53:43,600 over here on the main preview 12700 06:53:44,218 --> 06:53:45,218 I believe this is a rendering bug in the 12701 06:53:46,558 --> 06:53:47,558 current Tech version so right now 12702 06:53:48,360 --> 06:53:49,360 nothing is shown 12703 06:53:49,620 --> 06:53:50,620 so if you still don't see anything it's 12704 06:53:51,058 --> 06:53:52,058 actually pretty simple just go up here 12705 06:53:52,740 --> 06:53:53,740 on the top left side and make sure to 12706 06:53:54,240 --> 06:53:55,240 save the ascent okay save it great then 12707 06:53:56,878 --> 06:53:57,878 let's exit from our maximize View and 12708 06:53:59,520 --> 06:54:00,520 now let's close this tab let's click on 12709 06:54:01,978 --> 06:54:02,978 play just to play the game now let's 12710 06:54:04,080 --> 06:54:05,080 stop playing and now if we open the 12711 06:54:06,120 --> 06:54:07,120 Shader again if there go now we do see 12712 06:54:08,340 --> 06:54:09,340 the Shader compiling over there that 12713 06:54:09,718 --> 06:54:10,718 color that is the Shader compilation and 12714 06:54:11,878 --> 06:54:12,878 after a little bit it should work let's 12715 06:54:13,440 --> 06:54:14,440 just maximize this 12716 06:54:14,820 --> 06:54:15,820 see if there you go there we do see our 12717 06:54:16,500 --> 06:54:17,500 texture okay great 12718 06:54:17,940 --> 06:54:18,940 so again it's just a simple rendering 12719 06:54:19,740 --> 06:54:20,740 plug on the current Tech version if 12720 06:54:21,420 --> 06:54:22,420 you're watching this video in the future 12721 06:54:22,620 --> 06:54:23,620 chances are you don't even have this box 12722 06:54:24,298 --> 06:54:25,298 so there's no need to worry okay so 12723 06:54:26,280 --> 06:54:27,280 right now we do see it working we can 12724 06:54:27,780 --> 06:54:28,780 see our bread texture and it's currently 12725 06:54:29,458 --> 06:54:30,458 being applied on a sphere for a use case 12726 06:54:31,978 --> 06:54:32,978 we're working with 2D textures so this 12727 06:54:34,200 --> 06:54:35,200 would be best to be seen on the Quan so 12728 06:54:35,940 --> 06:54:36,940 we can right click over here on the 12729 06:54:37,138 --> 06:54:38,138 preview in order to select the preview 12730 06:54:38,458 --> 06:54:39,458 mesh so let's go with a simple quad and 12731 06:54:40,558 --> 06:54:41,558 if there it is we have our Knight Squad 12732 06:54:42,058 --> 06:54:43,058 okay great 12733 06:54:43,440 --> 06:54:44,440 so over here we have our basic Shader 12734 06:54:45,660 --> 06:54:46,660 all it does is just shows the texture 12735 06:54:48,000 --> 06:54:49,000 that's it now it's actually use this and 12736 06:54:50,878 --> 06:54:51,878 first let's always make sure to save the 12737 06:54:52,798 --> 06:54:53,798 asset on the top left side on the moving 12738 06:54:55,320 --> 06:54:56,320 visual if you see an asterisk here that 12739 06:54:57,000 --> 06:54:58,000 means you have unsafe changes so always 12740 06:54:59,218 --> 06:55:00,218 make sure to save them in my case I 12741 06:55:01,020 --> 06:55:02,020 don't but still never hurts to save now 12742 06:55:03,120 --> 06:55:04,120 over here in scene view let's go inside 12743 06:55:04,860 --> 06:55:05,860 art only three counters and let's open 12744 06:55:06,360 --> 06:55:07,360 it and now for the display for our Arrow 12745 06:55:09,000 --> 06:55:10,000 let's make it a flat one so let's right 12746 06:55:11,580 --> 06:55:12,580 click in the hierarchy and let's create 12747 06:55:12,958 --> 06:55:13,958 a new 3D object and let's make it a quad 12748 06:55:15,298 --> 06:55:16,298 let's call this the delivery Arrow 12749 06:55:18,360 --> 06:55:19,360 let's place this on top of the counter 12750 06:55:20,160 --> 06:55:21,160 so let's rotate it to face upwards by 12751 06:55:22,558 --> 06:55:23,558 the way on the rotation make sure the 12752 06:55:24,120 --> 06:55:25,120 collar is facing upwards most shaders by 12753 06:55:26,340 --> 06:55:27,340 default they only render one face and 12754 06:55:28,378 --> 06:55:29,378 not the other one so make sure you put 12755 06:55:30,478 --> 06:55:31,478 the face with the collar upwards and not 12756 06:55:32,218 --> 06:55:33,218 the other one okay so let's rotate this 12757 06:55:33,900 --> 06:55:34,900 one upwards so there we go 90 over there 12758 06:55:36,780 --> 06:55:37,780 and let's just put it just exactly on 12759 06:55:38,940 --> 06:55:39,940 top of the counter so just enough so 12760 06:55:40,920 --> 06:55:41,920 that it's visible okay great so now 12761 06:55:43,200 --> 06:55:44,200 let's make a material for our Arrow so 12762 06:55:45,420 --> 06:55:46,420 let's go inside the materials folder and 12763 06:55:47,400 --> 06:55:48,400 over here let's create a brand new 12764 06:55:49,200 --> 06:55:50,200 material 12765 06:55:50,218 --> 06:55:51,218 let's call this the delivery Arrow let's 12766 06:55:52,920 --> 06:55:53,920 make sure to use this material on the 12767 06:55:54,360 --> 06:55:55,360 quad so let's just drag it over there on 12768 06:55:56,100 --> 06:55:57,100 the mesh render okay so it's using our 12769 06:55:57,958 --> 06:55:58,958 custom material and over here on this 12770 06:56:00,298 --> 06:56:01,298 Shader graph drop down menu over here we 12771 06:56:02,638 --> 06:56:03,638 can select what Shader we want to use so 12772 06:56:04,680 --> 06:56:05,680 in our case let's go inside the founder 12773 06:56:06,240 --> 06:56:07,240 Shader graphs and inside yep here we 12774 06:56:08,940 --> 06:56:09,940 have our moving visual Shader so let's 12775 06:56:11,040 --> 06:56:12,040 go ahead and use this and here right 12776 06:56:12,958 --> 06:56:13,958 away we do see that it does work here we 12777 06:56:15,058 --> 06:56:16,058 have our texture being drawn exactly on 12778 06:56:16,978 --> 06:56:17,978 top of our material okay so far so good 12779 06:56:19,860 --> 06:56:20,860 now again here remember one very very 12780 06:56:22,080 --> 06:56:23,080 important thing that I said the texture 12781 06:56:24,298 --> 06:56:25,298 that you define the Shader over here the 12782 06:56:25,978 --> 06:56:26,978 default for the property this one is 12783 06:56:28,138 --> 06:56:29,138 only the default the important one is 12784 06:56:30,420 --> 06:56:31,420 the one that we have on the material I'm 12785 06:56:32,820 --> 06:56:33,820 emphasizing this point because I've seen 12786 06:56:34,440 --> 06:56:35,440 a bunch of people make this mistake if 12787 06:56:36,478 --> 06:56:37,478 you modify default texture whilst inside 12788 06:56:38,458 --> 06:56:39,458 the Shader like for example if I change 12789 06:56:40,620 --> 06:56:41,620 here from bread let's say into the 12790 06:56:42,420 --> 06:56:43,420 Cabbage slices 12791 06:56:43,558 --> 06:56:44,558 if I modify that note how it does not 12792 06:56:46,320 --> 06:56:47,320 modify any materials that were created 12793 06:56:48,240 --> 06:56:49,240 we are only changing defaults so if you 12794 06:56:51,058 --> 06:56:52,058 want to change the texture that is 12795 06:56:52,320 --> 06:56:53,320 actually used make sure you change the 12796 06:56:54,058 --> 06:56:55,058 one on the material that you created and 12797 06:56:56,100 --> 06:56:57,100 not the defaults I changed the default 12798 06:56:58,080 --> 06:56:59,080 but did not change this Shader however 12799 06:57:00,058 --> 06:57:01,058 if I now were to make another material 12800 06:57:01,620 --> 06:57:02,620 which by the way here's a quick tip you 12801 06:57:04,378 --> 06:57:05,378 can recollect directly on the Shader 12802 06:57:05,878 --> 06:57:06,878 file and going to create and create new 12803 06:57:07,500 --> 06:57:08,500 material and it will automatically 12804 06:57:09,000 --> 06:57:10,000 create the material using that Shader 12805 06:57:10,680 --> 06:57:11,680 naturally here then update default just 12806 06:57:12,840 --> 06:57:13,840 because I didn't save the Shader so I 12807 06:57:15,120 --> 06:57:16,120 modified this one for the camera slices 12808 06:57:16,558 --> 06:57:17,558 and now if I save the asset and now if I 12809 06:57:18,958 --> 06:57:19,958 right click there and I create a brand 12810 06:57:20,580 --> 06:57:21,580 new material and yep now that one does 12811 06:57:22,500 --> 06:57:23,500 have the new default but again remember 12812 06:57:24,718 --> 06:57:25,718 what you said over here is just the 12813 06:57:26,700 --> 06:57:27,700 default what really matters is what is 12814 06:57:29,100 --> 06:57:30,100 on the material after the material has 12815 06:57:31,138 --> 06:57:32,138 been created modifying default here does 12816 06:57:33,000 --> 06:57:34,000 nothing so always keep that in mind in 12817 06:57:35,458 --> 06:57:36,458 most cases you want to be changing the 12818 06:57:37,200 --> 06:57:38,200 property on the material itself not the 12819 06:57:39,058 --> 06:57:40,058 default on the Shader okay let's just 12820 06:57:41,100 --> 06:57:42,100 clean up both of these all right so 12821 06:57:42,900 --> 06:57:43,900 let's continue now here we have our 12822 06:57:44,940 --> 06:57:45,940 Sprite working okay except we don't want 12823 06:57:46,740 --> 06:57:47,740 to show some bread so let's actually use 12824 06:57:48,298 --> 06:57:49,298 the proper Arrow Sprite so let's select 12825 06:57:49,978 --> 06:57:50,978 this one 12826 06:57:50,820 --> 06:57:51,820 and yep it does work it is printing the 12827 06:57:52,558 --> 06:57:53,558 Sprite however one obvious thing is that 12828 06:57:54,958 --> 06:57:55,958 the arrow is not transparent like it 12829 06:57:56,400 --> 06:57:57,400 should be so let's solve that back in 12830 06:57:58,798 --> 06:57:59,798 our Shader graph in order to make this a 12831 06:58:01,020 --> 06:58:02,020 transparent Shader we need to actually 12832 06:58:02,340 --> 06:58:03,340 go into the graph settings so on the 12833 06:58:04,260 --> 06:58:05,260 graph inspector go into graph settings 12834 06:58:05,700 --> 06:58:06,700 and over here you see a bunch of 12835 06:58:07,200 --> 06:58:08,200 settings that relate to the graph itself 12836 06:58:08,638 --> 06:58:09,638 and not any selected property so let's 12837 06:58:10,620 --> 06:58:11,620 go into graph settings for example like 12838 06:58:12,478 --> 06:58:13,478 I mentioned a while ago you can modify 12839 06:58:13,860 --> 06:58:14,860 between lit and lit and so on so this is 12840 06:58:16,320 --> 06:58:17,320 where you would change that you can also 12841 06:58:18,240 --> 06:58:19,240 appear at multiple targets so you can 12842 06:58:20,458 --> 06:58:21,458 create a Shader in Shader graph and make 12843 06:58:22,080 --> 06:58:23,080 it work with the Universe on random 12844 06:58:23,520 --> 06:58:24,520 pipeline or the high definition render 12845 06:58:25,138 --> 06:58:26,138 pipeline or the built-in render pipeline 12846 06:58:26,820 --> 06:58:27,820 all of those are supported through 12847 06:58:28,320 --> 06:58:29,320 Shader graph now for a goal in order to 12848 06:58:30,478 --> 06:58:31,478 make this a transparent Shader let's 12849 06:58:32,218 --> 06:58:33,218 just go over here onto service type 12850 06:58:33,540 --> 06:58:34,540 instead of opaque and let's change to 12851 06:58:35,218 --> 06:58:36,218 transparent and as soon as we do look 12852 06:58:37,320 --> 06:58:38,320 what happens there and if there go it 12853 06:58:39,000 --> 06:58:40,000 adds a brand new Alpha Channel if we 12854 06:58:40,978 --> 06:58:41,978 just save the asset right now and open 12855 06:58:43,138 --> 06:58:44,138 look at that it still doesn't work it's 12856 06:58:44,820 --> 06:58:45,820 still not transparent basically we made 12857 06:58:46,920 --> 06:58:47,920 this Shader transparent but now we need 12858 06:58:48,718 --> 06:58:49,718 to fit in the transparent Channel over 12859 06:58:50,700 --> 06:58:51,700 here onto the alpha this is the one 12860 06:58:52,680 --> 06:58:53,680 thing that is different from a previous 12861 06:58:54,000 --> 06:58:55,000 version of shadowgraph previously you 12862 06:58:55,978 --> 06:58:56,978 could just feed the alpha Channel over 12863 06:58:57,420 --> 06:58:58,420 here onto the base color and Shader 12864 06:58:59,458 --> 06:59:00,458 graph would automatically apply it but 12865 06:59:01,620 --> 06:59:02,620 in recent versions you need to add it 12866 06:59:03,360 --> 06:59:04,360 over here separately so if you have any 12867 06:59:05,400 --> 06:59:06,400 issues with transparency when following 12868 06:59:07,138 --> 06:59:08,138 some older share graph tutorials always 12869 06:59:08,760 --> 06:59:09,760 remember this change I covered that 12870 06:59:10,798 --> 06:59:11,798 along with some other changes in a very 12871 06:59:12,420 --> 06:59:13,420 useful video so if you're following 12872 06:59:13,978 --> 06:59:14,978 along some other shade graph tutorials 12873 06:59:15,660 --> 06:59:16,660 make sure you watch that video to learn 12874 06:59:17,040 --> 06:59:18,040 what you need to do to update them to 12875 06:59:18,660 --> 06:59:19,660 the latest version okay so here on the 12876 06:59:20,820 --> 06:59:21,820 similar texture we already have the 12877 06:59:22,200 --> 06:59:23,200 alpha channel so we just connect this 12878 06:59:23,580 --> 06:59:24,580 onto the master Alpha and right there we 12879 06:59:25,920 --> 06:59:26,920 already see it working let's just go 12880 06:59:28,020 --> 06:59:29,020 ahead save our asset and here in scene 12881 06:59:30,240 --> 06:59:31,240 view if there go now we do see our Arrow 12882 06:59:32,878 --> 06:59:33,878 now one more small thing you might 12883 06:59:35,280 --> 06:59:36,280 notice that from some angles it's not 12884 06:59:36,958 --> 06:59:37,958 exactly transparent basically it 12885 06:59:39,120 --> 06:59:40,120 actually is transparent but since we 12886 06:59:40,620 --> 06:59:41,620 made this in literature sometimes the 12887 06:59:42,298 --> 06:59:43,298 light might make the transparent Parts 12888 06:59:43,740 --> 06:59:44,740 visible one option to solve that is over 12889 06:59:46,020 --> 06:59:47,020 here on the graph settings instead of 12890 06:59:47,218 --> 06:59:48,218 making it lit let's make it unlit that 12891 06:59:49,260 --> 06:59:50,260 would work say up with the unload Shader 12892 06:59:51,120 --> 06:59:52,120 the transparency is perfect but if you 12893 06:59:53,280 --> 06:59:54,280 really want to keep it lit then the 12894 06:59:55,378 --> 06:59:56,378 other thing you can do is just over here 12895 06:59:56,760 --> 06:59:57,760 play around with these settings you've 12896 06:59:58,680 --> 06:59:59,680 got smoothness AO and so on and over 12897 07:00:00,420 --> 07:00:01,420 here you can even modify the workflow 12898 07:00:01,860 --> 07:00:02,860 mode so for transparency instead of 12899 07:00:03,900 --> 07:00:04,900 making it metallic let's go with a 12900 07:00:05,280 --> 07:00:06,280 specular workflow and then over here set 12901 07:00:07,500 --> 07:00:08,500 the smoothness to 1 and the ambient 12902 07:00:09,180 --> 07:00:10,180 occlusion down to zero and now if we 12903 07:00:11,400 --> 07:00:12,400 save this Shader look at that and yep 12904 07:00:13,920 --> 07:00:14,920 now the transparent parts are indeed 12905 07:00:15,478 --> 07:00:16,478 fully transparent finally over here on 12906 07:00:17,638 --> 07:00:18,638 the right side on the mesh render if you 12907 07:00:19,320 --> 07:00:20,320 want you might want to play around over 12908 07:00:20,760 --> 07:00:21,760 here with the cast Shadows so maybe you 12909 07:00:23,100 --> 07:00:24,100 don't want this one to cast Shadows 12910 07:00:24,540 --> 07:00:25,540 maybe you don't want it to impact light 12911 07:00:26,458 --> 07:00:27,458 probes and so on okay so with this we 12912 07:00:28,680 --> 07:00:29,680 have our nice transparent Arrow 12913 07:00:30,600 --> 07:00:31,600 let's make sure to save our delivery 12914 07:00:32,100 --> 07:00:33,100 counter so let's go outside back into 12915 07:00:33,660 --> 07:00:34,660 scenes 12916 07:00:34,680 --> 07:00:35,680 and let's head on playing and if there 12917 07:00:36,780 --> 07:00:37,780 you go we have our transparent counter 12918 07:00:38,458 --> 07:00:39,458 with our nice Arrow now we want the 12919 07:00:40,440 --> 07:00:41,440 arrow to actually move and doing that is 12920 07:00:42,660 --> 07:00:43,660 actually super simple going back here in 12921 07:00:44,760 --> 07:00:45,760 our shadow graph let's just modify 12922 07:00:46,320 --> 07:00:47,320 default just so we can see the arrow 12923 07:00:47,940 --> 07:00:48,940 that we want to see so let's select the 12924 07:00:49,978 --> 07:00:50,978 arrow Sprite okay there's our Arrow now 12925 07:00:53,218 --> 07:00:54,218 for moving over here on the simple 12926 07:00:54,718 --> 07:00:55,718 texture we've got an input for the UV 12927 07:00:56,638 --> 07:00:57,638 the UV is what defines what portion of 12928 07:00:59,100 --> 07:01:00,100 the texture we're going to grab which by 12929 07:01:00,958 --> 07:01:01,958 default just gets the whole texture so 12930 07:01:03,360 --> 07:01:04,360 since this field represents where we're 12931 07:01:05,520 --> 07:01:06,520 going to grab from texture by playing 12932 07:01:07,320 --> 07:01:08,320 around with this we can grab different 12933 07:01:08,820 --> 07:01:09,820 parts so to do that let's just add a 12934 07:01:11,638 --> 07:01:12,638 standard UV node so here it is this is 12935 07:01:13,620 --> 07:01:14,620 the standard UV channel so if we connect 12936 07:01:15,780 --> 07:01:16,780 this then nothing changes everything 12937 07:01:17,160 --> 07:01:18,160 still renders exactly the same but now 12938 07:01:19,620 --> 07:01:20,620 we can modify this and to do that we're 12939 07:01:21,958 --> 07:01:22,958 really just going to use some basic math 12940 07:01:23,400 --> 07:01:24,400 remember that when working with shaders 12941 07:01:25,740 --> 07:01:26,740 even though you do see colors everything 12942 07:01:27,540 --> 07:01:28,540 is really just numbers so uv2 is just 12943 07:01:30,420 --> 07:01:31,420 number the converges the number the 12944 07:01:32,160 --> 07:01:33,160 alpha is just a number so visually 12945 07:01:33,900 --> 07:01:34,900 everything might look like images might 12946 07:01:35,638 --> 07:01:36,638 look like colors but really in the end 12947 07:01:37,200 --> 07:01:38,200 it's all just numbers so for example how 12948 07:01:39,478 --> 07:01:40,478 do we move this texture well it's 12949 07:01:41,100 --> 07:01:42,100 actually pretty simple we just add a 12950 07:01:42,780 --> 07:01:43,780 number onto it so we're here on the UVM 12951 07:01:45,058 --> 07:01:46,058 let's just add an add node so this just 12952 07:01:48,000 --> 07:01:49,000 adds two numbers together very basic so 12953 07:01:50,878 --> 07:01:51,878 let's take the regular UV and let's add 12954 07:01:52,860 --> 07:01:53,860 something on top of it for example we 12955 07:01:55,080 --> 07:01:56,080 can make a vector two 12956 07:01:56,760 --> 07:01:57,760 and let's put it on say 0.10 12957 07:01:59,340 --> 07:02:00,340 and let's add this one onto this one and 12958 07:02:01,860 --> 07:02:02,860 now if we drag this one onto the input 12959 07:02:03,360 --> 07:02:04,360 and look over there on the preview what 12960 07:02:04,620 --> 07:02:05,620 happens and if they're going like that 12961 07:02:06,478 --> 07:02:07,478 it moves slightly to the left so if I 12962 07:02:08,580 --> 07:02:09,580 modify this one put it on zero there you 12963 07:02:10,320 --> 07:02:11,320 go and that point one on that point two 12964 07:02:12,180 --> 07:02:13,180 on that and so on so you can see that by 12965 07:02:14,400 --> 07:02:15,400 modifying here I'm essentially 12966 07:02:15,660 --> 07:02:16,660 offsetting the texture I'm offsetting on 12967 07:02:18,058 --> 07:02:19,058 the X and over here I can also offset it 12968 07:02:20,040 --> 07:02:21,040 on the y basically I'm offsetting the 12969 07:02:22,020 --> 07:02:23,020 texture by ten percent the UV is a 12970 07:02:24,120 --> 07:02:25,120 normalized value this is not pixels so 12971 07:02:26,340 --> 07:02:27,340 that is why point one is ten percent 12972 07:02:27,958 --> 07:02:28,958 regardless of how big the texture is and 12973 07:02:30,600 --> 07:02:31,600 if we go way past one then texture 12974 07:02:32,760 --> 07:02:33,760 essentially Loops back so this is really 12975 07:02:34,920 --> 07:02:35,920 all we need 12976 07:02:36,058 --> 07:02:37,058 for our moving Arrow we're going to have 12977 07:02:38,458 --> 07:02:39,458 zero on the Y and on the X we're going 12978 07:02:40,920 --> 07:02:41,920 to constantly either increase or 12979 07:02:42,540 --> 07:02:43,540 decrease that's how we're going to have 12980 07:02:44,040 --> 07:02:45,040 our moving Arrow so again the only issue 12981 07:02:46,138 --> 07:02:47,138 here is that I'm modifying this manually 12982 07:02:47,638 --> 07:02:48,638 we don't want a fixed amount on the 12983 07:02:49,440 --> 07:02:50,440 Shader instead we want a nice animation 12984 07:02:51,180 --> 07:02:52,180 so for that we have the very useful the 12985 07:02:53,580 --> 07:02:54,580 time node 12986 07:02:54,780 --> 07:02:55,780 this one has various time-based outputs 12987 07:02:57,360 --> 07:02:58,360 the one that we want for this case is a 12988 07:02:59,520 --> 07:03:00,520 time which is just the total time this 12989 07:03:01,860 --> 07:03:02,860 one is constantly increasing since the 12990 07:03:03,360 --> 07:03:04,360 start of the game by the number of 12991 07:03:04,620 --> 07:03:05,620 seconds so if you use this over here 12992 07:03:06,660 --> 07:03:07,660 directly on the end and they're gonna 12993 07:03:08,700 --> 07:03:09,700 look that texture is constantly 12994 07:03:09,958 --> 07:03:10,958 scrolling okay so that's great except 12995 07:03:12,660 --> 07:03:13,660 obviously we have one issue we don't 12996 07:03:14,340 --> 07:03:15,340 want it to scroll diagonally we only 12997 07:03:16,558 --> 07:03:17,558 want to scroll in One Direction so for 12998 07:03:18,660 --> 07:03:19,660 that we can essentially create a simple 12999 07:03:20,280 --> 07:03:21,280 property to act as our spin so let's 13000 07:03:23,040 --> 07:03:24,040 over here on the Blackboard let's create 13001 07:03:25,080 --> 07:03:26,080 a new Vector two column Tower speed 13002 07:03:27,240 --> 07:03:28,240 property and for the phone let's see if 13003 07:03:29,520 --> 07:03:30,520 I want to say 0.1 on the x0 on the Y and 13004 07:03:32,520 --> 07:03:33,520 now if I drag the speed over here onto 13005 07:03:34,500 --> 07:03:35,500 our Blackboard okay great this is 13006 07:03:36,900 --> 07:03:37,900 basically a multiplier so we just need 13007 07:03:38,280 --> 07:03:39,280 to multiply the time by this so let's 13008 07:03:40,500 --> 07:03:41,500 add a multiply node also by the way 13009 07:03:43,080 --> 07:03:44,080 quick tip over here on each node you've 13010 07:03:44,760 --> 07:03:45,760 got a nice little arrow so if you want 13011 07:03:46,080 --> 07:03:47,080 to make it a bit more compact so if you 13012 07:03:47,638 --> 07:03:48,638 don't actually need to see the preview 13013 07:03:49,200 --> 07:03:50,200 so make that and in this case let's take 13014 07:03:51,718 --> 07:03:52,718 our time multiply it by our speed and 13015 07:03:54,298 --> 07:03:55,298 then for the output pass it into the end 13016 07:03:55,920 --> 07:03:56,920 okay so like that now it is indeed 13017 07:03:57,900 --> 07:03:58,900 moving in this direction and over here 13018 07:03:59,580 --> 07:04:00,580 on the speed we can play around the 13019 07:04:00,780 --> 07:04:01,780 values so if we put that 0.5 now it's 13020 07:04:03,180 --> 07:04:04,180 moving faster and if I put it on the Y 13021 07:04:05,700 --> 07:04:06,700 now it's moving diagonally put zero on 13022 07:04:07,740 --> 07:04:08,740 the X and now it's only moving 13023 07:04:08,878 --> 07:04:09,878 vertically okay so this is really what 13024 07:04:11,160 --> 07:04:12,160 we want let's just go ahead save our 13025 07:04:13,860 --> 07:04:14,860 Shader and now let's just select our 13026 07:04:15,780 --> 07:04:16,780 delivery Arrow material and over here 13027 07:04:17,940 --> 07:04:18,940 yep we've got the spin if you don't see 13028 07:04:20,160 --> 07:04:21,160 it make sure they're on the speed 13029 07:04:21,240 --> 07:04:22,240 property over here you have it exposed 13030 07:04:23,040 --> 07:04:24,040 so we have the speed instead of moving 13031 07:04:24,900 --> 07:04:25,900 on the Y let's move on the X and 13032 07:04:27,600 --> 07:04:28,600 actually like this it's reverse going 13033 07:04:29,340 --> 07:04:30,340 backwards so over here we can just put a 13034 07:04:31,260 --> 07:04:32,260 negative value so let's put it on minus 13035 07:04:32,760 --> 07:04:33,760 one and if there go now the arrow is 13036 07:04:34,680 --> 07:04:35,680 moving perfectly also here let me make 13037 07:04:37,200 --> 07:04:38,200 one important note just in case you're 13038 07:04:39,298 --> 07:04:40,298 using this Shader with a custom texture 13039 07:04:41,100 --> 07:04:42,100 instead of the one included in the 13040 07:04:42,298 --> 07:04:43,298 course if you do that make sure that the 13041 07:04:44,218 --> 07:04:45,218 texture that you use over here I'm using 13042 07:04:45,780 --> 07:04:46,780 the arrow texture 13043 07:04:47,040 --> 07:04:48,040 over here on the Arrow import settings 13044 07:04:49,020 --> 07:04:50,020 down here under wrap mode make sure it 13045 07:04:51,540 --> 07:04:52,540 is set to repeat if you set it as clamp 13046 07:04:53,760 --> 07:04:54,760 you might get some weird visuals or 13047 07:04:55,558 --> 07:04:56,558 nothing at all in order for the texture 13048 07:04:57,660 --> 07:04:58,660 to constantly Loop and constantly repeat 13049 07:04:59,160 --> 07:05:00,160 itself that one needs to be set to 13050 07:05:00,660 --> 07:05:01,660 repeat okay so here it is in game and we 13051 07:05:03,058 --> 07:05:04,058 have a really nice moving texture for 13052 07:05:05,280 --> 07:05:06,280 that we created the simple but really 13053 07:05:07,320 --> 07:05:08,320 nice useful custom Shader definitely go 13054 07:05:09,718 --> 07:05:10,718 ahead and watch the various effects that 13055 07:05:11,100 --> 07:05:12,100 I made in the shadow graph playlist this 13056 07:05:13,378 --> 07:05:14,378 tool is super useful definitely make 13057 07:05:15,058 --> 07:05:16,058 sure you know how to use it I've used it 13058 07:05:17,100 --> 07:05:18,100 for making a building effect I've made 13059 07:05:19,260 --> 07:05:20,260 some nice outlines a really nice wind 13060 07:05:21,420 --> 07:05:22,420 Shader also a really interesting the 13061 07:05:23,400 --> 07:05:24,400 sound of effect and even a cool 13062 07:05:25,440 --> 07:05:26,440 transition Shader just like in the game 13063 07:05:27,058 --> 07:05:28,058 Hades so this really is a super powerful 13064 07:05:29,638 --> 07:05:30,638 tool make sure you watch that playlist 13065 07:05:31,080 --> 07:05:32,080 to really learn how to use it alright so 13066 07:05:33,298 --> 07:05:34,298 here we'll learn about share graph and 13067 07:05:34,978 --> 07:05:35,978 created a really nice custom Shader 13068 07:05:36,780 --> 07:05:37,780 however the delivery counter still only 13069 07:05:38,940 --> 07:05:39,940 has a visual so let's create some proper 13070 07:05:41,400 --> 07:05:42,400 Logic for generating and delivering the 13071 07:05:43,320 --> 07:05:44,320 correct recipes in the next lecture 13072 07:05:46,260 --> 07:05:47,260 hello and welcome I'm your code monkey 13073 07:05:48,180 --> 07:05:49,180 in this lecture we're going to build a 13074 07:05:50,280 --> 07:05:51,280 proper delivery manager that will 13075 07:05:51,900 --> 07:05:52,900 generate recipes that customers are 13076 07:05:53,638 --> 07:05:54,638 ordering and validate to see if the 13077 07:05:55,260 --> 07:05:56,260 player made the right dishes alright so 13078 07:05:57,298 --> 07:05:58,298 right now we have the player capable of 13079 07:05:58,860 --> 07:05:59,860 making dishes so for example I can put 13080 07:06:00,660 --> 07:06:01,660 some cheese cook some meat cut the 13081 07:06:02,700 --> 07:06:03,700 cheese and then pick up both of them 13082 07:06:04,978 --> 07:06:05,978 then let's say pick up some bread there 13083 07:06:06,840 --> 07:06:07,840 you go got a nice cheeseburger and 13084 07:06:08,218 --> 07:06:09,218 deliver it okay so that works but right 13085 07:06:10,378 --> 07:06:11,378 now they just vanish on delivery counter 13086 07:06:12,780 --> 07:06:13,780 so there's no recipe we need to follow 13087 07:06:14,820 --> 07:06:15,820 no validation none of that so let's add 13088 07:06:16,920 --> 07:06:17,920 both those things okay first of all 13089 07:06:19,020 --> 07:06:20,020 let's make our script so let's create a 13090 07:06:20,700 --> 07:06:21,700 brand new sharp script for the delivery 13091 07:06:22,740 --> 07:06:23,740 manager let's make a new game object to 13092 07:06:25,200 --> 07:06:26,200 run it so we need delivery manager 13093 07:06:26,878 --> 07:06:27,878 attached to script let's make sure to 13094 07:06:28,740 --> 07:06:29,740 keep things lean so reset the transform 13095 07:06:30,360 --> 07:06:31,360 and also by the way since we're here 13096 07:06:32,100 --> 07:06:33,100 let's go ahead and put the plates and 13097 07:06:33,600 --> 07:06:34,600 delivery counter inside the counter so 13098 07:06:35,218 --> 07:06:36,218 everything is nice and organized okay 13099 07:06:37,500 --> 07:06:38,500 great so let's open up this script now 13100 07:06:40,320 --> 07:06:41,320 here basically we need to Define some 13101 07:06:42,180 --> 07:06:43,180 sort of list to store all the recipes 13102 07:06:43,920 --> 07:06:44,920 that the customers are waiting for which 13103 07:06:46,080 --> 07:06:47,080 of course begs the question what type is 13104 07:06:47,700 --> 07:06:48,700 that going to be now technically one 13105 07:06:50,280 --> 07:06:51,280 thing we could do since a recipe is 13106 07:06:52,020 --> 07:06:53,020 around just a list of kitchen objects 13107 07:06:53,580 --> 07:06:54,580 over here we could have a list of list 13108 07:06:56,520 --> 07:06:57,520 of kitchen objects this would be our 13109 07:06:58,978 --> 07:06:59,978 recipe list technically that would work 13110 07:07:01,020 --> 07:07:02,020 but that really looks quite dirty 13111 07:07:02,878 --> 07:07:03,878 instead of having a list of lists we 13112 07:07:04,860 --> 07:07:05,860 should probably have a proper type for 13113 07:07:06,478 --> 07:07:07,478 this so let's write some good clean code 13114 07:07:08,458 --> 07:07:09,458 and Define a proper recipe Script Mod 13115 07:07:10,620 --> 07:07:11,620 object back in unity let's go inside 13116 07:07:12,718 --> 07:07:13,718 script knowledge's folder and create a 13117 07:07:14,400 --> 07:07:15,400 brand new one let's call this the recipe 13118 07:07:16,500 --> 07:07:17,500 so and over here let's make this a 13119 07:07:19,200 --> 07:07:20,200 script Mall object so extend script on 13120 07:07:21,660 --> 07:07:22,660 object make the create asset menu 13121 07:07:24,120 --> 07:07:25,120 and over here for the films for that 13122 07:07:26,218 --> 07:07:27,218 that we need well like I said a recipe 13123 07:07:28,620 --> 07:07:29,620 is just a list of ingredients so just 13124 07:07:30,958 --> 07:07:31,958 taking a list of kitchen object that 13125 07:07:32,940 --> 07:07:33,940 sell for the kitchen object SM list 13126 07:07:35,940 --> 07:07:36,940 okay that's it that's really all the 13127 07:07:37,558 --> 07:07:38,558 data that we need to define a recipe 13128 07:07:38,878 --> 07:07:39,878 just to be able to identify them for the 13129 07:07:41,100 --> 07:07:42,100 player let's also add a public string 13130 07:07:43,440 --> 07:07:44,440 for the recipe name 13131 07:07:45,360 --> 07:07:46,360 so just a nice name String okay great 13132 07:07:47,400 --> 07:07:48,400 now back in the editor let's define so 13133 07:07:49,680 --> 07:07:50,680 let's go inside the certain objects and 13134 07:07:51,298 --> 07:07:52,298 make a brand new one for our recipe so 13135 07:07:54,780 --> 07:07:55,780 and now inside let's create a brand new 13136 07:07:57,180 --> 07:07:58,180 recipe SL for this one let's call it 13137 07:07:59,520 --> 07:08:00,520 just burger and over here first of all 13138 07:08:01,680 --> 07:08:02,680 for the name just name it burger and 13139 07:08:03,718 --> 07:08:04,718 then for the kitchen object list well to 13140 07:08:05,638 --> 07:08:06,638 make a burger let's well first let's add 13141 07:08:07,620 --> 07:08:08,620 some meat and we want some cooked meat 13142 07:08:09,660 --> 07:08:10,660 we don't want to serve uncooked or burnt 13143 07:08:11,700 --> 07:08:12,700 meat so only the cooked meat then for a 13144 07:08:13,978 --> 07:08:14,978 simple Burger obviously we need some 13145 07:08:15,540 --> 07:08:16,540 bread and that's about it so some bread 13146 07:08:17,700 --> 07:08:18,700 some meat that's our very basic Burger 13147 07:08:19,620 --> 07:08:20,620 now let's also make another one so let's 13148 07:08:21,540 --> 07:08:22,540 duplicate this one and name this one the 13149 07:08:23,040 --> 07:08:24,040 cheeseburger over here let's name it 13150 07:08:25,440 --> 07:08:26,440 cheeseburger 13151 07:08:28,080 --> 07:08:29,080 and lightning place has bread meat and 13152 07:08:31,378 --> 07:08:32,378 obviously some nice cheese slices 13153 07:08:33,660 --> 07:08:34,660 so there you go okay we have a 13154 07:08:35,760 --> 07:08:36,760 cheeseburger now let's also make a mega 13155 07:08:38,160 --> 07:08:39,160 Burger so something with everything 13156 07:08:39,900 --> 07:08:40,900 so let's call this one the mega burger 13157 07:08:41,878 --> 07:08:42,878 and over here for the string name for 13158 07:08:44,160 --> 07:08:45,160 the Mega burger and for that we have 13159 07:08:46,558 --> 07:08:47,558 meat bread cheese let's also have some 13160 07:08:50,160 --> 07:08:51,160 nice cabbage slices and also some tomato 13161 07:08:52,558 --> 07:08:53,558 slices alright that's our Mega burger 13162 07:08:54,780 --> 07:08:55,780 with everything and finally let's also 13163 07:08:56,820 --> 07:08:57,820 make just a nice simple salad so let's 13164 07:08:58,500 --> 07:08:59,500 duplicate this for a salad 13165 07:09:00,958 --> 07:09:01,958 let's name it salad 13166 07:09:03,058 --> 07:09:04,058 and for the salad we don't have any meat 13167 07:09:05,520 --> 07:09:06,520 we don't have any bread and also no 13168 07:09:07,440 --> 07:09:08,440 cheese so just cabbage slice and tomato 13169 07:09:09,660 --> 07:09:10,660 slice that's a simple salad okay so here 13170 07:09:12,478 --> 07:09:13,478 we have all of our recipes so back here 13171 07:09:14,760 --> 07:09:15,760 on the delivery manager script instead 13172 07:09:16,978 --> 07:09:17,978 of making a list of lists of game 13173 07:09:18,360 --> 07:09:19,360 objects let's just make a list of recipe 13174 07:09:20,218 --> 07:09:21,218 recipe so and name it the recipe so list 13175 07:09:23,340 --> 07:09:24,340 this is where we're going to probably 13176 07:09:24,660 --> 07:09:25,660 see recipes that the customers are 13177 07:09:26,160 --> 07:09:27,160 waiting for so it's actually rename this 13178 07:09:28,138 --> 07:09:29,138 let's put it waiting recipe on list okay 13179 07:09:31,080 --> 07:09:32,080 so the customers are waiting for 13180 07:09:32,638 --> 07:09:33,638 whatever is inside this list and now we 13181 07:09:35,040 --> 07:09:36,040 could make this a serialized field then 13182 07:09:36,540 --> 07:09:37,540 set it in the editor but we don't want 13183 07:09:38,580 --> 07:09:39,580 to have a fixed list we want to 13184 07:09:40,260 --> 07:09:41,260 periodically spawn new recipes in order 13185 07:09:42,780 --> 07:09:43,780 to spawn new recipes we also need to 13186 07:09:44,520 --> 07:09:45,520 know which ones we can spawn so for that 13187 07:09:46,680 --> 07:09:47,680 we could add a list of all of the 13188 07:09:48,240 --> 07:09:49,240 recipes then we could pick a random one 13189 07:09:50,520 --> 07:09:51,520 from the list and add it over here to 13190 07:09:52,080 --> 07:09:53,080 the waiting list that would work that's 13191 07:09:53,820 --> 07:09:54,820 one good approach but since we already 13192 07:09:55,620 --> 07:09:56,620 did something similar to that various 13193 07:09:57,360 --> 07:09:58,360 times in this course here don't let me 13194 07:09:58,860 --> 07:09:59,860 teach you a different approach that 13195 07:10:00,180 --> 07:10:01,180 sometimes might make more sense for that 13196 07:10:02,160 --> 07:10:03,160 second approach we just need one thing 13197 07:10:03,780 --> 07:10:04,780 we need a script more object to hold all 13198 07:10:05,700 --> 07:10:06,700 of our recipes so let's do that let's do 13199 07:10:08,100 --> 07:10:09,100 a brand new c-sharp script this is the 13200 07:10:10,798 --> 07:10:11,798 recipe list scriptable object and then 13201 07:10:13,500 --> 07:10:14,500 inside this one is going to be a 13202 07:10:15,600 --> 07:10:16,600 scriptable object let's add the create 13203 07:10:18,058 --> 07:10:19,058 asset menu 13204 07:10:19,378 --> 07:10:20,378 and inside we're just going to have a 13205 07:10:21,298 --> 07:10:22,298 list of recipe so 13206 07:10:23,400 --> 07:10:24,400 for the recipe SLS so that's it super 13207 07:10:26,580 --> 07:10:27,580 simple now let's just create one object 13208 07:10:28,860 --> 07:10:29,860 of this type we can put it inside the 13209 07:10:30,900 --> 07:10:31,900 recipe as soon as since we're only going 13210 07:10:32,580 --> 07:10:33,580 to have one so let's make a recipe on 13211 07:10:34,138 --> 07:10:35,138 Lister so namely the recipient list SL 13212 07:10:36,718 --> 07:10:37,718 and then over here let's just drag our 13213 07:10:38,760 --> 07:10:39,760 recipe so we've got a burger a 13214 07:10:40,680 --> 07:10:41,680 cheeseburger we have a mega burger and 13215 07:10:43,260 --> 07:10:44,260 finally a salad okay so basically we 13216 07:10:45,478 --> 07:10:46,478 have a script ball object with all of 13217 07:10:47,040 --> 07:10:48,040 our recipes and now just for safety 13218 07:10:49,080 --> 07:10:50,080 since we only want to ever have a single 13219 07:10:51,360 --> 07:10:52,360 one of these objects a recipe on SSO for 13220 07:10:54,058 --> 07:10:55,058 this one we can go back here in the 13221 07:10:55,440 --> 07:10:56,440 script and simply comment out the create 13222 07:10:56,940 --> 07:10:57,940 asset menu so now back in the game over 13223 07:10:59,340 --> 07:11:00,340 here we can no longer create another 13224 07:11:01,080 --> 07:11:02,080 type of recipient list so so just say 13225 07:11:03,540 --> 07:11:04,540 nice safety thing since we probably only 13226 07:11:05,218 --> 07:11:06,218 need just one and let's also add an 13227 07:11:07,500 --> 07:11:08,500 underscore just so it shows up at the 13228 07:11:09,120 --> 07:11:10,120 top-down list okay great so we have this 13229 07:11:11,638 --> 07:11:12,638 and over here on the recipe manager we 13230 07:11:14,458 --> 07:11:15,458 can basically expose that in a 13231 07:11:15,900 --> 07:11:16,900 serialization so let's make a serialized 13232 07:11:17,638 --> 07:11:18,638 field 13233 07:11:18,958 --> 07:11:19,958 make it private of type recipe so list 13234 07:11:22,020 --> 07:11:23,020 recipe enlisted so for the recipient 13235 07:11:24,840 --> 07:11:25,840 list so and now here in the editor we 13236 07:11:27,420 --> 07:11:28,420 just drag that reference alright that's 13237 07:11:29,040 --> 07:11:30,040 it so basically the difference that we 13238 07:11:31,080 --> 07:11:32,080 did with this method is over here on 13239 07:11:33,000 --> 07:11:34,000 delivery manager instead of having a 13240 07:11:34,440 --> 07:11:35,440 list of all of our recipes we just have 13241 07:11:36,058 --> 07:11:37,058 a reference to one object and then that 13242 07:11:37,860 --> 07:11:38,860 object holds a list of all the recipes 13243 07:11:39,360 --> 07:11:40,360 in this specific use case like I said 13244 07:11:41,520 --> 07:11:42,520 this approach doesn't really have many 13245 07:11:42,958 --> 07:11:43,958 benefits compared to just starting the 13246 07:11:44,580 --> 07:11:45,580 last year but let's say we had another 13247 07:11:46,860 --> 07:11:47,860 script that also needs a list of all of 13248 07:11:48,780 --> 07:11:49,780 our recipes if we did that we would 13249 07:11:50,820 --> 07:11:51,820 basically have duplicate references so 13250 07:11:53,160 --> 07:11:54,160 this script would have a list of all the 13251 07:11:54,600 --> 07:11:55,600 recipes then some other script would 13252 07:11:56,160 --> 07:11:57,160 also have a list of all the recipes and 13253 07:11:57,900 --> 07:11:58,900 then if you wanted to add a brand new 13254 07:11:59,458 --> 07:12:00,458 recipe you'd need to add it to all the 13255 07:12:01,260 --> 07:12:02,260 lists on all the scripts whereas like 13256 07:12:03,180 --> 07:12:04,180 this any script that needs to know about 13257 07:12:05,280 --> 07:12:06,280 all of the recipes just needs a 13258 07:12:07,138 --> 07:12:08,138 reference to the recipe on SSO and 13259 07:12:09,240 --> 07:12:10,240 whenever we want to add or remove a 13260 07:12:10,740 --> 07:12:11,740 recipe we just need to update this one 13261 07:12:12,420 --> 07:12:13,420 object and everything works perfectly 13262 07:12:14,340 --> 07:12:15,340 that's one of the benefits of this 13263 07:12:16,080 --> 07:12:17,080 approach where you have a script mode 13264 07:12:17,400 --> 07:12:18,400 object to hold a list of all the objects 13265 07:12:19,378 --> 07:12:20,378 of some type personally I find this 13266 07:12:21,180 --> 07:12:22,180 pattern to be quite useful okay so on 13267 07:12:23,340 --> 07:12:24,340 delivery manager we have a list of all 13268 07:12:25,260 --> 07:12:26,260 of our recipes now let's just make a 13269 07:12:27,298 --> 07:12:28,298 simple timer to spawn them like I 13270 07:12:29,040 --> 07:12:30,040 mentioned previously in the spawn point 13271 07:12:30,540 --> 07:12:31,540 logic you could just use Echo routine if 13272 07:12:32,520 --> 07:12:33,520 you like that 13273 07:12:33,600 --> 07:12:34,600 core routines can be useful for running 13274 07:12:35,280 --> 07:12:36,280 timers but personally like I mentioned I 13275 07:12:37,378 --> 07:12:38,378 do not like Co routines I don't like the 13276 07:12:39,180 --> 07:12:40,180 pattern they force it to use so over 13277 07:12:41,160 --> 07:12:42,160 here I'm just going to make a simple 13278 07:12:42,540 --> 07:12:43,540 flow timer 13279 07:12:43,798 --> 07:12:44,798 so a private fluid for the spawn recipe 13280 07:12:46,378 --> 07:12:47,378 timer another one for the recipe timer 13281 07:12:49,200 --> 07:12:50,200 Max and let's say 4 seconds 13282 07:12:51,840 --> 07:12:52,840 then we just do a simple and private 13283 07:12:53,878 --> 07:12:54,878 weight update 13284 07:12:55,020 --> 07:12:56,020 on update let's count down the timer so 13285 07:12:57,420 --> 07:12:58,420 time dot down for time 13286 07:12:59,580 --> 07:13:00,580 and if the spawn timer is under 0f let's 13287 07:13:03,000 --> 07:13:04,000 reset the timer 13288 07:13:04,500 --> 07:13:05,500 and now let's basically spawn a recipe 13289 07:13:06,180 --> 07:13:07,180 so for that let's grab a random one from 13290 07:13:08,458 --> 07:13:09,458 the list so we go into the recipe list 13291 07:13:10,920 --> 07:13:11,920 so and grab the recipe as a list then 13292 07:13:13,978 --> 07:13:14,978 we're going to grab a random one so 13293 07:13:15,660 --> 07:13:16,660 let's get a random index so random.range 13294 07:13:18,058 --> 07:13:19,058 between 0 and the recipient list so dot 13295 07:13:21,360 --> 07:13:22,360 recipes dot count so you get a random 13296 07:13:24,240 --> 07:13:25,240 one this is going to be a recipe so for 13297 07:13:26,580 --> 07:13:27,580 the waiting recipe so 13298 07:13:28,500 --> 07:13:29,500 and then we simply go into the waiting 13299 07:13:30,360 --> 07:13:31,360 rest PSL list and we add a brand new 13300 07:13:33,120 --> 07:13:34,120 recipe okay that's it super simple let's 13301 07:13:35,340 --> 07:13:36,340 just make sure to initialize the list so 13302 07:13:37,260 --> 07:13:38,260 let's do here a simple awake for the 13303 07:13:39,660 --> 07:13:40,660 waiting recipes and just initialize it 13304 07:13:42,660 --> 07:13:43,660 okay so like this it should be working 13305 07:13:44,280 --> 07:13:45,280 however we're also going to generate 13306 07:13:46,138 --> 07:13:47,138 recipes non-stop we don't want that so 13307 07:13:48,298 --> 07:13:49,298 let's define some kind of maximum 13308 07:13:50,400 --> 07:13:51,400 so let's Define a simple end for the 13309 07:13:53,160 --> 07:13:54,160 waiting recipes Max 13310 07:13:56,700 --> 07:13:57,700 let's say we kind of have a maximum of 13311 07:13:58,558 --> 07:13:59,558 four recipes waiting 13312 07:14:00,420 --> 07:14:01,420 and then down here when camera lapses so 13313 07:14:02,760 --> 07:14:03,760 if the waiting recipes only stock count 13314 07:14:04,920 --> 07:14:05,920 if it is under the maximum then we 13315 07:14:07,138 --> 07:14:08,138 generate and add it okay that's it 13316 07:14:09,240 --> 07:14:10,240 pretty simple 13317 07:14:10,320 --> 07:14:11,320 now for testing let's just set allow 13318 07:14:12,000 --> 07:14:13,000 here to print the name so debug.log on 13319 07:14:14,760 --> 07:14:15,760 the waiting recipe so that we generate 13320 07:14:16,860 --> 07:14:17,860 so let's print out the recipe name okay 13321 07:14:19,860 --> 07:14:20,860 so let's test so here we are in yep one 13322 07:14:22,320 --> 07:14:23,320 will spawn right away so we have a solid 13323 07:14:24,058 --> 07:14:25,058 and after four seconds Yep they're going 13324 07:14:25,740 --> 07:14:26,740 out of salad and if we wait for four 13325 07:14:27,840 --> 07:14:28,840 seconds we should have another one there 13326 07:14:29,280 --> 07:14:30,280 you go a mega butter recipe and finally 13327 07:14:31,798 --> 07:14:32,798 after four seconds we have yep we have 13328 07:14:33,900 --> 07:14:34,900 another burger and now no matter how 13329 07:14:35,940 --> 07:14:36,940 much time passes there should be no more 13330 07:14:38,100 --> 07:14:39,100 since we're at the limit any uptime pass 13331 07:14:40,320 --> 07:14:41,320 then no more okay all right awesome so 13332 07:14:42,840 --> 07:14:43,840 we are correctly generating recipes that 13333 07:14:44,820 --> 07:14:45,820 the customers are waiting for now it's a 13334 07:14:47,040 --> 07:14:48,040 logic to try to fulfill these orders so 13335 07:14:49,378 --> 07:14:50,378 over here on delivery manager let's make 13336 07:14:51,058 --> 07:14:52,058 a function to deliver a recipe 13337 07:14:53,520 --> 07:14:54,520 so let's make a public Point make it 13338 07:14:55,558 --> 07:14:56,558 public since we're going to access this 13339 07:14:57,000 --> 07:14:58,000 from the delivery counter currently 13340 07:14:59,340 --> 07:15:00,340 deliver recipe 13341 07:15:01,020 --> 07:15:02,020 and the recipes are going to be 13342 07:15:02,878 --> 07:15:03,878 delivered whilst on a point so let's 13343 07:15:04,920 --> 07:15:05,920 receive a parameter of type Plate 13344 07:15:06,540 --> 07:15:07,540 Kitchen object 13345 07:15:07,798 --> 07:15:08,798 and over here the logic is actually 13346 07:15:09,240 --> 07:15:10,240 going to be pretty simple we just need 13347 07:15:11,400 --> 07:15:12,400 to cycle through all of the recipes that 13348 07:15:13,440 --> 07:15:14,440 the customers are waiting for and see if 13349 07:15:15,420 --> 07:15:16,420 the ingredients on this plate matches 13350 07:15:17,280 --> 07:15:18,280 the ones on any waiting recipe 13351 07:15:19,378 --> 07:15:20,378 so over here let's cycle through all of 13352 07:15:21,360 --> 07:15:22,360 our recipes so let's do before 13353 07:15:23,760 --> 07:15:24,760 entire zero going through the entire 13354 07:15:26,760 --> 07:15:27,760 recipe only star count I plus plus okay 13355 07:15:29,700 --> 07:15:30,700 let's grab the recipe so for the waiting 13356 07:15:32,458 --> 07:15:33,458 recipe so 13357 07:15:34,138 --> 07:15:35,138 and we grab from The Waiting recipes on 13358 07:15:36,120 --> 07:15:37,120 list on this index okay so we have that 13359 07:15:38,218 --> 07:15:39,218 then first let's do a quick test just to 13360 07:15:40,558 --> 07:15:41,558 check if the waiting recipe has the same 13361 07:15:42,780 --> 07:15:43,780 number of ingredients as they are on the 13362 07:15:44,400 --> 07:15:45,400 plate if not then we already know that 13363 07:15:46,440 --> 07:15:47,440 it's not valid so over here let's do a 13364 07:15:48,900 --> 07:15:49,900 quick test SO waiting recipe so let's 13365 07:15:51,840 --> 07:15:52,840 check the kitchen object that's only 13366 07:15:53,160 --> 07:15:54,160 it's not count if this one matches the 13367 07:15:55,500 --> 07:15:56,500 play kitchen object let's get the 13368 07:15:57,180 --> 07:15:58,180 kitchen object that's on the list and 13369 07:15:59,040 --> 07:16:00,040 also check the count so over here we 13370 07:16:01,200 --> 07:16:02,200 know that has the same number of 13371 07:16:03,180 --> 07:16:04,180 ingredients 13372 07:16:04,558 --> 07:16:05,558 so this is the first check then we need 13373 07:16:07,080 --> 07:16:08,080 to cycle through all the ingredients on 13374 07:16:08,760 --> 07:16:09,760 this recipe and all of the ingredients 13375 07:16:10,260 --> 07:16:11,260 on the plate and basically see if both 13376 07:16:12,600 --> 07:16:13,600 of them match so let's first cycle 13377 07:16:14,580 --> 07:16:15,580 through the ingredients on the recipe so 13378 07:16:16,860 --> 07:16:17,860 for each 13379 07:16:18,240 --> 07:16:19,240 kitchen object as so let's call it the 13380 07:16:20,878 --> 07:16:21,878 recipe kitchen object so in the waiting 13381 07:16:25,020 --> 07:16:26,020 recipe so let's go into the waiting 13382 07:16:26,700 --> 07:16:27,700 recipe and get the kitchen object list 13383 07:16:29,160 --> 07:16:30,160 okay so here we are cycling through all 13384 07:16:33,000 --> 07:16:34,000 ingredients in the recipe 13385 07:16:35,160 --> 07:16:36,160 then we need to cycle through all the 13386 07:16:37,200 --> 07:16:38,200 ingredients on the plate so let's do 13387 07:16:39,660 --> 07:16:40,660 another cycle for the Plate Kitchen 13388 07:16:41,580 --> 07:16:42,580 object SL and we're going to go inside 13389 07:16:43,978 --> 07:16:44,978 the Plate Kitchen object get the kitchen 13390 07:16:45,900 --> 07:16:46,900 object that's on the list like this 13391 07:16:47,820 --> 07:16:48,820 so here we are cycling through all the 13392 07:16:49,500 --> 07:16:50,500 ingredients on the plate 13393 07:16:52,378 --> 07:16:53,378 okay so now here basically we need to 13394 07:16:54,180 --> 07:16:55,180 see if this ingredient that we're 13395 07:16:55,680 --> 07:16:56,680 cycling through if this one matches the 13396 07:16:57,900 --> 07:16:58,900 ingredient on the recipe so here we 13397 07:17:01,020 --> 07:17:02,020 check if the Plate Kitchen object does 13398 07:17:02,820 --> 07:17:03,820 so if this one matches the recipe 13399 07:17:05,100 --> 07:17:06,100 kitchen outlet 13400 07:17:07,320 --> 07:17:08,320 if so then the ingredient does match 13401 07:17:10,138 --> 07:17:11,138 so in order to keep track if it does 13402 07:17:12,240 --> 07:17:13,240 match 13403 07:17:13,080 --> 07:17:14,080 over here before we cycle through all 13404 07:17:15,240 --> 07:17:16,240 the ones on the plane let's define a 13405 07:17:16,680 --> 07:17:17,680 bone for found or ingredient found 13406 07:17:20,638 --> 07:17:21,638 let's default it too false and over here 13407 07:17:23,580 --> 07:17:24,580 if we have match then this one becomes 13408 07:17:25,378 --> 07:17:26,378 true and by the way over here we can 13409 07:17:27,298 --> 07:17:28,298 also break out of the cycle 13410 07:17:28,860 --> 07:17:29,860 now if you're not familiar with break 13411 07:17:30,360 --> 07:17:31,360 basically this is going to break out at 13412 07:17:32,100 --> 07:17:33,100 the for each so let's say the plate has 13413 07:17:34,978 --> 07:17:35,978 10 ingredients and the second one 13414 07:17:36,660 --> 07:17:37,660 matches when this cycle gets to the 13415 07:17:38,760 --> 07:17:39,760 second one it triggers a break so it no 13416 07:17:40,320 --> 07:17:41,320 longer goes through the remaining eight 13417 07:17:41,520 --> 07:17:42,520 so basically it breaks out of the cycle 13418 07:17:43,260 --> 07:17:44,260 so keeps writing some code right down 13419 07:17:44,940 --> 07:17:45,940 here okay so we cycle through all of the 13420 07:17:46,978 --> 07:17:47,978 ones on the aggressively then recycle 13421 07:17:48,900 --> 07:17:49,900 through the plate and if we do find that 13422 07:17:50,940 --> 07:17:51,940 ingredient on that plate then we have an 13423 07:17:53,458 --> 07:17:54,458 ingredient found so over here 13424 07:17:55,680 --> 07:17:56,680 if we have a not ingredient found 13425 07:17:59,878 --> 07:18:00,878 then over here that means this recipe 13426 07:18:03,540 --> 07:18:04,540 ingredient was not found on the plate 13427 07:18:07,320 --> 07:18:08,320 so if that happens then essentially over 13428 07:18:08,878 --> 07:18:09,878 here we have a phenocate so the 13429 07:18:10,558 --> 07:18:11,558 ingredient that this recipe requires is 13430 07:18:12,058 --> 07:18:13,058 not on the plate so let's go up here 13431 07:18:14,458 --> 07:18:15,458 when we have the same number of 13432 07:18:16,020 --> 07:18:17,020 ingredients let's define a Boolean 13433 07:18:17,638 --> 07:18:18,638 called the plate contents matches recipe 13434 07:18:20,638 --> 07:18:21,638 let's see found it to true and over here 13435 07:18:23,160 --> 07:18:24,160 if we don't find at least one of them 13436 07:18:24,900 --> 07:18:25,900 then the plate contents do not match the 13437 07:18:27,058 --> 07:18:28,058 recipe and afterwards we can check this 13438 07:18:29,520 --> 07:18:30,520 bowl again 13439 07:18:31,260 --> 07:18:32,260 so if this one is true that means they 13440 07:18:33,180 --> 07:18:34,180 all match if just one of them does not 13441 07:18:35,340 --> 07:18:36,340 matches then this one won't be false 13442 07:18:37,260 --> 07:18:38,260 so over here we know player delivered 13443 07:18:39,840 --> 07:18:40,840 the correct recipe 13444 07:18:42,478 --> 07:18:43,478 so over here on let's do a quick debug 13445 07:18:44,340 --> 07:18:45,340 down log and print out a message 13446 07:18:47,340 --> 07:18:48,340 and after we do let's also do a return 13447 07:18:49,080 --> 07:18:50,080 so we stop the rest of the execution so 13448 07:18:51,000 --> 07:18:52,000 basically if we find a waiting recipe 13449 07:18:52,978 --> 07:18:53,978 that matches we don't want to keep going 13450 07:18:55,320 --> 07:18:56,320 and also here if we do find it let's 13451 07:18:57,120 --> 07:18:58,120 also remove it from the list 13452 07:18:59,218 --> 07:19:00,218 so let's go into waiting queue remove at 13453 07:19:01,680 --> 07:19:02,680 and remove at this index okay so we're 13454 07:19:04,138 --> 07:19:05,138 going to remove this recipe but if this 13455 07:19:06,360 --> 07:19:07,360 doesn't happen then it's going to be 13456 07:19:07,500 --> 07:19:08,500 keep cycling and it's going to cycle 13457 07:19:09,000 --> 07:19:10,000 through all the recipes so basically if 13458 07:19:10,978 --> 07:19:11,978 it reaches the end this far 13459 07:19:12,958 --> 07:19:13,958 then basically no match is found 13460 07:19:16,978 --> 07:19:17,978 so the player did not 13461 07:19:19,500 --> 07:19:20,500 deliver a correct recipe 13462 07:19:23,700 --> 07:19:24,700 so let's do another debug in here 13463 07:19:29,040 --> 07:19:30,040 okay so this is done for logic it looks 13464 07:19:31,798 --> 07:19:32,798 a bit complex but I hope this was easy 13465 07:19:33,360 --> 07:19:34,360 to follow when we see it in action It 13466 07:19:35,700 --> 07:19:36,700 all becomes a bit more clear so all 13467 07:19:37,798 --> 07:19:38,798 that's left is just calling this 13468 07:19:39,120 --> 07:19:40,120 function from the delivery counter so 13469 07:19:40,860 --> 07:19:41,860 let's do that over here on the delivery 13470 07:19:43,260 --> 07:19:44,260 counter it accepts plates and destroys 13471 07:19:45,478 --> 07:19:46,478 plates but before we destroy 13472 07:19:47,580 --> 07:19:48,580 let's go into the delivery manager which 13473 07:19:49,500 --> 07:19:50,500 means we need to access a reference so 13474 07:19:51,718 --> 07:19:52,718 again we could add a serialized field or 13475 07:19:53,520 --> 07:19:54,520 in this case it makes perfect sense to 13476 07:19:55,138 --> 07:19:56,138 make this a Singleton so let's make it 13477 07:19:57,240 --> 07:19:58,240 here public static of type delivering 13478 07:19:59,400 --> 07:20:00,400 manager call it instance with a public 13479 07:20:01,920 --> 07:20:02,920 get and a private set 13480 07:20:05,820 --> 07:20:06,820 okay then over here on awake let's set 13481 07:20:08,520 --> 07:20:09,520 instance equals this 13482 07:20:10,920 --> 07:20:11,920 all right so now over here on the 13483 07:20:13,020 --> 07:20:14,020 delivery counter we can go into the 13484 07:20:14,820 --> 07:20:15,820 delivery manager access the instance and 13485 07:20:17,580 --> 07:20:18,580 deliver our recipe and pass in the Plate 13486 07:20:19,740 --> 07:20:20,740 Kitchen object 13487 07:20:21,780 --> 07:20:22,780 okay that should do it let's test all 13488 07:20:24,420 --> 07:20:25,420 right so let's look in the log to see 13489 07:20:25,978 --> 07:20:26,978 what they are waiting for so there are 13490 07:20:27,958 --> 07:20:28,958 two cheeseburgers waiting another Mega 13491 07:20:30,058 --> 07:20:31,058 burger and a cheeseburger so let's make 13492 07:20:32,458 --> 07:20:33,458 a cheeseburger to deliver so first of 13493 07:20:34,740 --> 07:20:35,740 all let's cook some meat let's slice 13494 07:20:36,600 --> 07:20:37,600 some cheese let's pick up the meat 13495 07:20:38,940 --> 07:20:39,940 before it burns pick up the cheese and 13496 07:20:40,740 --> 07:20:41,740 we just need the bread okay this is a 13497 07:20:42,840 --> 07:20:43,840 valley cheeseburger so let's deliver it 13498 07:20:45,718 --> 07:20:46,718 and if there go the players delivered 13499 07:20:47,280 --> 07:20:48,280 the correct recipe okay great 13500 07:20:49,500 --> 07:20:50,500 now let's deliver something that nobody 13501 07:20:51,180 --> 07:20:52,180 asked for let's say just some meat 13502 07:20:52,920 --> 07:20:53,920 actually let's burn it just for fun all 13503 07:20:55,680 --> 07:20:56,680 right so there we have a bunch of 13504 07:20:57,120 --> 07:20:58,120 charred meat so nobody really wants this 13505 07:20:58,978 --> 07:20:59,978 but if we deliver if their yield player 13506 07:21:01,200 --> 07:21:02,200 did not deliver a correct recipe alright 13507 07:21:03,600 --> 07:21:04,600 awesome so over here everything worked 13508 07:21:05,400 --> 07:21:06,400 we have a bunch of recipes being 13509 07:21:07,620 --> 07:21:08,620 generated and then we have the logic so 13510 07:21:10,500 --> 07:21:11,500 that when the player delivers something 13511 07:21:11,760 --> 07:21:12,760 it checks if the players delivered 13512 07:21:13,260 --> 07:21:14,260 something correct or incorrect so 13513 07:21:15,360 --> 07:21:16,360 everything is great all that's missing 13514 07:21:17,040 --> 07:21:18,040 is obviously some nice UI so let's do 13515 07:21:19,320 --> 07:21:20,320 that in the next lecture 13516 07:21:21,360 --> 07:21:22,360 hello and welcome I'm your code monkey 13517 07:21:23,340 --> 07:21:24,340 in this lecture we're going to create a 13518 07:21:25,558 --> 07:21:26,558 nice UI visual to display our waiting 13519 07:21:27,540 --> 07:21:28,540 recipes okay so our delivery manager is 13520 07:21:29,878 --> 07:21:30,878 already working we are randomly spawning 13521 07:21:31,680 --> 07:21:32,680 some random recipes every once in a 13522 07:21:33,298 --> 07:21:34,298 while now instead of looking at the 13523 07:21:34,978 --> 07:21:35,978 console let's add a proper UI so for 13524 07:21:37,260 --> 07:21:38,260 that over here in the editor let's go 13525 07:21:38,940 --> 07:21:39,940 inside the canvas and by the way let's 13526 07:21:40,500 --> 07:21:41,500 click on the button to unlock the canvas 13527 07:21:42,240 --> 07:21:43,240 and this is actually the first time 13528 07:21:44,100 --> 07:21:45,100 we're using the Ragnar canvas quite a 13529 07:21:46,020 --> 07:21:47,020 while ago we just created it we didn't 13530 07:21:47,638 --> 07:21:48,638 really set it up so let's quickly do 13531 07:21:49,260 --> 07:21:50,260 that for the render mode this one is 13532 07:21:51,420 --> 07:21:52,420 meant to be a regular UI so let's leave 13533 07:21:53,340 --> 07:21:54,340 it on the screen space overlay then over 13534 07:21:55,620 --> 07:21:56,620 here on the canvas scaler instead of 13535 07:21:57,840 --> 07:21:58,840 constant pixel size let's go with scale 13536 07:21:59,700 --> 07:22:00,700 with screen size then for the reference 13537 07:22:01,740 --> 07:22:02,740 resolution I like to use 1920x1080 13538 07:22:05,100 --> 07:22:06,100 and finally unlike to fully match with 13539 07:22:07,080 --> 07:22:08,080 the height basically this means that 13540 07:22:08,940 --> 07:22:09,940 objects in the canvas will be scaled if 13541 07:22:11,100 --> 07:22:12,100 the height changes for example let's add 13542 07:22:13,500 --> 07:22:14,500 inside just a quick UI image just a test 13543 07:22:15,718 --> 07:22:16,718 let's look in the game View 13544 07:22:17,400 --> 07:22:18,400 so there you go there's the image let's 13545 07:22:18,660 --> 07:22:19,660 just put on a different color okay so 13546 07:22:20,760 --> 07:22:21,760 there's the image and note how if I 13547 07:22:23,100 --> 07:22:24,100 modify the aspect ratio here so let's 13548 07:22:25,138 --> 07:22:26,138 say I put it on 5x4 there go the 13549 07:22:27,180 --> 07:22:28,180 horizontal side of the window change but 13550 07:22:28,680 --> 07:22:29,680 note how the element was not scaled so I 13551 07:22:31,440 --> 07:22:32,440 can put it even on free aspects so 13552 07:22:33,240 --> 07:22:34,240 really wide and does not change the size 13553 07:22:35,058 --> 07:22:36,058 whereas if I modify this if I modify the 13554 07:22:37,860 --> 07:22:38,860 vertical size the image does indeed get 13555 07:22:40,500 --> 07:22:41,500 Scaled up or down personally I like the 13556 07:22:42,660 --> 07:22:43,660 setup because means that I only have to 13557 07:22:44,160 --> 07:22:45,160 worry about positioning things 13558 07:22:45,298 --> 07:22:46,298 horizontally if the vericon part gets 13559 07:22:47,638 --> 07:22:48,638 changed everything gets automatically 13560 07:22:48,900 --> 07:22:49,900 scaled okay so great so over here let's 13561 07:22:51,180 --> 07:22:52,180 go back into 4G all right and let's get 13562 07:22:53,638 --> 07:22:54,638 rid of the image all right back in the 13563 07:22:55,740 --> 07:22:56,740 scene view let's quickly look at the 13564 07:22:57,540 --> 07:22:58,540 canvas so we can select the canvas press 13565 07:22:59,340 --> 07:23:00,340 the F in order to zoom out and also we 13566 07:23:01,920 --> 07:23:02,920 can press the 2D button up here to go 13567 07:23:03,780 --> 07:23:04,780 into 3D mode okay so here's our nice UI 13568 07:23:06,240 --> 07:23:07,240 now inside the canvas let's create them 13569 07:23:08,040 --> 07:23:09,040 to game object call it the delivery 13570 07:23:10,260 --> 07:23:11,260 manager UI then in the inspector let's 13571 07:23:13,080 --> 07:23:14,080 make it stretch to occupy the whole 13572 07:23:14,520 --> 07:23:15,520 thing so let's put zero on everything 13573 07:23:17,040 --> 07:23:18,040 okay so this window now occupies the 13574 07:23:19,200 --> 07:23:20,200 entire screen 13575 07:23:20,400 --> 07:23:21,400 now inside let's do just like we did a 13576 07:23:22,500 --> 07:23:23,500 while ago for the plate icons meaning 13577 07:23:24,420 --> 07:23:25,420 let's make a template that we can then 13578 07:23:26,218 --> 07:23:27,218 clone but let's also put those templates 13579 07:23:28,558 --> 07:23:29,558 inside of a container so first of all 13580 07:23:30,120 --> 07:23:31,120 let's make the containers so a new empty 13581 07:23:31,680 --> 07:23:32,680 game object 13582 07:23:32,820 --> 07:23:33,820 of currently just the container the 13583 07:23:34,920 --> 07:23:35,920 reason why I'm going with this approach 13584 07:23:36,298 --> 07:23:37,298 is because I also want to have other 13585 07:23:38,520 --> 07:23:39,520 objects outside of here if you remember 13586 07:23:40,500 --> 07:23:41,500 how we did with the templates we can 13587 07:23:42,958 --> 07:23:43,958 actually go there and see so let's go 13588 07:23:45,180 --> 07:23:46,180 inside the prefabs inside the counters 13589 07:23:46,978 --> 07:23:47,978 actually it's on the kitchen objects 13590 07:23:48,958 --> 07:23:49,958 let's go inside the plate over here for 13591 07:23:51,298 --> 07:23:52,298 the template basically we use the play 13592 07:23:53,160 --> 07:23:54,160 tokens UI this main canvas as the 13593 07:23:55,260 --> 07:23:56,260 container but if you remember how we did 13594 07:23:57,360 --> 07:23:58,360 that in order to make sure we didn't end 13595 07:23:58,558 --> 07:23:59,558 up with duplicate icons we always 13596 07:24:00,120 --> 07:24:01,120 destroyed the previous one when we 13597 07:24:01,740 --> 07:24:02,740 spawned a brand new one so every time we 13598 07:24:04,080 --> 07:24:05,080 were cycling through the children of 13599 07:24:05,820 --> 07:24:06,820 this object in order to destroy all of 13600 07:24:07,500 --> 07:24:08,500 them except the template so over here 13601 07:24:09,540 --> 07:24:10,540 we're going to use a container so that 13602 07:24:10,860 --> 07:24:11,860 we can apply the logic only to the 13603 07:24:12,540 --> 07:24:13,540 children of the container and that way 13604 07:24:14,218 --> 07:24:15,218 we can have other objects outside of the 13605 07:24:16,320 --> 07:24:17,320 container for example outside of here 13606 07:24:18,180 --> 07:24:19,180 let's say we want some nice text just 13607 07:24:19,860 --> 07:24:20,860 saying recipes and waiting so on 13608 07:24:22,378 --> 07:24:23,378 delivery mansion let's make it a 13609 07:24:23,820 --> 07:24:24,820 challenge down let's go into UI and 13610 07:24:25,860 --> 07:24:26,860 let's make a text text mesh Pro and this 13611 07:24:28,320 --> 07:24:29,320 is the first time that we're using text 13612 07:24:29,820 --> 07:24:30,820 mesh Pro so this window pops out it's 13613 07:24:32,100 --> 07:24:33,100 actually import mesh Pro Essentials okay 13614 07:24:34,440 --> 07:24:35,440 just let it import okay that's it we 13615 07:24:36,780 --> 07:24:37,780 don't need the examples are extras so 13616 07:24:38,218 --> 07:24:39,218 let's just close this window and over 13617 07:24:40,080 --> 07:24:41,080 here on this window let's name this the 13618 07:24:41,638 --> 07:24:42,638 title text let's set the text to 13619 07:24:43,860 --> 07:24:44,860 something like recipes waiting 13620 07:24:46,500 --> 07:24:47,500 let's put it up there on the corner so 13621 07:24:48,360 --> 07:24:49,360 let's anchor it on the top left corner 13622 07:24:50,340 --> 07:24:51,340 also for the text I like to put it on a 13623 07:24:52,680 --> 07:24:53,680 width and height of zero but of course 13624 07:24:54,120 --> 07:24:55,120 that makes the text really vertical so 13625 07:24:56,040 --> 07:24:57,040 then down here on the wrapping let's 13626 07:24:57,420 --> 07:24:58,420 just disable it so there you go looks 13627 07:24:59,160 --> 07:25:00,160 like that and let's put it over there on 13628 07:25:01,320 --> 07:25:02,320 that corner now in scene view we are 13629 07:25:03,298 --> 07:25:04,298 seeing things different so if you want 13630 07:25:05,218 --> 07:25:06,218 to see what this looks like just go into 13631 07:25:06,660 --> 07:25:07,660 the game View and over there yep we do 13632 07:25:08,160 --> 07:25:09,160 see the recipes and let's just make it 13633 07:25:09,360 --> 07:25:10,360 in bond so there you go just some nice 13634 07:25:10,860 --> 07:25:11,860 text okay so that's our text and then 13635 07:25:13,320 --> 07:25:14,320 for the container let's make inside the 13636 07:25:15,900 --> 07:25:16,900 delivery template so let's create an 13637 07:25:18,058 --> 07:25:19,058 empty game object let's go with the 13638 07:25:20,340 --> 07:25:21,340 recipe template and for this one we're 13639 07:25:22,680 --> 07:25:23,680 going to want to Anchor it to the top 13640 07:25:24,058 --> 07:25:25,058 left corner so with the template 13641 07:25:26,100 --> 07:25:27,100 selected over here in the inspector 13642 07:25:27,660 --> 07:25:28,660 let's click and we want to click up here 13643 07:25:29,940 --> 07:25:30,940 however we also want to set the pivot so 13644 07:25:33,120 --> 07:25:34,120 let's make sure to hold down shift in 13645 07:25:34,798 --> 07:25:35,798 order to set the pivot over there okay 13646 07:25:37,138 --> 07:25:38,138 great that's exactly what we want so we 13647 07:25:38,878 --> 07:25:39,878 want the template right on the corner 13648 07:25:40,378 --> 07:25:41,378 then let's give it a size of say 250 by 13649 07:25:43,320 --> 07:25:44,320 100 okay now inside template we just 13650 07:25:45,958 --> 07:25:46,958 need two things we want to name the 13651 07:25:48,000 --> 07:25:49,000 recipe as well as the list of all the 13652 07:25:49,680 --> 07:25:50,680 ingredients although before that let's 13653 07:25:51,360 --> 07:25:52,360 actually make a nice visual for the 13654 07:25:52,740 --> 07:25:53,740 background so a new UI image for the 13655 07:25:55,020 --> 07:25:56,020 background 13656 07:25:55,920 --> 07:25:56,920 let's make this one stretch to occupy 13657 07:25:57,900 --> 07:25:58,900 the whole thing let's put everything on 13658 07:25:59,700 --> 07:26:00,700 zero okay that's the background let's 13659 07:26:01,558 --> 07:26:02,558 put it on a black we're just a little 13660 07:26:03,900 --> 07:26:04,900 bit lower Alpha okay that's good then 13661 07:26:06,180 --> 07:26:07,180 for name let's make a text field so 13662 07:26:08,580 --> 07:26:09,580 inside the template let's create another 13663 07:26:10,378 --> 07:26:11,378 text call it the recipe name text then 13664 07:26:13,978 --> 07:26:14,978 over here let's put it a bit small so on 13665 07:26:15,540 --> 07:26:16,540 the font size of maybe just 20 let's put 13666 07:26:17,400 --> 07:26:18,400 it in bold 13667 07:26:18,540 --> 07:26:19,540 and let's also again put the width and 13668 07:26:20,760 --> 07:26:21,760 height of 0 and over here make sure to 13669 07:26:22,860 --> 07:26:23,860 disable wrapping okay so that's the text 13670 07:26:25,378 --> 07:26:26,378 so we've got it up there let's just 13671 07:26:27,000 --> 07:26:28,000 anchor it to the top left corner okay 13672 07:26:28,680 --> 07:26:29,680 great 13673 07:26:29,580 --> 07:26:30,580 over here we can change the name to 13674 07:26:31,500 --> 07:26:32,500 recipe and then what we need is the 13675 07:26:33,718 --> 07:26:34,718 icons on here and for that we're going 13676 07:26:35,760 --> 07:26:36,760 to do pretty much the exact same thing 13677 07:26:37,260 --> 07:26:38,260 that we done on plate but before we do 13678 07:26:39,478 --> 07:26:40,478 that logic let's just get this basic 13679 07:26:40,978 --> 07:26:41,978 setup working so let's just position 13680 07:26:42,840 --> 07:26:43,840 everything so first of all the container 13681 07:26:45,058 --> 07:26:46,058 for all the templates let's anchor it on 13682 07:26:47,340 --> 07:26:48,340 the top left corner and let's push it 13683 07:26:49,978 --> 07:26:50,978 all the way over there and for 13684 07:26:51,600 --> 07:26:52,600 positioning them let's use this time the 13685 07:26:53,940 --> 07:26:54,940 vertical layout group so inside let's 13686 07:26:56,340 --> 07:26:57,340 duplicate the template just to be able 13687 07:26:57,780 --> 07:26:58,780 to see them okay so that's pretty much 13688 07:26:59,940 --> 07:27:00,940 we want we can actually set the width 13689 07:27:01,440 --> 07:27:02,440 and height both to zero and let's set 13690 07:27:03,298 --> 07:27:04,298 the spacing to something like 30. okay 13691 07:27:05,520 --> 07:27:06,520 so that's our basic UI now let's make 13692 07:27:07,860 --> 07:27:08,860 the script to run this 13693 07:27:09,298 --> 07:27:10,298 so over here in our scripts let's create 13694 07:27:11,340 --> 07:27:12,340 a brand new C sharp script for the 13695 07:27:13,320 --> 07:27:14,320 delivery manager UI let's go into the 13696 07:27:15,900 --> 07:27:16,900 parent game object and let's attach your 13697 07:27:18,058 --> 07:27:19,058 script let's open okay so now here first 13698 07:27:20,340 --> 07:27:21,340 we need a field for the container 13699 07:27:21,900 --> 07:27:22,900 another one for the template 13700 07:27:24,540 --> 07:27:25,540 so let's do a serialized film private 13701 07:27:27,180 --> 07:27:28,180 transform for the container 13702 07:27:29,400 --> 07:27:30,400 and another one for the transform and 13703 07:27:31,860 --> 07:27:32,860 this is going to be the recipe template 13704 07:27:34,200 --> 07:27:35,200 then let's do pretty much same thing we 13705 07:27:35,940 --> 07:27:36,940 did previously so first of all let's 13706 07:27:37,440 --> 07:27:38,440 actually go on a way in order to hide 13707 07:27:39,420 --> 07:27:40,420 the template so game objects set active 13708 07:27:41,638 --> 07:27:42,638 into false okay so first we hide the 13709 07:27:43,920 --> 07:27:44,920 template then let's make an update 13710 07:27:45,900 --> 07:27:46,900 visual function so private void update 13711 07:27:47,820 --> 07:27:48,820 visual 13712 07:27:48,958 --> 07:27:49,958 and for updating we're going to do the 13713 07:27:50,878 --> 07:27:51,878 exact same thing that we did so first 13714 07:27:52,860 --> 07:27:53,860 let's cycle through the container and 13715 07:27:54,478 --> 07:27:55,478 destroy everything except for the 13716 07:27:55,860 --> 07:27:56,860 template so do a 40 inch transform child 13717 07:27:58,920 --> 07:27:59,920 in the container 13718 07:28:02,100 --> 07:28:03,100 and if the child is the template 13719 07:28:05,340 --> 07:28:06,340 if so then we're going to continue and 13720 07:28:07,740 --> 07:28:08,740 if not we're going to destroy the child 13721 07:28:09,420 --> 07:28:10,420 game object okay so we have the cleanup 13722 07:28:12,120 --> 07:28:13,120 now we need is the second through all of 13723 07:28:14,458 --> 07:28:15,458 the waiting recipes so that means that 13724 07:28:16,620 --> 07:28:17,620 over here on delivery manager we need to 13725 07:28:18,540 --> 07:28:19,540 expose our waiting recipes on list so 13726 07:28:20,760 --> 07:28:21,760 let's go down here make a function to do 13727 07:28:22,260 --> 07:28:23,260 that probably going to return a list of 13728 07:28:24,420 --> 07:28:25,420 recipes so get waiting recipe so list 13729 07:28:28,440 --> 07:28:29,440 and we just return the waiting recipes 13730 07:28:31,680 --> 07:28:32,680 on list 13731 07:28:33,298 --> 07:28:34,298 okay great 13732 07:28:35,218 --> 07:28:36,218 so now here on the UI we can now go into 13733 07:28:37,860 --> 07:28:38,860 the delivery manager xsc static instance 13734 07:28:40,080 --> 07:28:41,080 in order to get the waiting recipes on 13735 07:28:42,478 --> 07:28:43,478 list so let's cycle through this so do a 13736 07:28:45,360 --> 07:28:46,360 40 inch for each recipe so recipe so in 13737 07:28:48,718 --> 07:28:49,718 the waiting rest vsl list 13738 07:28:51,180 --> 07:28:52,180 for each of them let's instantiate 13739 07:28:54,240 --> 07:28:55,240 and let's spawn our recipe template 13740 07:28:56,700 --> 07:28:57,700 spawn it inside the container and then 13741 07:28:59,458 --> 07:29:00,458 we just need to set this to enabled so 13742 07:29:01,740 --> 07:29:02,740 let's read the transform for the recipe 13743 07:29:03,240 --> 07:29:04,240 transform we grab this one grab the game 13744 07:29:05,940 --> 07:29:06,940 object and set active into true okay so 13745 07:29:09,180 --> 07:29:10,180 like this the only thing missing is the 13746 07:29:10,740 --> 07:29:11,740 text but that's okay for now 13747 07:29:12,478 --> 07:29:13,478 let you see where we're going to call 13748 07:29:13,978 --> 07:29:14,978 this function to update the visuals and 13749 07:29:16,260 --> 07:29:17,260 as usual we want to be smart and write 13750 07:29:18,000 --> 07:29:19,000 some good clean code so let's not do the 13751 07:29:20,580 --> 07:29:21,580 dirty approach of just updating this on 13752 07:29:22,620 --> 07:29:23,620 every single update instead let's only 13753 07:29:24,660 --> 07:29:25,660 call this function when something 13754 07:29:25,740 --> 07:29:26,740 actually changes so over here on the 13755 07:29:27,840 --> 07:29:28,840 delivery manager let's just make some 13756 07:29:29,400 --> 07:29:30,400 simple events 13757 07:29:30,718 --> 07:29:31,718 so if I'm like event event handler 13758 07:29:33,478 --> 07:29:34,478 let's go on recipes fund and another one 13759 07:29:37,200 --> 07:29:38,200 call it on recipe completed 13760 07:29:41,280 --> 07:29:42,280 and actually as soon as I add the event 13761 07:29:43,020 --> 07:29:44,020 handler which also add the using system 13762 07:29:44,638 --> 07:29:45,638 now here we have an interesting thing 13763 07:29:46,320 --> 07:29:47,320 we've got a nice namespace Collision 13764 07:29:48,120 --> 07:29:49,120 it's telling us that random is an 13765 07:29:50,280 --> 07:29:51,280 ambiguous reference between Unity engine 13766 07:29:51,900 --> 07:29:52,900 now random and system.r random that is 13767 07:29:54,180 --> 07:29:55,180 because both these namespaces Unity 13768 07:29:55,978 --> 07:29:56,978 engine and system both of them have a 13769 07:29:57,718 --> 07:29:58,718 class named exactly random so the code 13770 07:30:00,120 --> 07:30:01,120 here does not know which class we're 13771 07:30:01,680 --> 07:30:02,680 trying to use to solve this component we 13772 07:30:03,958 --> 07:30:04,958 really just need to be more specific in 13773 07:30:06,058 --> 07:30:07,058 this case here we want to use the UNT 13774 07:30:07,320 --> 07:30:08,320 engine version so let's just write the 13775 07:30:09,120 --> 07:30:10,120 full name Unity engine.renom and yep 13776 07:30:12,120 --> 07:30:13,120 that works okay so now let's fire off 13777 07:30:14,100 --> 07:30:15,100 the events so first of all the own 13778 07:30:16,138 --> 07:30:17,138 recipe spawns over here when we spawn a 13779 07:30:18,478 --> 07:30:19,478 recipe let's invoke this event so this 13780 07:30:21,360 --> 07:30:22,360 is ventar is not empty and let's also 13781 07:30:23,700 --> 07:30:24,700 get rid of the log we know we need that 13782 07:30:25,138 --> 07:30:26,138 okay now we could also add the wedding 13783 07:30:27,420 --> 07:30:28,420 recipe on the event artist but in this 13784 07:30:28,920 --> 07:30:29,920 case we don't need it just firing the 13785 07:30:30,240 --> 07:30:31,240 event is enough and then down here when 13786 07:30:32,218 --> 07:30:33,218 the players delivers something if the 13787 07:30:33,958 --> 07:30:34,958 player delivers the correct recipe we 13788 07:30:35,700 --> 07:30:36,700 remove it from the list and then let's 13789 07:30:37,860 --> 07:30:38,860 fire off the event so on recipe 13790 07:30:39,240 --> 07:30:40,240 completing let's invoke with this and 13791 07:30:42,240 --> 07:30:43,240 event rx.mt okay so we have the event 13792 07:30:44,878 --> 07:30:45,878 and down here we also don't need analog 13793 07:30:47,458 --> 07:30:48,458 okay so that works and finally over here 13794 07:30:49,978 --> 07:30:50,978 on the delivery man GUI let's just make 13795 07:30:52,680 --> 07:30:53,680 a private void start on start going to 13796 07:30:54,840 --> 07:30:55,840 the delivery manager access the static 13797 07:30:57,058 --> 07:30:58,058 instance and listen to both these events 13798 07:30:58,978 --> 07:30:59,978 so they spawned and let's also listen to 13799 07:31:01,440 --> 07:31:02,440 the other ones the library manager 13800 07:31:02,700 --> 07:31:03,700 instance on recipe completed 13801 07:31:05,280 --> 07:31:06,280 when either of these work let's just go 13802 07:31:07,620 --> 07:31:08,620 and update the visual so just like this 13803 07:31:09,900 --> 07:31:10,900 let's also rename this because again 13804 07:31:12,000 --> 07:31:13,000 instance doesn't sound like a very good 13805 07:31:14,040 --> 07:31:15,040 name let's actually rename this to only 13806 07:31:16,200 --> 07:31:17,200 remanager and same thing up here by the 13807 07:31:18,958 --> 07:31:19,958 way I'm using the visual studio shortcut 13808 07:31:20,878 --> 07:31:21,878 control RR in order to rename this to 13809 07:31:23,280 --> 07:31:24,280 delivering manager 13810 07:31:25,440 --> 07:31:26,440 and finally we also need to update the 13811 07:31:27,600 --> 07:31:28,600 visual OnStar just make sure the 13812 07:31:29,280 --> 07:31:30,280 previous ones do not show up okay that's 13813 07:31:31,920 --> 07:31:32,920 it so like this it should be working we 13814 07:31:34,080 --> 07:31:35,080 should be able to see no Visual and then 13815 07:31:36,058 --> 07:31:37,058 as more our spawned we should be able to 13816 07:31:37,798 --> 07:31:38,798 see each one being spawned until the 13817 07:31:39,298 --> 07:31:40,298 maximum so let's see just over here in 13818 07:31:41,400 --> 07:31:42,400 the UI let's make sure to drag the 13819 07:31:42,718 --> 07:31:43,718 references so the container and the 13820 07:31:44,520 --> 07:31:45,520 template and let's hit on play and okay 13821 07:31:46,920 --> 07:31:47,920 right away actually it spawned one 13822 07:31:48,298 --> 07:31:49,298 recipe it spawned instantly then after 13823 07:31:50,458 --> 07:31:51,458 four seconds there you go a second one 13824 07:31:52,080 --> 07:31:53,080 and after four seconds we should be able 13825 07:31:54,360 --> 07:31:55,360 to see yep another one now four more 13826 07:31:56,700 --> 07:31:57,700 seconds and we should see the final one 13827 07:31:58,558 --> 07:31:59,558 and now no matter how long we wait it 13828 07:32:00,840 --> 07:32:01,840 should no longer spawn anymore and yep 13829 07:32:03,058 --> 07:32:04,058 that works alright awesome so the basic 13830 07:32:05,638 --> 07:32:06,638 logic is working now let's handle the 13831 07:32:07,860 --> 07:32:08,860 proper Logic on the template for that 13832 07:32:10,200 --> 07:32:11,200 like I mentioned previously one approach 13833 07:32:12,420 --> 07:32:13,420 would be over here you could go and do a 13834 07:32:15,180 --> 07:32:16,180 transform.find 13835 07:32:16,978 --> 07:32:17,978 the actual recipe name text then get the 13836 07:32:20,040 --> 07:32:21,040 text mesh component and set it that 13837 07:32:21,900 --> 07:32:22,900 would work but like I mentioned 13838 07:32:23,040 --> 07:32:24,040 previously that would be very dirty not 13839 07:32:25,020 --> 07:32:26,020 good at all we should avoid using find 13840 07:32:27,478 --> 07:32:28,478 at any time and we should also avoid the 13841 07:32:30,120 --> 07:32:31,120 individual logic from the total logic so 13842 07:32:32,878 --> 07:32:33,878 let's do it properly and make a proper 13843 07:32:34,740 --> 07:32:35,740 script to handle each spawn template so 13844 07:32:37,200 --> 07:32:38,200 let's create a brand new c-sharp script 13845 07:32:39,000 --> 07:32:40,000 call this delivery manager single UI 13846 07:32:42,240 --> 07:32:43,240 single just because it refers to a 13847 07:32:44,218 --> 07:32:45,218 single recipe and also right now we 13848 07:32:46,500 --> 07:32:47,500 already have quite a few UI scripts so 13849 07:32:48,718 --> 07:32:49,718 let's organize our project again so 13850 07:32:50,878 --> 07:32:51,878 let's organize new folder for the UI and 13851 07:32:54,058 --> 07:32:55,058 inside let's put all of our UI scripts 13852 07:32:55,798 --> 07:32:56,798 so if we manage is single this one 13853 07:32:57,680 --> 07:32:58,680 deployed icons white icons and the 13854 07:33:00,298 --> 07:33:01,298 progress bar so let's put all of these 13855 07:33:02,340 --> 07:33:03,340 nicely organized in the UI folder okay 13856 07:33:04,200 --> 07:33:05,200 so with the script let's go into the 13857 07:33:05,760 --> 07:33:06,760 recipe template and attach the script 13858 07:33:07,500 --> 07:33:08,500 now let's open and over here let's begin 13859 07:33:09,958 --> 07:33:10,958 by adding a film for our text so a 13860 07:33:12,478 --> 07:33:13,478 serialized field 13861 07:33:13,860 --> 07:33:14,860 and over here it's also very important 13862 07:33:16,378 --> 07:33:17,378 for the text we are not using the text 13863 07:33:19,138 --> 07:33:20,138 inside DNT engine.ui this is the in 13864 07:33:21,780 --> 07:33:22,780 Legacy text it is not text mesh Pro so 13865 07:33:24,058 --> 07:33:25,058 this is not what we were using instead 13866 07:33:26,340 --> 07:33:27,340 we want to use text mesh Pro U going 13867 07:33:28,920 --> 07:33:29,920 which is inside TM Pro 13868 07:33:31,558 --> 07:33:32,558 so we need to go up here and add using 13869 07:33:33,420 --> 07:33:34,420 TM Pro and now we can use this type and 13870 07:33:36,058 --> 07:33:37,058 also make sure you're using text mesh 13871 07:33:37,500 --> 07:33:38,500 Pro ugui and not text mesh Pro this one 13872 07:33:40,138 --> 07:33:41,138 also exists but don't mix these two 13873 07:33:41,940 --> 07:33:42,940 these are two very different types if we 13874 07:33:44,700 --> 07:33:45,700 go over here in the editor and if 13875 07:33:47,040 --> 07:33:48,040 outside the canvas if I just create and 13876 07:33:49,320 --> 07:33:50,320 create new 3D object a new text object 13877 07:33:51,600 --> 07:33:52,600 if I do that then if we look over here 13878 07:33:54,058 --> 07:33:55,058 in the inspector we see this one as a 13879 07:33:55,620 --> 07:33:56,620 type text mesh Pro whereas for the ones 13880 07:33:58,020 --> 07:33:59,020 that we're using inside the canvas if we 13881 07:33:59,638 --> 07:34:00,638 unlock this is text mesh Pro it's a UI 13882 07:34:01,860 --> 07:34:02,860 text so these are the two different 13883 07:34:03,780 --> 07:34:04,780 classes within text mesh Pro you have 13884 07:34:06,298 --> 07:34:07,298 text mesh Pro and text mesh Pro ugly 13885 07:34:08,400 --> 07:34:09,400 we're working on the UI so we want this 13886 07:34:10,620 --> 07:34:11,620 one okay so we named this the recipe 13887 07:34:12,958 --> 07:34:13,958 name text 13888 07:34:14,638 --> 07:34:15,638 okay that's it over here in the editor 13889 07:34:17,458 --> 07:34:18,458 let's drag our reference all right so 13890 07:34:19,620 --> 07:34:20,620 now this group let's make a function to 13891 07:34:21,058 --> 07:34:22,058 set the recipe so a public void and 13892 07:34:24,058 --> 07:34:25,058 let's call it set recipe SL 13893 07:34:29,280 --> 07:34:30,280 they're going to receive a recipe so 13894 07:34:31,020 --> 07:34:32,020 recipe so 13895 07:34:33,120 --> 07:34:34,120 then we just go into the recipe name 13896 07:34:35,040 --> 07:34:36,040 text and we set the text to recipe so 13897 07:34:37,020 --> 07:34:38,020 dot recipe name 13898 07:34:38,940 --> 07:34:39,940 okay so that's pretty much it now over 13899 07:34:41,280 --> 07:34:42,280 here on the Y script when we instantiate 13900 07:34:43,680 --> 07:34:44,680 our recipe transform let's get component 13901 07:34:46,860 --> 07:34:47,860 of type of our 13902 07:34:49,280 --> 07:34:50,280 delivery manager single UI and call set 13903 07:34:52,680 --> 07:34:53,680 recipe so and pass in the recipe so okay 13904 07:34:55,200 --> 07:34:56,200 so let's see if the name shows up any 13905 07:34:57,298 --> 07:34:58,298 operator wait does show up so we can see 13906 07:34:59,218 --> 07:35:00,218 that we generate a cheeseburger recipe 13907 07:35:00,958 --> 07:35:01,958 and right now a mega burger recipe okay 13908 07:35:03,180 --> 07:35:04,180 great so all that's left are the icons 13909 07:35:05,580 --> 07:35:06,580 on here so like I said that is going to 13910 07:35:07,740 --> 07:35:08,740 be yet another usage of our template 13911 07:35:10,320 --> 07:35:11,320 pattern 13912 07:35:11,520 --> 07:35:12,520 so inside the recipe template let's 13913 07:35:13,920 --> 07:35:14,920 create an empty game object currently 13914 07:35:15,780 --> 07:35:16,780 the icon container and then inside that 13915 07:35:18,360 --> 07:35:19,360 let's make the template and template is 13916 07:35:20,340 --> 07:35:21,340 just going to be an image so we can just 13917 07:35:21,660 --> 07:35:22,660 create an image to our way 13918 07:35:23,580 --> 07:35:24,580 called the ingredient image let's scale 13919 07:35:26,940 --> 07:35:27,940 it with a size of 40 and 40. let's put a 13920 07:35:30,240 --> 07:35:31,240 image by default just like that and on 13921 07:35:32,700 --> 07:35:33,700 the icon container let's put the width 13922 07:35:34,500 --> 07:35:35,500 of zero height of zero and let's put a 13923 07:35:36,780 --> 07:35:37,780 horizontal layout group put it over 13924 07:35:39,058 --> 07:35:40,058 there on the left side and we can create 13925 07:35:41,400 --> 07:35:42,400 a bunch more just to see how it looks 13926 07:35:43,020 --> 07:35:44,020 okay so that's pretty much it now over 13927 07:35:45,540 --> 07:35:46,540 here on the single script let's add a 13928 07:35:48,298 --> 07:35:49,298 serialized field private transform for 13929 07:35:51,298 --> 07:35:52,298 the icon container another one for the 13930 07:35:54,240 --> 07:35:55,240 icon template 13931 07:35:56,218 --> 07:35:57,218 then we do the same thing as usual so 13932 07:35:58,260 --> 07:35:59,260 when we set the recipe so let's first of 13933 07:36:00,780 --> 07:36:01,780 all clean up the container so let's do a 13934 07:36:02,520 --> 07:36:03,520 40 inch transform child in the icon 13935 07:36:05,638 --> 07:36:06,638 container 13936 07:36:07,020 --> 07:36:08,020 and if the channel is the template 13937 07:36:10,138 --> 07:36:11,138 then we want to continue and ignore it 13938 07:36:12,120 --> 07:36:13,120 if not we want to destroy the child.game 13939 07:36:14,700 --> 07:36:15,700 object okay so that's the cleanup 13940 07:36:17,638 --> 07:36:18,638 and then let's do a four inch kitchen 13941 07:36:19,740 --> 07:36:20,740 object as so 13942 07:36:21,298 --> 07:36:22,298 in the recipe so dot kitchen object.zone 13943 07:36:25,080 --> 07:36:26,080 list 13944 07:36:26,458 --> 07:36:27,458 second through all of this let's 13945 07:36:28,200 --> 07:36:29,200 instantiate our icon template 13946 07:36:31,200 --> 07:36:32,200 instantiate it inside the icon container 13947 07:36:34,138 --> 07:36:35,138 so this is going to be the transform for 13948 07:36:36,180 --> 07:36:37,180 the icon transform 13949 07:36:38,458 --> 07:36:39,458 then as usual we need to go into the 13950 07:36:40,138 --> 07:36:41,138 game object set active in order to 13951 07:36:41,940 --> 07:36:42,940 enable it 13952 07:36:43,378 --> 07:36:44,378 and also let's go up here make a private 13953 07:36:45,900 --> 07:36:46,900 way to wake and on awake the icon 13954 07:36:47,580 --> 07:36:48,580 template game object let's disable it 13955 07:36:50,400 --> 07:36:51,400 okay we don't want the template to be 13956 07:36:52,620 --> 07:36:53,620 visible 13957 07:36:53,580 --> 07:36:54,580 okay so we instantiate the template we 13958 07:36:56,520 --> 07:36:57,520 set it as active then since this one 13959 07:36:59,040 --> 07:37:00,040 just has an image we can just do a get 13960 07:37:01,020 --> 07:37:02,020 component of Type image 13961 07:37:03,298 --> 07:37:04,298 that's image not image conversion 13962 07:37:06,058 --> 07:37:07,058 so image so it's this one the one inside 13963 07:37:08,940 --> 07:37:09,940 Unity engine.ui so let's get this image 13964 07:37:11,940 --> 07:37:12,940 and let's modify the Sprites and set it 13965 07:37:14,458 --> 07:37:15,458 to this kitchen object so that's right 13966 07:37:16,138 --> 07:37:17,138 okay so that's it that should do it 13967 07:37:18,360 --> 07:37:19,360 let's test over here in the editor let's 13968 07:37:20,760 --> 07:37:21,760 just go into the template let's drag the 13969 07:37:22,798 --> 07:37:23,798 container reference and the template 13970 07:37:24,780 --> 07:37:25,780 reference and let's also rename this 13971 07:37:26,760 --> 07:37:27,760 instead of ingredient image put icon 13972 07:37:28,620 --> 07:37:29,620 template just to be a bit more clear and 13973 07:37:30,840 --> 07:37:31,840 we can get rid of the other ones or 13974 07:37:31,920 --> 07:37:32,920 leave them doesn't really matter okay 13975 07:37:33,180 --> 07:37:34,180 great so let's hit on play and see and 13976 07:37:36,180 --> 07:37:37,180 yep right away does work so we can see a 13977 07:37:37,978 --> 07:37:38,978 burger is composed of a burger and a bun 13978 07:37:40,138 --> 07:37:41,138 a satellite yep there you go some sliced 13979 07:37:42,600 --> 07:37:43,600 cabbage and sliced tomatoes then 13980 07:37:44,638 --> 07:37:45,638 cheeseburger same thing as the burger 13981 07:37:45,900 --> 07:37:46,900 with some cheese and then another Burger 13982 07:37:47,878 --> 07:37:48,878 let's just deliver until we see the mega 13983 07:37:49,620 --> 07:37:50,620 Burger so let's deliver a cheeseburger 13984 07:37:52,138 --> 07:37:53,138 let's cut it 13985 07:37:54,240 --> 07:37:55,240 get this get some bread place it in 13986 07:37:57,058 --> 07:37:58,058 there pick it up before it burns that's 13987 07:37:58,920 --> 07:37:59,920 a cheeseburger so that one should vanish 13988 07:38:00,420 --> 07:38:01,420 and if they're good does vanish let's 13989 07:38:02,520 --> 07:38:03,520 see something else not cheeseburgers so 13990 07:38:04,260 --> 07:38:05,260 let's keep doing until we get a Mega 13991 07:38:06,478 --> 07:38:07,478 burger just see that everything works 13992 07:38:08,520 --> 07:38:09,520 so let's deliver a regular burger okay 13993 07:38:11,218 --> 07:38:12,218 now let's deliver a regular salad 13994 07:38:17,638 --> 07:38:18,638 okay just pick up like that like that 13995 07:38:19,680 --> 07:38:20,680 and drop it 13996 07:38:21,120 --> 07:38:22,120 okay let's see 13997 07:38:23,218 --> 07:38:24,218 any up there it is the Mega butter all 13998 07:38:25,860 --> 07:38:26,860 right great so the visual logic is fully 13999 07:38:28,138 --> 07:38:29,138 working and the delivery logic all of it 14000 07:38:30,120 --> 07:38:31,120 is working 14001 07:38:31,200 --> 07:38:32,200 so I can deliver the right recipes and 14002 07:38:33,240 --> 07:38:34,240 get rid of them from the recipe waiting 14003 07:38:35,100 --> 07:38:36,100 list and more are spawned every time 14004 07:38:36,780 --> 07:38:37,780 here we can see the name of the recipe 14005 07:38:38,520 --> 07:38:39,520 as well as all of the nice icons okay so 14006 07:38:41,280 --> 07:38:42,280 with all this our game is really taking 14007 07:38:42,718 --> 07:38:43,718 shape everything is very close to being 14008 07:38:44,760 --> 07:38:45,760 done 14009 07:38:45,540 --> 07:38:46,540 one massive thing we're still missing is 14010 07:38:47,280 --> 07:38:48,280 an obvious one which is sound so let's 14011 07:38:49,378 --> 07:38:50,378 do that in the next lecture 14012 07:38:52,020 --> 07:38:53,020 hey again quick intermission you're 14013 07:38:54,000 --> 07:38:55,000 almost at the end so once again congrats 14014 07:38:56,040 --> 07:38:57,040 for making it this far this is the 14015 07:38:58,138 --> 07:38:59,138 second secret call out go ahead Post in 14016 07:39:00,180 --> 07:39:01,180 the comments a timestamp and a nice monk 14017 07:39:02,100 --> 07:39:03,100 Emoji it won't be fun to see how many 14018 07:39:04,020 --> 07:39:05,020 people make it to this point by now you 14019 07:39:06,120 --> 07:39:07,120 already know about the website I hope 14020 07:39:07,860 --> 07:39:08,860 it's been very useful to you and you 14021 07:39:09,780 --> 07:39:10,780 already know to ask any questions in the 14022 07:39:11,280 --> 07:39:12,280 comments if you need help with anything 14023 07:39:12,540 --> 07:39:13,540 so that's life for me to say right now 14024 07:39:14,820 --> 07:39:15,820 is thanks for watching the course so far 14025 07:39:16,500 --> 07:39:17,500 and I really hope you've already learned 14026 07:39:18,120 --> 07:39:19,120 a ton there's only a bunch more lectures 14027 07:39:20,760 --> 07:39:21,760 until we get to the final polish game so 14028 07:39:22,680 --> 07:39:23,680 let's continue on the next lecture 14029 07:39:25,080 --> 07:39:26,080 hello and welcome I'm your code monkey 14030 07:39:27,000 --> 07:39:28,000 in this lecture we're going to add some 14031 07:39:29,280 --> 07:39:30,280 audio to our game starting with a really 14032 07:39:31,320 --> 07:39:32,320 nice music track okay so our game is 14033 07:39:33,478 --> 07:39:34,478 already looking pretty good but 14034 07:39:35,040 --> 07:39:36,040 everything is still way too silent so 14035 07:39:37,260 --> 07:39:38,260 let's begin by adding some music adding 14036 07:39:39,478 --> 07:39:40,478 this is actually extremely new in the 14037 07:39:42,420 --> 07:39:43,420 included assets over here inside the 14038 07:39:44,218 --> 07:39:45,218 sounds we've got a really nice music 14039 07:39:46,020 --> 07:39:47,020 track I hired a musician to make this it 14040 07:39:48,360 --> 07:39:49,360 sounds really good it's a seamless Loop 14041 07:39:50,760 --> 07:39:51,760 so to add to our game it's going to be 14042 07:39:52,080 --> 07:39:53,080 super simple we just want a constant 14043 07:39:54,718 --> 07:39:55,718 never-ending Loop so let's begin by 14044 07:39:56,760 --> 07:39:57,760 creating an empty game object call it 14045 07:39:58,740 --> 07:39:59,740 the Music Manager 14046 07:40:00,298 --> 07:40:01,298 let's reset transform keep things 14047 07:40:02,400 --> 07:40:03,400 organized and let's add a component and 14048 07:40:04,440 --> 07:40:05,440 we want the component an audio Source 14049 07:40:06,660 --> 07:40:07,660 here it is this one like name implies 14050 07:40:09,420 --> 07:40:10,420 this one acts like a source of audio 14051 07:40:11,580 --> 07:40:12,580 you will note how by default on the main 14052 07:40:13,680 --> 07:40:14,680 camera down here it already has an audio 14053 07:40:16,138 --> 07:40:17,138 listener so the source plays some sound 14054 07:40:18,360 --> 07:40:19,360 and The Listener listens to it now for 14055 07:40:20,218 --> 07:40:21,218 here we just need to set these fields so 14056 07:40:22,440 --> 07:40:23,440 for example on the autoclave let's make 14057 07:40:24,058 --> 07:40:25,058 sure to drag the music audio okay great 14058 07:40:26,218 --> 07:40:27,218 next over here and let's enable and play 14059 07:40:28,500 --> 07:40:29,500 on a wink we wanted to start playing 14060 07:40:30,478 --> 07:40:31,478 right wing and for this track we do want 14061 07:40:32,878 --> 07:40:33,878 to enable looping okay great then for 14062 07:40:35,218 --> 07:40:36,218 priority basically UNT has limited to 14063 07:40:37,978 --> 07:40:38,978 how many sounds can be played at once if 14064 07:40:40,138 --> 07:40:41,138 you play too many then some sounds won't 14065 07:40:42,120 --> 07:40:43,120 play and which ones do you play is all 14066 07:40:44,280 --> 07:40:45,280 based on priority we always want the 14067 07:40:46,320 --> 07:40:47,320 music to play so let's put this one on 14068 07:40:47,940 --> 07:40:48,940 Max priority 14069 07:40:49,138 --> 07:40:50,138 then for the volume later on we're going 14070 07:40:51,840 --> 07:40:52,840 to make a proper option screen to handle 14071 07:40:53,580 --> 07:40:54,580 this 14072 07:40:54,298 --> 07:40:55,298 but for now let's put it on something 14073 07:40:55,860 --> 07:40:56,860 like 0.4 or 0.5 just make a nice 14074 07:40:58,860 --> 07:40:59,860 background track then we have here the 14075 07:41:01,260 --> 07:41:02,260 spatial blend for this music track we 14076 07:41:03,540 --> 07:41:04,540 wanted to play the same regardless of 14077 07:41:05,160 --> 07:41:06,160 where the camera is so let's make this 14078 07:41:07,440 --> 07:41:08,440 all the way if only a 2d sound okay 14079 07:41:09,780 --> 07:41:10,780 that's it we don't need to play around 14080 07:41:11,400 --> 07:41:12,400 with any of the other settings and just 14081 07:41:13,320 --> 07:41:14,320 like this if we are on play any up 14082 07:41:15,660 --> 07:41:16,660 there's the music now if you're not 14083 07:41:17,400 --> 07:41:18,400 hearing anything make sure that on the 14084 07:41:19,138 --> 07:41:20,138 game view first of all that the game is 14085 07:41:20,580 --> 07:41:21,580 actually selected make sure the scene is 14086 07:41:22,620 --> 07:41:23,620 in Focus so over here I can move around 14087 07:41:24,478 --> 07:41:25,478 so the game's in Focus then on game view 14088 07:41:26,820 --> 07:41:27,820 we are on the top right corner make sure 14089 07:41:28,920 --> 07:41:29,920 this sound icon is toggled if not then 14090 07:41:31,260 --> 07:41:32,260 everything is muted and also again make 14091 07:41:33,780 --> 07:41:34,780 sure like I mentioned on the main camera 14092 07:41:35,280 --> 07:41:36,280 that it has the audio and listener 14093 07:41:36,840 --> 07:41:37,840 component with all that yep you should 14094 07:41:38,700 --> 07:41:39,700 be able to hear the music 14095 07:41:40,080 --> 07:41:41,080 now this song is playing and it won't 14096 07:41:42,000 --> 07:41:43,000 Loop forever just like we wanted 14097 07:41:43,440 --> 07:41:44,440 personally I really like how it sounds 14098 07:41:45,360 --> 07:41:46,360 I'm really happy with what the composer 14099 07:41:47,280 --> 07:41:48,280 made it perfectly matches the E5 of the 14100 07:41:49,138 --> 07:41:50,138 game so it really is this simple to add 14101 07:41:51,298 --> 07:41:52,298 some music to the game let me just point 14102 07:41:53,520 --> 07:41:54,520 out one thing also related to sound one 14103 07:41:56,160 --> 07:41:57,160 of the things you can make is an audio 14104 07:41:57,718 --> 07:41:58,718 mixer so for example on the project 14105 07:41:59,400 --> 07:42:00,400 files let's create a brand new and let's 14106 07:42:02,580 --> 07:42:03,580 find over here the audio mixer so there 14107 07:42:05,160 --> 07:42:06,160 you go here is an audio mixer then you 14108 07:42:06,660 --> 07:42:07,660 can double click to open up the audio 14109 07:42:08,040 --> 07:42:09,040 mixer window and then over here you have 14110 07:42:10,378 --> 07:42:11,378 the masternode 14111 07:42:11,878 --> 07:42:12,878 and then you can create multiple groups 14112 07:42:13,740 --> 07:42:14,740 so let's create a brand new groove for 14113 07:42:15,660 --> 07:42:16,660 something else 14114 07:42:16,920 --> 07:42:17,920 and then you can play around over here 14115 07:42:18,540 --> 07:42:19,540 with the effects with the volume all 14116 07:42:20,638 --> 07:42:21,638 kinds of things all kinds of effects 14117 07:42:22,020 --> 07:42:23,020 everything then for each sound where you 14118 07:42:24,298 --> 07:42:25,298 have the audio Source over here note how 14119 07:42:25,978 --> 07:42:26,978 you have an output and for this output 14120 07:42:28,260 --> 07:42:29,260 you can set it to play on the message so 14121 07:42:29,700 --> 07:42:30,700 it plays on everything or set it on just 14122 07:42:31,680 --> 07:42:32,680 one individual group so with this you 14123 07:42:33,900 --> 07:42:34,900 could assign a group to one individual 14124 07:42:35,820 --> 07:42:36,820 type of sound effect or the music or so 14125 07:42:38,040 --> 07:42:39,040 on maybe you could even have your music 14126 07:42:40,138 --> 07:42:41,138 split into multiple stems so there's a 14127 07:42:42,780 --> 07:42:43,780 lot you can do but for me I'm not an 14128 07:42:44,638 --> 07:42:45,638 audio engineer audio is probably the 14129 07:42:46,378 --> 07:42:47,378 part of game development that I know 14130 07:42:47,820 --> 07:42:48,820 least about I just stick with the 14131 07:42:49,440 --> 07:42:50,440 absolute Basics but if you want to learn 14132 07:42:51,360 --> 07:42:52,360 more definitely look into the audio 14133 07:42:52,920 --> 07:42:53,920 mixer this is an extremely powerful tool 14134 07:42:55,020 --> 07:42:56,020 but like I said for me I don't know how 14135 07:42:57,058 --> 07:42:58,058 to work with it so I'm just going to 14136 07:42:58,378 --> 07:42:59,378 stick with the basics so on the output 14137 07:43:00,780 --> 07:43:01,780 let's revert back into none close the 14138 07:43:02,878 --> 07:43:03,878 audio mixer and get rid of this and 14139 07:43:05,340 --> 07:43:06,340 there it is music is playing and the 14140 07:43:06,840 --> 07:43:07,840 wrong sounds really nice alright so here 14141 07:43:09,058 --> 07:43:10,058 we very easily added some music to our 14142 07:43:11,040 --> 07:43:12,040 game this lecture is actually super 14143 07:43:12,718 --> 07:43:13,718 short because it is generally that 14144 07:43:14,340 --> 07:43:15,340 simple now the next thing that we need 14145 07:43:16,200 --> 07:43:17,200 is not going to be a little bit more 14146 07:43:17,820 --> 07:43:18,820 complex and that is adding sound effects 14147 07:43:19,798 --> 07:43:20,798 so let's do that in the next lecture 14148 07:43:22,920 --> 07:43:23,920 hello and welcome I'm your code monkey 14149 07:43:24,840 --> 07:43:25,840 in this lecture we're going to add some 14150 07:43:27,058 --> 07:43:28,058 sound effects for our game okay so 14151 07:43:29,218 --> 07:43:30,218 previously we already added some really 14152 07:43:31,020 --> 07:43:32,020 nice music now let's add a whole bunch 14153 07:43:33,000 --> 07:43:34,000 of sound effects in the project files if 14154 07:43:35,458 --> 07:43:36,458 we go inside the assets over here we've 14155 07:43:37,080 --> 07:43:38,080 got all kinds of sound effects recently 14156 07:43:39,298 --> 07:43:40,298 I heard the really nice sound designer 14157 07:43:40,860 --> 07:43:41,860 to make all of these and I think they 14158 07:43:42,240 --> 07:43:43,240 all sound really great so let's add them 14159 07:43:44,280 --> 07:43:45,280 to our game now when it comes to sound 14160 07:43:46,378 --> 07:43:47,378 effects there are two main ways to play 14161 07:43:47,940 --> 07:43:48,940 a sound one is just like we did for the 14162 07:43:50,218 --> 07:43:51,218 music so we can create a game object at 14163 07:43:52,260 --> 07:43:53,260 the audio Source component and play it 14164 07:43:53,820 --> 07:43:54,820 that's one approach but that basically 14165 07:43:55,860 --> 07:43:56,860 requires pre-preparing the sound objects 14166 07:43:58,080 --> 07:43:59,080 so there is another simpler way that 14167 07:44:00,240 --> 07:44:01,240 just requires one line of code so let's 14168 07:44:02,160 --> 07:44:03,160 begin by making a Sound Manager game 14169 07:44:03,780 --> 07:44:04,780 object so a new empty game object for 14170 07:44:05,820 --> 07:44:06,820 The Sound Manager let's reset the 14171 07:44:08,340 --> 07:44:09,340 transform now let's make our script so 14172 07:44:10,680 --> 07:44:11,680 let's go in the scripts folder create a 14173 07:44:13,020 --> 07:44:14,020 brand new c-sharp script for The Sound 14174 07:44:14,760 --> 07:44:15,760 Manager let's attach the script and open 14175 07:44:17,700 --> 07:44:18,700 okay so now here let's make a function 14176 07:44:19,920 --> 07:44:20,920 to play Simple sound so let's do a 14177 07:44:22,500 --> 07:44:23,500 private void just call it play sound and 14178 07:44:25,798 --> 07:44:26,798 over here the way we play sound through 14179 07:44:27,240 --> 07:44:28,240 code is actually super simple we just go 14180 07:44:29,520 --> 07:44:30,520 inside the audio Source class 14181 07:44:31,680 --> 07:44:32,680 and in here there's a static function 14182 07:44:33,600 --> 07:44:34,600 play clip at point this as you can see 14183 07:44:35,878 --> 07:44:36,878 it takes an audio clip a vector 3 for 14184 07:44:37,978 --> 07:44:38,978 the position and finally a volume so 14185 07:44:40,138 --> 07:44:41,138 basically it won't play that sound on 14186 07:44:41,700 --> 07:44:42,700 that position by default TNT already has 14187 07:44:44,218 --> 07:44:45,218 3D sound so if you play the sound on the 14188 07:44:46,440 --> 07:44:47,440 left or the right side of the camera it 14189 07:44:47,878 --> 07:44:48,878 won't play in the correct place also for 14190 07:44:49,920 --> 07:44:50,920 the volume the further away it is from 14191 07:44:51,478 --> 07:44:52,478 the camera the lower it will be and if 14192 07:44:53,458 --> 07:44:54,458 we don't want the 3D sound we can just 14193 07:44:55,020 --> 07:44:56,020 play it directly on top of the camera 14194 07:44:56,280 --> 07:44:57,280 position okay so in this function let's 14195 07:44:58,500 --> 07:44:59,500 receive our arguments so for the audio 14196 07:45:01,080 --> 07:45:02,080 clip 14197 07:45:02,218 --> 07:45:03,218 it's going to be our audio clip 14198 07:45:04,620 --> 07:45:05,620 then let's receive the vector 340 14199 07:45:06,478 --> 07:45:07,478 position and let's also receive an 14200 07:45:08,820 --> 07:45:09,820 optional one for the volume 14201 07:45:11,040 --> 07:45:12,040 let's just default this to 1f okay so 14202 07:45:13,740 --> 07:45:14,740 here we just pass this in into our 14203 07:45:15,540 --> 07:45:16,540 function so the position and the volume 14204 07:45:17,160 --> 07:45:18,160 okay great so now let's call this nice 14205 07:45:19,978 --> 07:45:20,978 function and for example let's start 14206 07:45:22,138 --> 07:45:23,138 with a simple one so let's start with 14207 07:45:23,638 --> 07:45:24,638 the delivery sounds so over here on the 14208 07:45:25,860 --> 07:45:26,860 delivery manager script down here we 14209 07:45:28,320 --> 07:45:29,320 have the logic for delivering a recipe 14210 07:45:30,120 --> 07:45:31,120 and over here we know when we completed 14211 07:45:32,760 --> 07:45:33,760 a successful recipe or when we failed 14212 07:45:34,860 --> 07:45:35,860 and the player delivered a wrong recipe 14213 07:45:36,360 --> 07:45:37,360 so this is where we want to play some 14214 07:45:38,400 --> 07:45:39,400 sounds and again here we have yet 14215 07:45:40,558 --> 07:45:41,558 another very important clean code 14216 07:45:42,000 --> 07:45:43,000 question 14217 07:45:42,958 --> 07:45:43,958 we could definitely call the play sound 14218 07:45:45,000 --> 07:45:46,000 function directly from here that would 14219 07:45:47,160 --> 07:45:48,160 work but of course that would make this 14220 07:45:48,958 --> 07:45:49,958 class tightly coupled with The Sound 14221 07:45:50,340 --> 07:45:51,340 Manager for a simple game on this scale 14222 07:45:53,040 --> 07:45:54,040 that approach can work just play sounds 14223 07:45:55,080 --> 07:45:56,080 directly from the logic code however 14224 07:45:57,180 --> 07:45:58,180 again to make things properly we should 14225 07:45:59,218 --> 07:46:00,218 really separate the logic from the sound 14226 07:46:00,900 --> 07:46:01,900 just like we separated in logic from the 14227 07:46:02,760 --> 07:46:03,760 visuals so instead let's not call the 14228 07:46:05,340 --> 07:46:06,340 sound directly from here instead let's 14229 07:46:07,378 --> 07:46:08,378 make two more events 14230 07:46:09,058 --> 07:46:10,058 so let's make one on recipe success 14231 07:46:12,058 --> 07:46:13,058 another one on recipe failed 14232 07:46:15,360 --> 07:46:16,360 okay so now let's fire off these events 14233 07:46:18,420 --> 07:46:19,420 so over here we have the success so on 14234 07:46:20,458 --> 07:46:21,458 recipe success and if we get down here 14235 07:46:23,040 --> 07:46:24,040 then we have a fail so on recipe fail 14236 07:46:25,558 --> 07:46:26,558 okay great we have two events now back 14237 07:46:28,740 --> 07:46:29,740 here on The Sound Manager we can just 14238 07:46:30,298 --> 07:46:31,298 listen to those so let's do a start go 14239 07:46:32,218 --> 07:46:33,218 into the delivering manager access the 14240 07:46:34,020 --> 07:46:35,020 instance and listen to the on success 14241 07:46:36,600 --> 07:46:37,600 and on failed events let's listen to 14242 07:46:39,180 --> 07:46:40,180 that one delivery manager instance on 14243 07:46:41,760 --> 07:46:42,760 recipe film listen to both of these 14244 07:46:43,920 --> 07:46:44,920 again let's write some good clean codes 14245 07:46:46,320 --> 07:46:47,320 so let's rename this one instead of 14246 07:46:48,000 --> 07:46:49,000 instance let's put it delivery manager 14247 07:46:50,218 --> 07:46:51,218 and same thing on this one also name it 14248 07:46:54,000 --> 07:46:55,000 correctly delivery menu 14249 07:46:56,700 --> 07:46:57,700 okay great so now when you have this we 14250 07:47:00,600 --> 07:47:01,600 want to call and play sound 14251 07:47:02,340 --> 07:47:03,340 and now I want to pass in a reference to 14252 07:47:04,500 --> 07:47:05,500 the recipe film sound so technically one 14253 07:47:07,320 --> 07:47:08,320 approach would be appear to add a 14254 07:47:08,760 --> 07:47:09,760 serialized film for an audio clip that 14255 07:47:10,558 --> 07:47:11,558 would work but since we've already done 14256 07:47:12,540 --> 07:47:13,540 that so many times in this course here 14257 07:47:14,160 --> 07:47:15,160 let's use a different approach that I 14258 07:47:15,840 --> 07:47:16,840 also like to use 14259 07:47:17,100 --> 07:47:18,100 let's create a scriptable object to home 14260 07:47:19,020 --> 07:47:20,020 the reference to all of our sounds so 14261 07:47:21,058 --> 07:47:22,058 similar to how we Define the script 14262 07:47:22,620 --> 07:47:23,620 object on all of our recipes let's just 14263 07:47:25,260 --> 07:47:26,260 comment this out just make sure the code 14264 07:47:26,638 --> 07:47:27,638 compounds okay great so back here in the 14265 07:47:28,920 --> 07:47:29,920 editor let's make a new script more 14266 07:47:30,478 --> 07:47:31,478 object type so let's create a brand new 14267 07:47:32,040 --> 07:47:33,040 c-sharp script 14268 07:47:33,420 --> 07:47:34,420 for the audio clip refs script long 14269 07:47:36,298 --> 07:47:37,298 object now here let's make this a simple 14270 07:47:39,080 --> 07:47:40,080 scriptable object with a create asset 14271 07:47:42,360 --> 07:47:43,360 menu 14272 07:47:43,620 --> 07:47:44,620 okay so now for the fields if we 14273 07:47:46,138 --> 07:47:47,138 unlocking the S over here the audio 14274 07:47:47,940 --> 07:47:48,940 design that I hired actually made 14275 07:47:49,680 --> 07:47:50,680 several variations for each sound so 14276 07:47:51,958 --> 07:47:52,958 we've got multiple chops multiple 14277 07:47:53,520 --> 07:47:54,520 delivery fails and so on 14278 07:47:55,200 --> 07:47:56,200 so back in the code here instead of 14279 07:47:56,820 --> 07:47:57,820 storing a reference for a single audio 14280 07:47:58,558 --> 07:47:59,558 clip let's store an array for all of 14281 07:48:01,320 --> 07:48:02,320 them so we have the chop then we have on 14282 07:48:03,840 --> 07:48:04,840 the other Solutions and all of the 14283 07:48:06,000 --> 07:48:07,000 references 14284 07:48:07,200 --> 07:48:08,200 so there's a job there's the delivery 14285 07:48:09,298 --> 07:48:10,298 fail 14286 07:48:10,740 --> 07:48:11,740 then we have delivery success then we 14287 07:48:14,100 --> 07:48:15,100 have footsteps 14288 07:48:17,280 --> 07:48:18,280 then the object drop then the object 14289 07:48:20,280 --> 07:48:21,280 pickup 14290 07:48:21,780 --> 07:48:22,780 then we have the stove Sizzle although 14291 07:48:24,058 --> 07:48:25,058 this one is just one then we have the 14292 07:48:26,820 --> 07:48:27,820 trash and finally we have the warning 14293 07:48:30,840 --> 07:48:31,840 alright so these are all of the sound 14294 07:48:32,700 --> 07:48:33,700 references we're going to use back in 14295 07:48:34,920 --> 07:48:35,920 the editor let's just create the object 14296 07:48:36,420 --> 07:48:37,420 so on the script mode objects let's 14297 07:48:38,400 --> 07:48:39,400 create a brand new one let's make it of 14298 07:48:40,740 --> 07:48:41,740 audio clip per episode 14299 07:48:42,420 --> 07:48:43,420 just name it audio clip refs so 14300 07:48:46,138 --> 07:48:47,138 and over here let's just write the 14301 07:48:47,638 --> 07:48:48,638 references so let's use that quick ENT 14302 07:48:49,680 --> 07:48:50,680 tip in order to unlock the inspector now 14303 07:48:51,780 --> 07:48:52,780 I can select all the chops and drag them 14304 07:48:53,878 --> 07:48:54,878 all the delivery fails drag them it's 14305 07:48:56,458 --> 07:48:57,458 only re-success drag it then for all of 14306 07:48:59,760 --> 07:49:00,760 the footsteps after that are all of the 14307 07:49:02,638 --> 07:49:03,638 object drops then the pickups then we 14308 07:49:06,298 --> 07:49:07,298 have the sizzle which is just one 14309 07:49:08,520 --> 07:49:09,520 finally we have the trash and the 14310 07:49:11,100 --> 07:49:12,100 warning okay those are all the 14311 07:49:13,080 --> 07:49:14,080 references so our script on object now 14312 07:49:15,478 --> 07:49:16,478 has all of the data we need let's unlock 14313 07:49:18,120 --> 07:49:19,120 the inspector okay and back in the code 14314 07:49:20,100 --> 07:49:21,100 here on The Sound Manager let's make 14315 07:49:22,200 --> 07:49:23,200 another version of this function so 14316 07:49:24,058 --> 07:49:25,058 let's make one play sound except instead 14317 07:49:25,920 --> 07:49:26,920 of receiving an audio clip it receives 14318 07:49:27,780 --> 07:49:28,780 an array of audio clips 14319 07:49:29,580 --> 07:49:30,580 then basically we just call the other 14320 07:49:31,200 --> 07:49:32,200 function so we call the other place on 14321 07:49:33,000 --> 07:49:34,000 function and pass in an audio clip from 14322 07:49:35,218 --> 07:49:36,218 this array so let's actually rename this 14323 07:49:36,898 --> 07:49:37,898 so audio clip array 14324 07:49:38,940 --> 07:49:39,940 and let's pass in an audio clip from 14325 07:49:41,100 --> 07:49:42,100 here so do a simple random.range 14326 07:49:44,520 --> 07:49:45,520 between 0 and the array down length 14327 07:49:47,820 --> 07:49:48,820 pressing the position and the volume 14328 07:49:50,878 --> 07:49:51,878 okay so just like this now we need is a 14329 07:49:53,520 --> 07:49:54,520 reference to our suitable object so it's 14330 07:49:55,020 --> 07:49:56,020 generalized film private of the audio 14331 07:49:57,540 --> 07:49:58,540 clip refs SL 14332 07:50:00,478 --> 07:50:01,478 okay we have this then here in the 14333 07:50:02,700 --> 07:50:03,700 editor and let's just assign the 14334 07:50:04,200 --> 07:50:05,200 reference so the audio clip refs okay 14335 07:50:05,820 --> 07:50:06,820 great and over here when we have the 14336 07:50:07,978 --> 07:50:08,978 recipe failed let's go into the audio 14337 07:50:10,020 --> 07:50:11,020 clip refs 14338 07:50:11,580 --> 07:50:12,580 and let's pick up this one instant 14339 07:50:13,200 --> 07:50:14,200 delivery fail 14340 07:50:14,580 --> 07:50:15,580 and then the other one is going to be 14341 07:50:16,020 --> 07:50:17,020 delivery success 14342 07:50:17,878 --> 07:50:18,878 for the position let's just default to 14343 07:50:19,860 --> 07:50:20,860 the camera dot main transform that 14344 07:50:22,020 --> 07:50:23,020 position 14345 07:50:24,840 --> 07:50:25,840 so like this it sounds like exactly on 14346 07:50:26,940 --> 07:50:27,940 top of the camera okay so let's test and 14347 07:50:29,100 --> 07:50:30,100 see if it all works okay so here we are 14348 07:50:31,620 --> 07:50:32,620 and let's do a wrong delivery now quick 14349 07:50:33,840 --> 07:50:34,840 warning if you're following along or if 14350 07:50:35,638 --> 07:50:36,638 you're just watching the video this 14351 07:50:37,138 --> 07:50:38,138 sound will probably be way too loud but 14352 07:50:38,878 --> 07:50:39,878 let's test 14353 07:50:40,260 --> 07:50:41,260 so if I just pick up the plate and I 14354 07:50:42,120 --> 07:50:43,120 just deliver an empty plate yep there 14355 07:50:44,820 --> 07:50:45,820 you go there's the sound 14356 07:50:46,138 --> 07:50:47,138 and now if I deliver a correct one so 14357 07:50:47,940 --> 07:50:48,940 someone wants a salad so let's cut a 14358 07:50:50,040 --> 07:50:51,040 nice salad 14359 07:50:51,240 --> 07:50:52,240 chop that chop this pick up the plate 14360 07:50:54,180 --> 07:50:55,180 pick up that one and that one don't be 14361 07:50:56,218 --> 07:50:57,218 the correct salad 14362 07:50:57,420 --> 07:50:58,420 any of that I go with those were all 14363 07:50:59,160 --> 07:51:00,160 right great so the sound effects work 14364 07:51:01,320 --> 07:51:02,320 they played perfectly but they're a bit 14365 07:51:03,478 --> 07:51:04,478 too loud basically that's because these 14366 07:51:05,280 --> 07:51:06,280 sounds were designed to be played in the 14367 07:51:06,958 --> 07:51:07,958 world rather than on top of the camera 14368 07:51:09,120 --> 07:51:10,120 so when we play the sound let's actually 14369 07:51:10,920 --> 07:51:11,920 play it on the position of the delivery 14370 07:51:12,718 --> 07:51:13,718 counter 14371 07:51:13,680 --> 07:51:14,680 here is the delivery counter script and 14372 07:51:16,378 --> 07:51:17,378 based on our design we're only going to 14373 07:51:18,000 --> 07:51:19,000 have a single military counter so we can 14374 07:51:19,860 --> 07:51:20,860 just make this a Singleton 14375 07:51:21,780 --> 07:51:22,780 so as usual public static of type on 14376 07:51:24,298 --> 07:51:25,298 Livery counter call it instance where 14377 07:51:26,940 --> 07:51:27,940 they probably get and a private set 14378 07:51:29,398 --> 07:51:30,398 then on privatoid awake 14379 07:51:32,040 --> 07:51:33,040 let's just set the instance equals this 14380 07:51:35,458 --> 07:51:36,458 okay so over here on The Sound Manager 14381 07:51:38,100 --> 07:51:39,100 we can just grab delivery counter 14382 07:51:40,160 --> 07:51:41,160 delivery counter and we just go into 14383 07:51:42,600 --> 07:51:43,600 Library counter and grab the static 14384 07:51:44,280 --> 07:51:45,280 instance 14385 07:51:45,240 --> 07:51:46,240 and then for the sound position we can 14386 07:51:47,458 --> 07:51:48,458 just go into delivery counter access the 14387 07:51:49,558 --> 07:51:50,558 transform that position 14388 07:51:51,718 --> 07:51:52,718 okay so just like this on that one and 14389 07:51:53,878 --> 07:51:54,878 on this one 14390 07:51:58,740 --> 07:51:59,740 okay so it says now it shouldn't be as 14391 07:52:00,780 --> 07:52:01,780 loud 14392 07:52:01,680 --> 07:52:02,680 okay so here we are and let's do a wrong 14393 07:52:03,718 --> 07:52:04,718 delivery any hope it does work 14394 07:52:06,600 --> 07:52:07,600 now let's be successful delivery so 14395 07:52:08,458 --> 07:52:09,458 let's make a nice cheeseburger so grab 14396 07:52:10,440 --> 07:52:11,440 some cheese slice it grab plate just 14397 07:52:14,040 --> 07:52:15,040 need some bread 14398 07:52:16,138 --> 07:52:17,138 and delivered any of there you go it 14399 07:52:18,660 --> 07:52:19,660 worked all right awesome 14400 07:52:20,820 --> 07:52:21,820 okay so this is really it this is how 14401 07:52:22,620 --> 07:52:23,620 we're going to play our simple sounds 14402 07:52:24,898 --> 07:52:25,898 now there are some that are going to 14403 07:52:26,340 --> 07:52:27,340 require more logic like the footstep 14404 07:52:27,958 --> 07:52:28,958 sounds and the stove Sizzle but first 14405 07:52:30,180 --> 07:52:31,180 let's begin by adding the simple ones 14406 07:52:32,878 --> 07:52:33,878 so let's begin with the chop sounds this 14407 07:52:35,340 --> 07:52:36,340 is super simple we just need to go over 14408 07:52:37,558 --> 07:52:38,558 here onto the cutting counter and 14409 07:52:39,180 --> 07:52:40,180 actually we already have the uncut event 14410 07:52:41,218 --> 07:52:42,218 that we made previously this was used to 14411 07:52:43,378 --> 07:52:44,378 spawn the visual so we can also use it 14412 07:52:45,058 --> 07:52:46,058 to spawn these sounds 14413 07:52:46,440 --> 07:52:47,440 however there's actually one difference 14414 07:52:48,378 --> 07:52:49,378 we're going to have multiple cutting 14415 07:52:50,760 --> 07:52:51,760 counters and this one as you can see 14416 07:52:53,100 --> 07:52:54,100 this one is not a static event meaning 14417 07:52:55,558 --> 07:52:56,558 each different counter is going to have 14418 07:52:57,120 --> 07:52:58,120 each list of listeners and we really 14419 07:52:59,458 --> 07:53:00,458 don't want to have to subscribe to every 14420 07:53:01,260 --> 07:53:02,260 single one of the counters individually 14421 07:53:02,700 --> 07:53:03,700 so what we can do is instead of making 14422 07:53:04,920 --> 07:53:05,920 it a regular event that belongs to each 14423 07:53:06,898 --> 07:53:07,898 instance of a cut encounter we can make 14424 07:53:09,240 --> 07:53:10,240 a static event which won't belong to the 14425 07:53:11,040 --> 07:53:12,040 entire class but we still want to leave 14426 07:53:12,958 --> 07:53:13,958 this one just for the visual so let's do 14427 07:53:14,700 --> 07:53:15,700 another one a public static event event 14428 07:53:17,398 --> 07:53:18,398 handler 14429 07:53:18,660 --> 07:53:19,660 and let's call it on any cut basically 14430 07:53:21,840 --> 07:53:22,840 for any static events that belong to any 14431 07:53:24,180 --> 07:53:25,180 object type I like to add the keyword 14432 07:53:25,620 --> 07:53:26,620 any we're going to fire this event when 14433 07:53:28,440 --> 07:53:29,440 any cutting counter is going to trigger 14434 07:53:30,360 --> 07:53:31,360 a cut action so where we fire this event 14435 07:53:33,058 --> 07:53:34,058 is exactly the same thing so over here 14436 07:53:34,440 --> 07:53:35,440 we've got the uncut and let's do the 14437 07:53:35,940 --> 07:53:36,940 exact same thing so on any cut with this 14438 07:53:38,040 --> 07:53:39,040 an event R is not empty okay so we have 14439 07:53:40,500 --> 07:53:41,500 our nice static event and over here on 14440 07:53:42,718 --> 07:53:43,718 The Sound Manager let's listen to it so 14441 07:53:44,280 --> 07:53:45,280 let's go into the cutting counter again 14442 07:53:46,080 --> 07:53:47,080 we're going to access through the class 14443 07:53:47,458 --> 07:53:48,458 name and let's listen to the on any cut 14444 07:53:50,100 --> 07:53:51,100 event and over here let's just play the 14445 07:53:52,500 --> 07:53:53,500 sound so let's play the sound let's go 14446 07:53:55,080 --> 07:53:56,080 inside the audio play prefsl and let's 14447 07:53:57,780 --> 07:53:58,780 grab the chop sound then for the 14448 07:54:00,240 --> 07:54:01,240 position 14449 07:54:01,138 --> 07:54:02,138 we want to know who fired this event and 14450 07:54:03,298 --> 07:54:04,298 by following the c-sharp standard over 14451 07:54:04,920 --> 07:54:05,920 here we already have the object sender 14452 07:54:07,320 --> 07:54:08,320 so we know this was the object that 14453 07:54:08,878 --> 07:54:09,878 fired this event and we know this is 14454 07:54:10,378 --> 07:54:11,378 going to be of type cutting counter so 14455 07:54:11,878 --> 07:54:12,878 we can just get cutting counter cutting 14456 07:54:14,160 --> 07:54:15,160 counter and we just grab the sender as a 14457 07:54:16,920 --> 07:54:17,920 cutting counter 14458 07:54:18,180 --> 07:54:19,180 okay so we have this and then over here 14459 07:54:19,798 --> 07:54:20,798 very simple access transform that 14460 07:54:21,478 --> 07:54:22,478 position 14461 07:54:22,798 --> 07:54:23,798 okay that's it great 14462 07:54:24,660 --> 07:54:25,660 that won't play The Cutting sound on 14463 07:54:26,878 --> 07:54:27,878 that position on that cutting counter 14464 07:54:28,558 --> 07:54:29,558 okay great now let's handle the player 14465 07:54:31,020 --> 07:54:32,020 picking up something and for that let's 14466 07:54:32,940 --> 07:54:33,940 go over here onto the player class and 14467 07:54:35,218 --> 07:54:36,218 the way we set up the kitchen object 14468 07:54:36,600 --> 07:54:37,600 parent system is actually already 14469 07:54:37,860 --> 07:54:38,860 perfect for this 14470 07:54:39,240 --> 07:54:40,240 down here we have a function so if we 14471 07:54:42,000 --> 07:54:43,000 scroll down Yep this function set 14472 07:54:43,680 --> 07:54:44,680 kitchen object this one is called 14473 07:54:45,780 --> 07:54:46,780 whenever the player receives a kitchen 14474 07:54:47,580 --> 07:54:48,580 object which means really when the 14475 07:54:49,320 --> 07:54:50,320 player picks up something so if this 14476 07:54:51,540 --> 07:54:52,540 kitchen object is not known then that 14477 07:54:53,100 --> 07:54:54,100 means the player picked up something so 14478 07:54:54,540 --> 07:54:55,540 let's do that 14479 07:54:55,680 --> 07:54:56,680 so up here and let's make the event 14480 07:54:57,840 --> 07:54:58,840 so a public event event handler 14481 07:55:01,080 --> 07:55:02,080 call it on pick something 14482 07:55:04,378 --> 07:55:05,378 and then down here just to be test so if 14483 07:55:06,600 --> 07:55:07,600 the kitchen object is not known so if 14484 07:55:08,760 --> 07:55:09,760 the player did pick up something then 14485 07:55:10,378 --> 07:55:11,378 let's just fire off this event so just 14486 07:55:12,478 --> 07:55:13,478 view our usual invoke with this an event 14487 07:55:15,478 --> 07:55:16,478 RX rmt 14488 07:55:18,660 --> 07:55:19,660 okay so that's great 14489 07:55:20,760 --> 07:55:21,760 then on the sound management let's just 14490 07:55:22,558 --> 07:55:23,558 listen to it so let's go into the player 14491 07:55:24,840 --> 07:55:25,840 Quest let's access these static instance 14492 07:55:26,820 --> 07:55:27,820 and let's listen to the on picked up 14493 07:55:28,860 --> 07:55:29,860 something event and again let's rename 14494 07:55:31,080 --> 07:55:32,080 this to a proper name so player on pick 14495 07:55:33,240 --> 07:55:34,240 something 14496 07:55:34,260 --> 07:55:35,260 and over here let's just play the sound 14497 07:55:36,298 --> 07:55:37,298 and for the sound go into the refs and 14498 07:55:39,058 --> 07:55:40,058 grab in this case the object pickup 14499 07:55:42,000 --> 07:55:43,000 and for the position let's just go 14500 07:55:43,740 --> 07:55:44,740 player 14501 07:55:44,878 --> 07:55:45,878 dot instance and gravity transform that 14502 07:55:47,458 --> 07:55:48,458 position 14503 07:55:48,360 --> 07:55:49,360 okay that's it next for item dropping 14504 07:55:51,240 --> 07:55:52,240 now we can only drop items on a counter 14505 07:55:53,638 --> 07:55:54,638 so over here we have the base counter 14506 07:55:55,798 --> 07:55:56,798 class and again we have the same thing 14507 07:55:57,600 --> 07:55:58,600 so we have the set kitchen object and 14508 07:55:59,878 --> 07:56:00,878 again the same thing as with the cutting 14509 07:56:01,500 --> 07:56:02,500 counter we don't want to be required to 14510 07:56:03,420 --> 07:56:04,420 listen to every single counter we just 14511 07:56:05,520 --> 07:56:06,520 want to listen to one event so let's 14512 07:56:07,080 --> 07:56:08,080 make it up here so if I'm like static 14513 07:56:09,420 --> 07:56:10,420 event of type event handler 14514 07:56:11,580 --> 07:56:12,580 and let's name it on any object placed 14515 07:56:15,000 --> 07:56:16,000 here 14516 07:56:17,340 --> 07:56:18,340 and then down here when we have the set 14517 07:56:19,138 --> 07:56:20,138 kitchen object we do the usual if 14518 07:56:21,000 --> 07:56:22,000 kitchen object is not known if so then 14519 07:56:23,940 --> 07:56:24,940 let's fire off this event 14520 07:56:28,620 --> 07:56:29,620 okay great 14521 07:56:30,240 --> 07:56:31,240 and on the song Imagine let's listen so 14522 07:56:32,218 --> 07:56:33,218 go into the base counter on any object 14523 07:56:34,620 --> 07:56:35,620 placed here when that happens play the 14524 07:56:37,200 --> 07:56:38,200 sound then let's go into the other top 14525 07:56:39,600 --> 07:56:40,600 prefs and this one is the object drop so 14526 07:56:42,660 --> 07:56:43,660 that one and for the position let's do 14527 07:56:44,940 --> 07:56:45,940 the same thing we did so we cast the 14528 07:56:46,798 --> 07:56:47,798 base counter equals the sender as a base 14529 07:56:49,680 --> 07:56:50,680 counter and then we go into the base 14530 07:56:52,020 --> 07:56:53,020 counter and let's grab the transformed 14531 07:56:54,478 --> 07:56:55,478 up position okay so we just need one 14532 07:56:56,638 --> 07:56:57,638 more special counter type 14533 07:56:58,378 --> 07:56:59,378 here we have the trash counter and this 14534 07:57:01,080 --> 07:57:02,080 one it never really changes the parent 14535 07:57:02,580 --> 07:57:03,580 it just destroys the object it's over 14536 07:57:04,558 --> 07:57:05,558 here on the trash counter itself let's 14537 07:57:06,058 --> 07:57:07,058 fire off an event but again let's make 14538 07:57:08,520 --> 07:57:09,520 it static even though we're only going 14539 07:57:09,840 --> 07:57:10,840 to have one trash but make it Saturday 14540 07:57:11,218 --> 07:57:12,218 just to be able to support multiple so 14541 07:57:13,440 --> 07:57:14,440 public static event 14542 07:57:15,440 --> 07:57:16,440 Handler 14543 07:57:17,100 --> 07:57:18,100 on any object trashed 14544 07:57:22,440 --> 07:57:23,440 and then over here just fire off this 14545 07:57:24,420 --> 07:57:25,420 event 14546 07:57:25,558 --> 07:57:26,558 so invoke with this and eventar is not 14547 07:57:29,218 --> 07:57:30,218 empty okay 14548 07:57:30,360 --> 07:57:31,360 so now if we go into The Sound Manager 14549 07:57:33,180 --> 07:57:34,180 and over here once again the trash 14550 07:57:35,580 --> 07:57:36,580 counter on any not the on any object 14551 07:57:38,820 --> 07:57:39,820 place but on any object trashed 14552 07:57:41,218 --> 07:57:42,218 and on this one let's do pretty much 14553 07:57:43,080 --> 07:57:44,080 exactly the same thing so let's copy 14554 07:57:44,940 --> 07:57:45,940 this the sound is going to be the trash 14555 07:57:47,040 --> 07:57:48,040 sound instead of a bass counter 14556 07:57:49,558 --> 07:57:50,558 we could just cast it to a base counter 14557 07:57:51,360 --> 07:57:52,360 but let's make it proper so let's make a 14558 07:57:53,218 --> 07:57:54,218 trash counter as a trash counter and 14559 07:57:55,680 --> 07:57:56,680 this is a trash counter okay great 14560 07:57:58,020 --> 07:57:59,020 that's it so these are all of our basic 14561 07:58:00,180 --> 07:58:01,180 simple sounds as you can see all the 14562 07:58:01,740 --> 07:58:02,740 logic is super simple so let's test and 14563 07:58:03,840 --> 07:58:04,840 see if it all works 14564 07:58:05,160 --> 07:58:06,160 okay so first of all let's pick up an 14565 07:58:07,260 --> 07:58:08,260 object so if I go into a container and I 14566 07:58:09,180 --> 07:58:10,180 pick it up and if there you go there's 14567 07:58:10,920 --> 07:58:11,920 the sound now if I drop it somewhere and 14568 07:58:13,200 --> 07:58:14,200 if there's a sound now for the trash 14569 07:58:14,878 --> 07:58:15,878 pick it up drop it on the trash anyhow 14570 07:58:17,458 --> 07:58:18,458 there's the trash down okay great 14571 07:58:19,920 --> 07:58:20,920 then also let's check out the cutting so 14572 07:58:22,320 --> 07:58:23,320 if I pick up some cheese drop it there 14573 07:58:23,940 --> 07:58:24,940 and cut and if there go got a really 14574 07:58:26,458 --> 07:58:27,458 nice cutting sound okay so far so good 14575 07:58:29,458 --> 07:58:30,458 now let's handle the more complex ones 14576 07:58:31,440 --> 07:58:32,440 starting off with the stove for this one 14577 07:58:33,898 --> 07:58:34,898 the sound is meant to be on looping but 14578 07:58:35,878 --> 07:58:36,878 only when the sub is on so we don't want 14579 07:58:37,978 --> 07:58:38,978 to just play once but play and stop 14580 07:58:40,138 --> 07:58:41,138 playing depending on the state of the 14581 07:58:41,700 --> 07:58:42,700 stove 14582 07:58:42,660 --> 07:58:43,660 so for this one instead of spawning the 14583 07:58:44,878 --> 07:58:45,878 sound through code let's actually spawn 14584 07:58:46,500 --> 07:58:47,500 it on the object itself so let's go 14585 07:58:48,780 --> 07:58:49,780 inside the stove object let's go on the 14586 07:58:51,478 --> 07:58:52,478 stove counter and open up the prefab and 14587 07:58:54,240 --> 07:58:55,240 inside this prefab let's create a brand 14588 07:58:56,760 --> 07:58:57,760 new empty game object name it sound 14589 07:58:59,520 --> 07:59:00,520 let's reset transform make sure it's on 14590 07:59:01,320 --> 07:59:02,320 zero zero zero okay great now let's add 14591 07:59:04,138 --> 07:59:05,138 an audio Source component 14592 07:59:06,360 --> 07:59:07,360 and for the auto clip let's use the pan 14593 07:59:08,580 --> 07:59:09,580 sizzle let's make sure to not talk on 14594 07:59:11,398 --> 07:59:12,398 play on awake but we do want it to Loop 14595 07:59:13,740 --> 07:59:14,740 and let's also make it a 3D sound 14596 07:59:17,398 --> 07:59:18,398 okay so that's the basic setup Now to 14597 07:59:20,280 --> 07:59:21,280 control this let's make a script so 14598 07:59:22,440 --> 07:59:23,440 let's go into our scripts folder and 14599 07:59:24,180 --> 07:59:25,180 let's create a brand new c-sharp script 14600 07:59:26,520 --> 07:59:27,520 come with the stove counter sound 14601 07:59:29,760 --> 07:59:30,760 let's attach the script over here and 14602 07:59:32,280 --> 07:59:33,280 let's open it 14603 07:59:33,478 --> 07:59:34,478 so now here first let's grab the audio 14604 07:59:35,398 --> 07:59:36,398 Source component so we've got a private 14605 07:59:37,620 --> 07:59:38,620 audio source for the audio source and 14606 07:59:40,920 --> 07:59:41,920 just go on awake and audio Source 14607 07:59:43,680 --> 07:59:44,680 sequence get component of type audio 14608 07:59:45,360 --> 07:59:46,360 Source okay 14609 07:59:46,920 --> 07:59:47,920 then we're also going to need a 14610 07:59:48,478 --> 07:59:49,478 reference to the stove counter so let's 14611 07:59:50,340 --> 07:59:51,340 uh appear a centralized film private 14612 07:59:53,760 --> 07:59:54,760 of type stove counter for the stove 14613 07:59:56,218 --> 07:59:57,218 counter 14614 07:59:57,298 --> 07:59:58,298 then back in the editor let's drag that 14615 07:59:59,340 --> 08:00:00,340 reference all right 14616 08:00:00,898 --> 08:00:01,898 now on the stove counter over here we 14617 08:00:02,638 --> 08:00:03,638 already have the states and we have the 14618 08:00:04,378 --> 08:00:05,378 on-site change event again the same one 14619 08:00:06,298 --> 08:00:07,298 that we use to modify the visual so on 14620 08:00:08,520 --> 08:00:09,520 the sound lets you pretty much examine 14621 08:00:10,200 --> 08:00:11,200 the same thing 14622 08:00:11,218 --> 08:00:12,218 over here let's do a private void start 14623 08:00:14,160 --> 08:00:15,160 and on certain let's go into the stove 14624 08:00:15,958 --> 08:00:16,958 counter and listen to the on stay 14625 08:00:17,760 --> 08:00:18,760 changed event 14626 08:00:19,500 --> 08:00:20,500 and basically when this changes we want 14627 08:00:22,138 --> 08:00:23,138 to check if it's frying or fried if so 14628 08:00:24,360 --> 08:00:25,360 then we want to play the sound if no 14629 08:00:25,920 --> 08:00:26,920 then we don't want to play it so let's 14630 08:00:27,600 --> 08:00:28,600 define a ball call it play sound and 14631 08:00:29,878 --> 08:00:30,878 we're going to play if the state equals 14632 08:00:32,218 --> 08:00:33,218 we are frying or the state equals that 14633 08:00:36,898 --> 08:00:37,898 it is currently fried and about to burn 14634 08:00:39,420 --> 08:00:40,420 Okay then if we have a play sound 14635 08:00:42,120 --> 08:00:43,120 then let's go into the audio source and 14636 08:00:44,398 --> 08:00:45,398 comp play 14637 08:00:47,160 --> 08:00:48,160 and if not then let's go into audio 14638 08:00:49,500 --> 08:00:50,500 source and call pause 14639 08:00:51,840 --> 08:00:52,840 all right so that's it pretty simple 14640 08:00:53,638 --> 08:00:54,638 let's just make sure to save our prefab 14641 08:00:55,920 --> 08:00:56,920 go back outside and let's start on play 14642 08:00:57,780 --> 08:00:58,780 and okay four stars there's no sound 14643 08:01:00,058 --> 08:01:01,058 playing now if I pick up some meat and I 14644 08:01:01,978 --> 08:01:02,978 drop it on there 14645 08:01:03,240 --> 08:01:04,240 and if there go there's a sizzling sound 14646 08:01:05,100 --> 08:01:06,100 and continues going and now it is still 14647 08:01:07,080 --> 08:01:08,080 sizzling but if it burns it should stop 14648 08:01:09,600 --> 08:01:10,600 so if I go 14649 08:01:11,100 --> 08:01:12,100 and if there go the sizzling soundstomp 14650 08:01:12,958 --> 08:01:13,958 all right awesome so let's take this one 14651 08:01:14,878 --> 08:01:15,878 out let's actually trash it now let's 14652 08:01:17,040 --> 08:01:18,040 pick up another one let it cook 14653 08:01:19,260 --> 08:01:20,260 and once let's go pick it up and there 14654 08:01:21,120 --> 08:01:22,120 you go the sound of the Stomp all right 14655 08:01:22,978 --> 08:01:23,978 awesome 14656 08:01:24,360 --> 08:01:25,360 so we just have one more final sound 14657 08:01:26,280 --> 08:01:27,280 remaining that's the footsteps 14658 08:01:28,620 --> 08:01:29,620 by the way the warning sound is going to 14659 08:01:30,478 --> 08:01:31,478 be added during the Polish lecture 14660 08:01:32,820 --> 08:01:33,820 for the footsteps we want very much the 14661 08:01:34,920 --> 08:01:35,920 same thing that we did on the stove so 14662 08:01:37,080 --> 08:01:38,080 we're going to want a script to handle 14663 08:01:38,398 --> 08:01:39,398 that logic 14664 08:01:39,780 --> 08:01:40,780 but this time we don't need an audio 14665 08:01:41,280 --> 08:01:42,280 Source on the player we're going to use 14666 08:01:42,840 --> 08:01:43,840 the same play Method as the other ones 14667 08:01:45,298 --> 08:01:46,298 let's just make a script to run the 14668 08:01:47,160 --> 08:01:48,160 sounds so let's make a new c-sharp 14669 08:01:48,660 --> 08:01:49,660 script for the player sounds 14670 08:01:51,298 --> 08:01:52,298 let's go into the player game object and 14671 08:01:54,058 --> 08:01:55,058 attach the sound okay so here let's 14672 08:01:56,340 --> 08:01:57,340 first grab the player reference 14673 08:01:58,680 --> 08:01:59,680 so private player player and on private 14674 08:02:02,160 --> 08:02:03,160 way the way let's get the component of 14675 08:02:03,898 --> 08:02:04,898 type player and assign it to the player 14676 08:02:06,898 --> 08:02:07,898 okay 14677 08:02:08,100 --> 08:02:09,100 then for the footsteps basically we want 14678 08:02:10,080 --> 08:02:11,080 to play them every certain amount of 14679 08:02:11,580 --> 08:02:12,580 time so let's do appear a private Cloud 14680 08:02:13,978 --> 08:02:14,978 for the footstep timer another one for 14681 08:02:16,740 --> 08:02:17,740 the footstep tower Max and let's say you 14682 08:02:18,718 --> 08:02:19,718 want to play say 10 times per second 14683 08:02:21,058 --> 08:02:22,058 then we do a basic update and on update 14684 08:02:23,820 --> 08:02:24,820 footstep timer countdown by time.com 14685 08:02:26,820 --> 08:02:27,820 time and if the footstep timer is under 14686 08:02:29,580 --> 08:02:30,580 zero 14687 08:02:31,138 --> 08:02:32,138 then let's reset it so set it to the 14688 08:02:33,360 --> 08:02:34,360 maximum 14689 08:02:34,558 --> 08:02:35,558 and it's in here that we're going to 14690 08:02:36,000 --> 08:02:37,000 play the sound so now here we have two 14691 08:02:38,280 --> 08:02:39,280 options we can fire an event here and we 14692 08:02:41,218 --> 08:02:42,218 can listen to it on The Sound Manager so 14693 08:02:42,958 --> 08:02:43,958 exactly the same thing that we've been 14694 08:02:44,340 --> 08:02:45,340 doing previously or we can just trigger 14695 08:02:46,978 --> 08:02:47,978 the sound directly from here doing that 14696 08:02:49,378 --> 08:02:50,378 will mean that this class is tightly 14697 08:02:51,360 --> 08:02:52,360 coupled with The Sound Manager usually 14698 08:02:53,340 --> 08:02:54,340 we want to avoid tight couplings however 14699 08:02:55,740 --> 08:02:56,740 in this case the player sounds class 14700 08:02:57,180 --> 08:02:58,180 this one is really only meant to exist 14701 08:02:58,860 --> 08:02:59,860 alongside the sound manager so in this 14702 08:03:01,200 --> 08:03:02,200 case it's perfectly fine to totally 14703 08:03:02,700 --> 08:03:03,700 coupon them so let's play the sound 14704 08:03:04,440 --> 08:03:05,440 directly from here which means we need a 14705 08:03:06,240 --> 08:03:07,240 reference to The Sound Manager we can 14706 08:03:08,458 --> 08:03:09,458 make a serialized field or just make 14707 08:03:09,958 --> 08:03:10,958 this a Singleton so let's do that 14708 08:03:12,240 --> 08:03:13,240 so a public static type Sound Manager 14709 08:03:16,620 --> 08:03:17,620 name it instance where they probably get 14710 08:03:18,898 --> 08:03:19,898 any private set 14711 08:03:21,360 --> 08:03:22,360 then on private void awake 14712 08:03:25,138 --> 08:03:26,138 we just set the instance equals this 14713 08:03:27,000 --> 08:03:28,000 okay 14714 08:03:28,200 --> 08:03:29,200 so then over here we can just access it 14715 08:03:30,540 --> 08:03:31,540 so just go into the sound manager access 14716 08:03:32,700 --> 08:03:33,700 the instance and we call play sound 14717 08:03:35,820 --> 08:03:36,820 which we actually need to make public 14718 08:03:37,340 --> 08:03:38,340 however this function also takes a 14719 08:03:39,718 --> 08:03:40,718 reference to the audio clip array 14720 08:03:42,000 --> 08:03:43,000 so that means we need a reference to the 14721 08:03:43,740 --> 08:03:44,740 audio clips so again we have multiple 14722 08:03:46,020 --> 08:03:47,020 options we could add over here on the 14723 08:03:48,240 --> 08:03:49,240 player sounds at a serialized film for 14724 08:03:50,340 --> 08:03:51,340 the footstep sounds or we can just make 14725 08:03:52,978 --> 08:03:53,978 a specialized function over here on The 14726 08:03:54,660 --> 08:03:55,660 Sound Manager both options can work just 14727 08:03:56,760 --> 08:03:57,760 fine let's go with the second one just 14728 08:03:58,440 --> 08:03:59,440 to be different so just make here a 14729 08:04:00,600 --> 08:04:01,600 public void play 14730 08:04:02,820 --> 08:04:03,820 footstep sound 14731 08:04:05,398 --> 08:04:06,398 we're just going to receive a vector 3 14732 08:04:07,378 --> 08:04:08,378 for the position 14733 08:04:09,240 --> 08:04:10,240 and then we just call play sound let's 14734 08:04:11,878 --> 08:04:12,878 go into the audio clip refs ASL and 14735 08:04:15,120 --> 08:04:16,120 let's pick up the footsteps and play it 14736 08:04:17,700 --> 08:04:18,700 on this position 14737 08:04:19,080 --> 08:04:20,080 and let's also receive the volume 14738 08:04:21,240 --> 08:04:22,240 just appear a fault for the volume 14739 08:04:23,760 --> 08:04:24,760 okay so that's right now we just need to 14740 08:04:25,260 --> 08:04:26,260 call this function 14741 08:04:26,638 --> 08:04:27,638 it's over here on the player instead of 14742 08:04:28,020 --> 08:04:29,020 calling play sound let's go on the other 14743 08:04:29,940 --> 08:04:30,940 one play the footstep sound 14744 08:04:31,860 --> 08:04:32,860 then for the position that's the player 14745 08:04:33,660 --> 08:04:34,660 transformed that position and for the 14746 08:04:36,000 --> 08:04:37,000 volume I just exposed the volume just in 14747 08:04:37,620 --> 08:04:38,620 case you want to make the footsteps a 14748 08:04:39,360 --> 08:04:40,360 bit more sound or not 14749 08:04:40,740 --> 08:04:41,740 but for now let's begin with one F and 14750 08:04:42,540 --> 08:04:43,540 then see if that's waiting around as 14751 08:04:44,580 --> 08:04:45,580 usual instead of using magic numbers 14752 08:04:46,260 --> 08:04:47,260 let's define a fluid for the volume put 14753 08:04:48,360 --> 08:04:49,360 it at 1f and over here use the volume 14754 08:04:51,058 --> 08:04:52,058 okay great however you might be noticing 14755 08:04:53,638 --> 08:04:54,638 an obvious issue here right now this is 14756 08:04:55,798 --> 08:04:56,798 going to play non-stop obviously we 14757 08:04:57,898 --> 08:04:58,898 don't want to do that we only want to 14758 08:04:59,340 --> 08:05:00,340 play footstep sounds if the player is 14759 08:05:00,898 --> 08:05:01,898 actually moving so this pre-semble we 14760 08:05:03,180 --> 08:05:04,180 just need to ask the player if it is 14761 08:05:04,440 --> 08:05:05,440 moving 14762 08:05:05,458 --> 08:05:06,458 and we already did that so player is 14763 08:05:08,280 --> 08:05:09,280 walking so if the player is walking then 14764 08:05:10,558 --> 08:05:11,558 you play The Sounds if not we don't okay 14765 08:05:12,660 --> 08:05:13,660 that's it so let's test so here we are 14766 08:05:15,240 --> 08:05:16,240 and if I'm standing still there's no 14767 08:05:16,620 --> 08:05:17,620 footsteps okay that's great and as soon 14768 08:05:18,420 --> 08:05:19,420 as I move yep there you go we got some 14769 08:05:20,398 --> 08:05:21,398 nice WhatsApp sounds 14770 08:05:21,898 --> 08:05:22,898 all right great so with all that we 14771 08:05:24,420 --> 08:05:25,420 added all of our sounds 14772 08:05:26,160 --> 08:05:27,160 now here note how we mostly use this 14773 08:05:28,320 --> 08:05:29,320 method of going into the audio source 14774 08:05:30,120 --> 08:05:31,120 and using the play clip at Point 14775 08:05:31,500 --> 08:05:32,500 function this one is great because it is 14776 08:05:33,478 --> 08:05:34,478 so simple but it does have limitations 14777 08:05:35,478 --> 08:05:36,478 specifically with regards to all of the 14778 08:05:37,620 --> 08:05:38,620 options if we look on the audio Source 14779 08:05:39,780 --> 08:05:40,780 component here we have all these options 14780 08:05:42,180 --> 08:05:43,180 so you can use an output use an audio 14781 08:05:44,340 --> 08:05:45,340 mixer like we saw in the previous 14782 08:05:45,780 --> 08:05:46,780 lecture we can play around priority play 14783 08:05:48,180 --> 08:05:49,180 around the pitch make it 2D or 3D play 14784 08:05:50,398 --> 08:05:51,398 around over here with how the sound 14785 08:05:51,958 --> 08:05:52,958 falls off so tons and tons of options 14786 08:05:54,120 --> 08:05:55,120 that you can't really access if you use 14787 08:05:55,680 --> 08:05:56,680 that simple function so one approach if 14788 08:05:58,260 --> 08:05:59,260 you need these options you could make 14789 08:06:00,298 --> 08:06:01,298 each sound a prefab so make a prefab for 14790 08:06:02,638 --> 08:06:03,638 each different audio clip and then 14791 08:06:04,440 --> 08:06:05,440 instead of calling that function you 14792 08:06:05,700 --> 08:06:06,700 would simply instantiate that prefab to 14793 08:06:07,260 --> 08:06:08,260 spawn that audio so if you have lots of 14794 08:06:09,478 --> 08:06:10,478 options depending on how complex you 14795 08:06:11,218 --> 08:06:12,218 want your sound to be 14796 08:06:12,540 --> 08:06:13,540 but for a simple game and for simple 14797 08:06:14,638 --> 08:06:15,638 sounds this one line of code is super 14798 08:06:16,740 --> 08:06:17,740 simple 14799 08:06:17,520 --> 08:06:18,520 alright so here we have added sound 14800 08:06:19,500 --> 08:06:20,500 effects to our game that component with 14801 08:06:21,600 --> 08:06:22,600 the music that we had previously already 14802 08:06:23,340 --> 08:06:24,340 makes everything sound so much more 14803 08:06:25,020 --> 08:06:26,020 alive it's really starting to look like 14804 08:06:26,638 --> 08:06:27,638 a proper game 14805 08:06:28,200 --> 08:06:29,200 the one thing we still don't have is 14806 08:06:30,298 --> 08:06:31,298 some kind of game start and game and 14807 08:06:32,040 --> 08:06:33,040 scenario so let's have that in the next 14808 08:06:34,320 --> 08:06:35,320 lecture 14809 08:06:37,020 --> 08:06:38,020 hello and welcome I'm your code Maki in 14810 08:06:39,718 --> 08:06:40,718 this lecture let's add a simple and 14811 08:06:41,340 --> 08:06:42,340 beginning state to our game so right now 14812 08:06:43,440 --> 08:06:44,440 we can play the game of the mechanics 14813 08:06:45,958 --> 08:06:46,958 everything works perfectly and it's all 14814 08:06:47,638 --> 08:06:48,638 been implemented however in the 14815 08:06:49,440 --> 08:06:50,440 beginning of the game it just starts 14816 08:06:50,760 --> 08:06:51,760 right away as it loads there's no start 14817 08:06:52,680 --> 08:06:53,680 no countdown no time for the player to 14818 08:06:54,600 --> 08:06:55,600 get ready 14819 08:06:55,440 --> 08:06:56,440 someone sort that out with a simple 14820 08:06:57,058 --> 08:06:58,058 countdown let's begin by making a 14821 08:06:59,340 --> 08:07:00,340 general game manager script to handle 14822 08:07:01,020 --> 08:07:02,020 all of our general game States so let's 14823 08:07:03,298 --> 08:07:04,298 create a brand new c-sharp script 14824 08:07:05,700 --> 08:07:06,700 and now here you could use the name game 14825 08:07:07,978 --> 08:07:08,978 manager so you could use this name 14826 08:07:10,218 --> 08:07:11,218 however for some reason yantian likes uh 14827 08:07:13,080 --> 08:07:14,080 this custom icon when a script is named 14828 08:07:15,000 --> 08:07:16,000 exactly game manager personally I don't 14829 08:07:17,398 --> 08:07:18,398 like this I don't want it to be a 14830 08:07:19,080 --> 08:07:20,080 different icon I want this script to 14831 08:07:20,940 --> 08:07:21,940 look and behave just like any other one 14832 08:07:22,620 --> 08:07:23,620 of my scripts so personally I don't like 14833 08:07:24,660 --> 08:07:25,660 this but if it doesn't bother you then 14834 08:07:26,100 --> 08:07:27,100 go ahead use it doesn't really change 14835 08:07:27,718 --> 08:07:28,718 anything just a visual but in my case I 14836 08:07:30,058 --> 08:07:31,058 prefer to give it a different name so 14837 08:07:31,620 --> 08:07:32,620 sometimes I call it game Handler or 14838 08:07:33,840 --> 08:07:34,840 other times just something related to 14839 08:07:35,280 --> 08:07:36,280 this game like for example the kitchen 14840 08:07:36,718 --> 08:07:37,718 game manager and just like that it won't 14841 08:07:39,240 --> 08:07:40,240 have that custom icon just need to go 14842 08:07:41,520 --> 08:07:42,520 inside and rename this to Kitchen game 14843 08:07:43,500 --> 08:07:44,500 manager okay save the script and all 14844 08:07:46,080 --> 08:07:47,080 right now let's make a game object to 14845 08:07:47,700 --> 08:07:48,700 run it so a new game object with the 14846 08:07:49,260 --> 08:07:50,260 same name let's attach the kitchen game 14847 08:07:51,120 --> 08:07:52,120 manager and reset transform okay let's 14848 08:07:53,040 --> 08:07:54,040 go now here we're going to Define all of 14849 08:07:55,500 --> 08:07:56,500 the various game states that our game 14850 08:07:57,058 --> 08:07:58,058 can be in so for that let's define an 14851 08:07:59,100 --> 08:08:00,100 enum so a simple enum call it state 14852 08:08:02,580 --> 08:08:03,580 and for the various States let's say we 14853 08:08:05,398 --> 08:08:06,398 are first of all waiting to start then 14854 08:08:08,100 --> 08:08:09,100 we are on countdown to start then the 14855 08:08:11,280 --> 08:08:12,280 game is playing and then we have a game 14856 08:08:13,378 --> 08:08:14,378 over okay so these are our states let's 14857 08:08:16,378 --> 08:08:17,378 do a private void awake and on the 14858 08:08:19,020 --> 08:08:20,020 waiting list of the state so we need to 14859 08:08:20,340 --> 08:08:21,340 store a state for our state 14860 08:08:22,798 --> 08:08:23,798 and on a week we set the state equals 14861 08:08:25,440 --> 08:08:26,440 and let's begin on waiting to start by 14862 08:08:27,600 --> 08:08:28,600 the way the point with this waiting to 14863 08:08:29,040 --> 08:08:30,040 start say it will also be very important 14864 08:08:30,660 --> 08:08:31,660 in the next video covering multiplayer 14865 08:08:32,398 --> 08:08:33,398 basically we're going to wait until 14866 08:08:33,958 --> 08:08:34,958 everyone is connected before we start 14867 08:08:35,638 --> 08:08:36,638 the actual countdown but over here for 14868 08:08:37,740 --> 08:08:38,740 now we're just going to wait a little 14869 08:08:39,298 --> 08:08:40,298 bit on the waiting to start then we're 14870 08:08:41,100 --> 08:08:42,100 going to trigger the countdown and then 14871 08:08:42,600 --> 08:08:43,600 after some time trigger the game playing 14872 08:08:44,040 --> 08:08:45,040 state so pretty much all of these states 14873 08:08:45,780 --> 08:08:46,780 are going to be time based so let's make 14874 08:08:47,940 --> 08:08:48,940 a simple timer so a private float for 14875 08:08:51,180 --> 08:08:52,180 the waiting to start timer let's begin 14876 08:08:54,478 --> 08:08:55,478 on something like 1f so we just wait for 14877 08:08:57,000 --> 08:08:58,000 one second then let's make a private 14878 08:08:58,920 --> 08:08:59,920 void update and let's make a state 14879 08:09:00,898 --> 08:09:01,898 machine just like we've done previously 14880 08:09:02,398 --> 08:09:03,398 so do a switch on our state 14881 08:09:06,420 --> 08:09:07,420 in case we are on state DOT waiting to 14882 08:09:09,058 --> 08:09:10,058 start 14883 08:09:09,840 --> 08:09:10,840 if so then let's go into the waiting to 14884 08:09:11,940 --> 08:09:12,940 start timer count it down by time dot 14885 08:09:14,100 --> 08:09:15,100 Delta time 14886 08:09:15,420 --> 08:09:16,420 then if the waiting to start timer if it 14887 08:09:17,580 --> 08:09:18,580 is under zero if so then let's move into 14888 08:09:20,100 --> 08:09:21,100 the state equal state DOT let's go into 14889 08:09:22,860 --> 08:09:23,860 the countdown to start okay so that's it 14890 08:09:25,320 --> 08:09:26,320 and the other states are going to be 14891 08:09:26,580 --> 08:09:27,580 pretty much exactly the same so let's 14892 08:09:27,898 --> 08:09:28,898 just copy this so we have the winning 14893 08:09:29,340 --> 08:09:30,340 start and the countdown to start then we 14894 08:09:31,978 --> 08:09:32,978 have the game playing and finally we 14895 08:09:34,138 --> 08:09:35,138 have the game over and that one doesn't 14896 08:09:35,580 --> 08:09:36,580 have anything so just like this like I 14897 08:09:38,280 --> 08:09:39,280 said we could reuse the same timer but 14898 08:09:40,260 --> 08:09:41,260 let's write our code nice and proper so 14899 08:09:42,298 --> 08:09:43,298 let's make different timers for each so 14900 08:09:44,340 --> 08:09:45,340 let's make three timers so we're going 14901 08:09:46,558 --> 08:09:47,558 to have the countdown to start timer 14902 08:09:49,138 --> 08:09:50,138 so countdown 14903 08:09:50,940 --> 08:09:51,940 for this one let's see Fallen two three 14904 08:09:52,798 --> 08:09:53,798 so we're going to wait three seconds 14905 08:09:53,820 --> 08:09:54,820 before we start and then the game 14906 08:09:55,860 --> 08:09:56,860 playing timer 14907 08:09:57,478 --> 08:09:58,478 and for this one let's put it something 14908 08:09:58,860 --> 08:09:59,860 short just for testing so let's put it 14909 08:10:00,478 --> 08:10:01,478 just test and then down here let's just 14910 08:10:02,940 --> 08:10:03,940 use them so on the countdown let's count 14911 08:10:04,680 --> 08:10:05,680 down this timer on the game playing 14912 08:10:06,420 --> 08:10:07,420 count down this timer when the countdown 14913 08:10:08,280 --> 08:10:09,280 ends we go into game playing and when 14914 08:10:10,798 --> 08:10:11,798 the game playing ends we go into game 14915 08:10:12,478 --> 08:10:13,478 over alright so that's our super basic 14916 08:10:15,000 --> 08:10:16,000 state machine just a bunch of timers 14917 08:10:16,740 --> 08:10:17,740 super simple 14918 08:10:17,820 --> 08:10:18,820 let's do a quick look just to see so 14919 08:10:19,860 --> 08:10:20,860 over here just say debug.log and let's 14920 08:10:22,200 --> 08:10:23,200 just print out the current state 14921 08:10:24,180 --> 08:10:25,180 okay so just like this let's test and 14922 08:10:26,940 --> 08:10:27,940 yep right away we are waiting to start 14923 08:10:28,378 --> 08:10:29,378 after one second going to countdown then 14924 08:10:30,298 --> 08:10:31,298 after three seconds go into game playing 14925 08:10:31,978 --> 08:10:32,978 and now if we wait for 10 seconds 14926 08:10:34,860 --> 08:10:35,860 after 10 seconds we should be able to 14927 08:10:37,080 --> 08:10:38,080 see just a little bit and yep there you 14928 08:10:39,240 --> 08:10:40,240 go we've got our game over okay great 14929 08:10:41,280 --> 08:10:42,280 all the logic is working although we 14930 08:10:43,500 --> 08:10:44,500 actually didn't change anything 14931 08:10:44,458 --> 08:10:45,458 technically the game right now is on a 14932 08:10:46,138 --> 08:10:47,138 game over but everything still works the 14933 08:10:47,458 --> 08:10:48,458 same experience only so I can still play 14934 08:10:48,840 --> 08:10:49,840 I can still do everything 14935 08:10:50,940 --> 08:10:51,940 so let's sort them when we are in any 14936 08:10:53,700 --> 08:10:54,700 state other than the game playing State 14937 08:10:55,440 --> 08:10:56,440 we don't want the player to be able to 14938 08:10:57,058 --> 08:10:58,058 interact with anything we want to leave 14939 08:10:59,040 --> 08:11:00,040 it movement because that's usually nice 14940 08:11:00,958 --> 08:11:01,958 and fun but we don't want it to be able 14941 08:11:02,580 --> 08:11:03,580 to interact pickup objects or do 14942 08:11:04,320 --> 08:11:05,320 anything so let's do that basically over 14943 08:11:06,540 --> 08:11:07,540 here on the game manager let's just 14944 08:11:08,218 --> 08:11:09,218 expose the function so public pool let's 14945 08:11:10,378 --> 08:11:11,378 call this is game playing 14946 08:11:12,600 --> 08:11:13,600 then over here pretty simple just return 14947 08:11:14,580 --> 08:11:15,580 if the state equals state DOT gameplay 14948 08:11:17,040 --> 08:11:18,040 that's it 14949 08:11:18,540 --> 08:11:19,540 so now we can go into the player script 14950 08:11:20,638 --> 08:11:21,638 so over here on the player script let's 14951 08:11:23,520 --> 08:11:24,520 go down into the interaction function so 14952 08:11:25,740 --> 08:11:26,740 over here we've got the interact 14953 08:11:26,940 --> 08:11:27,940 alternate and the interact and on both 14954 08:11:29,340 --> 08:11:30,340 of these basically let's just ask if the 14955 08:11:31,978 --> 08:11:32,978 game is in the game playing state if so 14956 08:11:33,898 --> 08:11:34,898 we want to interact but if not then we 14957 08:11:35,520 --> 08:11:36,520 don't want to do anything so to access 14958 08:11:37,378 --> 08:11:38,378 the game manager we could add a pure 14959 08:11:39,000 --> 08:11:40,000 serialized field or as usual let's just 14960 08:11:40,620 --> 08:11:41,620 make a nice Singleton so pure public 14961 08:11:42,840 --> 08:11:43,840 static of type kitchen game manager the 14962 08:11:45,120 --> 08:11:46,120 instance make a public get and a private 14963 08:11:48,120 --> 08:11:49,120 set 14964 08:11:49,378 --> 08:11:50,378 then down here on awake let's set the 14965 08:11:51,780 --> 08:11:52,780 instance equals this okay so now over 14966 08:11:54,240 --> 08:11:55,240 here on the player let's just go into 14967 08:11:55,680 --> 08:11:56,680 the kitchen game manager access the 14968 08:11:57,240 --> 08:11:58,240 instance and test is game playing 14969 08:11:59,820 --> 08:12:00,820 and we're going to do an if if the game 14970 08:12:01,558 --> 08:12:02,558 is not playing so if we are not playing 14971 08:12:03,840 --> 08:12:04,840 we want to stop this so let's just 14972 08:12:05,100 --> 08:12:06,100 return so if the game is not playing the 14973 08:12:07,020 --> 08:12:08,020 code is going to stop executing here and 14974 08:12:09,000 --> 08:12:10,000 same thing on the interaction so just 14975 08:12:10,860 --> 08:12:11,860 like that we won't be able to interact 14976 08:12:12,600 --> 08:12:13,600 with anything once we are not in the 14977 08:12:14,280 --> 08:12:15,280 game playing State okay so here we are 14978 08:12:16,558 --> 08:12:17,558 waiting to start nope I cannot pick up 14979 08:12:18,298 --> 08:12:19,298 anything count down to start nope I 14980 08:12:19,860 --> 08:12:20,860 can't and as soon as we go into game 14981 08:12:21,000 --> 08:12:22,000 playing yep now I can't interact so I 14982 08:12:22,860 --> 08:12:23,860 can cut a bunch of things 14983 08:12:24,360 --> 08:12:25,360 and as soon as it goes into game 14984 08:12:26,638 --> 08:12:27,638 overstate 14985 08:12:28,378 --> 08:12:29,378 there you go currently in game over 14986 08:12:29,700 --> 08:12:30,700 state so now if I try and interact nope 14987 08:12:31,440 --> 08:12:32,440 can't do it okay awesome everything 14988 08:12:33,360 --> 08:12:34,360 works perfectly 14989 08:12:35,160 --> 08:12:36,160 so in terms of logic this is really it 14990 08:12:37,138 --> 08:12:38,138 there's nothing else we need to do 14991 08:12:39,360 --> 08:12:40,360 but of course right now the player would 14992 08:12:40,860 --> 08:12:41,860 have no clue as to why sometimes they 14993 08:12:42,780 --> 08:12:43,780 can grab and sometimes they can't so 14994 08:12:44,280 --> 08:12:45,280 let's add a proper visual 14995 08:12:46,378 --> 08:12:47,378 first let's add a visual to the starting 14996 08:12:48,058 --> 08:12:49,058 countdown 14997 08:12:49,200 --> 08:12:50,200 so let's do that as a canvas element so 14998 08:12:51,360 --> 08:12:52,360 let's go inside our canvas create an 14999 08:12:52,978 --> 08:12:53,978 empty game object name this the game 15000 08:12:55,320 --> 08:12:56,320 start countdown UI let's press F to 15001 08:12:59,160 --> 08:13:00,160 focus on the object press 2 to turn this 15002 08:13:01,378 --> 08:13:02,378 into 2D okay so let's see and over here 15003 08:13:03,840 --> 08:13:04,840 we really just need a text object so 15004 08:13:05,638 --> 08:13:06,638 let's leave this one anchored on the 15005 08:13:06,958 --> 08:13:07,958 center let's put the width and height 15006 08:13:08,218 --> 08:13:09,218 both on zero we don't need that and then 15007 08:13:10,320 --> 08:13:11,320 let's go inside create a new text object 15008 08:13:12,600 --> 08:13:13,600 call this the countdown text and then 15009 08:13:15,600 --> 08:13:16,600 inside let's just put a number so just a 15010 08:13:17,280 --> 08:13:18,280 three 15011 08:13:18,000 --> 08:13:19,000 let's put the width and height both on 15012 08:13:20,218 --> 08:13:21,218 zero then down here let's put it in bond 15013 08:13:22,500 --> 08:13:23,500 on a really big font size so let's say 15014 08:13:24,478 --> 08:13:25,478 something like 250 okay really nice big 15015 08:13:26,700 --> 08:13:27,700 number then let's also put it centered 15016 08:13:28,920 --> 08:13:29,920 and down the middle okay that's right 15017 08:13:30,780 --> 08:13:31,780 we've got our nice big countdown number 15018 08:13:32,520 --> 08:13:33,520 also by the way when using text mesh Pro 15019 08:13:34,920 --> 08:13:35,920 we can easily add a whole bunch of 15020 08:13:36,478 --> 08:13:37,478 effects if we'll look down here we have 15021 08:13:38,820 --> 08:13:39,820 the default text mesh Pro material and 15022 08:13:40,920 --> 08:13:41,920 over here we can add an outline another 15023 08:13:42,420 --> 08:13:43,420 line and so on so that's really great 15024 08:13:44,218 --> 08:13:45,218 however there's one very very crucial 15025 08:13:46,920 --> 08:13:47,920 thing when you want to add some effects 15026 08:13:49,138 --> 08:13:50,138 always remember that the effects are 15027 08:13:50,820 --> 08:13:51,820 being applied to the material meaning 15028 08:13:52,740 --> 08:13:53,740 any text objects that are sharing this 15029 08:13:54,600 --> 08:13:55,600 material all of them won't modify so for 15030 08:13:57,058 --> 08:13:58,058 the most part usually you don't want to 15031 08:13:58,798 --> 08:13:59,798 modify the default material if you do 15032 08:14:01,080 --> 08:14:02,080 then everything using this default 15033 08:14:02,580 --> 08:14:03,580 material will change like for example I 15034 08:14:04,920 --> 08:14:05,920 want to add a nice thick outline to this 15035 08:14:06,780 --> 08:14:07,780 one but over here I've got some regular 15036 08:14:08,878 --> 08:14:09,878 text that is also using the default 15037 08:14:10,558 --> 08:14:11,558 material so if I now add an upline and I 15038 08:14:13,320 --> 08:14:14,320 increase the thickness and if there you 15039 08:14:14,700 --> 08:14:15,700 go those also got an upline as well as 15040 08:14:16,680 --> 08:14:17,680 this and if I wanted download make it 15041 08:14:18,958 --> 08:14:19,958 quite a lot bigger there you go all of 15042 08:14:20,878 --> 08:14:21,878 them modify because all of them are 15043 08:14:22,558 --> 08:14:23,558 sharing the same material so usually you 15044 08:14:25,080 --> 08:14:26,080 don't want to modify the default 15045 08:14:26,580 --> 08:14:27,580 material if you want to add some kind of 15046 08:14:28,978 --> 08:14:29,978 special effects always make sure to 15047 08:14:30,420 --> 08:14:31,420 create a brand new material beforehand 15048 08:14:31,798 --> 08:14:32,798 so over here let's remove the outline 15049 08:14:34,080 --> 08:14:35,080 put it back on the dilation and let's go 15050 08:14:37,080 --> 08:14:38,080 up here to create the brand new material 15051 08:14:38,398 --> 08:14:39,398 first we need to find our phones over 15052 08:14:40,020 --> 08:14:41,020 here on the font asset we can just click 15053 08:14:41,580 --> 08:14:42,580 on it and we can see it over here 15054 08:14:42,780 --> 08:14:43,780 highlighted on the project window so 15055 08:14:45,058 --> 08:14:46,058 it's inside the text mesh profiler the 15056 08:14:46,798 --> 08:14:47,798 resources phones and so on so here is 15057 08:14:48,420 --> 08:14:49,420 the default font and inside this one is 15058 08:14:50,760 --> 08:14:51,760 the font that we're using now in this 15059 08:14:52,558 --> 08:14:53,558 font there's a nice little error icon 15060 08:14:54,180 --> 08:14:55,180 and inside we can see the default 15061 08:14:55,740 --> 08:14:56,740 material so let's duplicate this 15062 08:14:57,898 --> 08:14:58,898 material although it's important make 15063 08:14:59,520 --> 08:15:00,520 sure you duplicate the material and not 15064 08:15:00,958 --> 08:15:01,958 the font so with this material selected 15065 08:15:02,760 --> 08:15:03,760 I'm going to press Ctrl D and there you 15066 08:15:04,798 --> 08:15:05,798 go it duplicates the material and over 15067 08:15:06,718 --> 08:15:07,718 here let's give it some name so let's 15068 08:15:09,180 --> 08:15:10,180 say this is material that I want to use 15069 08:15:10,500 --> 08:15:11,500 for the start countdown 15070 08:15:12,240 --> 08:15:13,240 so there you go just like this also one 15071 08:15:14,760 --> 08:15:15,760 very very important thing the name of 15072 08:15:16,978 --> 08:15:17,978 the material needs to include the font 15073 08:15:18,540 --> 08:15:19,540 name otherwise it won't show up for 15074 08:15:20,638 --> 08:15:21,638 example if I get rid of this the only 15075 08:15:22,200 --> 08:15:23,200 version Sans SDF if I name the material 15076 08:15:24,240 --> 08:15:25,240 just like this and now I'll look over 15077 08:15:26,458 --> 08:15:27,458 here on the countdown text look on text 15078 08:15:28,020 --> 08:15:29,020 mesh Pro here is the drop down menu for 15079 08:15:30,478 --> 08:15:31,478 selecting material and over here note 15080 08:15:32,700 --> 08:15:33,700 how that one does not show up so it is 15081 08:15:34,978 --> 08:15:35,978 extremely important in order for it to 15082 08:15:36,540 --> 08:15:37,540 show up in here it needs to have the 15083 08:15:38,160 --> 08:15:39,160 same starting name so over here if I 15084 08:15:40,020 --> 08:15:41,020 rename this material put Liberation 15085 08:15:41,940 --> 08:15:42,940 sends SDF and then the name and now back 15086 08:15:44,398 --> 08:15:45,398 in here now look and yep now I do see my 15087 08:15:46,620 --> 08:15:47,620 material okay so that's great and over 15088 08:15:48,840 --> 08:15:49,840 here we can add what kind of effects we 15089 08:15:51,000 --> 08:15:52,000 want and it will only affect this one 15090 08:15:52,798 --> 08:15:53,798 and not any others okay so for this one 15091 08:15:55,138 --> 08:15:56,138 let's add a nice outline and let's make 15092 08:15:57,240 --> 08:15:58,240 some nice thick numbers so over here on 15093 08:15:59,040 --> 08:16:00,040 donation let's handle it by quite a 15094 08:16:00,898 --> 08:16:01,898 little bit 15095 08:16:01,740 --> 08:16:02,740 then for the outline color let's put it 15096 08:16:03,780 --> 08:16:04,780 maybe on a blue something a bit like 15097 08:16:06,298 --> 08:16:07,298 this okay let's push it back just a 15098 08:16:08,760 --> 08:16:09,760 little bit okay I think that looks 15099 08:16:10,620 --> 08:16:11,620 pretty good now if you want you could 15100 08:16:12,958 --> 08:16:13,958 add even more effect to this I made 15101 08:16:15,240 --> 08:16:16,240 another video covering how to use custom 15102 08:16:16,978 --> 08:16:17,978 Textures in your font doing that you can 15103 08:16:19,558 --> 08:16:20,558 just import the font directly into 15104 08:16:21,000 --> 08:16:22,000 Photoshop and edit it with all kinds of 15105 08:16:23,160 --> 08:16:24,160 effects for example in that method is 15106 08:16:25,020 --> 08:16:26,020 example what I used in my game hypernite 15107 08:16:26,820 --> 08:16:27,820 make the head counter look really nice I 15108 08:16:28,920 --> 08:16:29,920 also have a tutorial specifically on 15109 08:16:30,360 --> 08:16:31,360 that so if you want even more custom 15110 08:16:32,160 --> 08:16:33,160 text definitely go ahead and watch those 15111 08:16:33,840 --> 08:16:34,840 videos but anyways here we have our 15112 08:16:35,700 --> 08:16:36,700 countdown text looking pretty nice now 15113 08:16:37,740 --> 08:16:38,740 the number itself will be written 15114 08:16:39,180 --> 08:16:40,180 through code so let's do that let's go 15115 08:16:41,218 --> 08:16:42,218 into our scripts into our UI folder 15116 08:16:42,780 --> 08:16:43,780 create a brand new c-sharp script for 15117 08:16:45,000 --> 08:16:46,000 the game start countdown UI okay and 15118 08:16:48,298 --> 08:16:49,298 let's select the parent object and 15119 08:16:50,218 --> 08:16:51,218 attach the script now here first thing 15120 08:16:52,320 --> 08:16:53,320 we need is a reference to that text 15121 08:16:53,940 --> 08:16:54,940 object so let's add a serialized film 15122 08:16:56,280 --> 08:16:57,280 private and again remember what I 15123 08:16:58,500 --> 08:16:59,500 mentioned a couple of night years ago 15124 08:16:59,940 --> 08:17:00,940 with regards to the types so we want 15125 08:17:02,160 --> 08:17:03,160 xmesh Pro U GUI we want this one so it's 15126 08:17:05,340 --> 08:17:06,340 going to be our countdown text and now 15127 08:17:07,860 --> 08:17:08,860 for updating this text basically we just 15128 08:17:10,020 --> 08:17:11,020 need to know the game state so we need 15129 08:17:11,580 --> 08:17:12,580 to know when the countdown should show 15130 08:17:13,138 --> 08:17:14,138 up and as usual let's use some nice 15131 08:17:15,360 --> 08:17:16,360 events so over here on the kitchen game 15132 08:17:17,580 --> 08:17:18,580 manager let's fire an event whenever the 15133 08:17:19,740 --> 08:17:20,740 state changes 15134 08:17:20,940 --> 08:17:21,940 so a public event event handler 15135 08:17:25,260 --> 08:17:26,260 let's call it on stay changed 15136 08:17:28,080 --> 08:17:29,080 okay just like this no need for the 15137 08:17:30,298 --> 08:17:31,298 arguments so let's go down here whenever 15138 08:17:32,820 --> 08:17:33,820 the state changes and let's just invoke 15139 08:17:34,320 --> 08:17:35,320 this event so invoke this eventar is 15140 08:17:36,898 --> 08:17:37,898 that empty 15141 08:17:38,280 --> 08:17:39,280 so we change in there change in there 15142 08:17:40,320 --> 08:17:41,320 and change down there okay that's it so 15143 08:17:42,718 --> 08:17:43,718 now over here on the game start 15144 08:17:43,860 --> 08:17:44,860 countdown let's see we've probably start 15145 08:17:45,660 --> 08:17:46,660 and on start let's go into the kitchen 15146 08:17:47,340 --> 08:17:48,340 game manager access the instance listen 15147 08:17:49,558 --> 08:17:50,558 to the on say changed event as usual 15148 08:17:52,020 --> 08:17:53,020 write some nice clean codes so let's 15149 08:17:53,638 --> 08:17:54,638 rename this the kitchen game manager 15150 08:17:56,458 --> 08:17:57,458 so when they say changes we basically 15151 08:17:58,440 --> 08:17:59,440 want to show this if we are on the 15152 08:18:00,600 --> 08:18:01,600 countdown to start so let's go here to 15153 08:18:02,700 --> 08:18:03,700 the kitchen game manager and let's make 15154 08:18:04,200 --> 08:18:05,200 another function so public boom is 15155 08:18:07,100 --> 08:18:08,100 countdown to start active 15156 08:18:12,360 --> 08:18:13,360 and we just return if the state 15157 08:18:15,958 --> 08:18:16,958 equals the state DOT countdown to start 15158 08:18:18,660 --> 08:18:19,660 okay so that's a nice simple function 15159 08:18:20,580 --> 08:18:21,580 and on the UI script if the kitchen game 15160 08:18:23,340 --> 08:18:24,340 manager 15161 08:18:25,260 --> 08:18:26,260 if this one dot is countdown to start 15162 08:18:27,540 --> 08:18:28,540 active 15163 08:18:29,458 --> 08:18:30,458 if so then let's show if not then let's 15164 08:18:31,798 --> 08:18:32,798 hide so else 15165 08:18:33,360 --> 08:18:34,360 let's do a hide 15166 08:18:35,760 --> 08:18:36,760 so let's make these functions so proud 15167 08:18:37,440 --> 08:18:38,440 void show 15168 08:18:39,000 --> 08:18:40,000 and a private void hide and on this 15169 08:18:41,700 --> 08:18:42,700 let's just do the usual thing so game 15170 08:18:43,200 --> 08:18:44,200 objects and active into true or over 15171 08:18:45,840 --> 08:18:46,840 here set it into false and on start 15172 08:18:48,360 --> 08:18:49,360 right after we subscribe to the event 15173 08:18:49,860 --> 08:18:50,860 let's also hide it by default okay so 15174 08:18:52,440 --> 08:18:53,440 that's the basic logic for showing or 15175 08:18:54,120 --> 08:18:55,120 hiding it and now for the timer text 15176 08:18:56,600 --> 08:18:57,600 technically over here once inside the 15177 08:18:59,040 --> 08:19:00,040 countdown to start we could fire an 15178 08:19:00,718 --> 08:19:01,718 event on every single update that would 15179 08:19:02,878 --> 08:19:03,878 work but it would have some unnecessary 15180 08:19:04,620 --> 08:19:05,620 overhead 15181 08:19:05,760 --> 08:19:06,760 so instead another option is just make a 15182 08:19:07,920 --> 08:19:08,920 function to expose it so let's go here 15183 08:19:10,200 --> 08:19:11,200 make a public returning float get the 15184 08:19:12,540 --> 08:19:13,540 countdown to start timer 15185 08:19:15,718 --> 08:19:16,718 and we just return the countdown to 15186 08:19:17,580 --> 08:19:18,580 start timer very simple so then over 15187 08:19:19,680 --> 08:19:20,680 here on the UI script we can just make a 15188 08:19:22,260 --> 08:19:23,260 regular proud void update and on update 15189 08:19:25,080 --> 08:19:26,080 go into the countdown text in order to 15190 08:19:27,058 --> 08:19:28,058 set the text 15191 08:19:28,440 --> 08:19:29,440 and let's go into the kitchen game 15192 08:19:30,000 --> 08:19:31,000 manager and let's get the countdown to 15193 08:19:32,760 --> 08:19:33,760 start timer and just do A2 string okay 15194 08:19:35,878 --> 08:19:36,878 so that's it super simple so on update 15195 08:19:37,620 --> 08:19:38,620 we're going to constantly update the 15196 08:19:39,000 --> 08:19:40,000 timer so let's see if this works 15197 08:19:41,160 --> 08:19:42,160 back here in the editor let's just make 15198 08:19:42,958 --> 08:19:43,958 sure to drag the countdown text 15199 08:19:44,160 --> 08:19:45,160 reference and let's hit on play and okay 15200 08:19:46,558 --> 08:19:47,558 waiting to start and after a bit yep 15201 08:19:48,180 --> 08:19:49,180 there you go there's the number it's 15202 08:19:49,620 --> 08:19:50,620 currently on countdown and now the game 15203 08:19:51,058 --> 08:19:52,058 is playing so the show and high did work 15204 08:19:52,860 --> 08:19:53,860 on the number seem quite a bit odd 15205 08:19:54,478 --> 08:19:55,478 that's because over here on the settings 15206 08:19:56,820 --> 08:19:57,820 we have wrapping enamel so now I just 15207 08:19:58,680 --> 08:19:59,680 quickly disable this and let's test 15208 08:20:00,180 --> 08:20:01,180 again 15209 08:20:01,138 --> 08:20:02,138 sir we are waiting to start and there 15210 08:20:02,878 --> 08:20:03,878 you go there's our countdown three two 15211 08:20:04,680 --> 08:20:05,680 one zero and there you go gameplay 15212 08:20:07,020 --> 08:20:08,020 okay so it did work now of course as it 15213 08:20:10,080 --> 08:20:11,080 comes to the visuals it depends on what 15214 08:20:11,700 --> 08:20:12,700 you want 15215 08:20:12,540 --> 08:20:13,540 for example if you want to limit the 15216 08:20:14,458 --> 08:20:15,458 decimals you can use over here the two 15217 08:20:16,200 --> 08:20:17,200 string this one can include all kinds of 15218 08:20:18,600 --> 08:20:19,600 string formats for example for 15219 08:20:20,760 --> 08:20:21,760 displaying just two decimal places you 15220 08:20:22,860 --> 08:20:23,860 can add the string format F2 15221 08:20:25,440 --> 08:20:26,440 let's see what this looks like waiting 15222 08:20:27,660 --> 08:20:28,660 for the countdown and there you go now 15223 08:20:29,160 --> 08:20:30,160 it does Show with two decimals okay so 15224 08:20:31,320 --> 08:20:32,320 this is one approach alternatively 15225 08:20:33,540 --> 08:20:34,540 another format you can use is 15226 08:20:35,820 --> 08:20:36,820 number sign Point number number and 15227 08:20:38,700 --> 08:20:39,700 let's see this one 15228 08:20:40,500 --> 08:20:41,500 and yep there you go now it looks like 15229 08:20:42,780 --> 08:20:43,780 this 15230 08:20:43,500 --> 08:20:44,500 so as you can see there's lots of things 15231 08:20:45,120 --> 08:20:46,120 you can play around with when it comes 15232 08:20:46,920 --> 08:20:47,920 to the two string formats but in our 15233 08:20:49,138 --> 08:20:50,138 case I don't really want any decimals I 15234 08:20:51,058 --> 08:20:52,058 really just want to see whole numbers so 15235 08:20:53,160 --> 08:20:54,160 for that let's just seal out this number 15236 08:20:54,718 --> 08:20:55,718 so in mathf.cl 15237 08:20:57,000 --> 08:20:58,000 let's see on this one out and then just 15238 08:20:59,638 --> 08:21:00,638 do a two string okay let's see 15239 08:21:02,760 --> 08:21:03,760 so wait a bit and we got three two and 15240 08:21:05,760 --> 08:21:06,760 one and there you go the game is winning 15241 08:21:07,798 --> 08:21:08,798 alright awesome so here we have our 15242 08:21:10,440 --> 08:21:11,440 waiting to start and the countdown to 15243 08:21:12,478 --> 08:21:13,478 start all of that logic is working 15244 08:21:13,978 --> 08:21:14,978 perfectly now the next thing we need is 15245 08:21:16,320 --> 08:21:17,320 to handle the game end so let's do that 15246 08:21:18,298 --> 08:21:19,298 in the next lecture 15247 08:21:21,120 --> 08:21:22,120 hello and welcome I'm your code monkey 15248 08:21:22,978 --> 08:21:23,978 in this lecture we're going to handle 15249 08:21:24,898 --> 08:21:25,898 the game over State now for the game 15250 08:21:27,000 --> 08:21:28,000 over State this is obviously a game 15251 08:21:28,500 --> 08:21:29,500 design question for example you can make 15252 08:21:30,360 --> 08:21:31,360 it so that each recipe had a timer 15253 08:21:32,160 --> 08:21:33,160 attached to it and the player had to 15254 08:21:33,840 --> 08:21:34,840 create that recipe within time limit 15255 08:21:35,340 --> 08:21:36,340 then if they failed enough recipes you 15256 08:21:37,978 --> 08:21:38,978 could trigger some kind of game over or 15257 08:21:40,080 --> 08:21:41,080 for something more simple let's just do 15258 08:21:41,520 --> 08:21:42,520 exactly what we did for the game start 15259 08:21:43,798 --> 08:21:44,798 let's just do a basic countdown timer 15260 08:21:46,798 --> 08:21:47,798 after the game is over let's pop up a 15261 08:21:48,780 --> 08:21:49,780 game over window and show how many 15262 08:21:50,458 --> 08:21:51,458 recipes the players delivered so let's 15263 08:21:51,958 --> 08:21:52,958 do that let's go into our canvas and 15264 08:21:54,478 --> 08:21:55,478 inside make an empty game object call it 15265 08:21:56,638 --> 08:21:57,638 the game over UI then over here let's 15266 08:21:59,580 --> 08:22:00,580 stretch it to occupy the entire parent 15267 08:22:01,378 --> 08:22:02,378 like this now inside let's begin by 15268 08:22:04,500 --> 08:22:05,500 making a UI image this is going to be 15269 08:22:06,780 --> 08:22:07,780 the background let's put it in black 15270 08:22:09,298 --> 08:22:10,298 with just a little bit of transparency 15271 08:22:11,040 --> 08:22:12,040 and let's also stretches to occupy the 15272 08:22:13,620 --> 08:22:14,620 entire thing 15273 08:22:14,700 --> 08:22:15,700 so just like this then let's make some 15274 08:22:17,700 --> 08:22:18,700 text so let's make a new UI text click 15275 08:22:20,638 --> 08:22:21,638 the game over text 15276 08:22:22,260 --> 08:22:23,260 and let's say just game over 15277 08:22:24,898 --> 08:22:25,898 let's set the width and height both at 15278 08:22:27,000 --> 08:22:28,000 zero then down here disable wrapping put 15279 08:22:29,940 --> 08:22:30,940 it centered let's put it pretty big so 15280 08:22:32,458 --> 08:22:33,458 maybe 135 put it a little bit higher 15281 08:22:35,638 --> 08:22:36,638 then for some more text let's duplicate 15282 08:22:38,820 --> 08:22:39,820 this let's call this the enlay bone 15283 08:22:41,040 --> 08:22:42,040 recipes delivered text and over here we 15284 08:22:44,340 --> 08:22:45,340 just say recipes 15285 08:22:46,558 --> 08:22:47,558 delivered 15286 08:22:48,298 --> 08:22:49,298 let's put this one a bit lower and quite 15287 08:22:50,458 --> 08:22:51,458 a bit smaller 15288 08:22:51,660 --> 08:22:52,660 say on 50 okay and also on this one 15289 08:22:54,780 --> 08:22:55,780 let's put it in bold then change the 15290 08:22:56,458 --> 08:22:57,458 color a little bit okay next let's make 15291 08:22:59,458 --> 08:23:00,458 yet another text this one is going to be 15292 08:23:01,500 --> 08:23:02,500 for the final number so let's call this 15293 08:23:03,360 --> 08:23:04,360 recipes don't deliver text 15294 08:23:06,000 --> 08:23:07,000 and this one is just going to have 15295 08:23:07,740 --> 08:23:08,740 whatever number of recipes we've 15296 08:23:09,000 --> 08:23:10,000 delivered and let's put it over here and 15297 08:23:10,680 --> 08:23:11,680 quite a bit bigger okay so this is the 15298 08:23:12,840 --> 08:23:13,840 game over window that we want also a 15299 08:23:15,120 --> 08:23:16,120 quick note like I mentioned previously 15300 08:23:16,620 --> 08:23:17,620 the Sorting order over here on the UI is 15301 08:23:18,780 --> 08:23:19,780 based on the ordering the hierarchy so 15302 08:23:21,058 --> 08:23:22,058 for the game over we want this one to 15303 08:23:23,160 --> 08:23:24,160 show up on top of everything else so 15304 08:23:24,958 --> 08:23:25,958 make sure the game over it is the last 15305 08:23:26,398 --> 08:23:27,398 one over here on the UI make sure it is 15306 08:23:28,500 --> 08:23:29,500 the bottom most child on the canvas okay 15307 08:23:31,320 --> 08:23:32,320 now let's make a game object to run this 15308 08:23:33,360 --> 08:23:34,360 so let's create a brand new script game 15309 08:23:36,360 --> 08:23:37,360 over UI let's go into the object wait 15310 08:23:39,120 --> 08:23:40,120 for the compilation and let's drag the 15311 08:23:41,280 --> 08:23:42,280 script okay now here the only reference 15312 08:23:43,378 --> 08:23:44,378 that we need is just for the text so 15313 08:23:45,120 --> 08:23:46,120 let's just make a serialized film of 15314 08:23:47,700 --> 08:23:48,700 type text mesh Pro ugly for the recipes 15315 08:23:50,940 --> 08:23:51,940 delivered text here in the editor let's 15316 08:23:53,580 --> 08:23:54,580 just drag the reference okay now let's 15317 08:23:56,040 --> 08:23:57,040 make some show and height functions and 15318 08:23:58,740 --> 08:23:59,740 also show it just on the game over so 15319 08:24:00,478 --> 08:24:01,478 really we're going to do the exact same 15320 08:24:01,860 --> 08:24:02,860 thing that we did over here on the game 15321 08:24:03,478 --> 08:24:04,478 start countdown so let's actually copy 15322 08:24:05,760 --> 08:24:06,760 exactly this let's go into game over UI 15323 08:24:07,860 --> 08:24:08,860 pass the exact same thing Okay so we've 15324 08:24:10,440 --> 08:24:11,440 got the show and hide functions we test 15325 08:24:12,298 --> 08:24:13,298 and then over here on the state change 15326 08:24:14,160 --> 08:24:15,160 instead of showing this one on the 15327 08:24:15,898 --> 08:24:16,898 countdown we want to show it on the game 15328 08:24:17,280 --> 08:24:18,280 over 15329 08:24:18,120 --> 08:24:19,120 so let's go over here and just make 15330 08:24:19,620 --> 08:24:20,620 another function so public goal is game 15331 08:24:22,680 --> 08:24:23,680 over and we just return if the state 15332 08:24:26,340 --> 08:24:27,340 equals the state that game over okay 15333 08:24:28,500 --> 08:24:29,500 that's a function 15334 08:24:30,000 --> 08:24:31,000 so over here if we are is State game 15335 08:24:32,580 --> 08:24:33,580 over 15336 08:24:33,898 --> 08:24:34,898 if so then we show if not we hide okay 15337 08:24:36,540 --> 08:24:37,540 the last thing we need is just for the 15338 08:24:38,280 --> 08:24:39,280 text so this is going to be the recipes 15339 08:24:39,840 --> 08:24:40,840 only vertex so we're going to set this 15340 08:24:42,540 --> 08:24:43,540 to something 15341 08:24:43,798 --> 08:24:44,798 which really means that we just need to 15342 08:24:45,360 --> 08:24:46,360 keep track of all of the recipes that 15343 08:24:46,920 --> 08:24:47,920 have been delivered so until here onto 15344 08:24:49,138 --> 08:24:50,138 the delivery manager script and let's 15345 08:24:51,360 --> 08:24:52,360 just keep track so just a simple end so 15346 08:24:53,458 --> 08:24:54,458 a private end for the successful recipes 15347 08:24:56,340 --> 08:24:57,340 amount 15348 08:24:58,620 --> 08:24:59,620 and then whenever we have a recipe 15349 08:25:00,478 --> 08:25:01,478 success so let's go here into our 15350 08:25:01,978 --> 08:25:02,978 delivery recipe function whenever we 15351 08:25:04,260 --> 08:25:05,260 have a success let's just increase this 15352 08:25:06,058 --> 08:25:07,058 by one okay so that's it now we just 15353 08:25:08,520 --> 08:25:09,520 need a function to expose this so we 15354 08:25:10,500 --> 08:25:11,500 probably can't for the get the 15355 08:25:12,298 --> 08:25:13,298 successful recipes amount and just 15356 08:25:14,580 --> 08:25:15,580 return the successful recipes amount 15357 08:25:16,440 --> 08:25:17,440 okay so finally back here on the game 15358 08:25:18,958 --> 08:25:19,958 over UI let's just print it so go into 15359 08:25:21,420 --> 08:25:22,420 the delivery manager xsc static instance 15360 08:25:23,820 --> 08:25:24,820 and get the successful recipes amount 15361 08:25:26,100 --> 08:25:27,100 and of course we need the string so to 15362 08:25:27,898 --> 08:25:28,898 string except for this one this is never 15363 08:25:30,058 --> 08:25:31,058 going to change after the game is 15364 08:25:31,440 --> 08:25:32,440 already over so let's not do this on 15365 08:25:33,180 --> 08:25:34,180 update that would be quite wasteful so 15366 08:25:34,920 --> 08:25:35,920 let's just do it up here so as soon as 15367 08:25:37,080 --> 08:25:38,080 we have the game over we show we print 15368 08:25:38,878 --> 08:25:39,878 the recipes and that's it okay so let's 15369 08:25:41,820 --> 08:25:42,820 test so here we are waiting for the 15370 08:25:43,978 --> 08:25:44,978 timer and let's wait and just wait five 15371 08:25:47,580 --> 08:25:48,580 seconds for it to finish and we should 15372 08:25:49,320 --> 08:25:50,320 see a zero so let's just make sure that 15373 08:25:51,540 --> 08:25:52,540 works so after a little bit of time yep 15374 08:25:54,540 --> 08:25:55,540 there you go we've got recipes all over 15375 08:25:55,860 --> 08:25:56,860 zero okay 15376 08:25:57,478 --> 08:25:58,478 now back here again let's try and 15377 08:25:59,100 --> 08:26:00,100 deliver some recipes now so let's try 15378 08:26:00,540 --> 08:26:01,540 and make a cheeseburger try it only for 15379 08:26:02,700 --> 08:26:03,700 that 15380 08:26:03,660 --> 08:26:04,660 cut this one pick up this one 15381 08:26:06,000 --> 08:26:07,000 pick it up put it in there 15382 08:26:08,340 --> 08:26:09,340 and okay quickly all right good and 15383 08:26:11,638 --> 08:26:12,638 there you go we've got a one all right 15384 08:26:13,080 --> 08:26:14,080 Awesome everything worked perfectly 15385 08:26:15,540 --> 08:26:16,540 let's just add one more final element 15386 08:26:17,520 --> 08:26:18,520 right now we cannot see what is the time 15387 08:26:19,620 --> 08:26:20,620 left in the game so let's add a nice 15388 08:26:21,600 --> 08:26:22,600 lock element 15389 08:26:23,218 --> 08:26:24,218 so over here on the canvas let's make 15390 08:26:24,958 --> 08:26:25,958 another empty game object 15391 08:26:26,820 --> 08:26:27,820 let's name this the game playing clock 15392 08:26:29,820 --> 08:26:30,820 UI 15393 08:26:31,320 --> 08:26:32,320 and let's also put it behind the game 15394 08:26:33,360 --> 08:26:34,360 over UI so let's put it above on the 15395 08:26:34,978 --> 08:26:35,978 hierarchy so that it shows up behind in 15396 08:26:37,138 --> 08:26:38,138 order to be able to see what we're doing 15397 08:26:38,340 --> 08:26:39,340 let's also just hide the game over UI 15398 08:26:40,200 --> 08:26:41,200 but only here on scene view so let's 15399 08:26:41,520 --> 08:26:42,520 click on the I icon okay so here we have 15400 08:26:44,218 --> 08:26:45,218 our window let's just anchor it on the 15401 08:26:46,440 --> 08:26:47,440 upper right corner so let's put it 15402 08:26:49,020 --> 08:26:50,020 somewhere in there then inside let's 15403 08:26:51,718 --> 08:26:52,718 create a new UI image come with the 15404 08:26:54,360 --> 08:26:55,360 background for the Sprite 15405 08:26:56,940 --> 08:26:57,940 let's go with these circles right so 15406 08:26:58,740 --> 08:26:59,740 let's click on the eye icon to show all 15407 08:27:00,540 --> 08:27:01,540 the default Sprites and let's use the 15408 08:27:02,280 --> 08:27:03,280 one included with the circle 15409 08:27:04,200 --> 08:27:05,200 so you have this one let's also add a 15410 08:27:06,298 --> 08:27:07,298 nice little outline so let's put it on 2 15411 08:27:09,000 --> 08:27:10,000 2 with phone Alpha and let's also add a 15412 08:27:12,840 --> 08:27:13,840 nice shadow just nice visual so on five 15413 08:27:15,360 --> 08:27:16,360 minus five like that and for the color 15414 08:27:17,520 --> 08:27:18,520 let's also put it some kind of dark gray 15415 08:27:19,558 --> 08:27:20,558 okay so this is our background now let's 15416 08:27:22,320 --> 08:27:23,320 duplicate this so Ctrl d 15417 08:27:24,360 --> 08:27:25,360 and let's rename this one the timer 15418 08:27:26,340 --> 08:27:27,340 image and for this one let's give it a 15419 08:27:28,860 --> 08:27:29,860 different color so maybe something like 15420 08:27:30,420 --> 08:27:31,420 a blue so something like this okay and 15421 08:27:33,360 --> 08:27:34,360 now over here on the image type instead 15422 08:27:34,978 --> 08:27:35,978 of simple let's go with filmed let's 15423 08:27:37,260 --> 08:27:38,260 choose Radeon 360. okay great and now 15424 08:27:39,898 --> 08:27:40,898 over here we can play around the film 15425 08:27:41,458 --> 08:27:42,458 Mount and this will be our timer then 15426 08:27:43,620 --> 08:27:44,620 you can set it up however you want for 15427 08:27:45,478 --> 08:27:46,478 me I'm going to choose to start from the 15428 08:27:47,100 --> 08:27:48,100 top so as it starts the time we're going 15429 08:27:49,320 --> 08:27:50,320 to countdown Until the End okay so 15430 08:27:51,600 --> 08:27:52,600 that's great now let's make the script 15431 08:27:53,700 --> 08:27:54,700 to run this so let's create the brand 15432 08:27:55,680 --> 08:27:56,680 new c-sharp script same thing the game 15433 08:27:57,660 --> 08:27:58,660 playing clock UI and over here let's 15434 08:28:00,660 --> 08:28:01,660 just attach a script so now all we need 15435 08:28:02,940 --> 08:28:03,940 is reference to our image 15436 08:28:04,860 --> 08:28:05,860 so let's make a serialized field 15437 08:28:08,218 --> 08:28:09,218 private image let's make sure to use 15438 08:28:10,200 --> 08:28:11,200 this one the image inside Unity 15439 08:28:11,760 --> 08:28:12,760 engine.ui this is going to be our timer 15440 08:28:14,638 --> 08:28:15,638 image okay like this back here in the 15441 08:28:17,760 --> 08:28:18,760 editor let's drag the reference all 15442 08:28:19,440 --> 08:28:20,440 right now that we have this we need to 15443 08:28:21,840 --> 08:28:22,840 ask the game manager to get the timer 15444 08:28:23,580 --> 08:28:24,580 normalized so let's go over here onto 15445 08:28:25,798 --> 08:28:26,798 the kitchen game manager and let's make 15446 08:28:27,540 --> 08:28:28,540 a function to return just that so a 15447 08:28:29,580 --> 08:28:30,580 public float let's call it get plane 15448 08:28:32,580 --> 08:28:33,580 timer normalized or game point timer 15449 08:28:35,700 --> 08:28:36,700 actually just to match the state 15450 08:28:38,218 --> 08:28:39,218 so get this one and up here we have the 15451 08:28:41,398 --> 08:28:42,398 playing timer we just need to define a 15452 08:28:42,958 --> 08:28:43,958 maximum in order to be able to calculate 15453 08:28:44,638 --> 08:28:45,638 the normalized value so let's duplicate 15454 08:28:46,920 --> 08:28:47,920 this call it the game timer Max and set 15455 08:28:49,558 --> 08:28:50,558 this one to 10 and this one leave it 15456 08:28:51,600 --> 08:28:52,600 like this 15457 08:28:52,620 --> 08:28:53,620 and down here when we change the timer 15458 08:28:54,540 --> 08:28:55,540 when we go into game pointing let's set 15459 08:28:56,638 --> 08:28:57,638 this one equals this.mex that way we 15460 08:28:59,218 --> 08:29:00,218 only Define the timer just up here okay 15461 08:29:01,378 --> 08:29:02,378 so with that now down here we can do the 15462 08:29:03,240 --> 08:29:04,240 compilation so we can return the game 15463 08:29:05,820 --> 08:29:06,820 playing timer divided by the game 15464 08:29:07,440 --> 08:29:08,440 playing timer Max 15465 08:29:09,000 --> 08:29:10,000 except just like this going to be 15466 08:29:10,680 --> 08:29:11,680 inverted because for the game playing 15467 08:29:12,660 --> 08:29:13,660 timer we're counting down instead of 15468 08:29:14,700 --> 08:29:15,700 counting up so all we need to do is our 15469 08:29:16,920 --> 08:29:17,920 simple just reverses so just one minus 15470 08:29:19,260 --> 08:29:20,260 just like this okay great so we have 15471 08:29:21,600 --> 08:29:22,600 this function and then over here on the 15472 08:29:23,700 --> 08:29:24,700 clock just go private void update and on 15473 08:29:26,160 --> 08:29:27,160 update let's go into the kitchen game 15474 08:29:27,780 --> 08:29:28,780 manager the instance let's get that and 15475 08:29:29,940 --> 08:29:30,940 we're going to use that on the timer 15476 08:29:31,458 --> 08:29:32,458 image.fillment okay that's it super 15477 08:29:34,080 --> 08:29:35,080 simple let's see okay here we are on the 15478 08:29:36,718 --> 08:29:37,718 waiting to start all right waiting and 15479 08:29:38,520 --> 08:29:39,520 as soon as we start if there you go 15480 08:29:40,020 --> 08:29:41,020 there's the timer going and we can see 15481 08:29:42,180 --> 08:29:43,180 it constantly increasing 15482 08:29:43,920 --> 08:29:44,920 so it's at the halfway point 15483 08:29:46,798 --> 08:29:47,798 and just a little bit more 15484 08:29:49,440 --> 08:29:50,440 and there you go yep we've got the time 15485 08:29:51,298 --> 08:29:52,298 over and we have our game over 15486 08:29:53,520 --> 08:29:54,520 all right awesome so over here we 15487 08:29:56,218 --> 08:29:57,218 implemented a really nice game over 15488 08:29:57,840 --> 08:29:58,840 Saint we have a playing timer with an 15489 08:30:00,240 --> 08:30:01,240 icui element and when it ends we get a 15490 08:30:02,458 --> 08:30:03,458 game over window showing you a bunch of 15491 08:30:03,958 --> 08:30:04,958 stats now with this working the next 15492 08:30:06,298 --> 08:30:07,298 task is to have some kind of main menu 15493 08:30:08,100 --> 08:30:09,100 so we can play again after the game is 15494 08:30:10,020 --> 08:30:11,020 done so let's do that in the next 15495 08:30:11,820 --> 08:30:12,820 lecture 15496 08:30:13,860 --> 08:30:14,860 hello and welcome I'm your code monkey 15497 08:30:15,840 --> 08:30:16,840 in this lecture we're going to make a 15498 08:30:18,120 --> 08:30:19,120 super simple main menu and downloading 15499 08:30:20,160 --> 08:30:21,160 system okay so every game needs a main 15500 08:30:22,740 --> 08:30:23,740 menu so let's build one let's begin by 15501 08:30:25,260 --> 08:30:26,260 making the scene so let's go into our 15502 08:30:26,638 --> 08:30:27,638 scenes and create a brand new scene call 15503 08:30:29,280 --> 08:30:30,280 this the main menu scene 15504 08:30:31,378 --> 08:30:32,378 and okay here's our default scene now 15505 08:30:33,840 --> 08:30:34,840 over here for the most part you really 15506 08:30:35,218 --> 08:30:36,218 just want some basic buttons so nothing 15507 08:30:36,718 --> 08:30:37,718 too special so let's create a brand new 15508 08:30:39,058 --> 08:30:40,058 UI canvas and let's set up as usual so 15509 08:30:41,760 --> 08:30:42,760 screen space overlay yep then let's go 15510 08:30:43,860 --> 08:30:44,860 with scale with screen size 1920 by 1080 15511 08:30:47,360 --> 08:30:48,360 and let's match with the height okay so 15512 08:30:50,340 --> 08:30:51,340 there's our canvas now inside let's make 15513 08:30:53,040 --> 08:30:54,040 an empty game object name this the main 15514 08:30:55,020 --> 08:30:56,020 menu UI let's stretch it to occupy the 15515 08:30:58,080 --> 08:30:59,080 entire thing so zero zero on everything 15516 08:30:59,940 --> 08:31:00,940 okay 15517 08:31:00,958 --> 08:31:01,958 now inside let's create a brand new UI 15518 08:31:03,780 --> 08:31:04,780 button let's name this the play button 15519 08:31:06,740 --> 08:31:07,740 then inside for the text let's say play 15520 08:31:09,860 --> 08:31:10,860 Let's size the button to be quite a bit 15521 08:31:12,420 --> 08:31:13,420 bigger so let's say 450 by 150 and on 15522 08:31:15,478 --> 08:31:16,478 the text itself let's put it in bold 15523 08:31:17,760 --> 08:31:18,760 only font size quite a bit bigger let's 15524 08:31:19,920 --> 08:31:20,920 say 70 then let's also change the color 15525 08:31:22,320 --> 08:31:23,320 let's put the text in White and the play 15526 08:31:24,240 --> 08:31:25,240 button over here the normal color for 15527 08:31:26,218 --> 08:31:27,218 the image let's put it on a dark gray 15528 08:31:27,898 --> 08:31:28,898 then also over here on the button 15529 08:31:29,940 --> 08:31:30,940 background let's add a nice outline 15530 08:31:32,100 --> 08:31:33,100 let's put it on foam black say something 15531 08:31:34,680 --> 08:31:35,680 like three three then let's make a 15532 08:31:37,260 --> 08:31:38,260 Shadow and for this one five minus five 15533 08:31:39,420 --> 08:31:40,420 okay so that's our basic button let's 15534 08:31:42,180 --> 08:31:43,180 just anchor the button so choose the 15535 08:31:43,978 --> 08:31:44,978 play button let's anchor it on the lower 15536 08:31:45,840 --> 08:31:46,840 left corner and let's push it just a bit 15537 08:31:48,958 --> 08:31:49,958 like this okay pre-symbal now let's 15538 08:31:51,540 --> 08:31:52,540 duplicate this one push it a bit lower 15539 08:31:53,340 --> 08:31:54,340 let's also make it just a tiny bit 15540 08:31:55,440 --> 08:31:56,440 smaller so just 120 this is going to be 15541 08:31:58,320 --> 08:31:59,320 our quit button so let's rename this to 15542 08:32:00,058 --> 08:32:01,058 the quit button and inside for the text 15543 08:32:02,820 --> 08:32:03,820 just say quit and put a bit more on the 15544 08:32:05,580 --> 08:32:06,580 font size okay like this okay so we have 15545 08:32:08,520 --> 08:32:09,520 the two basic buttons that we need now 15546 08:32:10,138 --> 08:32:11,138 let's make this crypto random so let's 15547 08:32:12,478 --> 08:32:13,478 make script with the same name so main 15548 08:32:14,100 --> 08:32:15,100 menu UI so let's go into our script UI 15549 08:32:16,680 --> 08:32:17,680 folder create new script for the main 15550 08:32:18,718 --> 08:32:19,718 menu UI let's attach the script and open 15551 08:32:21,540 --> 08:32:22,540 okay so now here let's begin by making 15552 08:32:23,878 --> 08:32:24,878 serialized films for our buttons so it's 15553 08:32:26,218 --> 08:32:27,218 always film private of type button 15554 08:32:28,378 --> 08:32:29,378 inside Unity engine.ei this is the play 15555 08:32:31,260 --> 08:32:32,260 button and then we have another one for 15556 08:32:33,240 --> 08:32:34,240 the quit button okay back in the editor 15557 08:32:35,700 --> 08:32:36,700 let's drag the references so that's the 15558 08:32:37,320 --> 08:32:38,320 only button and the quit button okay now 15559 08:32:39,958 --> 08:32:40,958 here in the code let's add some 15560 08:32:41,340 --> 08:32:42,340 listeners to these buttons and let's do 15561 08:32:43,080 --> 08:32:44,080 a private way to wake and on the way 15562 08:32:44,580 --> 08:32:45,580 let's go into the play button and going 15563 08:32:46,558 --> 08:32:47,558 to the on click event so the event when 15564 08:32:49,138 --> 08:32:50,138 the player clicks on the button and 15565 08:32:51,420 --> 08:32:52,420 let's add in listener and now we pass in 15566 08:32:53,580 --> 08:32:54,580 The Listener now for here to do this we 15567 08:32:55,798 --> 08:32:56,798 can add a function so we can make a 15568 08:32:57,660 --> 08:32:58,660 private void Play Click we can define a 15569 08:33:00,600 --> 08:33:01,600 function kind of like this and over here 15570 08:33:02,040 --> 08:33:03,040 add it as The Listener so that's one 15571 08:33:04,020 --> 08:33:05,020 approach or another alternative that 15572 08:33:05,940 --> 08:33:06,940 personally I like to use is to use what 15573 08:33:07,920 --> 08:33:08,920 is called a Lambda expression so instead 15574 08:33:10,260 --> 08:33:11,260 of defining an external function down 15575 08:33:11,700 --> 08:33:12,700 here we just go up here and directly 15576 08:33:13,740 --> 08:33:14,740 with the finding Lambda so we open 15577 08:33:15,600 --> 08:33:16,600 parameters to display the parameters for 15578 08:33:18,420 --> 08:33:19,420 the function which in this case we have 15579 08:33:19,798 --> 08:33:20,798 none so just open and close then we do a 15580 08:33:22,320 --> 08:33:23,320 nice little arrow and then we have 15581 08:33:24,600 --> 08:33:25,600 whatever we want to be our clear code so 15582 08:33:27,298 --> 08:33:28,298 both the code that I have here and one 15583 08:33:29,160 --> 08:33:30,160 that I have here both of these are 15584 08:33:30,660 --> 08:33:31,660 exactly the same thing this one is 15585 08:33:32,398 --> 08:33:33,398 called the unlimited expression which is 15586 08:33:34,020 --> 08:33:35,020 also a type of delegate definitely go 15587 08:33:36,240 --> 08:33:37,240 ahead and watch my video on C sharp 15588 08:33:37,860 --> 08:33:38,860 delicates in detail it's yet another 15589 08:33:39,840 --> 08:33:40,840 extremely powerful c-sharp feature I 15590 08:33:42,478 --> 08:33:43,478 find them especially useful especially 15591 08:33:44,100 --> 08:33:45,100 over here to setting the click listeners 15592 08:33:46,080 --> 08:33:47,080 there's no need to make another function 15593 08:33:47,940 --> 08:33:48,940 just use a Lambda expression that's it 15594 08:33:49,860 --> 08:33:50,860 so over here I'm going to use that 15595 08:33:51,478 --> 08:33:52,478 instead of an external function Okay so 15596 08:33:53,458 --> 08:33:54,458 we've got the play and then let's also 15597 08:33:55,500 --> 08:33:56,500 listen to the equip so on the quit 15598 08:33:57,298 --> 08:33:58,298 button the exact same thing okay now 15599 08:33:59,638 --> 08:34:00,638 first on the equip button it's actually 15600 08:34:01,138 --> 08:34:02,138 very simple we just go into application 15601 08:34:03,240 --> 08:34:04,240 and we call the quit function this will 15602 08:34:05,940 --> 08:34:06,940 quit the game that's it very similar 15603 08:34:07,558 --> 08:34:08,558 although one note if we actually test it 15604 08:34:09,718 --> 08:34:10,718 like this so here is the game playing 15605 08:34:11,580 --> 08:34:12,580 and if I click on quit and nope nothing 15606 08:34:13,920 --> 08:34:14,920 happens now the logic is actually 15607 08:34:15,780 --> 08:34:16,780 working we can see visually that the 15608 08:34:17,580 --> 08:34:18,580 button is changing state so we are 15609 08:34:19,080 --> 08:34:20,080 indeed capturing clicks however when the 15610 08:34:21,478 --> 08:34:22,478 game is running inside the editor 15611 08:34:22,920 --> 08:34:23,920 calling that function the 15612 08:34:24,058 --> 08:34:25,058 application.quit doesn't do anything but 15613 08:34:26,520 --> 08:34:27,520 if this were a phone bill then clicking 15614 08:34:28,320 --> 08:34:29,320 on that would indeed close their game 15615 08:34:29,820 --> 08:34:30,820 okay so now for the play button for this 15616 08:34:32,760 --> 08:34:33,760 one it's also very simple we just need 15617 08:34:34,500 --> 08:34:35,500 to go inside the scene manager which is 15618 08:34:37,080 --> 08:34:38,080 inside the unity engine.scene management 15619 08:34:38,940 --> 08:34:39,940 we just need to go inside of this one 15620 08:34:41,040 --> 08:34:42,040 and we call load scene 15621 08:34:43,680 --> 08:34:44,680 this function will load with a certain 15622 08:34:45,420 --> 08:34:46,420 scene and for loading we can either use 15623 08:34:47,940 --> 08:34:48,940 the scene film index or we can use the 15624 08:34:49,798 --> 08:34:50,798 scene name like I've mentioned several 15625 08:34:51,718 --> 08:34:52,718 times string names are horrible although 15626 08:34:53,878 --> 08:34:54,878 in this case the alternative using an 15627 08:34:55,440 --> 08:34:56,440 INT is also not very good just a number 15628 08:34:57,958 --> 08:34:58,958 is very hard to read the code and being 15629 08:35:00,000 --> 08:35:01,000 able to know what scene this is loading 15630 08:35:02,040 --> 08:35:03,040 so there's one better approach that I 15631 08:35:04,200 --> 08:35:05,200 prefer to use but first over here let's 15632 08:35:05,940 --> 08:35:06,940 just use the index just for testing so 15633 08:35:08,458 --> 08:35:09,458 we're going to load the scene on index 15634 08:35:10,080 --> 08:35:11,080 one so just like this and then here in 15635 08:35:13,320 --> 08:35:14,320 the editor and let's go into file and 15636 08:35:15,000 --> 08:35:16,000 build settings 15637 08:35:16,080 --> 08:35:17,080 and over here we see the scenes in our 15638 08:35:17,760 --> 08:35:18,760 build right now we just have the game 15639 08:35:19,260 --> 08:35:20,260 scene so let's just add our scene so 15640 08:35:21,478 --> 08:35:22,478 let's drag the main medicine and drag it 15641 08:35:23,160 --> 08:35:24,160 on there and also let's make sure it's 15642 08:35:24,780 --> 08:35:25,780 on the top of the list basically the 15643 08:35:26,340 --> 08:35:27,340 first scene is the one that won't be 15644 08:35:27,478 --> 08:35:28,478 unloaded as soon as the game starts so 15645 08:35:29,458 --> 08:35:30,458 let's try it right up top just like that 15646 08:35:31,440 --> 08:35:32,440 then over here on the right we see the 15647 08:35:33,240 --> 08:35:34,240 index so by loading the scene on the 15648 08:35:35,580 --> 08:35:36,580 next one we're going to be unloading the 15649 08:35:36,958 --> 08:35:37,958 game scene okay so with the slits test 15650 08:35:39,180 --> 08:35:40,180 so here we are and if I click on playing 15651 08:35:42,000 --> 08:35:43,000 and if there you go it doesn't load the 15652 08:35:43,740 --> 08:35:44,740 main scene okay great everything is 15653 08:35:46,080 --> 08:35:47,080 working so this is the seamless way to 15654 08:35:48,360 --> 08:35:49,360 do scene loading however this method 15655 08:35:50,398 --> 08:35:51,398 does have one issue it's not super 15656 08:35:52,378 --> 08:35:53,378 noticeable when a game of this scale 15657 08:35:53,820 --> 08:35:54,820 because it loads pretty quickly 15658 08:35:55,558 --> 08:35:56,558 but like this note how when we click on 15659 08:35:58,020 --> 08:35:59,020 play there you go everything freezes for 15660 08:35:59,878 --> 08:36:00,878 a little bit while the game is loading 15661 08:36:01,260 --> 08:36:02,260 like I mentioned in this case the freeze 15662 08:36:03,000 --> 08:36:04,000 is so small so not necessarily an issue 15663 08:36:04,680 --> 08:36:05,680 but if the game was much more complex 15664 08:36:06,478 --> 08:36:07,478 then the player would be staring at a 15665 08:36:08,040 --> 08:36:09,040 frozen main menu for perhaps 30 seconds 15666 08:36:09,780 --> 08:36:10,780 that would not be good one way to avoid 15667 08:36:12,180 --> 08:36:13,180 that is actually very simple basically 15668 08:36:13,798 --> 08:36:14,798 it's what I already covered in detail in 15669 08:36:15,420 --> 08:36:16,420 the scene loading video that video was 15670 08:36:17,398 --> 08:36:18,398 made quite a while ago but it's still 15671 08:36:18,780 --> 08:36:19,780 very much up to date here we're going to 15672 08:36:20,638 --> 08:36:21,638 do pretty much the same thing so we 15673 08:36:22,260 --> 08:36:23,260 first create the scene just empty just 15674 08:36:24,180 --> 08:36:25,180 saying loading and then from that scene 15675 08:36:26,340 --> 08:36:27,340 we load the final scene that way the 15676 08:36:28,320 --> 08:36:29,320 game stays Frozen on a scene that says 15677 08:36:29,820 --> 08:36:30,820 loading which is much more clear to the 15678 08:36:31,378 --> 08:36:32,378 player so let's do that first let's make 15679 08:36:33,958 --> 08:36:34,958 our scene so inside our scenes folder 15680 08:36:35,638 --> 08:36:36,638 let's create a brand new scene call this 15681 08:36:38,218 --> 08:36:39,218 the unloading scene okay let's go inside 15682 08:36:40,558 --> 08:36:41,558 and on this one we want this one to be 15683 08:36:42,840 --> 08:36:43,840 fully black so let's go into the main 15684 08:36:44,398 --> 08:36:45,398 camera and scroll down over here under 15685 08:36:46,260 --> 08:36:47,260 environment and instead of rendering the 15686 08:36:48,058 --> 08:36:49,058 Skybox for the background let's go with 15687 08:36:49,740 --> 08:36:50,740 a solid color and let's go with phone 15688 08:36:51,780 --> 08:36:52,780 black okay there's our black main camera 15689 08:36:54,478 --> 08:36:55,478 now let's make a canvas so a new UI 15690 08:36:57,660 --> 08:36:58,660 canvas let's set up as usual so scale 15691 08:37:00,540 --> 08:37:01,540 with screen size 1920 by 1080 and match 15692 08:37:04,200 --> 08:37:05,200 with the height okay then inside let's 15693 08:37:06,360 --> 08:37:07,360 just make a simple text object so just 15694 08:37:08,760 --> 08:37:09,760 say text then over here on let's say 15695 08:37:10,200 --> 08:37:11,200 just loading 15696 08:37:13,440 --> 08:37:14,440 let's put the text width and height on 15697 08:37:15,420 --> 08:37:16,420 zero put it on Bold let's make sure to 15698 08:37:18,000 --> 08:37:19,000 disable wrapping 15699 08:37:19,920 --> 08:37:20,920 and push it over there on the side and 15700 08:37:22,080 --> 08:37:23,080 maybe increase the font size down a 15701 08:37:23,398 --> 08:37:24,398 little bit okay there you go we have our 15702 08:37:25,440 --> 08:37:26,440 very basic loading screen now we're 15703 08:37:27,600 --> 08:37:28,600 going to unload this scene and then once 15704 08:37:29,398 --> 08:37:30,398 on this scene we're going to load the 15705 08:37:30,780 --> 08:37:31,780 final scene although also one very 15706 08:37:32,820 --> 08:37:33,820 important thing related to loading 15707 08:37:34,200 --> 08:37:35,200 scenes is you need to remember the 15708 08:37:36,058 --> 08:37:37,058 lifetime of the objects regular game 15709 08:37:38,398 --> 08:37:39,398 objects only for example the ones that 15710 08:37:39,718 --> 08:37:40,718 we see here in the hierarchy these get 15711 08:37:41,398 --> 08:37:42,398 destroyed when you do a scene change 15712 08:37:43,378 --> 08:37:44,378 so for the goal that we're trying to 15713 08:37:45,058 --> 08:37:46,058 achieve we need to unload this loading 15714 08:37:47,040 --> 08:37:48,040 scene but then also somehow transfer 15715 08:37:49,378 --> 08:37:50,378 data so that the loading scene here 15716 08:37:51,058 --> 08:37:52,058 knows which one is the final scene now 15717 08:37:53,340 --> 08:37:54,340 you might think that over here on the 15718 08:37:54,420 --> 08:37:55,420 main menu we could create a game object 15719 08:37:56,040 --> 08:37:57,040 attach a script that would hone the 15720 08:37:57,600 --> 08:37:58,600 reference to the final scene but like I 15721 08:37:59,520 --> 08:38:00,520 said game objects get destroyed as soon 15722 08:38:01,200 --> 08:38:02,200 as we unload the unloading scene so for 15723 08:38:03,298 --> 08:38:04,298 transferring data between scenes we 15724 08:38:04,920 --> 08:38:05,920 can't really use a regular script on a 15725 08:38:06,840 --> 08:38:07,840 regular game object now one approach is 15726 08:38:09,180 --> 08:38:10,180 to use the don't destroy on loan this is 15727 08:38:11,760 --> 08:38:12,760 a Unity function that helps you stop a 15728 08:38:13,798 --> 08:38:14,798 particular script or a game object from 15729 08:38:15,420 --> 08:38:16,420 being destroyed that way the object 15730 08:38:17,580 --> 08:38:18,580 won't process through scene changes so 15731 08:38:19,378 --> 08:38:20,378 that's one option but another option 15732 08:38:21,780 --> 08:38:22,780 that I prefer is very simple let's just 15733 08:38:24,058 --> 08:38:25,058 make it another class so let's create a 15734 08:38:26,280 --> 08:38:27,280 new c-sharp script call this loader and 15735 08:38:29,218 --> 08:38:30,218 over here let's go ahead and make this 15736 08:38:30,780 --> 08:38:31,780 class a static class and we are not 15737 08:38:33,120 --> 08:38:34,120 going to extend Model Behavior so just 15738 08:38:35,340 --> 08:38:36,340 like this 15739 08:38:36,420 --> 08:38:37,420 basically by making it static it means 15740 08:38:38,700 --> 08:38:39,700 that this one is not attached to any 15741 08:38:40,378 --> 08:38:41,378 specific instance of an object this 15742 08:38:42,540 --> 08:38:43,540 class cannot be attached to any object 15743 08:38:44,280 --> 08:38:45,280 and cannot have any instances 15744 08:38:45,840 --> 08:38:46,840 constructed then inside we can add 15745 08:38:47,700 --> 08:38:48,700 static functions in fields like for 15746 08:38:49,500 --> 08:38:50,500 example a static and for the Target 15747 08:38:51,840 --> 08:38:52,840 scene index 15748 08:38:53,638 --> 08:38:54,638 so now this field we could set this 15749 08:38:55,620 --> 08:38:56,620 field from over here on the main menu UI 15750 08:38:57,718 --> 08:38:58,718 and when we would load we would not be 15751 08:39:00,058 --> 08:39:01,058 resetting this field also here I should 15752 08:39:02,218 --> 08:39:03,218 point out one quick thing you can make 15753 08:39:04,500 --> 08:39:05,500 field static without making the entire 15754 08:39:06,360 --> 08:39:07,360 class itself static making the class 15755 08:39:08,638 --> 08:39:09,638 static is just a good approach if the 15756 08:39:10,740 --> 08:39:11,740 entire thing if everything in this class 15757 08:39:12,360 --> 08:39:13,360 is also meant to be static if you don't 15758 08:39:14,520 --> 08:39:15,520 make it static then you can have regular 15759 08:39:16,320 --> 08:39:17,320 films here 15760 08:39:18,240 --> 08:39:19,240 you can have both static and non-sanic 15761 08:39:20,398 --> 08:39:21,398 whereas if you make this static 15762 08:39:23,458 --> 08:39:24,458 then you're going to have an error 15763 08:39:24,840 --> 08:39:25,840 because you cannot have non-static 15764 08:39:26,340 --> 08:39:27,340 feelings so this is another clean code 15765 08:39:28,620 --> 08:39:29,620 thing if it's only meant to contain 15766 08:39:30,420 --> 08:39:31,420 static logic then make the class itself 15767 08:39:32,398 --> 08:39:33,398 static okay so we have a static field 15768 08:39:34,920 --> 08:39:35,920 for our Target scene but as usual we 15769 08:39:37,378 --> 08:39:38,378 don't want this to be a public field we 15770 08:39:39,600 --> 08:39:40,600 don't want the main menu to directly 15771 08:39:41,040 --> 08:39:42,040 write to this field so let's make this 15772 08:39:43,378 --> 08:39:44,378 class the only one responsible for 15773 08:39:45,000 --> 08:39:46,000 anything related with scene loading 15774 08:39:46,620 --> 08:39:47,620 since then let's make a function so a 15775 08:39:48,958 --> 08:39:49,958 public static void call it load 15776 08:39:51,600 --> 08:39:52,600 and for a printer let's receive a string 15777 08:39:54,000 --> 08:39:55,000 for the Target scene name then over here 15778 08:39:56,638 --> 08:39:57,638 we will load the actual scene so let's 15779 08:39:57,958 --> 08:39:58,958 go into the scene manager and load the 15780 08:40:00,240 --> 08:40:01,240 scene 15781 08:40:01,680 --> 08:40:02,680 analyst best in the Target scene name 15782 08:40:03,898 --> 08:40:04,898 okay that's it 15783 08:40:05,820 --> 08:40:06,820 and then over here on the main menu UI 15784 08:40:07,440 --> 08:40:08,440 instead of directly unloading a scene 15785 08:40:08,760 --> 08:40:09,760 let's go into the loader and con load 15786 08:40:11,280 --> 08:40:12,280 and pass in the scene name so that's the 15787 08:40:13,080 --> 08:40:14,080 game scene 15788 08:40:14,638 --> 08:40:15,638 okay so this is what we're going to do 15789 08:40:16,138 --> 08:40:17,138 that's good except it's obviously not 15790 08:40:18,360 --> 08:40:19,360 good over here we're using string names 15791 08:40:20,458 --> 08:40:21,458 that's horrible we should never use this 15792 08:40:22,440 --> 08:40:23,440 so let's avoid using strings as much as 15793 08:40:24,780 --> 08:40:25,780 possible in one simple way is to just 15794 08:40:26,638 --> 08:40:27,638 Define an enum for all of our scenes so 15795 08:40:29,040 --> 08:40:30,040 let's go here on the other and let's 15796 08:40:30,718 --> 08:40:31,718 define that so a public enum let's call 15797 08:40:33,600 --> 08:40:34,600 it scene 15798 08:40:34,860 --> 08:40:35,860 and for all of our scenes so we have the 15799 08:40:37,020 --> 08:40:38,020 main menu scene then we have the game 15800 08:40:39,718 --> 08:40:40,718 scene and the unloading scene 15801 08:40:42,478 --> 08:40:43,478 okay so then down here on this function 15802 08:40:44,820 --> 08:40:45,820 inside receiving a string we just 15803 08:40:46,978 --> 08:40:47,978 receive a scene for the Target scene and 15804 08:40:49,558 --> 08:40:50,558 we use the target scene although of 15805 08:40:51,540 --> 08:40:52,540 course the NT API does not support 15806 08:40:53,100 --> 08:40:54,100 unloading our custom enum it has to be 15807 08:40:55,378 --> 08:40:56,378 an index or string so the simple 15808 08:40:57,298 --> 08:40:58,298 approach is just to convert this one 15809 08:40:58,920 --> 08:40:59,920 into a string that's it so the only 15810 08:41:00,898 --> 08:41:01,898 thing you need to make sure is that the 15811 08:41:02,280 --> 08:41:03,280 enum values over here match the actual 15812 08:41:04,860 --> 08:41:05,860 name on the actual scenes perfectly so 15813 08:41:07,260 --> 08:41:08,260 don't make any mistakes keep it case 15814 08:41:09,540 --> 08:41:10,540 sensitive so don't do this make sure 15815 08:41:11,040 --> 08:41:12,040 everything matches perfectly okay so 15816 08:41:13,260 --> 08:41:14,260 just like this everything should already 15817 08:41:14,580 --> 08:41:15,580 be working the same as previously so the 15818 08:41:17,100 --> 08:41:18,100 main menu calls that let's actually just 15819 08:41:19,020 --> 08:41:20,020 use that so let's use scene Dot Game 15820 08:41:21,240 --> 08:41:22,240 scene 15821 08:41:22,138 --> 08:41:23,138 so on the main menu we do this and 15822 08:41:24,058 --> 08:41:25,058 unloader we load the scene okay let's 15823 08:41:25,860 --> 08:41:26,860 test here is the main menu and if we 15824 08:41:28,080 --> 08:41:29,080 click and wait a bit and after you go it 15825 08:41:30,240 --> 08:41:31,240 didn't load the game scene okay great so 15826 08:41:32,160 --> 08:41:33,160 everything still works the same as 15827 08:41:33,298 --> 08:41:34,298 presently except now all of the 15828 08:41:34,558 --> 08:41:35,558 unloading logic is inside of this class 15829 08:41:37,138 --> 08:41:38,138 and over here let's open a loading scene 15830 08:41:39,180 --> 08:41:40,180 in the middle basically when we have 15831 08:41:41,040 --> 08:41:42,040 this function to load a final scene 15832 08:41:42,360 --> 08:41:43,360 let's first off set this field so this 15833 08:41:44,940 --> 08:41:45,940 one instead of being type in let's make 15834 08:41:46,558 --> 08:41:47,558 it a type scene and this is going to be 15835 08:41:48,600 --> 08:41:49,600 the target scene and let's make it 15836 08:41:50,638 --> 08:41:51,638 private okay 15837 08:41:52,500 --> 08:41:53,500 so when we have this function let's set 15838 08:41:54,420 --> 08:41:55,420 that field although here remember how 15839 08:41:56,638 --> 08:41:57,638 this is a static class so in order to 15840 08:41:58,320 --> 08:41:59,320 access this field we need to exit 15841 08:41:59,700 --> 08:42:00,700 through the class name because over here 15842 08:42:01,558 --> 08:42:02,558 we also have a local variable with the 15843 08:42:03,240 --> 08:42:04,240 exact same name so what sex is the 15844 08:42:05,458 --> 08:42:06,458 unloader.target scene and set it to the 15845 08:42:07,620 --> 08:42:08,620 Target scene 15846 08:42:08,820 --> 08:42:09,820 so again don't be confused here you can 15847 08:42:11,340 --> 08:42:12,340 even use visual studio and put the 15848 08:42:12,660 --> 08:42:13,660 cursor on top to see what object 15849 08:42:14,218 --> 08:42:15,218 represents what so you can see the 15850 08:42:15,898 --> 08:42:16,898 unloader.target scene is referencing 15851 08:42:17,520 --> 08:42:18,520 this field whereas this one over here is 15852 08:42:19,320 --> 08:42:20,320 referencing the local field so we want 15853 08:42:21,360 --> 08:42:22,360 to assign the member field to the one 15854 08:42:23,040 --> 08:42:24,040 that we received as a parameter okay so 15855 08:42:25,440 --> 08:42:26,440 we store that and then let's immediately 15856 08:42:27,180 --> 08:42:28,180 unload the unloading scene so scene 15857 08:42:28,920 --> 08:42:29,920 manager let's load the scene and we're 15858 08:42:31,740 --> 08:42:32,740 going to load 15859 08:42:33,898 --> 08:42:34,898 the scene dot loading scene dot to 15860 08:42:36,540 --> 08:42:37,540 string okay so we're going to download 15861 08:42:37,860 --> 08:42:38,860 that and now here comes the tricky part 15862 08:42:40,138 --> 08:42:41,138 if we do this so if we load the 15863 08:42:42,540 --> 08:42:43,540 unloading scene and then immediately 15864 08:42:43,798 --> 08:42:44,798 unload the target scene if we didn't 15865 08:42:45,780 --> 08:42:46,780 like this it won't actually show the 15866 08:42:47,638 --> 08:42:48,638 loading scene 15867 08:42:48,898 --> 08:42:49,898 we're calling these functions one right 15868 08:42:50,820 --> 08:42:51,820 after the other so to unload the one and 15869 08:42:53,280 --> 08:42:54,280 immediately the other basically we need 15870 08:42:55,200 --> 08:42:56,200 to wait at least one frame to render so 15871 08:42:57,120 --> 08:42:58,120 that the unloading scene is visible and 15872 08:42:59,100 --> 08:43:00,100 then we can alert the final scene so 15873 08:43:01,020 --> 08:43:02,020 let's make a script to do a very simple 15874 08:43:02,580 --> 08:43:03,580 jump let's create a brand new c-sharp 15875 08:43:05,100 --> 08:43:06,100 script for the unloader comeback and now 15876 08:43:08,040 --> 08:43:09,040 let's go inside the unloading scene so 15877 08:43:10,320 --> 08:43:11,320 this is important let's make this on the 15878 08:43:11,700 --> 08:43:12,700 loading scene not the main menu or the 15879 08:43:13,260 --> 08:43:14,260 game scene so over here let's create an 15880 08:43:15,120 --> 08:43:16,120 empty game object for the unloader 15881 08:43:16,740 --> 08:43:17,740 comeback let's reset transform just keep 15882 08:43:19,320 --> 08:43:20,320 things nice and clean and let's attach a 15883 08:43:21,058 --> 08:43:22,058 script so the only other comeback okay 15884 08:43:22,558 --> 08:43:23,558 and on this script we want to basically 15885 08:43:25,080 --> 08:43:26,080 just wait for the very first update 15886 08:43:27,360 --> 08:43:28,360 so let's see private ball is first 15887 08:43:29,940 --> 08:43:30,940 update and we started off as true 15888 08:43:32,580 --> 08:43:33,580 actually 15889 08:43:33,660 --> 08:43:34,660 so is the first update is true then we 15890 08:43:36,120 --> 08:43:37,120 do a product void update so if it is the 15891 08:43:39,058 --> 08:43:40,058 first update if so then let's set is 15892 08:43:41,520 --> 08:43:42,520 first update to false 15893 08:43:43,978 --> 08:43:44,978 we have the first update although 15894 08:43:46,020 --> 08:43:47,020 technology I should point out that we 15895 08:43:47,340 --> 08:43:48,340 don't really need this we're going to 15896 08:43:49,020 --> 08:43:50,020 load right away so either way it will 15897 08:43:50,878 --> 08:43:51,878 only run One update but still I like to 15898 08:43:53,100 --> 08:43:54,100 add this just to make the logic 15899 08:43:54,478 --> 08:43:55,478 perfectly clear basically if it is the 15900 08:43:56,638 --> 08:43:57,638 first update then let's call a function 15901 08:43:58,200 --> 08:43:59,200 on the unloader so on the loader over 15902 08:44:00,058 --> 08:44:01,058 here let's make a function public static 15903 08:44:02,100 --> 08:44:03,100 void call it below their comeback 15904 08:44:05,760 --> 08:44:06,760 okay we have this function it's over 15905 08:44:07,798 --> 08:44:08,798 here on the other convex let's just go 15906 08:44:09,478 --> 08:44:10,478 into the unloader and call the unloader 15907 08:44:11,340 --> 08:44:12,340 convex function all right so basically 15908 08:44:13,558 --> 08:44:14,558 now here we have this function that is 15909 08:44:15,058 --> 08:44:16,058 going to be triggered on the first 15910 08:44:16,500 --> 08:44:17,500 update so we know for certain the 15911 08:44:18,240 --> 08:44:19,240 unloading scene has been rendered so 15912 08:44:20,160 --> 08:44:21,160 it's over here that we want to load the 15913 08:44:21,840 --> 08:44:22,840 actual final scene okay that's it here 15914 08:44:24,478 --> 08:44:25,478 we have a super simple loading system 15915 08:44:26,160 --> 08:44:27,160 just make perfectly sure that the 15916 08:44:28,138 --> 08:44:29,138 unloader come back with the script this 15917 08:44:29,760 --> 08:44:30,760 one only exists on the loading scene it 15918 08:44:31,680 --> 08:44:32,680 should not be on any of the other ones 15919 08:44:33,240 --> 08:44:34,240 so let's test and for that let's go 15920 08:44:35,520 --> 08:44:36,520 inside the main menu scene okay and now 15921 08:44:37,440 --> 08:44:38,440 let's hit on play okay so here we are on 15922 08:44:39,420 --> 08:44:40,420 main menu now if I click on play and 15923 08:44:41,700 --> 08:44:42,700 actually here's the thing that I forgot 15924 08:44:43,138 --> 08:44:44,138 so make sure you don't forget this we 15925 08:44:45,180 --> 08:44:46,180 need to add the unloading scene to the 15926 08:44:46,500 --> 08:44:47,500 builds in order to be able to load 15927 08:44:48,420 --> 08:44:49,420 so let's go up here into the build 15928 08:44:50,218 --> 08:44:51,218 settings let's go into the project drag 15929 08:44:52,080 --> 08:44:53,080 the unloading scene like that okay so 15930 08:44:53,940 --> 08:44:54,940 now let's test so here we are on the 15931 08:44:56,218 --> 08:44:57,218 main menu let's hit on play and there's 15932 08:44:58,080 --> 08:44:59,080 the loading scene after a bit yep here 15933 08:44:59,820 --> 08:45:00,820 we have our game scene all right awesome 15934 08:45:01,920 --> 08:45:02,920 so with that everything is working 15935 08:45:03,958 --> 08:45:04,958 perfectly all of the logic is working 15936 08:45:05,878 --> 08:45:06,878 great now the wrong words great let's 15937 08:45:08,160 --> 08:45:09,160 just make a nice proper visual for our 15938 08:45:09,898 --> 08:45:10,898 main menu so for that let's go inside 15939 08:45:12,180 --> 08:45:13,180 the game scene and over here let's copy 15940 08:45:14,580 --> 08:45:15,580 a few things so let's pick up the four 15941 08:45:16,920 --> 08:45:17,920 object and let's also pick up the global 15942 08:45:19,320 --> 08:45:20,320 volume with the post pressing so let's 15943 08:45:21,660 --> 08:45:22,660 copy both of these let's go into the 15944 08:45:23,700 --> 08:45:24,700 main menu scene and over here on let's 15945 08:45:25,558 --> 08:45:26,558 paste both objects okay now let's also 15946 08:45:28,378 --> 08:45:29,378 drag some player visuals so let's put 15947 08:45:30,298 --> 08:45:31,298 this in 3D go back down into the floor 15948 08:45:32,280 --> 08:45:33,280 and let's pick up some visuals so let's 15949 08:45:34,860 --> 08:45:35,860 go inside our assets on the prefabs 15950 08:45:36,840 --> 08:45:37,840 visuals let's find over here the player 15951 08:45:39,540 --> 08:45:40,540 visual again make sure you drag the 15952 08:45:41,398 --> 08:45:42,398 visual only we don't want any logic 15953 08:45:43,440 --> 08:45:44,440 components and by the way this is yet 15954 08:45:45,660 --> 08:45:46,660 another great benefit of separating the 15955 08:45:47,280 --> 08:45:48,280 logic from the visuals right now it's 15956 08:45:49,558 --> 08:45:50,558 super simple for us to play some players 15957 08:45:51,240 --> 08:45:52,240 here because we have just the visuals 15958 08:45:53,100 --> 08:45:54,100 commonly separated from the logic okay 15959 08:45:54,898 --> 08:45:55,898 so on the visual let's just make it look 15960 08:45:56,820 --> 08:45:57,820 at the camera let's position a bunch 15961 08:45:59,218 --> 08:46:00,218 more players so let's duplicate this 15962 08:46:01,440 --> 08:46:02,440 and put one to the side we're going to 15963 08:46:04,138 --> 08:46:05,138 move the camera in a bit but now let's 15964 08:46:05,580 --> 08:46:06,580 just place them and included assets 15965 08:46:08,160 --> 08:46:09,160 there are a bunch of materials so over 15966 08:46:09,958 --> 08:46:10,958 here we see the employer body then we've 15967 08:46:11,520 --> 08:46:12,520 got a blue a green and a red like I said 15968 08:46:13,798 --> 08:46:14,798 this first course is on making this game 15969 08:46:15,420 --> 08:46:16,420 in single player but the goal is to then 15970 08:46:17,218 --> 08:46:18,218 make a second course after this one on 15971 08:46:19,080 --> 08:46:20,080 converting this game into multiplier so 15972 08:46:21,000 --> 08:46:22,000 that's why I included multiple colors so 15973 08:46:23,100 --> 08:46:24,100 let's just drag these let's go into this 15974 08:46:25,620 --> 08:46:26,620 player Visual and on this one make it 15975 08:46:27,958 --> 08:46:28,958 blue so on the head and on the body then 15976 08:46:31,740 --> 08:46:32,740 on this one on the side here let's make 15977 08:46:33,660 --> 08:46:34,660 this one green so green there and green 15978 08:46:36,240 --> 08:46:37,240 on the head and for the one behind let's 15979 08:46:39,058 --> 08:46:40,058 make this one the red one so put it in 15980 08:46:40,920 --> 08:46:41,920 red and in red Okay so we've got our 15981 08:46:43,740 --> 08:46:44,740 nice four players now let's also add a 15982 08:46:46,020 --> 08:46:47,020 camera so we're going to have the camera 15983 08:46:47,340 --> 08:46:48,340 kind of like this kind of from below and 15984 08:46:49,920 --> 08:46:50,920 looking upwards I think that looks 15985 08:46:51,180 --> 08:46:52,180 pretty good for that let's use cine 15986 08:46:52,978 --> 08:46:53,978 machines and let's go into game object 15987 08:46:54,420 --> 08:46:55,420 go into cinemachine and let's create a 15988 08:46:57,240 --> 08:46:58,240 brand new version on camera okay unlike 15989 08:46:59,218 --> 08:47:00,218 this let's just push it up a little bit 15990 08:47:01,378 --> 08:47:02,378 okay so this is our nice composition 15991 08:47:03,780 --> 08:47:04,780 now on the virtual camera let's just go 15992 08:47:05,820 --> 08:47:06,820 ahead and add some noise so let's add 15993 08:47:07,680 --> 08:47:08,680 basic multi-channel purlin so let's do 15994 08:47:10,080 --> 08:47:11,080 it just like we did when we first had 15995 08:47:11,398 --> 08:47:12,398 the thin machine so let's use the 15996 08:47:13,080 --> 08:47:14,080 handheld normal mild and now let's just 15997 08:47:15,180 --> 08:47:16,180 play around these films which by the way 15998 08:47:16,978 --> 08:47:17,978 you can do that while the game is 15999 08:47:18,058 --> 08:47:19,058 playing so let's hit on play and over 16000 08:47:19,978 --> 08:47:20,978 here you can play around down the fields 16001 08:47:21,660 --> 08:47:22,660 although actually defaults already look 16002 08:47:23,638 --> 08:47:24,638 pretty good but let's put the frequency 16003 08:47:25,200 --> 08:47:26,200 maybe a little bit less and the 16004 08:47:27,120 --> 08:47:28,120 amplitude maybe a little bit bigger so 16005 08:47:29,580 --> 08:47:30,580 just some nice little Sway and by the 16006 08:47:31,920 --> 08:47:32,920 way if you make any changes to the send 16007 08:47:33,420 --> 08:47:34,420 machine virtual camera and now you stop 16008 08:47:35,398 --> 08:47:36,398 playing it will actually lose those 16009 08:47:36,898 --> 08:47:37,898 changes but over here on the virtual 16010 08:47:38,820 --> 08:47:39,820 camera there's this nice toggle save 16011 08:47:40,320 --> 08:47:41,320 during play so if you tick this and now 16012 08:47:42,898 --> 08:47:43,898 you exit play mode and there you go 16013 08:47:45,120 --> 08:47:46,120 those changes were saved okay great now 16014 08:47:47,040 --> 08:47:48,040 let's just make sure to untick this so 16015 08:47:48,478 --> 08:47:49,478 we don't accidentally modify okay so 16016 08:47:50,580 --> 08:47:51,580 here we have the basic Vision that we 16017 08:47:52,260 --> 08:47:53,260 want finally there's also a game logo in 16018 08:47:54,718 --> 08:47:55,718 the included assets 16019 08:47:56,100 --> 08:47:57,100 so let's just go into our canvas into 16020 08:47:57,840 --> 08:47:58,840 our main menu let's create a brand new 16021 08:47:59,700 --> 08:48:00,700 UI image let's assign the logo Sprite 16022 08:48:03,478 --> 08:48:04,478 then let's just position it on that 16023 08:48:05,878 --> 08:48:06,878 corner so let's move it all the way up 16024 08:48:08,218 --> 08:48:09,218 there we can anchor it to the top left 16025 08:48:09,660 --> 08:48:10,660 corner and let's make it a bit bigger 16026 08:48:11,760 --> 08:48:12,760 and by the way I want something like 16027 08:48:13,440 --> 08:48:14,440 this if you play around this it might 16028 08:48:15,000 --> 08:48:16,000 get a bit scratched so if so over here 16029 08:48:17,280 --> 08:48:18,280 on the options on the image you can 16030 08:48:18,718 --> 08:48:19,718 download this one to preserve the aspect 16031 08:48:20,280 --> 08:48:21,280 ratio so that way even if you stretch it 16032 08:48:22,320 --> 08:48:23,320 won't actually be stretch it will always 16033 08:48:23,760 --> 08:48:24,760 be perfect okay just like this okay so 16034 08:48:26,638 --> 08:48:27,638 here we have our basic main menu it's a 16035 08:48:28,620 --> 08:48:29,620 basic setup but it looks pretty good and 16036 08:48:30,600 --> 08:48:31,600 with that we have built a nice main menu 16037 08:48:32,520 --> 08:48:33,520 alongside with the unloading system so I 16038 08:48:34,860 --> 08:48:35,860 can click on play it goes into the 16039 08:48:36,540 --> 08:48:37,540 loading scene and then into the game 16040 08:48:37,978 --> 08:48:38,978 scene so that's great 16041 08:48:39,478 --> 08:48:40,478 the next thing that we need is some kind 16042 08:48:41,160 --> 08:48:42,160 of pause button so let's do that in the 16043 08:48:43,020 --> 08:48:44,020 next lecture 16044 08:48:44,580 --> 08:48:45,580 hello and welcome I'm your code monkey 16045 08:48:46,580 --> 08:48:47,580 in this lecture we're going to add a 16046 08:48:48,780 --> 08:48:49,780 pause button with a pulse window that 16047 08:48:50,580 --> 08:48:51,580 also has the ability to quit back to the 16048 08:48:52,320 --> 08:48:53,320 main menu and in doing so we're also 16049 08:48:54,120 --> 08:48:55,120 going to solve some sneaky issues with 16050 08:48:55,680 --> 08:48:56,680 loading okay so here in the main menu we 16051 08:48:57,958 --> 08:48:58,958 can click the play button in order to 16052 08:48:59,520 --> 08:49:00,520 unload the game and yep everything works 16053 08:49:01,260 --> 08:49:02,260 now I'm in the game but now let's say I 16054 08:49:03,120 --> 08:49:04,120 want to pause the game for a bit or quit 16055 08:49:04,740 --> 08:49:05,740 back to the main menu right now there's 16056 08:49:06,120 --> 08:49:07,120 no way so let's do that let's go here 16057 08:49:08,340 --> 08:49:09,340 onto the game scene and first let's send 16058 08:49:10,378 --> 08:49:11,378 on the pause and for that we're actually 16059 08:49:12,120 --> 08:49:13,120 going to need some input so let's first 16060 08:49:14,700 --> 08:49:15,700 go inside our player input actions let's 16061 08:49:16,740 --> 08:49:17,740 open this and then over here let's make 16062 08:49:19,138 --> 08:49:20,138 a brand new action let's name it the 16063 08:49:21,420 --> 08:49:22,420 pause 16064 08:49:22,260 --> 08:49:23,260 for the action type let's go with button 16065 08:49:24,058 --> 08:49:25,058 okay and for the bindings over here 16066 08:49:25,740 --> 08:49:26,740 let's go with escape and actually if we 16067 08:49:28,020 --> 08:49:29,020 use the same method that we've been 16068 08:49:29,280 --> 08:49:30,280 using if we listen and press on Escape 16069 08:49:31,020 --> 08:49:32,020 nope doesn't work because Escape just 16070 08:49:33,000 --> 08:49:34,000 cancels it so instead we need to use a 16071 08:49:35,280 --> 08:49:36,280 search bar here Search for escape 16072 08:49:36,958 --> 08:49:37,958 keyboard just like this okay great now 16073 08:49:39,600 --> 08:49:40,600 again as always let's make sure to save 16074 08:49:41,340 --> 08:49:42,340 the asset and wait for the compilation 16075 08:49:43,260 --> 08:49:44,260 to happen there it is so now here on the 16076 08:49:46,320 --> 08:49:47,320 game input list let's listen to it and 16077 08:49:48,600 --> 08:49:49,600 fire the event as usual so go into the 16078 08:49:50,820 --> 08:49:51,820 player input actions the player action 16079 08:49:52,440 --> 08:49:53,440 map let's go into the pause action and 16080 08:49:55,978 --> 08:49:56,978 listen to the performed event 16081 08:49:58,080 --> 08:49:59,080 and when this happens let's fire off an 16082 08:50:00,058 --> 08:50:01,058 event so a public event event handler 16083 08:50:04,080 --> 08:50:05,080 let's go on pause action 16084 08:50:07,260 --> 08:50:08,260 and then down here we're simply going to 16085 08:50:09,180 --> 08:50:10,180 invoke this event 16086 08:50:15,000 --> 08:50:16,000 okay just like this now from listening 16087 08:50:17,520 --> 08:50:18,520 to it here's the question where does 16088 08:50:19,440 --> 08:50:20,440 that make more sense should we do it 16089 08:50:21,780 --> 08:50:22,780 over here on the player script or 16090 08:50:23,398 --> 08:50:24,398 perhaps over here on the kitchen game 16091 08:50:24,780 --> 08:50:25,780 manager I think over here on the game 16092 08:50:26,878 --> 08:50:27,878 manager makes more sense since a pause 16093 08:50:28,680 --> 08:50:29,680 is more related to the game itself 16094 08:50:30,058 --> 08:50:31,058 rather than a specific action by the 16095 08:50:31,740 --> 08:50:32,740 player so let's add it over here let's 16096 08:50:34,378 --> 08:50:35,378 first of all listen to the event so 16097 08:50:35,820 --> 08:50:36,820 let's see what private void start and on 16098 08:50:37,558 --> 08:50:38,558 start let's listen to it so let's go 16099 08:50:39,120 --> 08:50:40,120 into the game input and we didn't 16100 08:50:41,340 --> 08:50:42,340 actually make it a Singleton yet so 16101 08:50:42,840 --> 08:50:43,840 let's do that over here let's make a 16102 08:50:44,760 --> 08:50:45,760 public static game input 16103 08:50:47,398 --> 08:50:48,398 for the instance with a public yet and a 16104 08:50:50,760 --> 08:50:51,760 private set 16105 08:50:52,500 --> 08:50:53,500 then down here on the Wake let's set 16106 08:50:54,298 --> 08:50:55,298 instance equals this okay there's our 16107 08:50:56,160 --> 08:50:57,160 Singleton so now back in the kitchen 16108 08:50:57,958 --> 08:50:58,958 game manager what's going to be instance 16109 08:50:59,760 --> 08:51:00,760 and listen to the on pause action event 16110 08:51:02,940 --> 08:51:03,940 and again let's rename this to give it a 16111 08:51:05,638 --> 08:51:06,638 proper name 16112 08:51:07,080 --> 08:51:08,080 so the C game input on pause action okay 16113 08:51:09,958 --> 08:51:10,958 so here we have it when we have this 16114 08:51:12,298 --> 08:51:13,298 let's call some kind of pause game 16115 08:51:14,280 --> 08:51:15,280 function so let's define this let's go 16116 08:51:16,558 --> 08:51:17,558 to the end of the file here and over 16117 08:51:18,360 --> 08:51:19,360 here let's make that function 16118 08:51:20,100 --> 08:51:21,100 so a private void pause game and over 16119 08:51:22,318 --> 08:51:23,318 here we're going to pause the game now 16120 08:51:24,660 --> 08:51:25,660 for pausing doing this is actually 16121 08:51:26,040 --> 08:51:27,040 surprisingly easy 16122 08:51:27,420 --> 08:51:28,420 basically all of our logic is using time 16123 08:51:29,398 --> 08:51:30,398 dot on time for example over here on the 16124 08:51:31,920 --> 08:51:32,920 player script we have our movement speed 16125 08:51:33,780 --> 08:51:34,780 yep then we get the inputs and over here 16126 08:51:36,600 --> 08:51:37,600 on the handle movement function yep for 16127 08:51:38,638 --> 08:51:39,638 the movement distance we have move speed 16128 08:51:40,318 --> 08:51:41,318 multiplied by time.10 is done or another 16129 08:51:42,718 --> 08:51:43,718 use case over here on the stove counter 16130 08:51:44,700 --> 08:51:45,700 we've got a frying timer and how we 16131 08:51:46,500 --> 08:51:47,500 count it down again is the same thing 16132 08:51:48,000 --> 08:51:49,000 time dot double time well it turns out 16133 08:51:50,100 --> 08:51:51,100 that behind the scenes time to time the 16134 08:51:52,200 --> 08:51:53,200 time actually already has a multiplier 16135 08:51:54,120 --> 08:51:55,120 when you access this it is after that 16136 08:51:56,218 --> 08:51:57,218 multiplier calculation so over here on 16137 08:51:58,260 --> 08:51:59,260 the pause game function we can just go 16138 08:52:00,000 --> 08:52:01,000 into time and we can modify the time 16139 08:52:01,978 --> 08:52:02,978 scale this one is the multiplier so if 16140 08:52:04,860 --> 08:52:05,860 we just put this at 0f then that's it 16141 08:52:06,898 --> 08:52:07,898 this is going to pause all of the other 16142 08:52:08,398 --> 08:52:09,398 Delta times so let's test so here we are 16143 08:52:11,398 --> 08:52:12,398 pay attention to that in the countdown 16144 08:52:12,898 --> 08:52:13,898 timer and I press on escape and there 16145 08:52:14,458 --> 08:52:15,458 you go everything pauses the countdown 16146 08:52:16,558 --> 08:52:17,558 timer pauses over here the script pauses 16147 08:52:18,540 --> 08:52:19,540 and I can no longer move nothing works 16148 08:52:20,340 --> 08:52:21,340 everything is perfectly paused alright 16149 08:52:22,440 --> 08:52:23,440 Awesome everything works except one 16150 08:52:24,780 --> 08:52:25,780 problem obviously right now we cannot 16151 08:52:26,458 --> 08:52:27,458 unpause if I press Escape it's not in 16152 08:52:28,558 --> 08:52:29,558 pausing so let's do that over here on 16153 08:52:30,660 --> 08:52:31,660 the kitchen game manager let's add a 16154 08:52:32,280 --> 08:52:33,280 simple bone so a private bone let's come 16155 08:52:34,740 --> 08:52:35,740 with is game paused and let's see found 16156 08:52:37,080 --> 08:52:38,080 it to phones okay so is game paused and 16157 08:52:39,840 --> 08:52:40,840 then down here on the pause game 16158 08:52:40,978 --> 08:52:41,978 function let's simply flip this one so 16159 08:52:42,840 --> 08:52:43,840 we set this one equals not this one so 16160 08:52:44,638 --> 08:52:45,638 that is going to flip that Boolean and 16161 08:52:46,680 --> 08:52:47,680 then we check if the game is paused if 16162 08:52:48,600 --> 08:52:49,600 so set it to zero f and if not then 16163 08:52:51,478 --> 08:52:52,478 we're going to set the time.time scale 16164 08:52:53,398 --> 08:52:54,398 back into one F okay so now this should 16165 08:52:56,580 --> 08:52:57,580 pause and unpause so essentially rename 16166 08:52:58,860 --> 08:52:59,860 this function since this is no longer 16167 08:53:00,360 --> 08:53:01,360 just going to pause let's rename this to 16168 08:53:03,180 --> 08:53:04,180 toggle and pause game this is going to 16169 08:53:05,040 --> 08:53:06,040 pause and unpause 16170 08:53:06,540 --> 08:53:07,540 okay so let's test 16171 08:53:08,580 --> 08:53:09,580 okay so here we are everything is 16172 08:53:10,138 --> 08:53:11,138 running now I pause and there you go 16173 08:53:11,878 --> 08:53:12,878 everything freeze I cannot move the 16174 08:53:13,440 --> 08:53:14,440 arrow will stop the countdown to stop 16175 08:53:14,760 --> 08:53:15,760 when I press again and there you go nice 16176 08:53:16,558 --> 08:53:17,558 and redeemed all right great so all of 16177 08:53:19,378 --> 08:53:20,378 the logic is working perfectly the only 16178 08:53:21,180 --> 08:53:22,180 thing we need is we don't just see 16179 08:53:22,318 --> 08:53:23,318 visual and as usual let's separate the 16180 08:53:24,718 --> 08:53:25,718 logic from the visuals so let's go 16181 08:53:27,120 --> 08:53:28,120 inside the canvas let's go into the 16182 08:53:28,740 --> 08:53:29,740 scene View and inside the canvas let's 16183 08:53:30,840 --> 08:53:31,840 create an empty game object call it the 16184 08:53:33,240 --> 08:53:34,240 game pause UI then let's stretch to 16185 08:53:36,660 --> 08:53:37,660 occupy the entire screen so zero on 16186 08:53:38,818 --> 08:53:39,818 everything okay great now inside let's 16187 08:53:41,340 --> 08:53:42,340 first of all add a background so a new 16188 08:53:43,318 --> 08:53:44,318 image name this the background let's 16189 08:53:46,260 --> 08:53:47,260 once again stretch to occupy everything 16190 08:53:49,378 --> 08:53:50,378 and on the color let's put it in black 16191 08:53:51,660 --> 08:53:52,660 with just a little bit of alpha okay 16192 08:53:53,458 --> 08:53:54,458 just like that then let's add some text 16193 08:53:55,740 --> 08:53:56,740 so let's create a brand new UI text 16194 08:53:58,200 --> 08:53:59,200 let's name it pause text 16195 08:54:00,840 --> 08:54:01,840 and in here let's just say paused let's 16196 08:54:03,420 --> 08:54:04,420 just make it big so the width and height 16197 08:54:05,458 --> 08:54:06,458 both on zero let's disable wrapping Put 16198 08:54:08,580 --> 08:54:09,580 It Center down the middle and let's 16199 08:54:10,558 --> 08:54:11,558 increase the font size by quite a bit 16200 08:54:12,120 --> 08:54:13,120 and put it in bold and let's also change 16201 08:54:14,878 --> 08:54:15,878 the color maybe a nice yellow something 16202 08:54:16,920 --> 08:54:17,920 like this okay that looks pretty good 16203 08:54:19,740 --> 08:54:20,740 let's just lift it up by a little bit 16204 08:54:21,840 --> 08:54:22,840 now let's make a script to show this so 16205 08:54:25,318 --> 08:54:26,318 on the UI folder let's create a brand 16206 08:54:27,000 --> 08:54:28,000 new c-sharp script call this the game 16207 08:54:29,398 --> 08:54:30,398 pause UI let's attach it then open now 16208 08:54:33,000 --> 08:54:34,000 here let's do the usual thing so let's 16209 08:54:34,620 --> 08:54:35,620 make two show and hide functions so 16210 08:54:36,540 --> 08:54:37,540 private void show and then a private 16211 08:54:38,940 --> 08:54:39,940 void hide 16212 08:54:40,740 --> 08:54:41,740 so on the show game object set active 16213 08:54:43,020 --> 08:54:44,020 into true and on the hides set it into 16214 08:54:45,898 --> 08:54:46,898 false 16215 08:54:47,280 --> 08:54:48,280 okay that's it pretty simple now we need 16216 08:54:49,620 --> 08:54:50,620 to know when to show our hide these 16217 08:54:51,180 --> 08:54:52,180 functions so we're here on the kitchen 16218 08:54:53,040 --> 08:54:54,040 game manager let's make two events to do 16219 08:54:55,080 --> 08:54:56,080 that so let's go up here make a public 16220 08:54:57,360 --> 08:54:58,360 event event handler 16221 08:54:59,940 --> 08:55:00,940 and let's name this on game pause 16222 08:55:02,160 --> 08:55:03,160 another one for on game unpaused okay we 16223 08:55:06,360 --> 08:55:07,360 have both events then down here on the 16224 08:55:08,760 --> 08:55:09,760 toggle pause game if we have this one 16225 08:55:10,798 --> 08:55:11,798 time scale 0 that means we have pause so 16226 08:55:12,840 --> 08:55:13,840 let's invoke the on game pause this 16227 08:55:15,240 --> 08:55:16,240 eventar is not empty okay and on this 16228 08:55:17,458 --> 08:55:18,458 one let's trigger the other one so on 16229 08:55:19,440 --> 08:55:20,440 game unpause 16230 08:55:21,120 --> 08:55:22,120 okay we've got the two basic events now 16231 08:55:24,000 --> 08:55:25,000 back here on the game pause UI let's 16232 08:55:25,798 --> 08:55:26,798 listen to it and as usual let's do it on 16233 08:55:27,540 --> 08:55:28,540 start so private start let's go into the 16234 08:55:29,940 --> 08:55:30,940 kitchen game manager access the static 16235 08:55:31,740 --> 08:55:32,740 instance and let's listen to the on game 16236 08:55:34,138 --> 08:55:35,138 pause 16237 08:55:35,040 --> 08:55:36,040 and I'm going to listen to the other one 16238 08:55:37,080 --> 08:55:38,080 so the instance on game unpaused so 16239 08:55:39,540 --> 08:55:40,540 listen to both of them and as usual 16240 08:55:41,458 --> 08:55:42,458 let's write the clean codes and let's 16241 08:55:43,020 --> 08:55:44,020 rename this so kitchen game manager and 16242 08:55:46,740 --> 08:55:47,740 on this one the same thing 16243 08:55:48,540 --> 08:55:49,540 so also the kitchen game manager 16244 08:55:51,540 --> 08:55:52,540 okay we have both and when the game is 16245 08:55:54,420 --> 08:55:55,420 unpaused then we want to hide the pause 16246 08:55:56,218 --> 08:55:57,218 window and when the game is paused then 16247 08:55:58,260 --> 08:55:59,260 we want to show the pause window and 16248 08:56:00,180 --> 08:56:01,180 finally of course we want to hide it by 16249 08:56:01,860 --> 08:56:02,860 defaults over here on sart after we add 16250 08:56:03,898 --> 08:56:04,898 listeners let's just hide it okay so 16251 08:56:06,360 --> 08:56:07,360 that's it that should work so let's test 16252 08:56:08,700 --> 08:56:09,700 so here we are everything is running now 16253 08:56:10,680 --> 08:56:11,680 press the pause and there you go got a 16254 08:56:12,298 --> 08:56:13,298 nice pause window press again and there 16255 08:56:14,040 --> 08:56:15,040 you go everything resumes okay great so 16256 08:56:16,740 --> 08:56:17,740 the last thing that we want is just a 16257 08:56:18,360 --> 08:56:19,360 button over here to go back to the main 16258 08:56:19,920 --> 08:56:20,920 menu and let's also add a button to 16259 08:56:22,020 --> 08:56:23,020 resume without having to press the 16260 08:56:23,458 --> 08:56:24,458 hotkey so over here let's create a new 16261 08:56:25,978 --> 08:56:26,978 UI let's make it a button this is going 16262 08:56:28,620 --> 08:56:29,620 to be the main menu button now let's 16263 08:56:31,138 --> 08:56:32,138 make it quite a bit bigger okay width 16264 08:56:33,898 --> 08:56:34,898 and height of 30 and 80. let's put this 16265 08:56:36,360 --> 08:56:37,360 one quite a bit down there and inside 16266 08:56:38,580 --> 08:56:39,580 for the text this one is the main menu 16267 08:56:41,398 --> 08:56:42,398 let's put the color in White and the 16268 08:56:44,520 --> 08:56:45,520 background for the button let's put this 16269 08:56:46,680 --> 08:56:47,680 one in a dark gray and let's also just 16270 08:56:49,200 --> 08:56:50,200 for fun add a nice upline and let's also 16271 08:56:52,080 --> 08:56:53,080 add a shadow 16272 08:56:53,340 --> 08:56:54,340 for the outline let's put it on for 16273 08:56:55,200 --> 08:56:56,200 Alpha and let's put it on about 3 3 and 16274 08:56:58,440 --> 08:56:59,440 for the effect on the shadow 5 minus 16275 08:57:00,298 --> 08:57:01,298 five okay so that's a nice outline and 16276 08:57:02,700 --> 08:57:03,700 nice shadow 16277 08:57:03,718 --> 08:57:04,718 and then for the text itself let's put 16278 08:57:06,000 --> 08:57:07,000 it in bold and raise it by just a little 16279 08:57:08,218 --> 08:57:09,218 bit okay just like that looks pretty 16280 08:57:10,020 --> 08:57:11,020 good so this is the main menu button and 16281 08:57:13,080 --> 08:57:14,080 then let's also make so duplicate this 16282 08:57:14,940 --> 08:57:15,940 let's make this one rename it this is 16283 08:57:16,978 --> 08:57:17,978 the resume button 16284 08:57:18,718 --> 08:57:19,718 and inside on the text let's say resume 16285 08:57:21,058 --> 08:57:22,058 okay we have our two basic buttons so 16286 08:57:24,240 --> 08:57:25,240 let's handle them in the script so over 16287 08:57:26,100 --> 08:57:27,100 here let's add as usual a serialized 16288 08:57:28,020 --> 08:57:29,020 field private of type button so that's 16289 08:57:30,298 --> 08:57:31,298 inside Unity engine.ui so it's for the 16290 08:57:34,020 --> 08:57:35,020 resume button and then we're going to 16291 08:57:36,000 --> 08:57:37,000 have the main menu button 16292 08:57:39,420 --> 08:57:40,420 okay let's save the script and back in 16293 08:57:41,700 --> 08:57:42,700 the editor let's drag those references 16294 08:57:43,440 --> 08:57:44,440 so that's the main menu button and the 16295 08:57:45,840 --> 08:57:46,840 resume button okay so now for these 16296 08:57:48,058 --> 08:57:49,058 let's add the click action so let's do a 16297 08:57:50,218 --> 08:57:51,218 private awake and on the way go into the 16298 08:57:52,020 --> 08:57:53,020 resume button the on click and let's add 16299 08:57:54,180 --> 08:57:55,180 a listener so this is going to be our 16300 08:57:55,920 --> 08:57:56,920 listener 16301 08:57:57,120 --> 08:57:58,120 and same thing for a main menu button so 16302 08:57:59,878 --> 08:58:00,878 main menu now for the main menu this one 16303 08:58:02,160 --> 08:58:03,160 is super simple let's just go into the 16304 08:58:03,660 --> 08:58:04,660 loader and call the unload function and 16305 08:58:06,298 --> 08:58:07,298 we're going to download the main menu 16306 08:58:07,500 --> 08:58:08,500 scene 16307 08:58:08,398 --> 08:58:09,398 okay that's the main menu very simple 16308 08:58:10,558 --> 08:58:11,558 and for the resume this one is only 16309 08:58:12,840 --> 08:58:13,840 going to be clickable when the game is 16310 08:58:14,580 --> 08:58:15,580 paused so we can just trigger the same 16311 08:58:16,860 --> 08:58:17,860 function on the kitchen game manager to 16312 08:58:18,420 --> 08:58:19,420 toggle the pause so kitchen can manager 16313 08:58:20,940 --> 08:58:21,940 the instance and toggle the pause game 16314 08:58:23,540 --> 08:58:24,540 this one is actually private so let's go 16315 08:58:26,100 --> 08:58:27,100 to it and let's make this public so we 16316 08:58:28,440 --> 08:58:29,440 can count from there okay that's it 16317 08:58:30,360 --> 08:58:31,360 super simple Let's test okay so here we 16318 08:58:32,878 --> 08:58:33,878 are and let's pause the game and now if 16319 08:58:34,620 --> 08:58:35,620 I click on resume if there go it does 16320 08:58:36,718 --> 08:58:37,718 work everything resumes and now pause 16321 08:58:38,280 --> 08:58:39,280 again and now let's go back to the main 16322 08:58:40,138 --> 08:58:41,138 menu loading any up there you go back in 16323 08:58:42,600 --> 08:58:43,600 the main menu alright awesome so 16324 08:58:44,520 --> 08:58:45,520 everything works perfectly 16325 08:58:46,020 --> 08:58:47,020 however there's one sneaky issue here 16326 08:58:48,360 --> 08:58:49,360 you can already see the issue by seeing 16327 08:58:50,520 --> 08:58:51,520 that all of these animations are still 16328 08:58:51,958 --> 08:58:52,958 but let's click on play and notebook 16329 08:58:54,478 --> 08:58:55,478 that issue everything is still frozen I 16330 08:58:56,878 --> 08:58:57,878 cannot move the character and over there 16331 08:58:58,740 --> 08:58:59,740 the Shader that one is completely Frozen 16332 08:59:00,718 --> 08:59:01,718 so the times can only still set to zero 16333 08:59:03,240 --> 08:59:04,240 basically we need to manually reset it 16334 08:59:05,340 --> 08:59:06,340 and the simplest way to do this is 16335 08:59:07,200 --> 08:59:08,200 really just in the main menu 16336 08:59:08,940 --> 08:59:09,940 so we can go here on the main menu UI 16337 08:59:11,100 --> 08:59:12,100 and we can just use this as our reset 16338 08:59:13,020 --> 08:59:14,020 function so let's just go into time.time 16339 08:59:16,020 --> 08:59:17,020 scale and let's set this one back into 16340 08:59:18,420 --> 08:59:19,420 one F that's it that's the only change 16341 08:59:20,340 --> 08:59:21,340 Let's test so here we are let's pause 16342 08:59:22,740 --> 08:59:23,740 let's go back into the main menu 16343 08:59:24,718 --> 08:59:25,718 and we can see the animations are indeed 16344 08:59:26,760 --> 08:59:27,760 playing and if we go back into play and 16345 08:59:28,860 --> 08:59:29,860 if there you go everything works 16346 08:59:30,058 --> 08:59:31,058 perfectly we can pause and yep here we 16347 08:59:32,818 --> 08:59:33,818 do see one of the other two sneaky 16348 08:59:34,680 --> 08:59:35,680 issues left basically it has to do with 16349 08:59:36,898 --> 08:59:37,898 scene loading and cleanup so the first 16350 08:59:39,180 --> 08:59:40,180 one is on input 16351 08:59:40,978 --> 08:59:41,978 over here on the game input class we are 16352 08:59:43,378 --> 08:59:44,378 constructing our player input actions 16353 08:59:45,298 --> 08:59:46,298 and we are listening to these events and 16354 08:59:48,240 --> 08:59:49,240 technically this object the one where 16355 08:59:49,920 --> 08:59:50,920 the game input is attached this object 16356 08:59:51,898 --> 08:59:52,898 is going to be destroyed when the scene 16357 08:59:53,340 --> 08:59:54,340 changes 16358 08:59:54,420 --> 08:59:55,420 however this object that we're creating 16359 08:59:56,520 --> 08:59:57,520 this instance of player input actions 16360 08:59:58,798 --> 08:59:59,798 this one does not get destroyed 16361 09:00:00,600 --> 09:00:01,600 automatically so that is why when I went 16362 09:00:02,580 --> 09:00:03,580 into the pause menu again for the second 16363 09:00:04,680 --> 09:00:05,680 time over here we've got a missing 16364 09:00:06,840 --> 09:00:07,840 reference exception basically the player 16365 09:00:09,180 --> 09:00:10,180 input actions of the previous game is 16366 09:00:11,160 --> 09:00:12,160 trying to show the pause window also of 16367 09:00:12,958 --> 09:00:13,958 the previous game which has since been 16368 09:00:14,700 --> 09:00:15,700 destroyed so obviously we have a missing 16369 09:00:16,920 --> 09:00:17,920 reference exception because that object 16370 09:00:18,478 --> 09:00:19,478 no longer exists so in this case we have 16371 09:00:21,000 --> 09:00:22,000 two options to solve this one option is 16372 09:00:23,760 --> 09:00:24,760 we can just unsubscribe to these events 16373 09:00:25,620 --> 09:00:26,620 Unity mono behaviors have a really nice 16374 09:00:28,020 --> 09:00:29,020 combat called on destroying so over here 16375 09:00:30,240 --> 09:00:31,240 private void on Destroy so this is the 16376 09:00:32,398 --> 09:00:33,398 default one this one is called when the 16377 09:00:34,020 --> 09:00:35,020 mono behavior is destroyed 16378 09:00:36,120 --> 09:00:37,120 so we can go into this one and we can 16379 09:00:38,280 --> 09:00:39,280 manually unsubscribe and the way that 16380 09:00:40,378 --> 09:00:41,378 you unsubscribe is you just do minus 16381 09:00:42,360 --> 09:00:43,360 equals 16382 09:00:45,478 --> 09:00:46,478 so this would solve that problem because 16383 09:00:47,160 --> 09:00:48,160 when this object is destroyed it's going 16384 09:00:48,898 --> 09:00:49,898 to unsubscribe from those events so the 16385 09:00:50,760 --> 09:00:51,760 next time it will no longer trigger so 16386 09:00:52,798 --> 09:00:53,798 that would fix it however on the game 16387 09:00:54,958 --> 09:00:55,958 input class we are still creating a new 16388 09:00:57,240 --> 09:00:58,240 object of this type I'm not 100 sure how 16389 09:01:00,540 --> 09:01:01,540 the input system works in the background 16390 09:01:02,280 --> 09:01:03,280 so perhaps this object might say in 16391 09:01:04,200 --> 09:01:05,200 memory which is not good so another 16392 09:01:06,478 --> 09:01:07,478 approach we can do or perhaps in 16393 09:01:08,160 --> 09:01:09,160 combination with this is we can 16394 09:01:09,540 --> 09:01:10,540 unsubscribe and then we can properly 16395 09:01:11,398 --> 09:01:12,398 dispose of this object how we do that is 16396 09:01:14,040 --> 09:01:15,040 very simple let's just go into the 16397 09:01:16,260 --> 09:01:17,260 player input actions and we just call 16398 09:01:18,360 --> 09:01:19,360 the dispose function that's it 16399 09:01:21,180 --> 09:01:22,180 this should clean up that object and 16400 09:01:23,160 --> 09:01:24,160 free up any memory so let's test so here 16401 09:01:25,978 --> 09:01:26,978 in the game view let's pause let's go 16402 09:01:27,660 --> 09:01:28,660 back into the main menu now let's go 16403 09:01:29,818 --> 09:01:30,818 back into the main game and now if I hit 16404 09:01:31,920 --> 09:01:32,920 pause and if there you go we no longer 16405 09:01:33,660 --> 09:01:34,660 have any errors okay so that's good 16406 09:01:35,940 --> 09:01:36,940 however now we still have one more 16407 09:01:38,100 --> 09:01:39,100 potential issue and this one has to do 16408 09:01:40,318 --> 09:01:41,318 with Statics like I mentioned before 16409 09:01:42,420 --> 09:01:43,420 Statics belong to the class and not any 16410 09:01:44,638 --> 09:01:45,638 instance of that class so that means 16411 09:01:46,860 --> 09:01:47,860 that static films will not be destroyed 16412 09:01:48,780 --> 09:01:49,780 or reset when the scene changes in the 16413 09:01:51,058 --> 09:01:52,058 case of our unloader here where we have 16414 09:01:52,798 --> 09:01:53,798 a private static field this one the fact 16415 09:01:55,200 --> 09:01:56,200 that this one doesn't reset 16416 09:01:56,340 --> 09:01:57,340 automatically that was a good thing 16417 09:01:57,540 --> 09:01:58,540 that's what allowed this to make the 16418 09:01:58,920 --> 09:01:59,920 unloading system but in the case of 16419 09:02:01,080 --> 09:02:02,080 maybe static events that might not be as 16420 09:02:02,940 --> 09:02:03,940 good it might mean that we might be 16421 09:02:05,100 --> 09:02:06,100 keeping some state from the previous 16422 09:02:06,478 --> 09:02:07,478 game which might cause everything to 16423 09:02:08,340 --> 09:02:09,340 break so basically we have a similar 16424 09:02:10,500 --> 09:02:11,500 problem to what we had in the input 16425 09:02:12,000 --> 09:02:13,000 where some logic from the previous game 16426 09:02:14,160 --> 09:02:15,160 might be affecting the next game in all 16427 09:02:16,558 --> 09:02:17,558 the code that we wrote the main place 16428 09:02:18,000 --> 09:02:19,000 where we use Statics were in The 16429 09:02:19,680 --> 09:02:20,680 Singletons and these are going to be 16430 09:02:21,840 --> 09:02:22,840 cleared automatically when the 16431 09:02:23,100 --> 09:02:24,100 underlying instance object when that one 16432 09:02:24,840 --> 09:02:25,840 is destroying so these do not cause any 16433 09:02:27,180 --> 09:02:28,180 problems however for example over here 16434 09:02:29,638 --> 09:02:30,638 on the cutting counter we've got a 16435 09:02:31,620 --> 09:02:32,620 static event when the scene changes this 16436 09:02:34,200 --> 09:02:35,200 will not be cleared so this will still 16437 09:02:36,360 --> 09:02:37,360 have the same number of listeners we can 16438 09:02:38,638 --> 09:02:39,638 actually see how many listeners there 16439 09:02:40,080 --> 09:02:41,080 are by printing it so let's go down here 16440 09:02:41,940 --> 09:02:42,940 before we're invoking the event let's do 16441 09:02:44,458 --> 09:02:45,458 a debug download let's go inside the on 16442 09:02:46,740 --> 09:02:47,740 any cut event and over here we can get 16443 09:02:49,440 --> 09:02:50,440 the invocation list this one is a list 16444 09:02:52,138 --> 09:02:53,138 of all of the functions that are 16445 09:02:53,398 --> 09:02:54,398 listening to this event 16446 09:02:54,958 --> 09:02:55,958 and we can just print out the link to 16447 09:02:56,818 --> 09:02:57,818 see how many listeners are listening to 16448 09:02:58,620 --> 09:02:59,620 this event so let's see what this 16449 09:03:00,420 --> 09:03:01,420 returns okay so over here let's pick up 16450 09:03:03,000 --> 09:03:04,000 some cheese and slice it and if I'm 16451 09:03:04,740 --> 09:03:05,740 working the log yep there you go one 16452 09:03:06,360 --> 09:03:07,360 there's only one listener okay that's 16453 09:03:08,040 --> 09:03:09,040 correct 16454 09:03:09,000 --> 09:03:10,000 however now if I go back into the main 16455 09:03:11,280 --> 09:03:12,280 menu and now I go back and I play again 16456 09:03:14,160 --> 09:03:15,160 okay so let's play let's just wait for 16457 09:03:16,860 --> 09:03:17,860 the countdown and once the countdown 16458 09:03:19,080 --> 09:03:20,080 ends pick up some cheese go there slice 16459 09:03:20,760 --> 09:03:21,760 it and there you go there's the problem 16460 09:03:21,898 --> 09:03:22,898 now we have two listeners in this case 16461 09:03:24,298 --> 09:03:25,298 doesn't really cause an error because 16462 09:03:25,740 --> 09:03:26,740 the tune listeners they're just over 16463 09:03:27,780 --> 09:03:28,780 here on The Sound Manager so we are 16464 09:03:29,580 --> 09:03:30,580 subscribing to this event and we're 16465 09:03:31,138 --> 09:03:32,138 doing the cut and playing the cut object 16466 09:03:32,878 --> 09:03:33,878 however if here we do something with 16467 09:03:35,160 --> 09:03:36,160 this transform like for example let's 16468 09:03:37,378 --> 09:03:38,378 just do a debug download on this 16469 09:03:39,240 --> 09:03:40,240 transform that position if we do this 16470 09:03:41,760 --> 09:03:42,760 here let's go ahead on the first one 16471 09:03:44,040 --> 09:03:45,040 let's slice and okay that works let's go 16472 09:03:46,138 --> 09:03:47,138 back into the main menu now play again 16473 09:03:48,120 --> 09:03:49,120 now wait for the timer 16474 09:03:50,458 --> 09:03:51,458 pick up some cheese go there slice any 16475 09:03:52,440 --> 09:03:53,440 of that I go there we have our air that 16476 09:03:54,540 --> 09:03:55,540 is because we are now accessing The 16477 09:03:55,798 --> 09:03:56,798 Sound Manager transform and that one has 16478 09:03:57,478 --> 09:03:58,478 since been destroyed so if you do use 16479 09:03:59,638 --> 09:04:00,638 static events like this one here if you 16480 09:04:02,040 --> 09:04:03,040 do that always remember you need to 16481 09:04:03,780 --> 09:04:04,780 manually reset that state it won't 16482 09:04:05,878 --> 09:04:06,878 happen automatically on the scene load 16483 09:04:07,680 --> 09:04:08,680 and one way that I normally do it is 16484 09:04:09,540 --> 09:04:10,540 just make a class responsible for doing 16485 09:04:11,458 --> 09:04:12,458 that so let's go ahead and let's create 16486 09:04:13,558 --> 09:04:14,558 a brand new c-sharp class let's call 16487 09:04:15,898 --> 09:04:16,898 this the reset static data manager and 16488 09:04:19,200 --> 09:04:20,200 for this one we want this one to run 16489 09:04:20,878 --> 09:04:21,878 only on the main menu That's only where 16490 09:04:22,860 --> 09:04:23,860 we're going to reset things so let's go 16491 09:04:25,378 --> 09:04:26,378 inside the main menu scene let's go 16492 09:04:27,298 --> 09:04:28,298 there let's create a brand new empty 16493 09:04:29,280 --> 09:04:30,280 game object for the reset static data 16494 09:04:32,700 --> 09:04:33,700 manager let's reset transform just keep 16495 09:04:35,218 --> 09:04:36,218 things clean and let's attach that 16496 09:04:37,440 --> 09:04:38,440 script again it's very important that 16497 09:04:39,298 --> 09:04:40,298 this object only exists on the main menu 16498 09:04:41,040 --> 09:04:42,040 then over here we're basically just 16499 09:04:42,898 --> 09:04:43,898 going to go into any script and reset 16500 09:04:44,878 --> 09:04:45,878 any data so for that on all those 16501 09:04:46,798 --> 09:04:47,798 scripts let's make a function 16502 09:04:48,718 --> 09:04:49,718 so over here on the cutting counter 16503 09:04:50,340 --> 09:04:51,340 let's make a public static function 16504 09:04:52,378 --> 09:04:53,378 let's call this reset static data in 16505 09:04:56,040 --> 09:04:57,040 order to reset any listeners let's just 16506 09:04:57,898 --> 09:04:58,898 go into the on any cut and set it to 16507 09:04:59,700 --> 09:05:00,700 null that will clear all the listeners 16508 09:05:01,680 --> 09:05:02,680 so we just do this and then on this 16509 09:05:04,020 --> 09:05:05,020 script Let's see we practically awake 16510 09:05:05,878 --> 09:05:06,878 and on awake let's go into the cutting 16511 09:05:08,040 --> 09:05:09,040 counter under the class so not any 16512 09:05:10,440 --> 09:05:11,440 instance so we're going to access the 16513 09:05:11,878 --> 09:05:12,878 static and we're going to reset the 16514 09:05:13,740 --> 09:05:14,740 static data that will clear all the 16515 09:05:15,898 --> 09:05:16,898 listeners on The Cutting counter all we 16516 09:05:17,818 --> 09:05:18,818 need to do is make sure to do this on 16517 09:05:19,558 --> 09:05:20,558 every single static event that we have 16518 09:05:21,360 --> 09:05:22,360 so on The Sound Manager and by the way 16519 09:05:23,580 --> 09:05:24,580 here we can get rid of the testing code 16520 09:05:25,978 --> 09:05:26,978 here we can see all the static events 16521 09:05:28,440 --> 09:05:29,440 that we're using so we've got the 16522 09:05:29,638 --> 09:05:30,638 cutting counter then we've got the base 16523 09:05:30,840 --> 09:05:31,840 counter and trash counter so let's go 16524 09:05:32,940 --> 09:05:33,940 here on the base counter and paste the 16525 09:05:34,500 --> 09:05:35,500 exact same thing and reset this event 16526 09:05:36,478 --> 09:05:37,478 okay and now let's go into the trash 16527 09:05:38,760 --> 09:05:39,760 counter 16528 09:05:39,780 --> 09:05:40,780 so here on trash counter same thing 16529 09:05:41,398 --> 09:05:42,398 reset this event set them all into null 16530 09:05:44,218 --> 09:05:45,218 and by the way here we have a warning 16531 09:05:46,318 --> 09:05:47,318 that's because trash counter extends 16532 09:05:48,120 --> 09:05:49,120 base counter so basically this is 16533 09:05:49,378 --> 09:05:50,378 telling us that we are hiding another 16534 09:05:50,638 --> 09:05:51,638 function with the exact same name in 16535 09:05:52,798 --> 09:05:53,798 this case we do want to hide it so 16536 09:05:54,478 --> 09:05:55,478 what's actually make this new to make 16537 09:05:55,978 --> 09:05:56,978 sure that this one is a different one 16538 09:05:57,298 --> 09:05:58,298 just to avoid that warning and same 16539 09:06:00,120 --> 09:06:01,120 thing over here on the cutting counter 16540 09:06:01,620 --> 09:06:02,620 we also need to make a new okay so 16541 09:06:03,780 --> 09:06:04,780 that's it and now we just need to go 16542 09:06:05,878 --> 09:06:06,878 over here onto the reset static data 16543 09:06:07,558 --> 09:06:08,558 manager let's go into the base counter 16544 09:06:09,598 --> 09:06:10,598 and reset the static data go into the 16545 09:06:11,878 --> 09:06:12,878 trash counter and reset the static data 16546 09:06:13,980 --> 09:06:14,980 okay that should do it let's see so here 16547 09:06:16,378 --> 09:06:17,378 we are in the game let's pick it up and 16548 09:06:18,058 --> 09:06:19,058 slice it and yep we've got just one 16549 09:06:20,040 --> 09:06:21,040 listener that's good let's go back 16550 09:06:21,718 --> 09:06:22,718 outside back into the main menu let's 16551 09:06:23,878 --> 09:06:24,878 play once more and over here let's pick 16552 09:06:26,398 --> 09:06:27,398 it up again go there drop it and there 16553 09:06:28,078 --> 09:06:29,078 you go still just one listener because 16554 09:06:29,578 --> 09:06:30,578 we are now correctly eliminating all of 16555 09:06:31,438 --> 09:06:32,438 the previous listeners 16556 09:06:32,820 --> 09:06:33,820 so this is the one sneaky issue that you 16557 09:06:35,040 --> 09:06:36,040 must be careful with when it comes to 16558 09:06:36,540 --> 09:06:37,540 object Lifetime and Statics for static 16559 09:06:39,180 --> 09:06:40,180 Fields you need to remember that they 16560 09:06:40,680 --> 09:06:41,680 don't manually get cleaned up that's up 16561 09:06:42,480 --> 09:06:43,480 to you so that's something you have to 16562 09:06:44,398 --> 09:06:45,398 keep in mind but you can also see how 16563 09:06:45,960 --> 09:06:46,960 easy it is to solve now that this is 16564 09:06:47,700 --> 09:06:48,700 solved let's just go into the cutting 16565 09:06:49,258 --> 09:06:50,258 counter and just get rid of our testing 16566 09:06:50,878 --> 09:06:51,878 log alright so with all of that all of 16567 09:06:52,980 --> 09:06:53,980 our scenes are working so we can start 16568 09:06:54,598 --> 09:06:55,598 from here from the main menu and go 16569 09:06:56,640 --> 09:06:57,640 straight into the game then here we are 16570 09:06:58,558 --> 09:06:59,558 in the game playing normally we can 16571 09:07:00,300 --> 09:07:01,300 pause the game at any point from the 16572 09:07:02,218 --> 09:07:03,218 pause screen we cannot resume or we can 16573 09:07:04,438 --> 09:07:05,438 go back into the main menu and from back 16574 09:07:06,718 --> 09:07:07,718 into the main menu we can once again 16575 09:07:08,218 --> 09:07:09,218 play the game from scratch and if there 16576 09:07:10,258 --> 09:07:11,258 you go everything works alright awesome 16577 09:07:13,320 --> 09:07:14,320 now the next thing that every game 16578 09:07:15,180 --> 09:07:16,180 requires is some options so let's do 16579 09:07:17,160 --> 09:07:18,160 that in the next lecture 16580 09:07:19,500 --> 09:07:20,500 hello and welcome I'm your code monkey 16581 09:07:21,438 --> 09:07:22,438 in this lecture we're going to create a 16582 09:07:23,758 --> 09:07:24,758 simple options menu where we can modify 16583 09:07:25,738 --> 09:07:26,738 the audio levels okay so here let's make 16584 09:07:28,140 --> 09:07:29,140 the options menu so on our game scene 16585 09:07:30,360 --> 09:07:31,360 let's go into the canvas and create a 16586 09:07:32,160 --> 09:07:33,160 new empty game object let's make this 16587 09:07:34,438 --> 09:07:35,438 the options UI let's stretch out this 16588 09:07:37,140 --> 09:07:38,140 one to occupy the entire screen 16589 09:07:39,180 --> 09:07:40,180 then inside let's make a UI image once 16590 09:07:42,480 --> 09:07:43,480 again let's stretch out everything 16591 09:07:45,180 --> 09:07:46,180 let's put this one in black in just 16592 09:07:48,540 --> 09:07:49,540 almost full Alpha okay now let's make 16593 09:07:50,878 --> 09:07:51,878 some texts so let's create a brand new 16594 09:07:52,860 --> 09:07:53,860 UI text call it the options text 16595 09:07:56,460 --> 09:07:57,460 then for text let's say just options 16596 09:07:58,820 --> 09:07:59,820 let's put the width and height at zero 16597 09:08:02,098 --> 09:08:03,098 let's disable wrapping Put It Center 16598 09:08:04,800 --> 09:08:05,800 down the middle and put it quite a lot 16599 09:08:07,140 --> 09:08:08,140 bigger 16600 09:08:08,398 --> 09:08:09,398 okay that's the options now just move it 16601 09:08:10,438 --> 09:08:11,438 slightly upwards all right now let's 16602 09:08:12,540 --> 09:08:13,540 make some simple buttons to handle our 16603 09:08:14,398 --> 09:08:15,398 audio controls we're going to make it 16604 09:08:16,258 --> 09:08:17,258 super simple literally just a button we 16605 09:08:18,122 --> 09:08:19,122 can click so inside the options UI let's 16606 09:08:20,520 --> 09:08:21,520 create a brand new button 16607 09:08:22,438 --> 09:08:23,438 call this the sound effects button then 16608 09:08:26,282 --> 09:08:27,282 let's make the button a bit bigger 16609 09:08:27,898 --> 09:08:28,898 something like this okay 16610 09:08:32,340 --> 09:08:33,340 and inside for the text let's say sound 16611 09:08:35,218 --> 09:08:36,218 effects and then we're going to have a 16612 09:08:36,960 --> 09:08:37,960 number for the sound effects let's just 16613 09:08:39,058 --> 09:08:40,058 quickly change the color so put the text 16614 09:08:41,098 --> 09:08:42,098 in White and the button over here the 16615 09:08:44,340 --> 09:08:45,340 button image let's put it in a dark ring 16616 09:08:46,860 --> 09:08:47,860 okay let's also make it just a tiny bit 16617 09:08:49,020 --> 09:08:50,020 thinner it's just like that okay so this 16618 09:08:51,058 --> 09:08:52,058 is the sound effects button now let's 16619 09:08:52,980 --> 09:08:53,980 duplicate this one this one is going to 16620 09:08:54,418 --> 09:08:55,418 be the music button so let's name this 16621 09:08:56,040 --> 09:08:57,040 the music button 16622 09:08:58,140 --> 09:08:59,140 then inside for the text music and then 16623 09:09:00,782 --> 09:09:01,782 a number 16624 09:09:01,918 --> 09:09:02,918 and that's pretty much it so by clicking 16625 09:09:04,500 --> 09:09:05,500 on either of these buttons we're going 16626 09:09:06,000 --> 09:09:07,000 to increase and then Loop the volume so 16627 09:09:08,282 --> 09:09:09,282 let's make a simple script to handle our 16628 09:09:10,258 --> 09:09:11,258 options window so in our scripts inside 16629 09:09:12,360 --> 09:09:13,360 the UI let's create a brand new c-sharp 16630 09:09:14,398 --> 09:09:15,398 script for the options UI let's go ahead 16631 09:09:17,700 --> 09:09:18,700 and attach a script and open 16632 09:09:19,918 --> 09:09:20,918 so here as usual let's get some films 16633 09:09:22,320 --> 09:09:23,320 for our buttons so a serialized film 16634 09:09:24,360 --> 09:09:25,360 private of type button for the sound 16635 09:09:27,782 --> 09:09:28,782 effects button and then there's another 16636 09:09:30,300 --> 09:09:31,300 one for the music button 16637 09:09:35,398 --> 09:09:36,398 okay both buttons now let's add the 16638 09:09:37,500 --> 09:09:38,500 click event so on private awake let's go 16639 09:09:39,540 --> 09:09:40,540 into the sound effects button and on the 16640 09:09:41,640 --> 09:09:42,640 on click let's add a listener 16641 09:09:45,058 --> 09:09:46,058 and we're going to do the same thing on 16642 09:09:46,860 --> 09:09:47,860 the music button 16643 09:09:48,660 --> 09:09:49,660 okay so now when we click we want to 16644 09:09:51,660 --> 09:09:52,660 change the volume so let's go here onto 16645 09:09:54,058 --> 09:09:55,058 The Sound Manager and make a function to 16646 09:09:55,860 --> 09:09:56,860 modify the volume 16647 09:09:57,660 --> 09:09:58,660 let's make a private void change volume 16648 09:10:03,000 --> 09:10:04,000 and here we're going to increase the 16649 09:10:04,500 --> 09:10:05,500 volume by 0.1 percent so constantly 16650 09:10:06,782 --> 09:10:07,782 increase in 10 increments so that means 16651 09:10:09,300 --> 09:10:10,300 we need to keep track of the volume so 16652 09:10:10,860 --> 09:10:11,860 up here in order to find a SIM phone 16653 09:10:12,480 --> 09:10:13,480 private float for the volume 16654 09:10:18,782 --> 09:10:19,782 well it's default it to one F okay so 16655 09:10:22,020 --> 09:10:23,020 now down here we take the volume and we 16656 09:10:24,418 --> 09:10:25,418 increase it by 0.1 F and now let's Loop 16657 09:10:27,300 --> 09:10:28,300 it back to zero 16658 09:10:28,622 --> 09:10:29,622 now for looping usually you do it using 16659 09:10:30,898 --> 09:10:31,898 the modular operator so here you could 16660 09:10:33,000 --> 09:10:34,000 do volume equals volume module of 1.1 f 16661 09:10:37,258 --> 09:10:38,258 that way when it gets to 1.1 f it would 16662 09:10:39,718 --> 09:10:40,718 reset back to zero but here since we're 16663 09:10:42,180 --> 09:10:43,180 working with floats which can have a bit 16664 09:10:44,160 --> 09:10:45,160 of odd Precision with this let's just do 16665 09:10:46,438 --> 09:10:47,438 a simple lift to make sure that always 16666 09:10:48,058 --> 09:10:49,058 works 16667 09:10:49,078 --> 09:10:50,078 so if the volume is above one f 16668 09:10:52,622 --> 09:10:53,622 if so then let's just reset it to zero 16669 09:10:55,020 --> 09:10:56,020 okay 16670 09:10:56,460 --> 09:10:57,460 so here we modified volume and let's 16671 09:10:58,258 --> 09:10:59,258 just make sure to use it over here when 16672 09:10:59,820 --> 09:11:00,820 we actually call the audio 16673 09:11:01,160 --> 09:11:02,160 source.playclip Point here we've got a 16674 09:11:03,598 --> 09:11:04,598 volume but this is the one that we 16675 09:11:04,800 --> 09:11:05,800 received as a parameter so let's 16676 09:11:06,960 --> 09:11:07,960 actually receive this one rename this to 16677 09:11:09,180 --> 09:11:10,180 volume multiplier 16678 09:11:11,398 --> 09:11:12,398 and we're going to basically multiply 16679 09:11:13,200 --> 09:11:14,200 the one that we receive in the parameter 16680 09:11:15,058 --> 09:11:16,058 by the one that we actually store 16681 09:11:17,460 --> 09:11:18,460 so this way on these functions when we 16682 09:11:19,500 --> 09:11:20,500 play a certain sound we can still give 16683 09:11:21,058 --> 09:11:22,058 an optional volume if we want to make it 16684 09:11:23,398 --> 09:11:24,398 louder or quieter then the regular sound 16685 09:11:25,438 --> 09:11:26,438 effects okay so we have our change 16686 09:11:27,598 --> 09:11:28,598 volume function now we just need to call 16687 09:11:29,820 --> 09:11:30,820 this from the options UI so that means 16688 09:11:31,558 --> 09:11:32,558 this one actually needs to be public 16689 09:11:32,820 --> 09:11:33,820 okay so now here on the options UI we go 16690 09:11:36,122 --> 09:11:37,122 into the sound manager access the 16691 09:11:37,738 --> 09:11:38,738 instance and call change volume okay so 16692 09:11:40,140 --> 09:11:41,140 that is going to change the volume then 16693 09:11:41,820 --> 09:11:42,820 we just need to update the values on the 16694 09:11:43,738 --> 09:11:44,738 options UI so let's make a proud void 16695 09:11:46,378 --> 09:11:47,378 update visual 16696 09:11:48,898 --> 09:11:49,898 and this one we need to update the text 16697 09:11:51,000 --> 09:11:52,000 so up here on let's add once again some 16698 09:11:53,098 --> 09:11:54,098 more serialized Fields so text mesh Pro 16699 09:11:56,218 --> 09:11:57,218 ugly one for the sound effects text and 16700 09:11:59,398 --> 09:12:00,398 another one for the music text 16701 09:12:02,098 --> 09:12:03,098 okay we have both these then here the 16702 09:12:04,622 --> 09:12:05,622 sound effects text not text 16703 09:12:07,200 --> 09:12:08,200 equals and we go into The Sound Manager 16704 09:12:09,360 --> 09:12:10,360 the instance 16705 09:12:13,078 --> 09:12:14,078 and then we need to get the volume 16706 09:12:15,360 --> 09:12:16,360 so over here on the sound management 16707 09:12:16,500 --> 09:12:17,500 let's make a function together so a 16708 09:12:18,180 --> 09:12:19,180 public float return get volume and we 16709 09:12:22,622 --> 09:12:23,622 just return the volume okay so then here 16710 09:12:25,378 --> 09:12:26,378 let's get volume except volume is going 16711 09:12:28,140 --> 09:12:29,140 to be a normalized value so rather than 16712 09:12:30,058 --> 09:12:31,058 showing 0.1.2.3 on the UI let's just 16713 09:12:34,258 --> 09:12:35,258 multiply the volume by 10f that way we 16714 09:12:37,200 --> 09:12:38,200 show between 1 and 10 okay then let's 16715 09:12:39,598 --> 09:12:40,598 just round out this number 16716 09:12:42,360 --> 09:12:43,360 and then add the text 16717 09:12:45,360 --> 09:12:46,360 so here's sound effects and then we have 16718 09:12:48,238 --> 09:12:49,238 the bone okay so that's pretty much it 16719 09:12:50,578 --> 09:12:51,578 and up here when we change the volume 16720 09:12:52,378 --> 09:12:53,378 let's just update the visual 16721 09:12:55,258 --> 09:12:56,258 and let's also make a private void start 16722 09:12:57,360 --> 09:12:58,360 and on start let's also update the video 16723 09:12:59,578 --> 09:13:00,578 okay that's it pretty simple now let's 16724 09:13:01,558 --> 09:13:02,558 do the exact same thing on the music 16725 09:13:03,258 --> 09:13:04,258 except on the Music Manager we named it 16726 09:13:06,360 --> 09:13:07,360 music manager but over here we just have 16727 09:13:07,980 --> 09:13:08,980 an audio Source there's no actual 16728 09:13:09,300 --> 09:13:10,300 manager so let's actually make one let's 16729 09:13:11,640 --> 09:13:12,640 create new c-sharp script for the Music 16730 09:13:14,040 --> 09:13:15,040 Manager let's go into the Music Manager 16731 09:13:17,160 --> 09:13:18,160 object let's attach a script and let's 16732 09:13:20,218 --> 09:13:21,218 open so here we really just need pretty 16733 09:13:22,800 --> 09:13:23,800 much exactly the same thing that we had 16734 09:13:24,238 --> 09:13:25,238 so let's just go here into The Sound 16735 09:13:26,160 --> 09:13:27,160 Manager and just copy these 16736 09:13:28,140 --> 09:13:29,140 so on the Music Manager let's paste them 16737 09:13:29,820 --> 09:13:30,820 we need a volume so a private mode for 16738 09:13:32,700 --> 09:13:33,700 the volume just like this okay so that 16739 09:13:34,800 --> 09:13:35,800 changes the volume except again the 16740 09:13:36,718 --> 09:13:37,718 Music Manager this one the music is 16741 09:13:38,520 --> 09:13:39,520 constantly going to be unlooping so 16742 09:13:40,438 --> 09:13:41,438 after we modify the volume we need to 16743 09:13:42,540 --> 09:13:43,540 update the actual audio source so let's 16744 09:13:44,460 --> 09:13:45,460 begin by grabbing the audio source audio 16745 09:13:47,700 --> 09:13:48,700 source and we just do a pro void awake 16746 09:13:50,520 --> 09:13:51,520 and on a week let's grab the audio 16747 09:13:52,020 --> 09:13:53,020 source 16748 09:13:53,398 --> 09:13:54,398 get the component of time Body Source 16749 09:13:55,438 --> 09:13:56,438 okay so we have this and when we change 16750 09:13:57,782 --> 09:13:58,782 the volume let's go here and update this 16751 09:13:59,820 --> 09:14:00,820 phone okay that's it and let's also 16752 09:14:01,980 --> 09:14:02,980 default it to some like 0.3f okay good 16753 09:14:04,738 --> 09:14:05,738 then in order to be able to call this 16754 09:14:06,480 --> 09:14:07,480 from the option Cy we just need to make 16755 09:14:08,098 --> 09:14:09,098 it a single turn so as usual public 16756 09:14:10,320 --> 09:14:11,320 static Music Manager for the instance 16757 09:14:12,300 --> 09:14:13,300 and we have a public get and a private 16758 09:14:15,238 --> 09:14:16,238 set 16759 09:14:16,378 --> 09:14:17,378 and then an awake just set instance 16760 09:14:18,540 --> 09:14:19,540 equals this okay 16761 09:14:20,340 --> 09:14:21,340 so then here on the options UI we can go 16762 09:14:22,558 --> 09:14:23,558 into the Music Manager the instance and 16763 09:14:24,898 --> 09:14:25,898 change the volume and afterwards let's 16764 09:14:26,758 --> 09:14:27,758 update the visual and down here on the 16765 09:14:28,918 --> 09:14:29,918 update visual lets you pretty much the 16766 09:14:30,960 --> 09:14:31,960 same thing so on the music text modify 16767 09:14:33,660 --> 09:14:34,660 the text to say music then we go into 16768 09:14:36,660 --> 09:14:37,660 the music manager and get the volume all 16769 09:14:39,540 --> 09:14:40,540 right that's it all this should be 16770 09:14:41,098 --> 09:14:42,098 working let's just drag our references 16771 09:14:42,718 --> 09:14:43,718 so back in the afternoon let's drag 16772 09:14:44,700 --> 09:14:45,700 firstly button so the sound effects 16773 09:14:46,500 --> 09:14:47,500 button that's this one then the music 16774 09:14:48,660 --> 09:14:49,660 button that's this one then we have the 16775 09:14:50,938 --> 09:14:51,938 music text that's this one and the sound 16776 09:14:53,040 --> 09:14:54,040 effects that's like that okay let's test 16777 09:14:55,918 --> 09:14:56,918 okay so here we are the music is playing 16778 09:14:58,200 --> 09:14:59,200 and as I click the music is currently 16779 09:15:00,058 --> 09:15:01,058 getting louder and louder 16780 09:15:01,738 --> 09:15:02,738 and their game I'm using is at max 16781 09:15:03,540 --> 09:15:04,540 volume and if I click again no the music 16782 09:15:05,578 --> 09:15:06,578 is completely muted alright awesome any 16783 09:15:07,860 --> 09:15:08,860 sound effects also work so like this 16784 09:15:09,598 --> 09:15:10,598 they should be less leather than usual 16785 09:15:11,700 --> 09:15:12,700 okay great so everything works perfectly 16786 09:15:13,980 --> 09:15:14,980 except obviously we have one big issue 16787 09:15:16,140 --> 09:15:17,140 the options window is on top of 16788 09:15:18,122 --> 09:15:19,122 everything 16789 09:15:19,020 --> 09:15:20,020 the goal is for the options window to be 16790 09:15:21,238 --> 09:15:22,238 kind of a sub menu of the pause window 16791 09:15:23,578 --> 09:15:24,578 we want to have an options button on the 16792 09:15:25,622 --> 09:15:26,622 pause window that won't bring up the 16793 09:15:27,180 --> 09:15:28,180 options window so let's do that let's 16794 09:15:29,820 --> 09:15:30,820 first hide the options window let's go 16795 09:15:31,680 --> 09:15:32,680 into the game pause UI and over here we 16796 09:15:34,140 --> 09:15:35,140 have these buttons let's just make one 16797 09:15:35,520 --> 09:15:36,520 more let's put it down the middle this 16798 09:15:37,738 --> 09:15:38,738 is going to be the options button 16799 09:15:40,020 --> 09:15:41,020 and inside let's modify the text to 16800 09:15:42,000 --> 09:15:43,000 options okay 16801 09:15:43,800 --> 09:15:44,800 now let's edit this script so we're 16802 09:15:46,078 --> 09:15:47,078 going to have another button so this is 16803 09:15:47,878 --> 09:15:48,878 the options button and down here we're 16804 09:15:50,398 --> 09:15:51,398 going to have another click so the 16805 09:15:51,960 --> 09:15:52,960 options button okay 16806 09:15:53,758 --> 09:15:54,758 and when this happens we want to just 16807 09:15:56,340 --> 09:15:57,340 show the options window so in order to 16808 09:15:58,738 --> 09:15:59,738 access it let's make this a Singleton so 16809 09:16:00,718 --> 09:16:01,718 public static for the options UI 16810 09:16:04,378 --> 09:16:05,378 a static instance 16811 09:16:08,878 --> 09:16:09,878 with a getting a private set 16812 09:16:11,340 --> 09:16:12,340 and on weak as usual instance equals 16813 09:16:13,980 --> 09:16:14,980 this 16814 09:16:14,938 --> 09:16:15,938 so over here on the game POS UI we go 16815 09:16:17,282 --> 09:16:18,282 into the options UI access the instance 16816 09:16:19,378 --> 09:16:20,378 and then call a show function so we need 16817 09:16:21,300 --> 09:16:22,300 to make this 16818 09:16:23,758 --> 09:16:24,758 so here on the options UI let's make 16819 09:16:25,738 --> 09:16:26,738 those so a public void show 16820 09:16:28,738 --> 09:16:29,738 and this one as usual just game objects 16821 09:16:31,140 --> 09:16:32,140 that active into true 16822 09:16:39,840 --> 09:16:40,840 and then we have a private hide 16823 09:16:42,660 --> 09:16:43,660 and this set active in two phones 16824 09:16:45,898 --> 09:16:46,898 okay we have both these on the other 16825 09:16:47,820 --> 09:16:48,820 side we show it and over here on start 16826 09:16:50,398 --> 09:16:51,398 let's also hide it okay 16827 09:16:53,218 --> 09:16:54,218 then let's also hide it manually so 16828 09:16:55,320 --> 09:16:56,320 let's add a button to close the options 16829 09:16:57,000 --> 09:16:58,000 UI so over here let's show the options 16830 09:16:59,578 --> 09:17:00,578 UI and let's make another button let's 16831 09:17:02,282 --> 09:17:03,282 put it on the bottom this one is the 16832 09:17:04,680 --> 09:17:05,680 close button 16833 09:17:05,938 --> 09:17:06,938 and over here let's just say close 16834 09:17:08,160 --> 09:17:09,160 so then here on the options UI just make 16835 09:17:10,320 --> 09:17:11,320 another button the close button and down 16836 09:17:12,898 --> 09:17:13,898 here for the click event 16837 09:17:16,200 --> 09:17:17,200 we go into the close button and we just 16838 09:17:18,660 --> 09:17:19,660 call height 16839 09:17:20,460 --> 09:17:21,460 okay so that won't hide the window 16840 09:17:22,218 --> 09:17:23,218 however remember that the pause window 16841 09:17:24,718 --> 09:17:25,718 can also be closed by just pressing 16842 09:17:26,398 --> 09:17:27,398 escape if we resume with the hotkey it 16843 09:17:29,578 --> 09:17:30,578 won't hide the pause window so let's 16844 09:17:31,320 --> 09:17:32,320 also make sure this one hides on the 16845 09:17:32,640 --> 09:17:33,640 same thing so we can do pretty much 16846 09:17:34,558 --> 09:17:35,558 going to the kitchen game manager the 16847 09:17:36,058 --> 09:17:37,058 instance and let's listen when the game 16848 09:17:37,980 --> 09:17:38,980 is unpaused so when that happens let's 16849 09:17:40,320 --> 09:17:41,320 hide this window 16850 09:17:41,820 --> 09:17:42,820 so once again let's do things nice and 16851 09:17:43,800 --> 09:17:44,800 clean let's rename this so the kitchen 16852 09:17:46,558 --> 09:17:47,558 game manager 16853 09:17:48,540 --> 09:17:49,540 and when this happens let's just hide 16854 09:17:50,640 --> 09:17:51,640 okay this should work let's just drag on 16855 09:17:53,340 --> 09:17:54,340 the references so first here on the 16856 09:17:55,200 --> 09:17:56,200 options UI let's drag the close button 16857 09:17:57,598 --> 09:17:58,598 and then on the game pause UI let's drag 16858 09:18:00,898 --> 09:18:01,898 the options button okay so let's test 16859 09:18:03,480 --> 09:18:04,480 and if right away the options window is 16860 09:18:05,758 --> 09:18:06,758 not showing the trade and if I press in 16861 09:18:07,378 --> 09:18:08,378 this game there you go there's the pause 16862 09:18:08,640 --> 09:18:09,640 window and if I can click on options if 16863 09:18:10,558 --> 09:18:11,558 there's the options window now if I can 16864 09:18:12,238 --> 09:18:13,238 go and close back here back into resume 16865 09:18:13,980 --> 09:18:14,980 okay works now if I pause options and 16866 09:18:17,218 --> 09:18:18,218 now press on the Escape key and you 16867 09:18:19,320 --> 09:18:20,320 better go closes everything all right 16868 09:18:21,122 --> 09:18:22,122 great so everything is working fine 16869 09:18:23,218 --> 09:18:24,218 however we have one slight issue 16870 09:18:27,540 --> 09:18:28,540 the option does work so I can modify 16871 09:18:30,122 --> 09:18:31,122 this to change the sound effects and 16872 09:18:31,558 --> 09:18:32,558 Music volume so for example let's mute 16873 09:18:34,200 --> 09:18:35,200 the music and put the sound effects on 16874 09:18:35,878 --> 09:18:36,878 five so I put it like this but now if I 16875 09:18:39,058 --> 09:18:40,058 stop playing and I hit play again 16876 09:18:42,180 --> 09:18:43,180 and working the options and oh there's 16877 09:18:44,460 --> 09:18:45,460 the issue basically that is back to the 16878 09:18:46,438 --> 09:18:47,438 default obviously that is resetting 16879 09:18:48,782 --> 09:18:49,782 since we didn't actually save anything 16880 09:18:50,160 --> 09:18:51,160 so let's save it now in unity the 16881 09:18:53,282 --> 09:18:54,282 easiest way to save some data is using 16882 09:18:55,078 --> 09:18:56,078 player prefs so let's go over here on 16883 09:18:57,718 --> 09:18:58,718 The Sound Manager and when we modify the 16884 09:19:00,058 --> 09:19:01,058 volume over here when we do that let's 16885 09:19:02,520 --> 09:19:03,520 access the Unity Player prefs and over 16886 09:19:05,160 --> 09:19:06,160 here we've got a bunch of set functions 16887 09:19:07,078 --> 09:19:08,078 so we can save a float an INT or a 16888 09:19:09,418 --> 09:19:10,418 string this one as you can see it takes 16889 09:19:11,398 --> 09:19:12,398 a string and a value so this is pretty 16890 09:19:14,098 --> 09:19:15,098 much essentially just a dictionary now 16891 09:19:16,560 --> 09:19:17,560 for the key as you can see it's a type 16892 09:19:18,060 --> 09:19:19,060 string but again we should not be using 16893 09:19:20,040 --> 09:19:21,040 strings directly 16894 09:19:21,300 --> 09:19:22,300 so let's go up here in order to make a 16895 09:19:23,340 --> 09:19:24,340 proper constant so a private con string 16896 09:19:25,680 --> 09:19:26,680 let's go with Pro layer 16897 09:19:27,980 --> 09:19:28,980 prefs sound effects volume 16898 09:19:32,460 --> 09:19:33,460 and let's go sound effects volume 16899 09:19:36,180 --> 09:19:37,180 okay we have our nice Center in content 16900 09:19:38,820 --> 09:19:39,820 and down here when we set the float 16901 09:19:40,740 --> 09:19:41,740 let's use this string and say the volume 16902 09:19:43,500 --> 09:19:44,500 okay so that is going to set the float 16903 09:19:45,960 --> 09:19:46,960 and now technically Unity is going to 16904 09:19:48,180 --> 09:19:49,180 automatically save the player perhaps 16905 09:19:49,800 --> 09:19:50,800 basically there are only problems if 16906 09:19:51,840 --> 09:19:52,840 Unity somehow crashes in between when 16907 09:19:54,240 --> 09:19:55,240 you can't set float and when it actually 16908 09:19:56,340 --> 09:19:57,340 saves but if you want to prevent that 16909 09:19:59,040 --> 09:20:00,040 from happening you can just go and tell 16910 09:20:00,900 --> 09:20:01,900 it to save manually just like that that 16911 09:20:03,596 --> 09:20:04,596 won't definitely save it and now we just 16912 09:20:05,700 --> 09:20:06,700 need to handle loading so here on awake 16913 09:20:08,580 --> 09:20:09,580 when we have this let's go into the play 16914 09:20:10,020 --> 09:20:11,020 prefs and let's use get float let's pass 16915 09:20:13,020 --> 09:20:14,020 in the same key so this one takes the 16916 09:20:15,480 --> 09:20:16,480 key and default value so let's default 16917 09:20:17,280 --> 09:20:18,280 it to one F basically the default value 16918 09:20:19,256 --> 09:20:20,256 is used if there's no save data on 16919 09:20:22,080 --> 09:20:23,080 display prefs on this key so the first 16920 09:20:24,360 --> 09:20:25,360 time we run it's actually going to use 16921 09:20:25,980 --> 09:20:26,980 this default and this one's going to 16922 09:20:28,020 --> 09:20:29,020 return these saved value so let's just 16923 09:20:29,400 --> 09:20:30,400 set it on the volume 16924 09:20:30,660 --> 09:20:31,660 okay so that's it that's only takes to 16925 09:20:32,936 --> 09:20:33,936 save some basic data now let's do the 16926 09:20:34,916 --> 09:20:35,916 exact same thing on music so over here 16927 09:20:37,080 --> 09:20:38,080 on the Music Manager let's first Define 16928 09:20:39,660 --> 09:20:40,660 our private con string for the player 16929 09:20:43,916 --> 09:20:44,916 pref's music volume 16930 09:20:46,560 --> 09:20:47,560 and this is going to be the music volume 16931 09:20:50,040 --> 09:20:51,040 okay we have our string and then down 16932 09:20:52,560 --> 09:20:53,560 here when you change the volume layer 16933 09:20:54,540 --> 09:20:55,540 press 16934 09:20:58,256 --> 09:20:59,256 and let's set the float on this key and 16935 09:21:01,560 --> 09:21:02,560 let's pass in the Music Volume okay and 16936 09:21:03,900 --> 09:21:04,900 then what's going to player prefs and 16937 09:21:05,820 --> 09:21:06,820 actually save it and now appear on the 16938 09:21:08,096 --> 09:21:09,096 wake 16939 09:21:08,880 --> 09:21:09,880 let's grab the volume 16940 09:21:11,460 --> 09:21:12,460 and it's going to be going to the player 16941 09:21:13,256 --> 09:21:14,256 prefs in order to get the float on this 16942 09:21:15,596 --> 09:21:16,596 key 16943 09:21:17,340 --> 09:21:18,340 and default value is 0.3f however over 16944 09:21:20,460 --> 09:21:21,460 here on the music again we are not 16945 09:21:21,840 --> 09:21:22,840 spawning the sound afterwards the sound 16946 09:21:24,416 --> 09:21:25,416 starts playing right away 16947 09:21:26,160 --> 09:21:27,160 so let's make sure to set the audio 16948 09:21:28,020 --> 09:21:29,020 Source volume to the one we grab from 16949 09:21:29,880 --> 09:21:30,880 there okay that's it so like this it 16950 09:21:32,400 --> 09:21:33,400 should be working so let's test so here 16951 09:21:35,040 --> 09:21:36,040 we are and the music is playing let's 16952 09:21:36,596 --> 09:21:37,596 pause go into the options let's bring 16953 09:21:39,180 --> 09:21:40,180 the music completely down so let's mute 16954 09:21:41,220 --> 09:21:42,220 the music okay the music is gone and 16955 09:21:43,020 --> 09:21:44,020 sound effects let's put a note 5. now 16956 09:21:45,416 --> 09:21:46,416 let's stop playing and now play again 16957 09:21:47,580 --> 09:21:48,580 and going to the menu options and if 16958 09:21:50,640 --> 09:21:51,640 there you go the data was indeed saved 16959 09:21:52,380 --> 09:21:53,380 and the music is indeed muted alright 16960 09:21:54,596 --> 09:21:55,596 awesome so here we have some basic data 16961 09:21:57,660 --> 09:21:58,660 being saved and also just quick note 16962 09:21:59,580 --> 09:22:00,580 related to saving for this simple game 16963 09:22:01,740 --> 09:22:02,740 decisions are pretty quick so I didn't 16964 09:22:03,480 --> 09:22:04,480 include any kind of save system for the 16965 09:22:05,340 --> 09:22:06,340 actual game data but if you want to know 16966 09:22:07,500 --> 09:22:08,500 how to do that I also have video 16967 09:22:08,820 --> 09:22:09,820 covering that topic okay so with that we 16968 09:22:11,460 --> 09:22:12,460 have our options window working the 16969 09:22:13,320 --> 09:22:14,320 volume sliders work perfectly the next 16970 09:22:15,780 --> 09:22:16,780 thing we need to add to our options is 16971 09:22:17,400 --> 09:22:18,400 some key rebinding so let's do that in 16972 09:22:19,800 --> 09:22:20,800 the next lecture 16973 09:22:21,360 --> 09:22:22,360 hello and welcome I'm your code monkey 16974 09:22:23,340 --> 09:22:24,340 in this lecture we're going to add key 16975 09:22:25,560 --> 09:22:26,560 rebinding to our options menu so here we 16976 09:22:28,320 --> 09:22:29,320 already have this nice options menu we 16977 09:22:30,240 --> 09:22:31,240 can modify the volume of the sound 16978 09:22:31,620 --> 09:22:32,620 effects or the music next let's handle 16979 09:22:33,900 --> 09:22:34,900 key rebinding okay so first let's build 16980 09:22:36,060 --> 09:22:37,060 the elements over here on the UI so 16981 09:22:38,276 --> 09:22:39,276 let's create a bunch more buttons but 16982 09:22:40,560 --> 09:22:41,560 before that let's actually make some 16983 09:22:41,756 --> 09:22:42,756 text on the side and buttons in the 16984 09:22:43,080 --> 09:22:44,080 middle so let's create a brand new UI 16985 09:22:45,720 --> 09:22:46,720 text 16986 09:22:46,620 --> 09:22:47,620 call this move of text 16987 09:22:49,020 --> 09:22:50,020 let's put it on the same size as the 16988 09:22:50,756 --> 09:22:51,756 other one so these got a font of 24 so 16989 09:22:52,740 --> 09:22:53,740 let's put it same thing font of 24 width 16990 09:22:55,320 --> 09:22:56,320 and height let's put both of these on 16991 09:22:57,120 --> 09:22:58,120 zero and down here anchor it to the left 16992 09:22:59,220 --> 09:23:00,220 okay down the middle and with no 16993 09:23:00,900 --> 09:23:01,900 wrapping okay so then over here this is 16994 09:23:03,416 --> 09:23:04,416 going to be the move up action 16995 09:23:05,756 --> 09:23:06,756 so we have move up then we have the move 16996 09:23:08,340 --> 09:23:09,340 down move left move right then we have 16997 09:23:11,276 --> 09:23:12,276 the interact the interact alternate and 16998 09:23:13,256 --> 09:23:14,256 finally the pause so these are all of 16999 09:23:15,480 --> 09:23:16,480 our actions so let's just make all of 17000 09:23:16,916 --> 09:23:17,916 these 17001 09:23:17,700 --> 09:23:18,700 so rename this so this one is the move 17002 09:23:19,800 --> 09:23:20,800 down 17003 09:23:20,820 --> 09:23:21,820 then this one over here is the move left 17004 09:23:23,360 --> 09:23:24,360 this one is the move right this one is 17005 09:23:27,416 --> 09:23:28,416 the interact text then the interact 17006 09:23:30,320 --> 09:23:31,320 alternate text and finally the pause 17007 09:23:33,596 --> 09:23:34,596 text now let's just modify the text on 17008 09:23:35,756 --> 09:23:36,756 these so that's the pause 17009 09:23:37,620 --> 09:23:38,620 that one is the indirect Alt 17010 09:23:40,680 --> 09:23:41,680 then this one is the interact then we've 17011 09:23:44,040 --> 09:23:45,040 got the move right 17012 09:23:46,140 --> 09:23:47,140 then over here the move left and finally 17013 09:23:49,500 --> 09:23:50,500 we have the move down 17014 09:23:51,900 --> 09:23:52,900 okay so those are our labels for our 17015 09:23:54,060 --> 09:23:55,060 controls now let's just make buttons 17016 09:23:56,040 --> 09:23:57,040 over here on the right side so let's 17017 09:23:57,300 --> 09:23:58,300 duplicate one of these buttons let's put 17018 09:23:59,340 --> 09:24:00,340 it over here and put it on something 17019 09:24:01,200 --> 09:24:02,200 like 50 by 50. so this is going to be 17020 09:24:04,200 --> 09:24:05,200 the move up button and inside on the 17021 09:24:07,256 --> 09:24:08,256 text this is going to be pretty much 17022 09:24:09,300 --> 09:24:10,300 just a w okay so we have the move up 17023 09:24:12,960 --> 09:24:13,960 then we're going to have the move down 17024 09:24:14,700 --> 09:24:15,700 move left move right the interact the 17025 09:24:19,380 --> 09:24:20,380 interact alternate and the pause 17026 09:24:21,660 --> 09:24:22,660 so we just need a bit more space so 17027 09:24:23,400 --> 09:24:24,400 let's move all of these up by quite a 17028 09:24:25,500 --> 09:24:26,500 bit let's also move the music and the 17029 09:24:28,320 --> 09:24:29,320 sound effects so move all of these like 17030 09:24:31,080 --> 09:24:32,080 that okay let's just name all these 17031 09:24:33,720 --> 09:24:34,720 buttons so this one 17032 09:24:35,756 --> 09:24:36,756 is the second one so this may move down 17033 09:24:38,880 --> 09:24:39,880 then over here the move left 17034 09:24:42,120 --> 09:24:43,120 then the move right then the interact 17035 09:24:45,900 --> 09:24:46,900 button the interact alternate button 17036 09:24:50,220 --> 09:24:51,220 and finally the pause button okay those 17037 09:24:53,756 --> 09:24:54,756 are on the buttons let's just position 17038 09:24:55,500 --> 09:24:56,500 all of the labels exactly where they 17039 09:24:57,660 --> 09:24:58,660 should be 17040 09:25:02,520 --> 09:25:03,520 okay so here we have all of the options 17041 09:25:04,680 --> 09:25:05,680 all of our bindings now in code let's 17042 09:25:06,776 --> 09:25:07,776 grab references to all the buttons and 17043 09:25:08,700 --> 09:25:09,700 all the text inside the buttons so here 17044 09:25:11,040 --> 09:25:12,040 inside the options URL let's add all of 17045 09:25:12,660 --> 09:25:13,660 those so first of all for the attacks 17046 09:25:15,060 --> 09:25:16,060 we're going to have the move of text 17047 09:25:16,980 --> 09:25:17,980 then the down left right and so on so 17048 09:25:19,200 --> 09:25:20,200 let you see all of these so down 17049 09:25:21,660 --> 09:25:22,660 then over here the left then the right 17050 09:25:24,120 --> 09:25:25,120 then the interact text the interact 17051 09:25:27,060 --> 09:25:28,060 alternate text and finally we have the 17052 09:25:30,360 --> 09:25:31,360 pause text 17053 09:25:31,436 --> 09:25:32,436 and for the buttons let's go up here 17054 09:25:33,596 --> 09:25:34,596 make all the buttons so they move up 17055 09:25:35,276 --> 09:25:36,276 button then they move down button 17056 09:25:40,140 --> 09:25:41,140 then we have the move left button then 17057 09:25:43,500 --> 09:25:44,500 the move right button then we have the 17058 09:25:46,200 --> 09:25:47,200 interact button the interact alternate 17059 09:25:48,360 --> 09:25:49,360 button 17060 09:25:49,436 --> 09:25:50,436 and finally the pause button 17061 09:25:52,140 --> 09:25:53,140 okay so we have all of these references 17062 09:25:55,020 --> 09:25:56,020 over here in the editor let's just drag 17063 09:25:56,756 --> 09:25:57,756 them so let's make sure we drag them on 17064 09:25:58,740 --> 09:25:59,740 correctly so let's do it one by one so 17065 09:26:01,200 --> 09:26:02,200 the move up this is the text and 17066 09:26:03,416 --> 09:26:04,416 actually it's not that one so that's 17067 09:26:04,620 --> 09:26:05,620 already a mistake right there we want 17068 09:26:06,000 --> 09:26:07,000 the text from inside buttons 17069 09:26:07,980 --> 09:26:08,980 so let's pick up all of these text 17070 09:26:09,660 --> 09:26:10,660 objects so let's go into the options so 17071 09:26:11,820 --> 09:26:12,820 text inside the move up let's grab that 17072 09:26:13,740 --> 09:26:14,740 one then inside the move down let's grab 17073 09:26:15,960 --> 09:26:16,960 that one and then left and so on so 17074 09:26:18,480 --> 09:26:19,480 definitely make sure you grab the right 17075 09:26:20,040 --> 09:26:21,040 ones okay that's on text now for the 17076 09:26:22,436 --> 09:26:23,436 button so let's move up button then you 17077 09:26:25,140 --> 09:26:26,140 move down 17078 09:26:26,160 --> 09:26:27,160 then they move left 17079 09:26:28,080 --> 09:26:29,080 the move right the interact interact 17080 09:26:32,040 --> 09:26:33,040 alternate and finally the pause button 17081 09:26:34,740 --> 09:26:35,740 okay great and just to verify that 17082 09:26:36,660 --> 09:26:37,660 everything is working let's give proper 17083 09:26:37,980 --> 09:26:38,980 names to these objects 17084 09:26:39,840 --> 09:26:40,840 so the move up button text 17085 09:26:48,540 --> 09:26:49,540 okay so I've renamed all the buttons so 17086 09:26:50,276 --> 09:26:51,276 now over here it's much easier to verify 17087 09:26:52,080 --> 09:26:53,080 that we have the correct references so 17088 09:26:54,000 --> 09:26:55,000 the sound sound music music and so on so 17089 09:26:56,220 --> 09:26:57,220 definitely make sure all of these are 17090 09:26:57,660 --> 09:26:58,660 correct otherwise you might go crazy 17091 09:26:59,096 --> 09:27:00,096 when things start to go a bit weird so 17092 09:27:01,256 --> 09:27:02,256 make sure these are all correct all 17093 09:27:02,640 --> 09:27:03,640 right now let's begin by updating the 17094 09:27:04,800 --> 09:27:05,800 text inside over here so let's go into 17095 09:27:07,140 --> 09:27:08,140 our update visual so we go into this set 17096 09:27:09,416 --> 09:27:10,416 the text and now we need to get the 17097 09:27:10,980 --> 09:27:11,980 binding text for this binding so for 17098 09:27:13,080 --> 09:27:14,080 that let's make that function on the 17099 09:27:14,520 --> 09:27:15,520 game input over here let's just comment 17100 09:27:16,680 --> 09:27:17,680 this out 17101 09:27:17,700 --> 09:27:18,700 then over here on the game input script 17102 09:27:19,740 --> 09:27:20,740 let's make a function to get the 17103 09:27:21,300 --> 09:27:22,300 bindings certainly we could make 17104 09:27:23,276 --> 09:27:24,276 something just to grab this player input 17105 09:27:24,900 --> 09:27:25,900 actions but again we don't want the 17106 09:27:26,880 --> 09:27:27,880 options UI to know what input system 17107 09:27:28,620 --> 09:27:29,620 we're using it should work regardless of 17108 09:27:31,140 --> 09:27:32,140 what input system 17109 09:27:32,756 --> 09:27:33,756 so we don't want the game input to 17110 09:27:34,680 --> 09:27:35,680 return anything of this type instead we 17111 09:27:36,776 --> 09:27:37,776 want to make a nice layer of abstraction 17112 09:27:38,400 --> 09:27:39,400 so for that let's make an enum to Define 17113 09:27:40,620 --> 09:27:41,620 all of our bindings so let's make a 17114 09:27:43,200 --> 09:27:44,200 public since we're going to access it 17115 09:27:44,640 --> 09:27:45,640 enum call it binding 17116 09:27:46,980 --> 09:27:47,980 and over here let's add all the bindings 17117 09:27:48,776 --> 09:27:49,776 so we've got the move up then we have 17118 09:27:51,480 --> 09:27:52,480 the move down the move left the move 17119 09:27:55,380 --> 09:27:56,380 right then we have the interact the 17120 09:27:58,560 --> 09:27:59,560 interact alternate 17121 09:28:00,720 --> 09:28:01,720 and finally the pause so these are all 17122 09:28:03,060 --> 09:28:04,060 of the bindings now let's make a 17123 09:28:04,980 --> 09:28:05,980 function to return the binding text 17124 09:28:07,140 --> 09:28:08,140 so over here let's make a public we're 17125 09:28:09,300 --> 09:28:10,300 going to return a string 17126 09:28:11,040 --> 09:28:12,040 let's just name it get binding text and 17127 09:28:13,620 --> 09:28:14,620 as a parameter let's receive a binding 17128 09:28:17,220 --> 09:28:18,220 okay so now here let's just do a switch 17129 09:28:19,500 --> 09:28:20,500 switch on this binding and basically 17130 09:28:22,200 --> 09:28:23,200 just match up the enum to whatever 17131 09:28:24,120 --> 09:28:25,120 action we have 17132 09:28:25,680 --> 09:28:26,680 so for example let's begin with the 17133 09:28:27,480 --> 09:28:28,480 interact since these are the simplest 17134 09:28:29,040 --> 09:28:30,040 ones 17135 09:28:30,180 --> 09:28:31,180 so for this one to get the bindings we 17136 09:28:32,820 --> 09:28:33,820 first go inside the player input actions 17137 09:28:35,160 --> 09:28:36,160 then let's go inside the player action 17138 09:28:37,080 --> 09:28:38,080 map then for the action so in this case 17139 09:28:39,300 --> 09:28:40,300 the interact and anything inside we've 17140 09:28:41,640 --> 09:28:42,640 got the bindings this is an array of all 17141 09:28:44,340 --> 09:28:45,340 of the bindings in our input map we 17142 09:28:46,740 --> 09:28:47,740 defined all of the keyboard bindings on 17143 09:28:48,416 --> 09:28:49,416 index 0. later on we're going to add 17144 09:28:50,460 --> 09:28:51,460 Gamepad bindings but for now we're going 17145 09:28:52,436 --> 09:28:53,436 to have the keyboard always on index 0. 17146 09:28:55,020 --> 09:28:56,020 so over here going to bindings axis on 17147 09:28:57,180 --> 09:28:58,180 zero and let's just do a two string 17148 09:28:59,880 --> 09:29:00,880 okay so let's just return this and let's 17149 09:29:02,640 --> 09:29:03,640 do a default to return always this one 17150 09:29:04,320 --> 09:29:05,320 just like this okay so let's do a quick 17151 09:29:06,596 --> 09:29:07,596 unlock to see what this returns so let's 17152 09:29:08,160 --> 09:29:09,160 do it over here on the game input just a 17153 09:29:10,436 --> 09:29:11,436 debug.log go into there get the binding 17154 09:29:12,900 --> 09:29:13,900 tags for the interact 17155 09:29:14,820 --> 09:29:15,820 okay so let's test and right away yep we 17156 09:29:17,580 --> 09:29:18,580 do see it working so the interact and 17157 09:29:19,980 --> 09:29:20,980 The Binding is on keyboard slash e but 17158 09:29:22,560 --> 09:29:23,560 we don't want all of this text we really 17159 09:29:24,180 --> 09:29:25,180 just want to see the E thankfully the 17160 09:29:26,340 --> 09:29:27,340 input system has a really great function 17161 09:29:28,080 --> 09:29:29,080 for just that so instead of calling the 17162 09:29:29,936 --> 09:29:30,936 general to string let's call to display 17163 09:29:32,276 --> 09:29:33,276 string let's see any of this one does 17164 09:29:35,276 --> 09:29:36,276 return just easy okay great so this is 17165 09:29:37,500 --> 09:29:38,500 the one that we want let's do the same 17166 09:29:39,300 --> 09:29:40,300 thing for all of the other simple 17167 09:29:40,740 --> 09:29:41,740 actions 17168 09:29:42,000 --> 09:29:43,000 so we've got the interact then we have 17169 09:29:44,220 --> 09:29:45,220 the interact alternate and we have the 17170 09:29:47,820 --> 09:29:48,820 pause so these are all the super simple 17171 09:29:49,380 --> 09:29:50,380 ones so just going to interact alternate 17172 09:29:51,840 --> 09:29:52,840 grab the binding on zero and for the 17173 09:29:54,000 --> 09:29:55,000 pause binding on zero okay so these are 17174 09:29:55,980 --> 09:29:56,980 all super simple now the more complex 17175 09:29:58,256 --> 09:29:59,256 one is the move it's more complex 17176 09:30:00,540 --> 09:30:01,540 because you can see all the others just 17177 09:30:02,096 --> 09:30:03,096 have one binding except for the move 17178 09:30:04,200 --> 09:30:05,200 over here we have a composite binding so 17179 09:30:06,960 --> 09:30:07,960 that's basically a binding which inside 17180 09:30:08,580 --> 09:30:09,580 has four separate bindings basically the 17181 09:30:10,980 --> 09:30:11,980 way that this works is that when you use 17182 09:30:12,416 --> 09:30:13,416 a composed binding all of these are 17183 09:30:13,860 --> 09:30:14,860 added to the array so this to the vector 17184 09:30:16,256 --> 09:30:17,256 is going to be on binding 0 then the up 17185 09:30:18,180 --> 09:30:19,180 is going to be on binding one two three 17186 09:30:19,980 --> 09:30:20,980 four and so on then the arrow keys this 17187 09:30:22,320 --> 09:30:23,320 one is going to be on five then we have 17188 09:30:25,256 --> 09:30:26,256 six seven eight nine and ten let's do a 17189 09:30:27,840 --> 09:30:28,840 log just to verify 17190 09:30:29,520 --> 09:30:30,520 so here if we do one for the move up 17191 09:30:32,820 --> 09:30:33,820 action for this one let's go into the 17192 09:30:35,096 --> 09:30:36,096 move and let's print out just the 17193 09:30:37,020 --> 09:30:38,020 binding zero let's do a regular two 17194 09:30:38,880 --> 09:30:39,880 string let's see what this returns so up 17195 09:30:41,520 --> 09:30:42,520 here let's just modify our log to say 17196 09:30:44,276 --> 09:30:45,276 the move up okay so let's see any up 17197 09:30:46,680 --> 09:30:47,680 index 0 does have the move to the vector 17198 09:30:48,776 --> 09:30:49,776 and now if we print the one on binding 17199 09:30:51,120 --> 09:30:52,120 of one yep now this one does have the 17200 09:30:53,400 --> 09:30:54,400 move on the w 17201 09:30:54,776 --> 09:30:55,776 so like I said we can see that all of 17202 09:30:56,820 --> 09:30:57,820 these Composites these are technically 17203 09:30:58,200 --> 09:30:59,200 inside that one but in terms of that 17204 09:31:00,300 --> 09:31:01,300 array it's just a flat array so this one 17205 09:31:02,460 --> 09:31:03,460 index 0 1 2 3 and 4. so that makes it 17206 09:31:05,820 --> 09:31:06,820 super simple to add over here so they 17207 09:31:08,220 --> 09:31:09,220 move up down left right 17208 09:31:10,200 --> 09:31:11,200 and let's just do all these 17209 09:31:13,800 --> 09:31:14,800 so we have all the bindings and over 17210 09:31:15,596 --> 09:31:16,596 here just one two three and four 17211 09:31:19,680 --> 09:31:20,680 and set a two string let's call the 17212 09:31:21,416 --> 09:31:22,416 display string okay so the binding text 17213 09:31:24,416 --> 09:31:25,416 this is all set up so let's go up here 17214 09:31:26,400 --> 09:31:27,400 and get rid of our testing code we can 17215 09:31:28,740 --> 09:31:29,740 now call this from the options UI so 17216 09:31:30,776 --> 09:31:31,776 over here let's do exam with that so 17217 09:31:32,220 --> 09:31:33,220 when we update the visual 17218 09:31:33,900 --> 09:31:34,900 let's go into the game and put let's 17219 09:31:36,180 --> 09:31:37,180 access the static instance let's get the 17220 09:31:38,400 --> 09:31:39,400 binding text and this one is going to do 17221 09:31:40,800 --> 09:31:41,800 the move up 17222 09:31:42,060 --> 09:31:43,060 so that's it this one is going to return 17223 09:31:43,680 --> 09:31:44,680 a string 17224 09:31:44,820 --> 09:31:45,820 let's write all of them 17225 09:31:52,740 --> 09:31:53,740 okay here are all of them so let's see 17226 09:31:54,720 --> 09:31:55,720 and if there they are all perfect don't 17227 09:31:57,060 --> 09:31:58,060 we SCD EF Escape okay great so the 17228 09:32:00,060 --> 09:32:01,060 visual is working now let's end on the 17229 09:32:01,800 --> 09:32:02,800 rebinding so let's add a click event 17230 09:32:04,256 --> 09:32:05,256 let's go into the move up button 17231 09:32:07,800 --> 09:32:08,800 let's go into the on click let's add in 17232 09:32:10,140 --> 09:32:11,140 listener and for the enlistener over 17233 09:32:12,660 --> 09:32:13,660 here let's make a function on the game 17234 09:32:14,220 --> 09:32:15,220 input to rebind this binding 17235 09:32:16,740 --> 09:32:17,740 so over here on the game input let's see 17236 09:32:19,020 --> 09:32:20,020 public void rebind binding and we 17237 09:32:22,256 --> 09:32:23,256 receive a binding 17238 09:32:25,200 --> 09:32:26,200 now for rebinding I cover this in detail 17239 09:32:27,960 --> 09:32:28,960 in the dedicated input system video 17240 09:32:29,640 --> 09:32:30,640 first basically we need to disable the 17241 09:32:31,980 --> 09:32:32,980 action map so let's go into the player 17242 09:32:33,596 --> 09:32:34,596 input actions let's access the player 17243 09:32:36,000 --> 09:32:37,000 and disable it so we need to do this 17244 09:32:37,620 --> 09:32:38,620 first then we're going to need to find 17245 09:32:39,300 --> 09:32:40,300 the action so player input actions and 17246 09:32:42,776 --> 09:32:43,776 for now let's go into the player and 17247 09:32:44,520 --> 09:32:45,520 let's just modify the move up action so 17248 09:32:47,220 --> 09:32:48,220 we're going to call the function perform 17249 09:32:48,840 --> 09:32:49,840 Interactive rebinding 17250 09:32:51,480 --> 09:32:52,480 this one as you can see takes a binding 17251 09:32:53,520 --> 09:32:54,520 index and if you remember up here we saw 17252 09:32:55,620 --> 09:32:56,620 that in order to modify the move up it's 17253 09:32:58,080 --> 09:32:59,080 on bindings index one so let's modify 17254 09:32:59,820 --> 09:33:00,820 the one on index one 17255 09:33:01,436 --> 09:33:02,436 okay so this is the function this 17256 09:33:04,200 --> 09:33:05,200 returns an object of this type a 17257 09:33:05,936 --> 09:33:06,936 rebinding operation this is a pretty 17258 09:33:08,756 --> 09:33:09,756 complex object where you can modify all 17259 09:33:10,680 --> 09:33:11,680 kinds of things add a bunch of 17260 09:33:12,060 --> 09:33:13,060 limitations and so on like for example 17261 09:33:14,276 --> 09:33:15,276 make a key not be able to be bound to 17262 09:33:15,960 --> 09:33:16,960 the mouse or something so there's tons 17263 09:33:18,180 --> 09:33:19,180 and tons of options you can play with 17264 09:33:19,500 --> 09:33:20,500 over here for the simple thing let's 17265 09:33:22,140 --> 09:33:23,140 just add an on complete listener so this 17266 09:33:24,720 --> 09:33:25,720 one takes in a convex and this will be 17267 09:33:26,756 --> 09:33:27,756 called whenever the interactive 17268 09:33:29,040 --> 09:33:30,040 rebinding completes 17269 09:33:30,840 --> 09:33:31,840 so over here on let's define and Lambda 17270 09:33:33,180 --> 09:33:34,180 so we come back and inside we have this 17271 09:33:35,640 --> 09:33:36,640 by the way over here this is the same 17272 09:33:37,200 --> 09:33:38,200 line of the expression that we saw 17273 09:33:38,400 --> 09:33:39,400 previously so exactly the same thing as 17274 09:33:40,680 --> 09:33:41,680 this except when we have just one 17275 09:33:42,540 --> 09:33:43,540 parenthesis we don't need to add them 17276 09:33:44,040 --> 09:33:45,040 okay so like this so then on this convex 17277 09:33:46,740 --> 09:33:47,740 we can see all kinds of things like for 17278 09:33:48,480 --> 09:33:49,480 example we can see the action that we 17279 09:33:50,040 --> 09:33:51,040 just rebound this is going to contain 17280 09:33:52,320 --> 09:33:53,320 all the data on the rebind operation so 17281 09:33:54,960 --> 09:33:55,960 for example let's print out the path so 17282 09:33:56,756 --> 09:33:57,756 let's go into the action 17283 09:33:58,560 --> 09:33:59,560 let's go into the bindings 17284 09:34:00,660 --> 09:34:01,660 on index 1 and let's print out the path 17285 09:34:03,720 --> 09:34:04,720 similar to a debug.log 17286 09:34:09,660 --> 09:34:10,660 and there's actually another one so 17287 09:34:11,756 --> 09:34:12,756 let's log the path and also the override 17288 09:34:14,340 --> 09:34:15,340 path these are two different things 17289 09:34:16,080 --> 09:34:17,080 let's see why in a bit we do this and 17290 09:34:18,180 --> 09:34:19,180 after we log we also need to rename on 17291 09:34:20,160 --> 09:34:21,160 the player action map so let's go into 17292 09:34:21,596 --> 09:34:22,596 the player input actions deep layer and 17293 09:34:24,360 --> 09:34:25,360 back enable this okay so we're only 17294 09:34:26,880 --> 09:34:27,880 going to need these settings on the 17295 09:34:28,436 --> 09:34:29,436 rewind action then we can just call 17296 09:34:30,540 --> 09:34:31,540 start in order to start the rebinding 17297 09:34:32,340 --> 09:34:33,340 process okay so this should work let's 17298 09:34:34,916 --> 09:34:35,916 just call this from the options UI so 17299 09:34:36,776 --> 09:34:37,776 over here we have the click let's go 17300 09:34:38,756 --> 09:34:39,756 into game input instance and let's 17301 09:34:41,756 --> 09:34:42,756 rebind The Binding and for this one is 17302 09:34:43,916 --> 09:34:44,916 the move up 17303 09:34:46,256 --> 09:34:47,256 okay with this let's test okay so here 17304 09:34:49,380 --> 09:34:50,380 if I click on the button and I click on 17305 09:34:51,360 --> 09:34:52,360 the T key and if there go it did work so 17306 09:34:54,120 --> 09:34:55,120 you can see that it print out the 17307 09:34:55,620 --> 09:34:56,620 regular path that is w and the override 17308 09:34:57,960 --> 09:34:58,960 path which is C so now if I exit out of 17309 09:35:01,256 --> 09:35:02,256 the options go back into the game if I 17310 09:35:03,300 --> 09:35:04,300 press W nope it does not move but if I 17311 09:35:05,276 --> 09:35:06,276 press T yep it does move upwards okay 17312 09:35:08,276 --> 09:35:09,276 great so we have successfully rebound 17313 09:35:10,860 --> 09:35:11,860 this one key now here just one thing in 17314 09:35:14,220 --> 09:35:15,220 previous versions of the input system 17315 09:35:15,720 --> 09:35:16,720 when doing a rebind operation you need 17316 09:35:18,060 --> 09:35:19,060 to manually dispose of this comeback 17317 09:35:20,040 --> 09:35:21,040 otherwise it would throw a memory error 17318 09:35:22,256 --> 09:35:23,256 in the recent version that I'm using 17319 09:35:23,936 --> 09:35:24,936 here there's no error so it seems 17320 09:35:25,620 --> 09:35:26,620 perhaps it's no longer needed to dispose 17321 09:35:27,360 --> 09:35:28,360 of the compact manually but still 17322 09:35:29,096 --> 09:35:30,096 there's no harm doing it just in case 17323 09:35:30,660 --> 09:35:31,660 over here combat dot dispose 17324 09:35:33,180 --> 09:35:34,180 okay so with that the key rebinding is 17325 09:35:35,340 --> 09:35:36,340 working except we have two issues the 17326 09:35:37,680 --> 09:35:38,680 first one is that it's not very clear 17327 09:35:38,820 --> 09:35:39,820 that it's listening for an input and the 17328 09:35:41,160 --> 09:35:42,160 second one is that the text options also 17329 09:35:43,200 --> 09:35:44,200 does not update so it's on both those 17330 09:35:45,360 --> 09:35:46,360 first let's add a visual when waiting 17331 09:35:47,460 --> 09:35:48,460 for a key press so inside the game 17332 09:35:49,800 --> 09:35:50,800 options UI let's create an empty game 17333 09:35:51,300 --> 09:35:52,300 object call this the press to rebind 17334 09:35:54,900 --> 09:35:55,900 team 17335 09:35:56,096 --> 09:35:57,096 let's stretch it out so put it on zero 17336 09:35:58,560 --> 09:35:59,560 on everything okay then inside let's add 17337 09:36:01,980 --> 09:36:02,980 a UI image 17338 09:36:03,416 --> 09:36:04,416 let's put it in black and once again 17339 09:36:05,756 --> 09:36:06,756 let's stretch it out 17340 09:36:07,680 --> 09:36:08,680 okay now let's also add a simple text 17341 09:36:10,980 --> 09:36:11,980 and for text let's say press a key 17342 09:36:14,340 --> 09:36:15,340 to rebind as usual let's put the width 17343 09:36:17,460 --> 09:36:18,460 and height on zero put it in bold Center 17344 09:36:20,096 --> 09:36:21,096 down the middle with no wrapping and 17345 09:36:22,680 --> 09:36:23,680 increase the size by quite a bit okay so 17346 09:36:25,436 --> 09:36:26,436 that's our super basic window now in the 17347 09:36:27,240 --> 09:36:28,240 code we just want to show and hide this 17348 09:36:28,740 --> 09:36:29,740 so let's do that and let's actually 17349 09:36:30,360 --> 09:36:31,360 begin with this hidden by default so 17350 09:36:32,040 --> 09:36:33,040 let's disable this object so here on the 17351 09:36:34,860 --> 09:36:35,860 options UI let's add another serialized 17352 09:36:36,960 --> 09:36:37,960 film it's going to be a transform for 17353 09:36:39,720 --> 09:36:40,720 the press to rebind key transform 17354 09:36:45,000 --> 09:36:46,000 so you have this let's make two show and 17355 09:36:47,040 --> 09:36:48,040 hide functions 17356 09:36:49,500 --> 09:36:50,500 so we show press to rebind key 17357 09:36:53,520 --> 09:36:54,520 we just go into that one game objects 17358 09:36:55,860 --> 09:36:56,860 and active this one into true 17359 09:36:58,140 --> 09:36:59,140 and another one where we set it to 17360 09:36:59,756 --> 09:37:00,756 phones so just 17361 09:37:01,380 --> 09:37:02,380 hide and set it to false okay pretty 17362 09:37:03,960 --> 09:37:04,960 simple let's make sure to hide this over 17363 09:37:06,540 --> 09:37:07,540 here on our start okay just like that 17364 09:37:09,200 --> 09:37:10,200 and for showing let's show it when we 17365 09:37:12,060 --> 09:37:13,060 actually rebind an action so right in 17366 09:37:13,980 --> 09:37:14,980 here but since we're going to have tons 17367 09:37:16,020 --> 09:37:17,020 of listeners to these events let's 17368 09:37:17,520 --> 09:37:18,520 actually make a nice separate function 17369 09:37:19,080 --> 09:37:20,080 to handle all of the rebinding logic so 17370 09:37:21,720 --> 09:37:22,720 down here let's make a function rebind 17371 09:37:24,660 --> 09:37:25,660 binding 17372 09:37:26,400 --> 09:37:27,400 we receive a game input.binding 17373 09:37:31,320 --> 09:37:32,320 then first we show the press rewind key 17374 09:37:33,660 --> 09:37:34,660 and then let's go into game input access 17375 09:37:36,416 --> 09:37:37,416 the instance and time to rebind binding 17376 09:37:38,640 --> 09:37:39,640 and pass in the same binding 17377 09:37:40,500 --> 09:37:41,500 okay so we have this and now up here on 17378 09:37:42,900 --> 09:37:43,900 the button event let's just call in this 17379 09:37:44,820 --> 09:37:45,820 function okay very simple so this will 17380 09:37:47,936 --> 09:37:48,936 work for actually showing the window but 17381 09:37:50,520 --> 09:37:51,520 now we need to know when to hide it and 17382 09:37:52,620 --> 09:37:53,620 for that let's use something that we've 17383 09:37:54,060 --> 09:37:55,060 used a few times in this course but 17384 09:37:55,500 --> 09:37:56,500 never directly let's use a c-sharp 17385 09:37:57,660 --> 09:37:58,660 donate as usual I have a dedicated video 17386 09:37:59,936 --> 09:38:00,936 on them this is basically how you can 17387 09:38:01,916 --> 09:38:02,916 define a field or a parameter of a type 17388 09:38:04,080 --> 09:38:05,080 which can hold a function it's another 17389 09:38:06,540 --> 09:38:07,540 Super useful CCR feature definitely 17390 09:38:08,880 --> 09:38:09,880 watch that video to learn all about it 17391 09:38:10,560 --> 09:38:11,560 let's go here on the game input and down 17392 09:38:13,860 --> 09:38:14,860 here when we have our rewind binding 17393 09:38:16,020 --> 09:38:17,020 over here let's receive a second 17394 09:38:17,936 --> 09:38:18,936 parameter this one is going to be of 17395 09:38:19,380 --> 09:38:20,380 type action this is one of the built-in 17396 09:38:21,776 --> 09:38:22,776 dongates it takes no parameters and 17397 09:38:23,820 --> 09:38:24,820 returns void so this one is perfect for 17398 09:38:26,040 --> 09:38:27,040 a simple comeback just like this one 17399 09:38:27,540 --> 09:38:28,540 let's go with on action rebound and 17400 09:38:30,480 --> 09:38:31,480 we're going to trigger this right here 17401 09:38:32,160 --> 09:38:33,160 after we achieve the convex so we get 17402 09:38:34,200 --> 09:38:35,200 the comeback let's trigger this just 17403 09:38:36,180 --> 09:38:37,180 like that and let's also get rid of 17404 09:38:38,040 --> 09:38:39,040 these testing logs we no longer need 17405 09:38:39,416 --> 09:38:40,416 them so just like this 17406 09:38:40,980 --> 09:38:41,980 now back here on the options UI so we've 17407 09:38:43,436 --> 09:38:44,436 got that and for the second parameter 17408 09:38:45,300 --> 09:38:46,300 let's just pass in the function to hide 17409 09:38:47,820 --> 09:38:48,820 that window so hi the press the rewind 17410 09:38:50,220 --> 09:38:51,220 key that's it again remember we're 17411 09:38:52,980 --> 09:38:53,980 passing in the function itself we're not 17412 09:38:54,900 --> 09:38:55,900 calling it so there's no parentheses 17413 09:38:56,936 --> 09:38:57,936 we're just passing in the function 17414 09:38:58,320 --> 09:38:59,320 itself okay so with this let's test so 17415 09:39:01,500 --> 09:39:02,500 here on the options let's rebind the 17416 09:39:03,120 --> 09:39:04,120 move W and there you go it does show up 17417 09:39:04,860 --> 09:39:05,860 to window and now if I press the key you 17418 09:39:06,480 --> 09:39:07,480 better go down hides okay great so this 17419 09:39:09,000 --> 09:39:10,000 is working but over here the text is 17420 09:39:10,560 --> 09:39:11,560 still not updating so over here on the 17421 09:39:12,720 --> 09:39:13,720 second comeback instead of just calling 17422 09:39:14,700 --> 09:39:15,700 this function we need to call this and 17423 09:39:16,740 --> 09:39:17,740 then also call the update visual 17424 09:39:18,120 --> 09:39:19,120 function so as usual let's use a simple 17425 09:39:20,340 --> 09:39:21,340 Lambda expression to do exactly both 17426 09:39:22,800 --> 09:39:23,800 so let's open and close the parentheses 17427 09:39:25,500 --> 09:39:26,500 and we do exactly this 17428 09:39:28,620 --> 09:39:29,620 so we hide the price of rebind and then 17429 09:39:30,480 --> 09:39:31,480 we update the visual okay that's it 17430 09:39:32,880 --> 09:39:33,880 let's test so here we are let's rewind 17431 09:39:34,916 --> 09:39:35,916 the move down we press on the T key and 17432 09:39:36,960 --> 09:39:37,960 there you go we did rebind and it did 17433 09:39:38,460 --> 09:39:39,460 update all right great now let's just 17434 09:39:41,220 --> 09:39:42,220 apply this to all of the other bindings 17435 09:39:42,900 --> 09:39:43,900 so first up here on the buttons let's 17436 09:39:45,240 --> 09:39:46,240 set listeners to all the buttons so 17437 09:39:47,756 --> 09:39:48,756 let's see move left 17438 09:39:49,380 --> 09:39:50,380 actually be moved down 17439 09:39:51,540 --> 09:39:52,540 then the move left move right the 17440 09:39:55,200 --> 09:39:56,200 interact button 17441 09:39:56,936 --> 09:39:57,936 the interact alternate button and 17442 09:39:59,580 --> 09:40:00,580 finally the pause button and for the 17443 09:40:01,980 --> 09:40:02,980 bindings this one is the fast binding 17444 09:40:03,720 --> 09:40:04,720 the interact alternate then the interact 17445 09:40:07,200 --> 09:40:08,200 then the move this one is the right 17446 09:40:10,436 --> 09:40:11,436 again make sure you don't make mistakes 17447 09:40:12,060 --> 09:40:13,060 here you call them the exact same one so 17448 09:40:14,276 --> 09:40:15,276 they move down okay so all of it is 17449 09:40:16,380 --> 09:40:17,380 correct here 17450 09:40:17,276 --> 09:40:18,276 and over here on the player input let's 17451 09:40:19,860 --> 09:40:20,860 do a switch on our binding 17452 09:40:30,540 --> 09:40:31,540 so Keys move up we do something and now 17453 09:40:33,120 --> 09:40:34,120 we could write this code directly up 17454 09:40:34,680 --> 09:40:35,680 here and then make a move down and write 17455 09:40:37,256 --> 09:40:38,256 a bunch more code that would work but 17456 09:40:38,936 --> 09:40:39,936 that would be way too worthy so let's 17457 09:40:40,980 --> 09:40:41,980 write our code in a nice clean way 17458 09:40:42,800 --> 09:40:43,800 basically the only thing we need down 17459 09:40:44,640 --> 09:40:45,640 here is we need to know the actual 17460 09:40:46,436 --> 09:40:47,436 action we're going to rebind and we need 17461 09:40:48,540 --> 09:40:49,540 to know the action index so let's just 17462 09:40:50,756 --> 09:40:51,756 find up here exactly that so an input 17463 09:40:52,860 --> 09:40:53,860 action for the input action 17464 09:40:54,840 --> 09:40:55,840 and then an end for the binding index 17465 09:40:57,180 --> 09:40:58,180 okay and then over here when we have the 17466 09:40:59,520 --> 09:41:00,520 switch for all of our bindings we just 17467 09:41:00,960 --> 09:41:01,960 set those so the input action in this 17468 09:41:03,416 --> 09:41:04,416 case it's going to be the player input 17469 09:41:05,580 --> 09:41:06,580 actions player and it's the move action 17470 09:41:08,276 --> 09:41:09,276 and for The Binding index 17471 09:41:10,916 --> 09:41:11,916 this one is on index one 17472 09:41:13,200 --> 09:41:14,200 then we're going to have the other moves 17473 09:41:14,936 --> 09:41:15,936 so they move down is going to be on 17474 09:41:17,580 --> 09:41:18,580 index 2. 17475 09:41:19,380 --> 09:41:20,380 then left and right 17476 09:41:25,256 --> 09:41:26,256 these are on index 3 and 4. okay so we 17477 09:41:28,620 --> 09:41:29,620 have all these and now for the other 17478 09:41:30,120 --> 09:41:31,120 ones 17479 09:41:31,020 --> 09:41:32,020 so for the interact this is the interact 17480 09:41:33,416 --> 09:41:34,416 action on binding zero then we've got 17481 09:41:36,000 --> 09:41:37,000 the interact alternate and the pause 17482 09:41:38,460 --> 09:41:39,460 so interact alternate and the pause 17483 09:41:42,120 --> 09:41:43,120 and this one is the pause action and the 17484 09:41:44,160 --> 09:41:45,160 interact alternate action and all of 17485 09:41:45,960 --> 09:41:46,960 them are on finding index of zero okay 17486 09:41:48,000 --> 09:41:49,000 so that's good so over here we are 17487 09:41:49,320 --> 09:41:50,320 assigning the input action and defining 17488 09:41:50,756 --> 09:41:51,756 index and also one thing we need to make 17489 09:41:52,860 --> 09:41:53,860 sure to always assign these values 17490 09:41:55,256 --> 09:41:56,256 so let's make sure to add a default here 17491 09:41:57,300 --> 09:41:58,300 just make sure it always works okay 17492 09:41:58,860 --> 09:41:59,860 great so now down here instead of always 17493 09:42:01,256 --> 09:42:02,256 accessing the move let's access whatever 17494 09:42:03,000 --> 09:42:04,000 is stored in the input action 17495 09:42:05,400 --> 09:42:06,400 and for The Binding whatever it is on 17496 09:42:07,320 --> 09:42:08,320 The Binding index okay so now this will 17497 09:42:09,596 --> 09:42:10,596 work with all of our bindings so here we 17498 09:42:11,880 --> 09:42:12,880 are and let's try rebinding all of them 17499 09:42:13,560 --> 09:42:14,560 so let's put them over here on the side 17500 09:42:15,060 --> 09:42:16,060 so before it move up let's put on T down 17501 09:42:17,580 --> 09:42:18,580 on G A on F then D on H for the interact 17502 09:42:22,320 --> 09:42:23,320 on y interact jumped on J and for the 17503 09:42:26,640 --> 09:42:27,640 Escape let's put it on E okay so all 17504 09:42:28,980 --> 09:42:29,980 these Keys have been rebound let's just 17505 09:42:30,540 --> 09:42:31,540 make sure they work so here I am moving 17506 09:42:32,640 --> 09:42:33,640 with these keys and yep it does work go 17507 09:42:34,500 --> 09:42:35,500 up here to interact and do the alt 17508 09:42:36,416 --> 09:42:37,416 interact and now the pause and if there 17509 09:42:38,520 --> 09:42:39,520 you go everything works perfectly 17510 09:42:39,776 --> 09:42:40,776 alright awesome so everything worked 17511 09:42:42,360 --> 09:42:43,360 perfectly although again we have the 17512 09:42:44,220 --> 09:42:45,220 same issue as previously so all the keys 17513 09:42:46,680 --> 09:42:47,680 have been rebound so it's not correct 17514 09:42:48,180 --> 09:42:49,180 right however now if I stop playing and 17515 09:42:51,120 --> 09:42:52,120 now if I play again 17516 09:42:52,740 --> 09:42:53,740 and nope there's the issue the rebinding 17517 09:42:54,840 --> 09:42:55,840 was lost so just like with the sound we 17518 09:42:57,596 --> 09:42:58,596 also need to save the new state now 17519 09:42:59,756 --> 09:43:00,756 thankfully the new input system has a 17520 09:43:01,560 --> 09:43:02,560 function that makes that super easy 17521 09:43:03,020 --> 09:43:04,020 let's go down to where we are rebinding 17522 09:43:05,820 --> 09:43:06,820 things and when we finish rebinding 17523 09:43:07,860 --> 09:43:08,860 let's just go into the player input 17524 09:43:09,300 --> 09:43:10,300 actions and let's call this function the 17525 09:43:12,180 --> 09:43:13,180 save bindings overrides as Json 17526 09:43:15,240 --> 09:43:16,240 this one is going to return a Json 17527 09:43:17,340 --> 09:43:18,340 string now if you don't know what is 17528 09:43:19,380 --> 09:43:20,380 Json go watch my quick video on it 17529 09:43:21,180 --> 09:43:22,180 basically it's a super easy to 17530 09:43:22,980 --> 09:43:23,980 understand and widely used file format 17531 09:43:25,020 --> 09:43:26,020 it's very easy to read and modify it's a 17532 09:43:28,140 --> 09:43:29,140 format where it's stored as just text so 17533 09:43:30,480 --> 09:43:31,480 let's look at what this says once we 17534 09:43:32,580 --> 09:43:33,580 debug down log over here after rebinding 17535 09:43:34,916 --> 09:43:35,916 something let's see so here if I rebind 17536 09:43:37,680 --> 09:43:38,680 one of these and if there you go there 17537 09:43:39,776 --> 09:43:40,776 we have our Json so the override 17538 09:43:41,880 --> 09:43:42,880 Bindings that overload the move on this 17539 09:43:44,160 --> 09:43:45,160 ID on this new path so basically we just 17540 09:43:46,680 --> 09:43:47,680 need to sort this string somewhere and 17541 09:43:48,660 --> 09:43:49,660 just like we did with the sound let's 17542 09:43:50,096 --> 09:43:51,096 just store it in the player prefs so 17543 09:43:52,320 --> 09:43:53,320 first let's define our constant so 17544 09:43:54,776 --> 09:43:55,776 private constring for the player prefs 17545 09:43:58,320 --> 09:43:59,320 bindings 17546 09:43:59,936 --> 09:44:00,936 and let's call this the input bindings 17547 09:44:04,140 --> 09:44:05,140 okay just like this 17548 09:44:07,200 --> 09:44:08,200 so then down here after we rebind the 17549 09:44:09,900 --> 09:44:10,900 king 17550 09:44:10,620 --> 09:44:11,620 let's go into player prefs and let's set 17551 09:44:13,436 --> 09:44:14,436 a string on the player prefs 17552 09:44:17,276 --> 09:44:18,276 bindings 17553 09:44:18,776 --> 09:44:19,776 and we're going to save the overrides as 17554 09:44:20,640 --> 09:44:21,640 Json 17555 09:44:23,096 --> 09:44:24,096 and after we do let's just make sure the 17556 09:44:24,840 --> 09:44:25,840 player perhaps is correctly saved okay 17557 09:44:26,580 --> 09:44:27,580 so that saves it then let's go on a way 17558 09:44:29,400 --> 09:44:30,400 to unload it so over here on awake let's 17559 09:44:31,860 --> 09:44:32,860 load that 17560 09:44:33,120 --> 09:44:34,120 let's first do a quick test to see if 17561 09:44:34,740 --> 09:44:35,740 there's a save so if the player prefs if 17562 09:44:38,460 --> 09:44:39,460 it has a king and if it has this key 17563 09:44:42,540 --> 09:44:43,540 if so then let's get it so the player 17564 09:44:45,060 --> 09:44:46,060 prefs let's get the string on this key 17565 09:44:48,240 --> 09:44:49,240 that returns this ring and we're going 17566 09:44:49,860 --> 09:44:50,860 to use the string let's just go into the 17567 09:44:51,416 --> 09:44:52,416 player input actions 17568 09:44:53,220 --> 09:44:54,220 and let's call the function load binding 17569 09:44:55,500 --> 09:44:56,500 overrides from Json just like this and 17570 09:44:58,080 --> 09:44:59,080 also let's make sure we do this right 17571 09:44:59,880 --> 09:45:00,880 after we construct the object and before 17572 09:45:01,800 --> 09:45:02,800 we enable the action map okay so that's 17573 09:45:04,256 --> 09:45:05,256 really it let's test so here we are 17574 09:45:06,720 --> 09:45:07,720 let's rebind the move up to T okay hit 17575 09:45:09,060 --> 09:45:10,060 rebound now stop playing now playing 17576 09:45:11,400 --> 09:45:12,400 again and you appeared is still rebound 17577 09:45:13,740 --> 09:45:14,740 to T alright awesome okay so here we 17578 09:45:16,980 --> 09:45:17,980 created a really nice options menu where 17579 09:45:19,080 --> 09:45:20,080 we can modify the volume and rebind keys 17580 09:45:21,416 --> 09:45:22,416 the only issue that we still have is 17581 09:45:23,220 --> 09:45:24,220 that we can only navigate the menus with 17582 09:45:25,020 --> 09:45:26,020 the mouse so let's add support for many 17583 09:45:27,120 --> 09:45:28,120 navigation with a controller in the next 17584 09:45:28,980 --> 09:45:29,980 lecture 17585 09:45:30,416 --> 09:45:31,416 hello and welcome I'm your code monkey 17586 09:45:32,400 --> 09:45:33,400 in this lecture we're going to set up 17587 09:45:34,436 --> 09:45:35,436 phone controller support for our game 17588 09:45:35,820 --> 09:45:36,820 including regular actions and menu 17589 09:45:38,040 --> 09:45:39,040 navigation okay so first let's just set 17590 09:45:40,500 --> 09:45:41,500 up the controller input I have an Xbox 17591 09:45:42,776 --> 09:45:43,776 impact controller connected so let's 17592 09:45:45,360 --> 09:45:46,360 open up our player input actions and 17593 09:45:47,520 --> 09:45:48,520 over here we have all of our actions and 17594 09:45:49,620 --> 09:45:50,620 we already made the move one a long time 17595 09:45:51,300 --> 09:45:52,300 ago so let's just add the bindings for 17596 09:45:53,460 --> 09:45:54,460 the other ones for example over here on 17597 09:45:55,020 --> 09:45:56,020 the interact let's add a brand new 17598 09:45:56,400 --> 09:45:57,400 binding let's go into the path and 17599 09:45:58,256 --> 09:45:59,256 listen and for interact I'm going to 17600 09:46:00,660 --> 09:46:01,660 press the A Button and again here you 17601 09:46:03,360 --> 09:46:04,360 can specify just the a button on Xbox 17602 09:46:05,160 --> 09:46:06,160 controller or you can use the generic 17603 09:46:07,080 --> 09:46:08,080 South button which will mean a on an 17604 09:46:09,060 --> 09:46:10,060 Xbox or cross on a PlayStation or B on a 17605 09:46:12,000 --> 09:46:13,000 switch or anything else so let's go with 17606 09:46:14,276 --> 09:46:15,276 the generic one for the internal 17607 09:46:16,320 --> 09:46:17,320 alternate let's add a binding and for 17608 09:46:18,180 --> 09:46:19,180 this one I'm going to put it on the X on 17609 09:46:19,860 --> 09:46:20,860 the Xbox so the button West 17610 09:46:21,900 --> 09:46:22,900 and for the pause let's add let's listen 17611 09:46:24,360 --> 09:46:25,360 and I'm going to press the menu which is 17612 09:46:26,340 --> 09:46:27,340 the start button okay so these are the 17613 09:46:28,740 --> 09:46:29,740 basic inputs let's make sure they work 17614 09:46:31,140 --> 09:46:32,140 and thanks to this new input system we 17615 09:46:33,480 --> 09:46:34,480 really don't need to modify any code 17616 09:46:34,916 --> 09:46:35,916 let's just save this asset 17617 09:46:37,200 --> 09:46:38,200 let's wait for the compilation and then 17618 09:46:39,120 --> 09:46:40,120 we can do a test so here we are and yep 17619 09:46:41,640 --> 09:46:42,640 I'm using my control to move now let's 17620 09:46:43,500 --> 09:46:44,500 just wait for the countdown 17621 09:46:45,000 --> 09:46:46,000 and go up there and pick up a cheese put 17622 09:46:47,640 --> 09:46:48,640 it and slice some cheese yep I can do 17623 09:46:49,916 --> 09:46:50,916 that pick up a plate and so on all right 17624 09:46:51,540 --> 09:46:52,540 so everything works let's also pause and 17625 09:46:53,520 --> 09:46:54,520 yep that also works okay great so 17626 09:46:55,680 --> 09:46:56,680 everything works except there are two 17627 09:46:57,900 --> 09:46:58,900 issues with the GamePad especially one 17628 09:47:00,300 --> 09:47:01,300 with the movement that I only noticed 17629 09:47:01,680 --> 09:47:02,680 just now the first issue that we have is 17630 09:47:04,080 --> 09:47:05,080 the dead zone right now we don't have 17631 09:47:05,700 --> 09:47:06,700 one so if I just lightly touch my 17632 09:47:08,220 --> 09:47:09,220 Gamepad joystick there you go it starts 17633 09:47:10,020 --> 09:47:11,020 moving automatically in Gamepad games 17634 09:47:12,000 --> 09:47:13,000 you should always have some kind of dead 17635 09:47:13,436 --> 09:47:14,436 zone to prevent any kind of joy-con 17636 09:47:15,120 --> 09:47:16,120 drift thankfully that is super easy to 17637 09:47:16,980 --> 09:47:17,980 Zone let's just go into the player input 17638 09:47:18,540 --> 09:47:19,540 action so let's go into the move find 17639 09:47:20,096 --> 09:47:21,096 the left stick binding 17640 09:47:21,840 --> 09:47:22,840 and over here for the processors let's 17641 09:47:23,880 --> 09:47:24,880 add one and let's add a stick dead zone 17642 09:47:25,800 --> 09:47:26,800 so that's it pretty simple this 17643 09:47:28,200 --> 09:47:29,200 basically considers that inputs under 17644 09:47:30,000 --> 09:47:31,000 this minimum to be zero and above this 17645 09:47:32,400 --> 09:47:33,400 maximum to be one so if you have 17646 09:47:34,500 --> 09:47:35,500 joystick drift where when the joystick 17647 09:47:36,840 --> 09:47:37,840 is Idle it's always moving by say 0.1 17648 09:47:39,000 --> 09:47:40,000 and direction this helps solve that 17649 09:47:41,040 --> 09:47:42,040 problem except in our case for a game 17650 09:47:42,960 --> 09:47:43,960 we're only using normalized inputs so 17651 09:47:45,240 --> 09:47:46,240 actually for our use case let's increase 17652 09:47:46,860 --> 09:47:47,860 the minimum by quite a bit I did some 17653 09:47:49,080 --> 09:47:50,080 testing in 0.5 Works quite great and the 17654 09:47:51,660 --> 09:47:52,660 max that default that is just fine okay 17655 09:47:54,000 --> 09:47:55,000 so that's it one problem solved let's 17656 09:47:56,160 --> 09:47:57,160 just go ahead save this Ascent now the 17657 09:47:58,380 --> 09:47:59,380 other bigger issue that we have is if I 17658 09:48:00,360 --> 09:48:01,360 approach a counter and I try and look at 17659 09:48:01,980 --> 09:48:02,980 it it's really difficult it tries moving 17660 09:48:04,380 --> 09:48:05,380 left and right instead of actually 17661 09:48:05,400 --> 09:48:06,400 facing the counter that's because the 17662 09:48:07,560 --> 09:48:08,560 logic that we added in a long time ago 17663 09:48:09,360 --> 09:48:10,360 that logic to help the character 17664 09:48:10,800 --> 09:48:11,800 controller feel better when moving on 17665 09:48:12,416 --> 09:48:13,416 diagonals against the counter 17666 09:48:14,400 --> 09:48:15,400 that works great for keyboard because 17667 09:48:16,140 --> 09:48:17,140 it's digital so it's either moving phone 17668 09:48:18,596 --> 09:48:19,596 and left probably right or on the 17669 09:48:19,980 --> 09:48:20,980 diagonals 17670 09:48:21,000 --> 09:48:22,000 but it messes up the control which is 17671 09:48:22,860 --> 09:48:23,860 analog on the player movement if we are 17672 09:48:25,020 --> 09:48:26,020 not moving perfectly up or perfectly 17673 09:48:26,520 --> 09:48:27,520 down then it's considered a diagonal and 17674 09:48:28,620 --> 09:48:29,620 on a Gamepad it's really difficult to 17675 09:48:30,120 --> 09:48:31,120 get a perfect just up or just down input 17676 09:48:32,340 --> 09:48:33,340 we're always going to have a tiny bit of 17677 09:48:34,140 --> 09:48:35,140 either left or right so that's the issue 17678 09:48:36,360 --> 09:48:37,360 that we have here and thankfully the 17679 09:48:38,040 --> 09:48:39,040 solution is actually pretty simple let's 17680 09:48:40,020 --> 09:48:41,020 go over here on to our player script and 17681 09:48:42,180 --> 09:48:43,180 let's scroll down into the handle 17682 09:48:43,800 --> 09:48:44,800 movement function okay 17683 09:48:45,180 --> 09:48:46,180 so we're doing a can move using the 17684 09:48:47,096 --> 09:48:48,096 regular move Direction and if it doesn't 17685 09:48:48,540 --> 09:48:49,540 work then it's over here that we are 17686 09:48:50,096 --> 09:48:51,096 attempting only the X movement or only 17687 09:48:51,840 --> 09:48:52,840 the Z movement and for doing that we 17688 09:48:54,180 --> 09:48:55,180 made it so we can move if there is 17689 09:48:56,096 --> 09:48:57,096 nothing only on the X and if we have any 17690 09:48:58,620 --> 09:48:59,620 movement at all on the X so if it is 17691 09:49:00,776 --> 09:49:01,776 different from zero basically the issue 17692 09:49:02,580 --> 09:49:03,580 here is if the move dear.x is let's say 17693 09:49:05,060 --> 09:49:06,060 0.001 that is still different from zero 17694 09:49:07,560 --> 09:49:08,560 so it is still going to trigger this 17695 09:49:08,880 --> 09:49:09,880 logic so basically let's just widen this 17696 09:49:11,040 --> 09:49:12,040 Gap instead of testing literally just 17697 09:49:13,140 --> 09:49:14,140 different from zero let's test if they 17698 09:49:15,240 --> 09:49:16,240 moved here.x if it is under say minus 17699 09:49:18,960 --> 09:49:19,960 0.5 F or if moved here dot X if it is 17700 09:49:22,800 --> 09:49:23,800 bigger than plus 0.5 f 17701 09:49:24,900 --> 09:49:25,900 so instead of being exactly just on zero 17702 09:49:27,180 --> 09:49:28,180 we're only going to consider diagonals 17703 09:49:28,916 --> 09:49:29,916 if we are at least moving 0.5 either 17704 09:49:30,840 --> 09:49:31,840 left or right so we just did this and 17705 09:49:33,000 --> 09:49:34,000 same thing over here except we just test 17706 09:49:34,740 --> 09:49:35,740 for this n so we moved here.z and they 17707 09:49:37,680 --> 09:49:38,680 move the other dot set okay so like this 17708 09:49:40,020 --> 09:49:41,020 it should feel much better on the 17709 09:49:41,340 --> 09:49:42,340 GamePad and still work exactly the same 17710 09:49:43,200 --> 09:49:44,200 on the keyboard so let's test 17711 09:49:45,120 --> 09:49:46,120 so here I am moving around and yep now 17712 09:49:47,220 --> 09:49:48,220 it is much easier to just stay around 17713 09:49:48,960 --> 09:49:49,960 and look straight at the counter okay so 17714 09:49:51,720 --> 09:49:52,720 that's great so I can pick up and this 17715 09:49:53,400 --> 09:49:54,400 is all much much easier and the 17716 09:49:55,020 --> 09:49:56,020 character is no longer just sliding left 17717 09:49:56,820 --> 09:49:57,820 and right Non-Stop okay that's great so 17718 09:50:00,060 --> 09:50:01,060 now that this is working let's set 17719 09:50:01,680 --> 09:50:02,680 support for rebinding our controller 17720 09:50:03,300 --> 09:50:04,300 bindings so over here on the game input 17721 09:50:05,640 --> 09:50:06,640 let's do it just like we did for the 17722 09:50:07,256 --> 09:50:08,256 keyboard so let's add a bunch more 17723 09:50:08,756 --> 09:50:09,756 bindings over here on the enum let's add 17724 09:50:10,860 --> 09:50:11,860 the GamePad interact then the GamePad 17725 09:50:13,340 --> 09:50:14,340 interact alternate and then the GamePad 17726 09:50:17,040 --> 09:50:18,040 pause 17727 09:50:18,360 --> 09:50:19,360 okay so we have our bindings then let's 17728 09:50:20,756 --> 09:50:21,756 go down and add them to both our 17729 09:50:22,140 --> 09:50:23,140 functions so of course the text and then 17730 09:50:23,700 --> 09:50:24,700 the bindings so we're here on the text 17731 09:50:25,680 --> 09:50:26,680 let's copy pretty much this we're going 17732 09:50:28,020 --> 09:50:29,020 to have the GamePad interact then we're 17733 09:50:30,900 --> 09:50:31,900 going to have the other two so the 17734 09:50:32,880 --> 09:50:33,880 GamePad tracked alternate and the 17735 09:50:34,860 --> 09:50:35,860 GamePad pause okay 17736 09:50:36,540 --> 09:50:37,540 now for these bindings we're going to 17737 09:50:38,460 --> 09:50:39,460 use the same actions so this one is the 17738 09:50:40,140 --> 09:50:41,140 interact alternate and over here we have 17739 09:50:42,060 --> 09:50:43,060 the interact and over here on the input 17740 09:50:44,160 --> 09:50:45,160 actions we saw that we added for all of 17741 09:50:45,960 --> 09:50:46,960 them on index 0 we have the keyboard and 17742 09:50:48,480 --> 09:50:49,480 on the next one we have all the gamepads 17743 09:50:50,580 --> 09:50:51,580 so over here that's literally don't 17744 09:50:52,200 --> 09:50:53,200 change for the GamePad let's go into 17745 09:50:54,300 --> 09:50:55,300 bindings and access the array on index 17746 09:50:56,276 --> 09:50:57,276 one 17747 09:50:57,120 --> 09:50:58,120 okay and then over here on the rebind 17748 09:50:59,520 --> 09:51:00,520 binding it's going to be pretty much the 17749 09:51:01,320 --> 09:51:02,320 exact same thing so let's copy all these 17750 09:51:03,000 --> 09:51:04,000 change this to the GamePad interact then 17751 09:51:06,480 --> 09:51:07,480 the GamePad interact alternate and then 17752 09:51:09,240 --> 09:51:10,240 the GamePad pause some of these all we 17753 09:51:12,416 --> 09:51:13,416 need to change is just by an index put 17754 09:51:14,340 --> 09:51:15,340 them all on one okay so with that all of 17755 09:51:16,980 --> 09:51:17,980 the code over here on the game input is 17756 09:51:18,416 --> 09:51:19,416 working perfectly now let's go over here 17757 09:51:20,340 --> 09:51:21,340 into our options UI so we've got all of 17758 09:51:22,860 --> 09:51:23,860 our buttons so let's duplicate our 17759 09:51:25,080 --> 09:51:26,080 buttons let's just go into the 17760 09:51:26,276 --> 09:51:27,276 interactive pause and so on let's 17761 09:51:27,596 --> 09:51:28,596 duplicate push them to the right side 17762 09:51:29,276 --> 09:51:30,276 okay 17763 09:51:30,596 --> 09:51:31,596 and just change the name so let's get 17764 09:51:32,820 --> 09:51:33,820 into all of them so this one's the game 17765 09:51:35,160 --> 09:51:36,160 pad interact button then the game pad 17766 09:51:38,936 --> 09:51:39,936 interact alternate and finally the 17767 09:51:40,860 --> 09:51:41,860 GamePad Parts okay 17768 09:51:42,480 --> 09:51:43,480 also inside let's also rename these 17769 09:51:44,820 --> 09:51:45,820 buttons just to make sure the text works 17770 09:51:46,436 --> 09:51:47,436 great 17771 09:51:49,256 --> 09:51:50,256 and let's also make sure that these show 17772 09:51:51,240 --> 09:51:52,240 up behind the press the rebound key so 17773 09:51:53,580 --> 09:51:54,580 let's drag them put them above okay so 17774 09:51:56,160 --> 09:51:57,160 that's our setup over here on the 17775 09:51:57,776 --> 09:51:58,776 options UI now let's go over here on the 17776 09:51:59,820 --> 09:52:00,820 options UI script and let's add 17777 09:52:01,620 --> 09:52:02,620 references to our buttons and to our 17778 09:52:03,120 --> 09:52:04,120 text objects 17779 09:52:04,380 --> 09:52:05,380 so let's copy all these the GamePad and 17780 09:52:07,980 --> 09:52:08,980 add all these this is the pause the 17781 09:52:09,900 --> 09:52:10,900 interact and the interact confident and 17782 09:52:12,360 --> 09:52:13,360 then down here the exact same thing 17783 09:52:14,700 --> 09:52:15,700 let's add all of these 17784 09:52:18,480 --> 09:52:19,480 okay like this now over here let's drag 17785 09:52:21,000 --> 09:52:22,000 all of our references so on the options 17786 09:52:22,800 --> 09:52:23,800 UI let's make sure to always write the 17787 09:52:25,080 --> 09:52:26,080 correct things so the GamePad interact 17788 09:52:27,840 --> 09:52:28,840 text the interact alternate text and the 17789 09:52:31,500 --> 09:52:32,500 pause button text and then the buttons 17790 09:52:33,720 --> 09:52:34,720 themselves so the pause button interact 17791 09:52:36,360 --> 09:52:37,360 alt and the interact button again make 17792 09:52:38,820 --> 09:52:39,820 sure you always drag the correct 17793 09:52:40,140 --> 09:52:41,140 references so check and double check 17794 09:52:41,700 --> 09:52:42,700 make sure everything is correct okay 17795 09:52:43,680 --> 09:52:44,680 then over here for our code let's first 17796 09:52:46,080 --> 09:52:47,080 handle the text over here 17797 09:52:48,840 --> 09:52:49,840 so the text for all these 17798 09:52:51,360 --> 09:52:52,360 so the GamePad interact text then the 17799 09:52:54,480 --> 09:52:55,480 GamePad interact alternate text and 17800 09:52:56,220 --> 09:52:57,220 finally the GamePad pause text and we 17801 09:52:58,740 --> 09:52:59,740 just go the game file pause the GamePad 17802 09:53:01,200 --> 09:53:02,200 interact alternate and the GamePad 17803 09:53:03,180 --> 09:53:04,180 interact finally over here on the 17804 09:53:05,580 --> 09:53:06,580 buttons let's do the exact same thing 17805 09:53:08,276 --> 09:53:09,276 so Gamepad interact interact alternate 17806 09:53:10,680 --> 09:53:11,680 and the pause 17807 09:53:14,880 --> 09:53:15,880 okay so we added everything let's do a 17808 09:53:17,880 --> 09:53:18,880 test and see if everything is working so 17809 09:53:19,740 --> 09:53:20,740 over here let's pause the game go into 17810 09:53:21,300 --> 09:53:22,300 the options and for the interact let's 17811 09:53:23,640 --> 09:53:24,640 modify this one instead of a and let's 17812 09:53:25,200 --> 09:53:26,200 put it on B and yeah there you go it did 17813 09:53:27,000 --> 09:53:28,000 go so let's close let's resume and now 17814 09:53:29,400 --> 09:53:30,400 let's see so if I approach and I press a 17815 09:53:31,256 --> 09:53:32,256 nothing happens Press B and there you go 17816 09:53:33,120 --> 09:53:34,120 it does interact okay awesome so the 17817 09:53:36,416 --> 09:53:37,416 rebinding is all working perfectly 17818 09:53:37,980 --> 09:53:38,980 except we have another obvious issue 17819 09:53:40,916 --> 09:53:41,916 I can pause with the GamePad however now 17820 09:53:43,436 --> 09:53:44,436 with this pause I cannot click on any of 17821 09:53:45,240 --> 09:53:46,240 those buttons and if I go back to the 17822 09:53:47,460 --> 09:53:48,460 main menu 17823 09:53:48,416 --> 09:53:49,416 over here I also cannot do anything with 17824 09:53:50,400 --> 09:53:51,400 a controller so at some of that the 17825 09:53:52,560 --> 09:53:53,560 first step is on the event system object 17826 09:53:54,596 --> 09:53:55,596 look at how it shows us this warning 17827 09:53:56,700 --> 09:53:57,700 basically if we're using the new input 17828 09:53:58,620 --> 09:53:59,620 system we should be using a different 17829 09:54:00,060 --> 09:54:01,060 input Handler here thankfully this is 17830 09:54:02,276 --> 09:54:03,276 super easy we just need to click on this 17831 09:54:04,020 --> 09:54:05,020 button and yep that's it it 17832 09:54:05,276 --> 09:54:06,276 automatically sets it up now the way 17833 09:54:07,200 --> 09:54:08,200 that this works is by pre-selecting 17834 09:54:09,300 --> 09:54:10,300 buttons in order to better see which 17835 09:54:11,756 --> 09:54:12,756 button is selected we should probably 17836 09:54:13,020 --> 09:54:14,020 add a more visible color let's go into 17837 09:54:15,540 --> 09:54:16,540 our pause window so for now let's hide 17838 09:54:17,880 --> 09:54:18,880 over here the options UI show the pause 17839 09:54:19,916 --> 09:54:20,916 window and we have these three buttons 17840 09:54:21,776 --> 09:54:22,776 let's select all of them 17841 09:54:23,580 --> 09:54:24,580 and over here on the right side on the 17842 09:54:25,436 --> 09:54:26,436 button we can see one option for the 17843 09:54:27,960 --> 09:54:28,960 selected color 17844 09:54:29,220 --> 09:54:30,220 so instead of being white which is going 17845 09:54:30,900 --> 09:54:31,900 to be really difficult to see let's put 17846 09:54:32,460 --> 09:54:33,460 something really visible so let's say 17847 09:54:33,900 --> 09:54:34,900 like a bright green okay like this 17848 09:54:37,380 --> 09:54:38,380 let's do the same thing for all of the 17849 09:54:39,060 --> 09:54:40,060 buttons on the options UI so let's show 17850 09:54:41,520 --> 09:54:42,520 this one and find all the buttons so 17851 09:54:44,220 --> 09:54:45,220 we've got all of these ones down here 17852 09:54:47,040 --> 09:54:48,040 and these three ones up here and let's 17853 09:54:49,256 --> 09:54:50,256 do the same thing so on the selected 17854 09:54:50,756 --> 09:54:51,756 let's put it all on my screen okay so 17855 09:54:53,400 --> 09:54:54,400 all the buttons have a nice selected 17856 09:54:55,020 --> 09:54:56,020 color and just like this if we test and 17857 09:54:57,900 --> 09:54:58,900 if I pause the game 17858 09:54:59,400 --> 09:55:00,400 and right now nothing is selected so 17859 09:55:01,560 --> 09:55:02,560 right now I cannot do anything with the 17860 09:55:03,120 --> 09:55:04,120 controller however if I press over here 17861 09:55:05,936 --> 09:55:06,936 with the mouse on this button and then 17862 09:55:07,740 --> 09:55:08,740 let go once outside the button yep look 17863 09:55:10,140 --> 09:55:11,140 at that now that button is selected so 17864 09:55:12,416 --> 09:55:13,416 now as long as that one is selected now 17865 09:55:13,916 --> 09:55:14,916 if I move with the mouse pad yep now I 17866 09:55:15,960 --> 09:55:16,960 can navigate through this menu and if I 17867 09:55:17,936 --> 09:55:18,936 press on a yep I can essentially click 17868 09:55:19,916 --> 09:55:20,916 that button so that's great basically 17869 09:55:22,020 --> 09:55:23,020 all we need is to make sure that we 17870 09:55:23,340 --> 09:55:24,340 select the button as soon as the pause 17871 09:55:24,840 --> 09:55:25,840 menu shows up so let's go over here on 17872 09:55:27,000 --> 09:55:28,000 the game pause UI script and then over 17873 09:55:29,160 --> 09:55:30,160 here let's go into the show function so 17874 09:55:30,960 --> 09:55:31,960 when we show this window when we do 17875 09:55:32,820 --> 09:55:33,820 let's go into the resume button and just 17876 09:55:34,500 --> 09:55:35,500 call the select function this will make 17877 09:55:36,360 --> 09:55:37,360 it selected so that's it and with this 17878 09:55:38,640 --> 09:55:39,640 if we test and now here with the game 17879 09:55:40,500 --> 09:55:41,500 playing if I pause whilst pressing the 17880 09:55:42,960 --> 09:55:43,960 button on the GamePad and if they go 17881 09:55:45,000 --> 09:55:46,000 down and selected and now I can select 17882 09:55:46,560 --> 09:55:47,560 any option okay that's great so now it 17883 09:55:49,380 --> 09:55:50,380 works fully with just the GamePad except 17884 09:55:51,840 --> 09:55:52,840 now if I go into options yep now you can 17885 09:55:54,480 --> 09:55:55,480 see that the button that is selected is 17886 09:55:55,860 --> 09:55:56,860 on the options one over there on the 17887 09:55:57,480 --> 09:55:58,480 background so let's also make sure to 17888 09:55:59,040 --> 09:56:00,040 select a button on the options as soon 17889 09:56:00,720 --> 09:56:01,720 as the options window shows up so over 17890 09:56:02,580 --> 09:56:03,580 here on the options UI let's go into our 17891 09:56:05,040 --> 09:56:06,040 show function 17892 09:56:06,360 --> 09:56:07,360 and let's just select the sound effects 17893 09:56:08,276 --> 09:56:09,276 button and just console it okay let's 17894 09:56:10,680 --> 09:56:11,680 test so here let's pause go into options 17895 09:56:13,500 --> 09:56:14,500 select any of the Lego that did work 17896 09:56:15,180 --> 09:56:16,180 okay great except we have another issue 17897 09:56:18,240 --> 09:56:19,240 as I move up or down over here on these 17898 09:56:21,060 --> 09:56:22,060 buttons you have a look at that some of 17899 09:56:23,220 --> 09:56:24,220 them are a bit strange like for example 17900 09:56:25,320 --> 09:56:26,320 over here on a I'm moving up and look at 17901 09:56:28,080 --> 09:56:29,080 that it actually selected the resume 17902 09:56:29,820 --> 09:56:30,820 button behind it so as we are moving up 17903 09:56:32,640 --> 09:56:33,640 or down we are actually selecting 17904 09:56:34,256 --> 09:56:35,256 buttons on both menus that's very 17905 09:56:36,720 --> 09:56:37,720 strange basically what is going on is 17906 09:56:39,060 --> 09:56:40,060 that since both windows are visible the 17907 09:56:40,860 --> 09:56:41,860 game is trying to guess which button we 17908 09:56:42,720 --> 09:56:43,720 want to select basically what is 17909 09:56:44,580 --> 09:56:45,580 happening is Unity is trying to use 17910 09:56:46,256 --> 09:56:47,256 automatic navigation if we select the 17911 09:56:48,776 --> 09:56:49,776 button so let's go for example let's 17912 09:56:50,700 --> 09:56:51,700 hide the options and show just the game 17913 09:56:54,060 --> 09:56:55,060 pause okay let's select one of these 17914 09:56:55,800 --> 09:56:56,800 buttons and over there on the button 17915 09:56:57,660 --> 09:56:58,660 component we can see navigation is set 17916 09:56:59,400 --> 09:57:00,400 to automatic and we have a button to 17917 09:57:01,320 --> 09:57:02,320 visualize and if we click on that yep 17918 09:57:03,596 --> 09:57:04,596 over here we can see all kinds of arrows 17919 09:57:05,460 --> 09:57:06,460 for example we we can see one over here 17920 09:57:07,680 --> 09:57:08,680 on the options that seems to be going to 17921 09:57:09,360 --> 09:57:10,360 some button in there that is going to be 17922 09:57:11,520 --> 09:57:12,520 the button that is showing over there so 17923 09:57:14,040 --> 09:57:15,040 if we move down from the options we're 17924 09:57:15,596 --> 09:57:16,596 going to end up over here on the 17925 09:57:16,860 --> 09:57:17,860 interact alt button now usually the 17926 09:57:19,380 --> 09:57:20,380 automatic navigation actually works very 17927 09:57:21,180 --> 09:57:22,180 well the only reason why we're having 17928 09:57:22,980 --> 09:57:23,980 problems is because we have both windows 17929 09:57:25,200 --> 09:57:26,200 active at once one solution to this is 17930 09:57:27,480 --> 09:57:28,480 to make the navigation explicit so let's 17931 09:57:29,880 --> 09:57:30,880 hide the options here and over here on 17932 09:57:31,560 --> 09:57:32,560 the resume on the navigation instead of 17933 09:57:33,776 --> 09:57:34,776 automatic let's put none and then let's 17934 09:57:36,060 --> 09:57:37,060 select explicit and if now we have our 17935 09:57:38,640 --> 09:57:39,640 own four Fields so we can decide which 17936 09:57:40,980 --> 09:57:41,980 object gets selected when we are here 17937 09:57:42,596 --> 09:57:43,596 and we move up down left or right so for 17938 09:57:45,060 --> 09:57:46,060 example here we would drag for the up 17939 09:57:46,980 --> 09:57:47,980 going up we could go into the main menu 17940 09:57:48,960 --> 09:57:49,960 so we will drag that button and going 17941 09:57:51,060 --> 09:57:52,060 down we could drag the options button so 17942 09:57:53,276 --> 09:57:54,276 that's one solution just add the 17943 09:57:55,200 --> 09:57:56,200 explicit navigation to every single 17944 09:57:56,756 --> 09:57:57,756 button or another simpler solution is 17945 09:57:59,400 --> 09:58:00,400 let's leave this one on automatic and it 17946 09:58:02,160 --> 09:58:03,160 said we're just going to hide the pause 17947 09:58:03,776 --> 09:58:04,776 window once we are in the options window 17948 09:58:05,640 --> 09:58:06,640 so over here on the game pause UI let's 17949 09:58:08,820 --> 09:58:09,820 see over here we are showing the options 17950 09:58:10,436 --> 09:58:11,436 you Ai and when we do let's just call 17951 09:58:12,480 --> 09:58:13,480 hide on this so we are going to hide 17952 09:58:14,880 --> 09:58:15,880 this window when we show the options and 17953 09:58:17,220 --> 09:58:18,220 then on the options we want to know when 17954 09:58:19,560 --> 09:58:20,560 the options closes so that we can show 17955 09:58:21,180 --> 09:58:22,180 this one again so over here on the show 17956 09:58:23,276 --> 09:58:24,276 function let's receive an action this is 17957 09:58:26,400 --> 09:58:27,400 what we're going to do when we close the 17958 09:58:28,020 --> 09:58:29,020 options let's call it on close button 17959 09:58:31,080 --> 09:58:32,080 action 17960 09:58:32,340 --> 09:58:33,340 and let's store it up here so let's 17961 09:58:34,916 --> 09:58:35,916 store 17962 09:58:36,060 --> 09:58:37,060 a simple and private action for this 17963 09:58:38,220 --> 09:58:39,220 okay so we have this and then down here 17964 09:58:40,800 --> 09:58:41,800 when we have our show function when we 17965 09:58:43,320 --> 09:58:44,320 have let's set this equals this we store 17966 09:58:45,060 --> 09:58:46,060 this and then we're just going to run 17967 09:58:46,916 --> 09:58:47,916 this action whenever we click on the 17968 09:58:48,660 --> 09:58:49,660 close button so let's go over here the 17969 09:58:50,400 --> 09:58:51,400 close button we've got that one let's 17970 09:58:52,980 --> 09:58:53,980 hide the options window and Trigger this 17971 09:58:54,840 --> 09:58:55,840 action so now we need is over here on 17972 09:58:56,756 --> 09:58:57,756 the game plus UI let's pass in and 17973 09:58:58,800 --> 09:58:59,800 basically when we close the options UI 17974 09:59:01,020 --> 09:59:02,020 we want to show the POS UI okay so let's 17975 09:59:04,256 --> 09:59:05,256 test so here we are let's pause the game 17976 09:59:06,540 --> 09:59:07,540 okay let's go into options and open it 17977 09:59:08,400 --> 09:59:09,400 and if there go it only shows the 17978 09:59:10,020 --> 09:59:11,020 options and over here moving up or down 17979 09:59:11,820 --> 09:59:12,820 works perfectly and moving left and 17980 09:59:13,740 --> 09:59:14,740 right also works perfectly 17981 09:59:15,596 --> 09:59:16,596 and now if I want to go back let's go 17982 09:59:17,340 --> 09:59:18,340 into close press it and there you go 17983 09:59:18,900 --> 09:59:19,900 back into the pause menu 17984 09:59:20,580 --> 09:59:21,580 all right awesome so everything is 17985 09:59:22,680 --> 09:59:23,680 working perfectly now the last thing we 17986 09:59:24,480 --> 09:59:25,480 need is over here on the main menu so 17987 09:59:26,276 --> 09:59:27,276 let's do the same thing first let's open 17988 09:59:28,680 --> 09:59:29,680 up the main menu scene 17989 09:59:30,416 --> 09:59:31,416 let's save the changes okay and over 17990 09:59:32,936 --> 09:59:33,936 here let's begin by doing the same thing 17991 09:59:34,436 --> 09:59:35,436 on the event system so let's replace it 17992 09:59:36,180 --> 09:59:37,180 okay great 17993 09:59:37,560 --> 09:59:38,560 then let's go inside our canvas inside 17994 09:59:39,540 --> 09:59:40,540 main menu y let's select our buttons and 17995 09:59:43,320 --> 09:59:44,320 once again let's modify the select color 17996 09:59:45,000 --> 09:59:46,000 put it on my screen all right and since 17997 09:59:47,756 --> 09:59:48,756 over here we only have one menu we could 17998 09:59:50,936 --> 09:59:51,936 set a test selected over here on the 17999 09:59:52,740 --> 09:59:53,740 main menu UI script 18000 09:59:54,360 --> 09:59:55,360 that's one option or we can just go into 18001 09:59:56,580 --> 09:59:57,580 the event system and over here on the 18002 09:59:58,320 --> 09:59:59,320 event system there's a film for the 18003 09:59:59,756 --> 10:00:00,756 first selected so you can just drag the 18004 10:00:02,040 --> 10:00:03,040 play button and that will automatically 18005 10:00:03,660 --> 10:00:04,660 make it the selected one so it says and 18006 10:00:06,720 --> 10:00:07,720 yep the play button starts off as 18007 10:00:08,040 --> 10:00:09,040 selected and I can move up or down 18008 10:00:10,436 --> 10:00:11,436 and if I press a button yep there you go 18009 10:00:13,020 --> 10:00:14,020 here I am playing the game I can pause I 18010 10:00:14,756 --> 10:00:15,756 can resume go back to the main menu and 18011 10:00:16,320 --> 10:00:17,320 so on all right awesome so here we have 18012 10:00:18,960 --> 10:00:19,960 the final thing we needed to make our 18013 10:00:20,460 --> 10:00:21,460 game fully playable with the GamePad 18014 10:00:22,080 --> 10:00:23,080 thanks to how the input system works and 18015 10:00:24,416 --> 10:00:25,416 the menu automatic navigation this was a 18016 10:00:26,460 --> 10:00:27,460 pretty simple task for this our game is 18017 10:00:28,800 --> 10:00:29,800 pretty much completely done however the 18018 10:00:30,840 --> 10:00:31,840 next lecture is also one of the most 18019 10:00:32,460 --> 10:00:33,460 important lectures it's all about 18020 10:00:34,020 --> 10:00:35,020 publish so let's do that in the next 18021 10:00:35,756 --> 10:00:36,756 lecture 18022 10:00:37,320 --> 10:00:38,320 hello and welcome I'm your code monkey 18023 10:00:39,300 --> 10:00:40,300 in this lecture we're going to add all 18024 10:00:41,756 --> 10:00:42,756 kinds of small things to polish our 18025 10:00:43,380 --> 10:00:44,380 power game if you are regular on this 18026 10:00:45,300 --> 10:00:46,300 channel then you've certainly heard me 18027 10:00:46,560 --> 10:00:47,560 say that polish is what separates good 18028 10:00:48,300 --> 10:00:49,300 games from great games so as you build 18029 10:00:50,460 --> 10:00:51,460 your own games make sure you don't 18030 10:00:51,900 --> 10:00:52,900 neglect polish here let's add a bunch of 18031 10:00:54,540 --> 10:00:55,540 small tiny things that will make a big 18032 10:00:56,580 --> 10:00:57,580 difference in the final game let's begin 18033 10:00:58,560 --> 10:00:59,560 with a very simple very visual one let's 18034 10:01:01,080 --> 10:01:02,080 just add some ones to our map and first 18035 10:01:03,540 --> 10:01:04,540 let's just hide our canvas so that it's 18036 10:01:05,520 --> 10:01:06,520 not blocking our view so again over here 18037 10:01:07,800 --> 10:01:08,800 we can use the buttons on the hierarchy 18038 10:01:09,300 --> 10:01:10,300 to hide it okay great 18039 10:01:11,040 --> 10:01:12,040 so let's add some walls and for that 18040 10:01:13,140 --> 10:01:14,140 let's create a brand new 3D cube let's 18041 10:01:16,380 --> 10:01:17,380 name this a wall let's put it quite a 18042 10:01:18,840 --> 10:01:19,840 bit thin so over here on the scale for 18043 10:01:20,700 --> 10:01:21,700 the X so let's put it 0.25 then on the 18044 10:01:23,276 --> 10:01:24,276 one let's put three so something like 18045 10:01:25,436 --> 10:01:26,436 this then we modified Z so let's put it 18046 10:01:27,480 --> 10:01:28,480 over here on the side right next to the 18047 10:01:29,936 --> 10:01:30,936 counters okay so that's the wall let's 18048 10:01:31,980 --> 10:01:32,980 just stretch it out One Direction and 18049 10:01:34,560 --> 10:01:35,560 the other one okay so that's our basic 18050 10:01:37,140 --> 10:01:38,140 one 18051 10:01:37,916 --> 10:01:38,916 now when you included project files 18052 10:01:40,020 --> 10:01:41,020 there's a nice one material so let's go 18053 10:01:41,520 --> 10:01:42,520 over here into assets under materials 18054 10:01:43,436 --> 10:01:44,436 and you appeared as you want material so 18055 10:01:45,416 --> 10:01:46,416 let's just drag it and use this one and 18056 10:01:47,160 --> 10:01:48,160 if there you go it's just a nice simple 18057 10:01:48,660 --> 10:01:49,660 gradient this is also an example of how 18058 10:01:51,240 --> 10:01:52,240 you can take something simple and make 18059 10:01:52,860 --> 10:01:53,860 it a bit more interesting if you look at 18060 10:01:54,900 --> 10:01:55,900 this material the base texture is really 18061 10:01:56,820 --> 10:01:57,820 just this it is literally just a simple 18062 10:01:59,520 --> 10:02:00,520 vertical gradient texture and then with 18063 10:02:02,096 --> 10:02:03,096 the color point to it and looks pretty 18064 10:02:03,660 --> 10:02:04,660 good okay so this dual let's put the 18065 10:02:06,120 --> 10:02:07,120 wall on on three sides so let's 18066 10:02:07,740 --> 10:02:08,740 supplicate this so just select and press 18067 10:02:09,480 --> 10:02:10,480 Ctrl D 2.8 let's put one on the other 18068 10:02:12,480 --> 10:02:13,480 side so right there right next to the 18069 10:02:15,180 --> 10:02:16,180 counters okay and finally the one there 18070 10:02:17,400 --> 10:02:18,400 so Ctrl D to duplicate it let's push it 18071 10:02:19,680 --> 10:02:20,680 over there on the side and rotate it 90 18072 10:02:21,960 --> 10:02:22,960 degrees 18073 10:02:23,096 --> 10:02:24,096 and let's put it just like that let's 18074 10:02:26,340 --> 10:02:27,340 just scale it to get to that end and to 18075 10:02:29,040 --> 10:02:30,040 get to that end okay so we have our nice 18076 10:02:31,620 --> 10:02:32,620 walls but over here if we're playing the 18077 10:02:33,840 --> 10:02:34,840 game we can still see the floor on the 18078 10:02:35,520 --> 10:02:36,520 outside that looks a bit ugly so let's 18079 10:02:37,380 --> 10:02:38,380 fix that 18080 10:02:38,340 --> 10:02:39,340 let's create another object and let's 18081 10:02:40,740 --> 10:02:41,740 create a 3D object another Cube and for 18082 10:02:43,500 --> 10:02:44,500 this Cube let's put it over here on the 18083 10:02:45,060 --> 10:02:46,060 side and this one let's use the black 18084 10:02:46,620 --> 10:02:47,620 material so again in the included assets 18085 10:02:48,960 --> 10:02:49,960 there's this nice black material there 18086 10:02:50,880 --> 10:02:51,880 you go it's completely black nothing to 18087 10:02:52,560 --> 10:02:53,560 it 18088 10:02:53,340 --> 10:02:54,340 so let's just use this as kind of a 18089 10:02:55,256 --> 10:02:56,256 Hider so let's just scale it quite a bit 18090 10:02:58,560 --> 10:02:59,560 and lift it up 18091 10:03:02,520 --> 10:03:03,520 okay so there it is a black material 18092 10:03:04,500 --> 10:03:05,500 right next to the wall and let's put 18093 10:03:06,480 --> 10:03:07,480 another one over here on the left side 18094 10:03:09,000 --> 10:03:10,000 and just like that 18095 10:03:10,860 --> 10:03:11,860 you can also put another one on the back 18096 10:03:12,416 --> 10:03:13,416 there even though I don't think the 18097 10:03:13,740 --> 10:03:14,740 camera can see that part but still let's 18098 10:03:15,776 --> 10:03:16,776 put it so just put it like that and 18099 10:03:18,720 --> 10:03:19,720 stretch it out okay that's good by the 18100 10:03:21,596 --> 10:03:22,596 way over here on the outside it doesn't 18101 10:03:23,040 --> 10:03:24,040 have to be perfect doesn't have to 18102 10:03:24,540 --> 10:03:25,540 perfectly match the camera is never 18103 10:03:26,276 --> 10:03:27,276 going to see that position so it doesn't 18104 10:03:27,900 --> 10:03:28,900 matter it only matters what the camera 18105 10:03:29,640 --> 10:03:30,640 can see and if we pull it like this and 18106 10:03:32,580 --> 10:03:33,580 if they're yellow now that looks quite 18107 10:03:34,200 --> 10:03:35,200 nice if we want over there we can get it 18108 10:03:36,776 --> 10:03:37,776 together just a little bit and we can 18109 10:03:38,936 --> 10:03:39,936 also move the camera forward a tiny bit 18110 10:03:41,400 --> 10:03:42,400 so over here on this one let's push it 18111 10:03:44,460 --> 10:03:45,460 just a little bit to the left okay and 18112 10:03:46,500 --> 10:03:47,500 now in the virtual camera 18113 10:03:48,000 --> 10:03:49,000 let's play the game 18114 10:03:50,040 --> 10:03:51,040 and now here if we want we can push it 18115 10:03:52,140 --> 10:03:53,140 up a little bit something like this so 18116 10:03:54,240 --> 10:03:55,240 let's put it on this set so let's copy 18117 10:03:56,160 --> 10:03:57,160 it stop playing the game and let's paste 18118 10:03:59,096 --> 10:04:00,096 it just like that 18119 10:04:00,240 --> 10:04:01,240 okay so here's our game and as you can 18120 10:04:02,400 --> 10:04:03,400 see with just this one tiny chain just 18121 10:04:04,500 --> 10:04:05,500 adding some walls and a nice black 18122 10:04:06,180 --> 10:04:07,180 outside just with that it already looks 18123 10:04:08,460 --> 10:04:09,460 so much better than having some counters 18124 10:04:10,140 --> 10:04:11,140 in wide open space now for another 18125 10:04:12,360 --> 10:04:13,360 simple one let's add some nice particles 18126 10:04:14,340 --> 10:04:15,340 while the player is moving 18127 10:04:16,020 --> 10:04:17,020 so in the included assets if we go 18128 10:04:18,300 --> 10:04:19,300 inside the prefab visuals over here is a 18129 10:04:20,220 --> 10:04:21,220 nice one for player moving particles 18130 10:04:21,776 --> 10:04:22,776 this one as you can see is a particle 18131 10:04:24,060 --> 10:04:25,060 system so let's drag it over here into 18132 10:04:26,220 --> 10:04:27,220 the world see what it looks like and as 18133 10:04:28,256 --> 10:04:29,256 you can see by default it's actually not 18134 10:04:29,700 --> 10:04:30,700 spawning anything so I can make sure 18135 10:04:31,620 --> 10:04:32,620 that this one is running and nope 18136 10:04:32,936 --> 10:04:33,936 nothing is spawning so this is actually 18137 10:04:34,916 --> 10:04:35,916 set up in a really interesting way is 18138 10:04:36,840 --> 10:04:37,840 that instead of spawning particles all 18139 10:04:38,520 --> 10:04:39,520 the time it only emits while moving so 18140 10:04:40,800 --> 10:04:41,800 if I click to move this object there you 18141 10:04:42,900 --> 10:04:43,900 go the particles start emitting and if I 18142 10:04:44,700 --> 10:04:45,700 stop they stop so this one is definitely 18143 10:04:46,916 --> 10:04:47,916 perfect for a player particle system the 18144 10:04:49,740 --> 10:04:50,740 way this setup is over here on the 18145 10:04:51,540 --> 10:04:52,540 emission on rate over time it is set to 18146 10:04:54,120 --> 10:04:55,120 zero so it doesn't spawn anything 18147 10:04:55,436 --> 10:04:56,436 automatically and it only has over here 18148 10:04:57,480 --> 10:04:58,480 the rate over distance so as it moves 18149 10:04:59,756 --> 10:05:00,756 it's going to spawn that number of 18150 10:05:01,140 --> 10:05:02,140 particles then the other settings 18151 10:05:02,880 --> 10:05:03,880 they're all pretty basic so there's some 18152 10:05:05,460 --> 10:05:06,460 gravity so they fall down just like the 18153 10:05:07,380 --> 10:05:08,380 stove counter particles simulation is 18154 10:05:10,256 --> 10:05:11,256 over here on space so that as I move the 18155 10:05:12,180 --> 10:05:13,180 particle stay behind this is important 18156 10:05:14,340 --> 10:05:15,340 if I were to put that in local and I 18157 10:05:16,320 --> 10:05:17,320 move it around look at that this is not 18158 10:05:17,756 --> 10:05:18,756 what we want we want the particles to 18159 10:05:19,800 --> 10:05:20,800 essentially stay behind instead of 18160 10:05:21,480 --> 10:05:22,480 following this transform so that is why 18161 10:05:23,400 --> 10:05:24,400 this change is super important if that 18162 10:05:25,860 --> 10:05:26,860 one is set to whirl and as I move yep 18163 10:05:27,416 --> 10:05:28,416 the particles stay behind okay great and 18164 10:05:29,936 --> 10:05:30,936 the other property is around pretty 18165 10:05:31,256 --> 10:05:32,256 basic for the shape it's a cone pointing 18166 10:05:33,720 --> 10:05:34,720 upwards then for the size of our 18167 10:05:35,820 --> 10:05:36,820 lifetime again just a basic curve 18168 10:05:37,500 --> 10:05:38,500 constantly becoming smaller and smaller 18169 10:05:39,416 --> 10:05:40,416 and down here on the renderer instead of 18170 10:05:42,120 --> 10:05:43,120 rendering your quads actually rendering 18171 10:05:43,680 --> 10:05:44,680 a mesh and it's rendering a sphere mesh 18172 10:05:45,840 --> 10:05:46,840 so that's just so that it looks a little 18173 10:05:47,520 --> 10:05:48,520 bit better I think than just having a 18174 10:05:49,380 --> 10:05:50,380 Sprite particle okay so that's it so in 18175 10:05:51,720 --> 10:05:52,720 order to make this work really all we 18176 10:05:53,160 --> 10:05:54,160 need is just attach it to the player 18177 10:05:55,436 --> 10:05:56,436 so let's find the player make this 18178 10:05:57,240 --> 10:05:58,240 object a child of the player game object 18179 10:05:59,276 --> 10:06:00,276 and again let's also make sure to set 18180 10:06:01,916 --> 10:06:02,916 all of this to zero so the position on 18181 10:06:03,660 --> 10:06:04,660 zero zero and zero 18182 10:06:06,000 --> 10:06:07,000 and there you go just with this that's 18183 10:06:07,436 --> 10:06:08,436 all we need if we test here we are 18184 10:06:09,720 --> 10:06:10,720 stopping there are no particles and as I 18185 10:06:11,520 --> 10:06:12,520 start moving if there you go some nice 18186 10:06:13,256 --> 10:06:14,256 particles around the player okay great 18187 10:06:16,080 --> 10:06:17,080 next let's add a pretty obvious one some 18188 10:06:18,660 --> 10:06:19,660 kind of mini tutorial we want a window 18189 10:06:21,240 --> 10:06:22,240 to show the controls and the goal of the 18190 10:06:23,040 --> 10:06:24,040 game and wait for the player input 18191 10:06:24,660 --> 10:06:25,660 before we start the countdown 18192 10:06:26,580 --> 10:06:27,580 so for that let's go into our canvas so 18193 10:06:28,800 --> 10:06:29,800 let's show our canvas and inside let's 18194 10:06:31,916 --> 10:06:32,916 create an empty game object called the 18195 10:06:34,080 --> 10:06:35,080 tutorial UI 18196 10:06:35,640 --> 10:06:36,640 let's drag this one above the game pause 18197 10:06:37,860 --> 10:06:38,860 window so that it shows up behind it 18198 10:06:39,416 --> 10:06:40,416 let's double click to center it and 18199 10:06:41,700 --> 10:06:42,700 let's press on the 2D button to go into 18200 10:06:43,680 --> 10:06:44,680 2D mode okay let's also hide those two 18201 10:06:46,436 --> 10:06:47,436 windows so you can actually see what 18202 10:06:47,880 --> 10:06:48,880 we're doing so outside all of these okay 18203 10:06:49,620 --> 10:06:50,620 great 18204 10:06:50,640 --> 10:06:51,640 now this one first of all let's stretch 18205 10:06:52,500 --> 10:06:53,500 it to occupy everything so put zero on 18206 10:06:54,300 --> 10:06:55,300 everything okay then inside let's make a 18207 10:06:57,960 --> 10:06:58,960 UI image for our background once again 18208 10:07:01,320 --> 10:07:02,320 let's stretch it put it like this 18209 10:07:04,320 --> 10:07:05,320 and for this one instead of black like 18210 10:07:06,060 --> 10:07:07,060 we've used for all of our Windows let's 18211 10:07:07,680 --> 10:07:08,680 actually leave it on white put it on an 18212 10:07:09,776 --> 10:07:10,776 alpha something like half so something 18213 10:07:11,340 --> 10:07:12,340 like this just to be a bit different 18214 10:07:12,540 --> 10:07:13,540 then on top of this let's make another 18215 10:07:14,700 --> 10:07:15,700 image so let's make another UI image and 18216 10:07:17,276 --> 10:07:18,276 for this one instead of stretching let's 18217 10:07:18,660 --> 10:07:19,660 give it a size so let's put it on 1280 18218 10:07:20,756 --> 10:07:21,756 by 800 and for the image I created a 18219 10:07:24,240 --> 10:07:25,240 nice image for the tutorial if we go 18220 10:07:26,936 --> 10:07:27,936 inside the assets and then inside 18221 10:07:28,500 --> 10:07:29,500 textures yup here is a really nice 18222 10:07:30,540 --> 10:07:31,540 tutorial image 18223 10:07:32,040 --> 10:07:33,040 so let's just go ahead and use it so on 18224 10:07:34,320 --> 10:07:35,320 the image let's drag it all right 18225 10:07:36,416 --> 10:07:37,416 there's our nice internal image so this 18226 10:07:38,700 --> 10:07:39,700 has a pre-based tutorial so the recipe 18227 10:07:40,436 --> 10:07:41,436 is coming from the customers then the 18228 10:07:42,060 --> 10:07:43,060 player has to prepare the correct 18229 10:07:43,140 --> 10:07:44,140 recipes and deliver them on a plate on 18230 10:07:45,120 --> 10:07:46,120 the delivery counter so just a very base 18231 10:07:47,580 --> 10:07:48,580 tutorial and also over here it's very 18232 10:07:50,160 --> 10:07:51,160 important for the player to know how to 18233 10:07:51,840 --> 10:07:52,840 actually play the game so there are some 18234 10:07:53,936 --> 10:07:54,936 labels for the controls and now we're 18235 10:07:55,680 --> 10:07:56,680 going to dynamically add some keys on 18236 10:07:57,300 --> 10:07:58,300 top so let's do that let's create an 18237 10:07:59,756 --> 10:08:00,756 empty game object call this the king 18238 10:08:02,640 --> 10:08:03,640 let's put it on a size of 40 by 40 okay 18239 10:08:06,000 --> 10:08:07,000 now let's go inside and inside let's 18240 10:08:09,180 --> 10:08:10,180 make an image let's name this the 18241 10:08:11,700 --> 10:08:12,700 background 18242 10:08:12,840 --> 10:08:13,840 and for the Sprite let's go with the 18243 10:08:15,960 --> 10:08:16,960 included Circle so default Circle 18244 10:08:18,360 --> 10:08:19,360 and for the size let's stretch it occupy 18245 10:08:20,700 --> 10:08:21,700 everything put it on zero zero zero okay 18246 10:08:23,340 --> 10:08:24,340 there's our nice key 18247 10:08:25,200 --> 10:08:26,200 so we have the background and for the 18248 10:08:27,900 --> 10:08:28,900 background let's actually make it just a 18249 10:08:29,460 --> 10:08:30,460 little bit darker 18250 10:08:30,960 --> 10:08:31,960 and let's also add just a nice shadow so 18251 10:08:34,080 --> 10:08:35,080 maybe three minus three and let's also 18252 10:08:36,776 --> 10:08:37,776 make a nice upline 18253 10:08:38,400 --> 10:08:39,400 let's put it on two by two 18254 10:08:41,220 --> 10:08:42,220 full Alpha so something like this just 18255 10:08:43,140 --> 10:08:44,140 to be a nice one maybe one by one okay 18256 10:08:45,480 --> 10:08:46,480 so that's just the visual and then on 18257 10:08:47,460 --> 10:08:48,460 top of it let's add a text 18258 10:08:49,800 --> 10:08:50,800 and this one's essentially going to be 18259 10:08:51,180 --> 10:08:52,180 the king so let's put a key for the 18260 10:08:53,460 --> 10:08:54,460 width and height let's stretch it to 18261 10:08:56,160 --> 10:08:57,160 match the parent size okay then for the 18262 10:08:58,800 --> 10:08:59,800 phone here let's go with maybe just say 18263 10:09:00,480 --> 10:09:01,480 20 let's put it Center down the middle 18264 10:09:02,660 --> 10:09:03,660 and also let's put it on bond okay so 18265 10:09:05,520 --> 10:09:06,520 that's our nice key indicator 18266 10:09:07,500 --> 10:09:08,500 so this is our key and we're going to 18267 10:09:10,436 --> 10:09:11,436 have the movement so the movement on the 18268 10:09:11,880 --> 10:09:12,880 keyboard is going to have four keys so 18269 10:09:13,980 --> 10:09:14,980 let's just implicate so one two three 18270 10:09:16,740 --> 10:09:17,740 and four Keys okay then on the GamePad 18271 10:09:20,040 --> 10:09:21,040 that one is actually not rebindable so 18272 10:09:22,020 --> 10:09:23,020 let's put this one as static 18273 10:09:24,840 --> 10:09:25,840 so let's just go inside inside the text 18274 10:09:27,720 --> 10:09:28,720 and just say left stick and let's lower 18275 10:09:31,080 --> 10:09:32,080 the font size so that it fits in there 18276 10:09:32,756 --> 10:09:33,756 okay great 18277 10:09:33,960 --> 10:09:34,960 then for some more keys 18278 10:09:36,240 --> 10:09:37,240 we're going to have the interact action 18279 10:09:38,400 --> 10:09:39,400 then the interact alternate 18280 10:09:41,276 --> 10:09:42,276 and finally the pause action 18281 10:09:43,620 --> 10:09:44,620 then let's just duplicate these to be on 18282 10:09:45,840 --> 10:09:46,840 the other side 18283 10:09:52,380 --> 10:09:53,380 okay so these are all of our keys now 18284 10:09:55,140 --> 10:09:56,140 instead of having key one two three this 18285 10:09:57,060 --> 10:09:58,060 is very difficult to understand so let's 18286 10:09:58,560 --> 10:09:59,560 give it some proper names so this is the 18287 10:10:00,900 --> 10:10:01,900 key move up then we have the key move 18288 10:10:03,960 --> 10:10:04,960 down 18289 10:10:05,276 --> 10:10:06,276 then the key moves left then the key 18290 10:10:08,340 --> 10:10:09,340 move right 18291 10:10:09,900 --> 10:10:10,900 then this one is going to be the key 18292 10:10:12,436 --> 10:10:13,436 Gamepad move 18293 10:10:14,700 --> 10:10:15,700 then we have the key interact 18294 10:10:17,580 --> 10:10:18,580 the key interact alternates 18295 10:10:21,060 --> 10:10:22,060 the key pause 18296 10:10:23,096 --> 10:10:24,096 this one is the key Gamepad interact 18297 10:10:26,520 --> 10:10:27,520 alternate 18298 10:10:28,500 --> 10:10:29,500 this one is the key Gamepad interact and 18299 10:10:31,680 --> 10:10:32,680 finally the key Gamepad pause 18300 10:10:36,360 --> 10:10:37,360 okay all of these and since we're going 18301 10:10:38,220 --> 10:10:39,220 to drag references to the text objects 18302 10:10:40,020 --> 10:10:41,020 let's also give those a name 18303 10:10:41,936 --> 10:10:42,936 so just copy drop it with text 18304 10:10:45,540 --> 10:10:46,540 just like this 18305 10:10:51,416 --> 10:10:52,416 okay so those are all the names so 18306 10:10:53,220 --> 10:10:54,220 everything is nice and organized okay 18307 10:10:54,840 --> 10:10:55,840 great now let's make the script to run 18308 10:10:57,480 --> 10:10:58,480 this so our tutorial UI let's go down 18309 10:10:59,880 --> 10:11:00,880 into our UI scripts create the brand new 18310 10:11:02,096 --> 10:11:03,096 c-sharp script for the tutorial UI and 18311 10:11:05,220 --> 10:11:06,220 let's attach the script okay 18312 10:11:07,436 --> 10:11:08,436 so first let's drag references to all of 18313 10:11:09,840 --> 10:11:10,840 our keys we only need the text so let's 18314 10:11:12,300 --> 10:11:13,300 do a serialize field of type text mesh 18315 10:11:15,416 --> 10:11:16,416 Pro U going again never make the mistake 18316 10:11:17,756 --> 10:11:18,756 always use the ugly one if we're working 18317 10:11:19,740 --> 10:11:20,740 the UI so the key move of text 18318 10:11:23,400 --> 10:11:24,400 so let's add all of these 18319 10:11:28,020 --> 10:11:29,020 okay these are all the references then 18320 10:11:30,596 --> 10:11:31,596 over here let's drag on and make sure to 18321 10:11:32,820 --> 10:11:33,820 drag the correct ones 18322 10:11:37,980 --> 10:11:38,980 okay let's double check to make sure all 18323 10:11:40,020 --> 10:11:41,020 the references are correct okay they 18324 10:11:41,700 --> 10:11:42,700 don't seem correct all right great and 18325 10:11:43,800 --> 10:11:44,800 then over here only to pretty much 18326 10:11:45,300 --> 10:11:46,300 exactly the same thing that we did over 18327 10:11:46,680 --> 10:11:47,680 here on the options so we need exactly 18328 10:11:49,436 --> 10:11:50,436 this so let's copy this and over here 18329 10:11:52,200 --> 10:11:53,200 and let's do just that 18330 10:11:54,180 --> 10:11:55,180 let's see a private void update visual 18331 10:11:57,660 --> 10:11:58,660 and on this one let's do pretty much 18332 10:11:59,520 --> 10:12:00,520 this so the key move up text 18333 10:12:01,860 --> 10:12:02,860 I know this one you get binding text to 18334 10:12:03,480 --> 10:12:04,480 move up yep let's just do all the others 18335 10:12:15,776 --> 10:12:16,776 okay so those are all the bindings 18336 10:12:17,580 --> 10:12:18,580 that's great now let's go over here on a 18337 10:12:20,756 --> 10:12:21,756 proud void start and on start let's 18338 10:12:23,160 --> 10:12:24,160 update our visual all right and also 18339 10:12:25,916 --> 10:12:26,916 let's make sure this updates just in 18340 10:12:27,776 --> 10:12:28,776 case the player rebinds something from 18341 10:12:29,460 --> 10:12:30,460 the pause menu once the tutorial is 18342 10:12:31,256 --> 10:12:32,256 still visible 18343 10:12:32,340 --> 10:12:33,340 so we just need to know when that 18344 10:12:34,080 --> 10:12:35,080 happens so let's go over here onto the 18345 10:12:35,580 --> 10:12:36,580 game input and make a nice event so 18346 10:12:37,860 --> 10:12:38,860 public event even Handler let's call it 18347 10:12:40,680 --> 10:12:41,680 on binding rebind 18348 10:12:43,020 --> 10:12:44,020 okay we have this event and down here 18349 10:12:45,540 --> 10:12:46,540 when we have our rebind binding function 18350 10:12:47,460 --> 10:12:48,460 we do this we rebind and over here let's 18351 10:12:50,220 --> 10:12:51,220 invoke this event 18352 10:12:57,000 --> 10:12:58,000 okay just like this 18353 10:12:59,040 --> 10:13:00,040 so then on TTR only y let's go into the 18354 10:13:02,220 --> 10:13:03,220 game input the instance on binding 18355 10:13:05,220 --> 10:13:06,220 rebind let's listen to this event and as 18356 10:13:08,460 --> 10:13:09,460 always let's rename this so let's put a 18357 10:13:10,620 --> 10:13:11,620 game input okay when this happens let's 18358 10:13:13,200 --> 10:13:14,200 simply update the visual 18359 10:13:15,300 --> 10:13:16,300 okay that's it pretty simple so let's 18360 10:13:17,580 --> 10:13:18,580 test and see if the inputs are correct 18361 10:13:19,560 --> 10:13:20,560 and if there it is we do see it correct 18362 10:13:21,480 --> 10:13:22,480 so we've got ones we've got e to 18363 10:13:23,640 --> 10:13:24,640 interact F and over there we've got the 18364 10:13:25,680 --> 10:13:26,680 GamePad okay great so all the buttons 18365 10:13:28,800 --> 10:13:29,800 are correct all that's left is the show 18366 10:13:30,360 --> 10:13:31,360 and hide so over here let's make the 18367 10:13:32,400 --> 10:13:33,400 usual two functions so product void show 18368 10:13:35,096 --> 10:13:36,096 and a proud boy in Hind and for these 18369 10:13:38,520 --> 10:13:39,520 game objects set active and this one is 18370 10:13:41,460 --> 10:13:42,460 going to be into false and this one's 18371 10:13:43,560 --> 10:13:44,560 going to be true okay 18372 10:13:45,000 --> 10:13:46,000 so for show up here on start let's 18373 10:13:47,460 --> 10:13:48,460 actually show it by default even though 18374 10:13:49,620 --> 10:13:50,620 it's actually already going to be shown 18375 10:13:51,000 --> 10:13:52,000 but still okay then for the hind this 18376 10:13:54,416 --> 10:13:55,416 one we want to hide when we press the 18377 10:13:56,340 --> 10:13:57,340 interaction 18378 10:13:57,840 --> 10:13:58,840 however when that happens we don't want 18379 10:14:00,416 --> 10:14:01,416 just this window to hide we want the 18380 10:14:02,700 --> 10:14:03,700 kitchen game manager to change the state 18381 10:14:04,980 --> 10:14:05,980 so we're here on the kitchen game 18382 10:14:06,360 --> 10:14:07,360 manager we currently have the waiting to 18383 10:14:08,580 --> 10:14:09,580 start and that one actually has a timer 18384 10:14:10,200 --> 10:14:11,200 so we count down the timer and then we 18385 10:14:12,300 --> 10:14:13,300 start whereas right now we want it to be 18386 10:14:14,160 --> 10:14:15,160 based on player input so let's modify 18387 10:14:16,500 --> 10:14:17,500 this to not be based on timer so let's 18388 10:14:18,300 --> 10:14:19,300 just get rid of this timer 18389 10:14:20,220 --> 10:14:21,220 and now let's see all these errors so 18390 10:14:22,436 --> 10:14:23,436 I'm waiting to start we are not going to 18391 10:14:24,240 --> 10:14:25,240 count down any timers instead let's 18392 10:14:26,936 --> 10:14:27,936 listen to the game input so game input 18393 10:14:30,120 --> 10:14:31,120 let's listen to the on interact action 18394 10:14:32,820 --> 10:14:33,820 event and rename this to the game input 18395 10:14:36,180 --> 10:14:37,180 okay so when we have this event when the 18396 10:14:39,660 --> 10:14:40,660 player presses the interact action let's 18397 10:14:41,880 --> 10:14:42,880 check if the state if this one is on 18398 10:14:44,160 --> 10:14:45,160 waiting to start 18399 10:14:45,480 --> 10:14:46,480 if so then let's modify the state so 18400 10:14:47,400 --> 10:14:48,400 let's go into State and we're going to 18401 10:14:49,020 --> 10:14:50,020 go into the countdown to start and let's 18402 10:14:51,360 --> 10:14:52,360 trigger the on state changed event 18403 10:14:58,200 --> 10:14:59,200 okay so that's it so we're only going to 18404 10:15:00,300 --> 10:15:01,300 change it on the player input and 18405 10:15:01,980 --> 10:15:02,980 nothing over here on the updates then 18406 10:15:04,080 --> 10:15:05,080 for hiding the tutorial over here one 18407 10:15:06,900 --> 10:15:07,900 approach would be to listen to the 18408 10:15:08,276 --> 10:15:09,276 interact action and hide it but I think 18409 10:15:10,500 --> 10:15:11,500 it makes more sense for this to only 18410 10:15:12,416 --> 10:15:13,416 listen to the kitchen game manager state 18411 10:15:14,460 --> 10:15:15,460 that way if we wanted we could also 18412 10:15:16,560 --> 10:15:17,560 modify how this one changes the waiting 18413 10:15:18,360 --> 10:15:19,360 to start 18414 10:15:19,256 --> 10:15:20,256 so let's listen to distinct over here on 18415 10:15:22,200 --> 10:15:23,200 tutorial we want let's go into the 18416 10:15:23,580 --> 10:15:24,580 kitchen game manager the incense and 18417 10:15:25,560 --> 10:15:26,560 let's listen when the state changes 18418 10:15:30,960 --> 10:15:31,960 so here we are going to check if the 18419 10:15:33,000 --> 10:15:34,000 kitchen game manager instance if it is 18420 10:15:35,460 --> 10:15:36,460 on the countdown to start active so if 18421 10:15:37,380 --> 10:15:38,380 the countdown is active then we're going 18422 10:15:39,180 --> 10:15:40,180 to hide this 18423 10:15:40,320 --> 10:15:41,320 okay so that should do it now let's just 18424 10:15:42,900 --> 10:15:43,900 do one more small thing the delivery 18425 10:15:45,416 --> 10:15:46,416 manager is currently spanning a recipe 18426 10:15:46,916 --> 10:15:47,916 whilst we're still reading the tutorial 18427 10:15:48,596 --> 10:15:49,596 that's not quite right 18428 10:15:50,400 --> 10:15:51,400 so let's go over here on the delivery 18429 10:15:52,436 --> 10:15:53,436 manager and right now this one starts 18430 10:15:55,020 --> 10:15:56,020 off at 0f and starts counting it down 18431 10:15:56,756 --> 10:15:57,756 right away 18432 10:15:57,720 --> 10:15:58,720 instead of only doing it like this let's 18433 10:15:59,820 --> 10:16:00,820 just make sure that we only spawn a 18434 10:16:01,200 --> 10:16:02,200 recipe if the game is playing so that's 18435 10:16:02,700 --> 10:16:03,700 super simple over here kitchen game 18436 10:16:04,620 --> 10:16:05,620 manager instance is game playing if so 18437 10:16:08,040 --> 10:16:09,040 then we are going to spawn a recipe and 18438 10:16:10,320 --> 10:16:11,320 let's do the same thing on the points 18439 10:16:12,416 --> 10:16:13,416 counter so let's go in the plates 18440 10:16:14,640 --> 10:16:15,640 counter 18441 10:16:15,720 --> 10:16:16,720 so here we are on the plates counter so 18442 10:16:17,700 --> 10:16:18,700 we count on time responsive lights but 18443 10:16:19,500 --> 10:16:20,500 let's also make sure we only spawn 18444 10:16:20,820 --> 10:16:21,820 plates if the game swing 18445 10:16:22,680 --> 10:16:23,680 okay so with all of this let's test and 18446 10:16:25,380 --> 10:16:26,380 right away here we are we can see our 18447 10:16:27,300 --> 10:16:28,300 nice tutorial teaching the player how to 18448 10:16:28,980 --> 10:16:29,980 play okay great here we've got the 18449 10:16:30,360 --> 10:16:31,360 controls everything and we're currently 18450 10:16:32,460 --> 10:16:33,460 waiting for an interaction we can see 18451 10:16:34,500 --> 10:16:35,500 over there plates are not being spawned 18452 10:16:36,120 --> 10:16:37,120 and recipes are also not being spawned 18453 10:16:37,800 --> 10:16:38,800 but as soon as I press the E key 18454 10:16:40,020 --> 10:16:41,020 and if there go the countdown starts 18455 10:16:41,880 --> 10:16:42,880 playing and we've got everything else 18456 10:16:43,560 --> 10:16:44,560 any up there you go the game starts and 18457 10:16:45,840 --> 10:16:46,840 after a while yep we've got plates and 18458 10:16:47,460 --> 10:16:48,460 we've got recipes alright awesome so 18459 10:16:50,580 --> 10:16:51,580 next let's publish the countdown visual 18460 10:16:52,680 --> 10:16:53,680 right now it's pretty basic it's just a 18461 10:16:54,840 --> 10:16:55,840 static number so let's add a nice 18462 10:16:56,520 --> 10:16:57,520 animation to it let's go inside the 18463 10:16:58,500 --> 10:16:59,500 canvas let's find the countdown UI so 18464 10:17:00,960 --> 10:17:01,960 the game start countdown okay 18465 10:17:02,820 --> 10:17:03,820 so here it is we just have some basic 18466 10:17:04,620 --> 10:17:05,620 text now let's go into the main game 18467 10:17:07,080 --> 10:17:08,080 object and let's add an animator 18468 10:17:08,820 --> 10:17:09,820 component 18469 10:17:10,080 --> 10:17:11,080 then let's create a brand new animated 18470 10:17:12,000 --> 10:17:13,000 controller so let's create a new down 18471 10:17:14,936 --> 10:17:15,936 here an animated controller for the 18472 10:17:16,620 --> 10:17:17,620 countdown UI over there let's assign 18473 10:17:19,020 --> 10:17:20,020 this controller okay now let's open up 18474 10:17:21,300 --> 10:17:22,300 the animation window so window animation 18475 10:17:23,220 --> 10:17:24,220 open up the animation window okay let's 18476 10:17:24,960 --> 10:17:25,960 create an animation clip and over here 18477 10:17:26,700 --> 10:17:27,700 on let's name this the countdown UI 18478 10:17:28,500 --> 10:17:29,500 number pop-up okay that's great now for 18479 10:17:31,380 --> 10:17:32,380 making the animation we want to 18480 10:17:33,360 --> 10:17:34,360 basically make it shake and also make it 18481 10:17:35,096 --> 10:17:36,096 fade away so one very useful component 18482 10:17:37,680 --> 10:17:38,680 is the canvas group so over here once on 18483 10:17:39,776 --> 10:17:40,776 the parent let's attach a canvas group 18484 10:17:42,120 --> 10:17:43,120 component this one is a really useful 18485 10:17:44,520 --> 10:17:45,520 component in this case the main benefit 18486 10:17:46,500 --> 10:17:47,500 is it let's just easily animate the 18487 10:17:48,360 --> 10:17:49,360 alpha so let's go ahead and turn on 18488 10:17:50,640 --> 10:17:51,640 recording let's go into the frame just 18489 10:17:53,220 --> 10:17:54,220 before one second so let's go into 60 18490 10:17:55,200 --> 10:17:56,200 frames because we are on 60 frames per 18491 10:17:57,180 --> 10:17:58,180 second over here let's record the normal 18492 10:17:59,400 --> 10:18:00,400 keyframe so let's modify the scale on 18493 10:18:01,680 --> 10:18:02,680 the tiny bit just to record it and let's 18494 10:18:03,300 --> 10:18:04,300 reset it back to one okay just to record 18495 10:18:05,276 --> 10:18:06,276 the keyframe then for rotation let's 18496 10:18:07,980 --> 10:18:08,980 rotate on Z then put it on zero again 18497 10:18:09,960 --> 10:18:10,960 just record the keyframe okay great so 18498 10:18:12,480 --> 10:18:13,480 now we can go back into the first frame 18499 10:18:14,220 --> 10:18:15,220 and over here let's first make it 18500 10:18:16,200 --> 10:18:17,200 smaller so for the size let's put it on 18501 10:18:18,120 --> 10:18:19,120 0.6 then let's rotate it to the left so 18502 10:18:20,756 --> 10:18:21,756 let's put 17 over here on the set 18503 10:18:22,680 --> 10:18:23,680 rotation okay like that now let's move 18504 10:18:25,080 --> 10:18:26,080 up by just three frames so on frame 18505 10:18:26,820 --> 10:18:27,820 three over here let's make it quite a 18506 10:18:28,800 --> 10:18:29,800 lot bigger so let's put it on 1.3 and 18507 10:18:31,256 --> 10:18:32,256 let's rotate it to the opposite position 18508 10:18:33,000 --> 10:18:34,000 so -17 okay that's great that's a nice 18509 10:18:36,480 --> 10:18:37,480 start now let's put it on frame 10 and 18510 10:18:39,540 --> 10:18:40,540 over here let's set the rotation to zero 18511 10:18:42,000 --> 10:18:43,000 and for the scale put it on 1.1 okay so 18512 10:18:44,936 --> 10:18:45,936 now finally over here on frame 50 let's 18513 10:18:47,880 --> 10:18:48,880 set the alpha onto one and then on one 18514 10:18:51,120 --> 10:18:52,120 second let's put the alpha zero okay so 18515 10:18:53,340 --> 10:18:54,340 let's preview and if they go a nice 18516 10:18:55,320 --> 10:18:56,320 simple animation okay so that was great 18517 10:18:57,720 --> 10:18:58,720 now we just need to play this when the 18518 10:18:59,700 --> 10:19:00,700 countdown happens so let's stop 18519 10:19:01,800 --> 10:19:02,800 recording let's go inside the animator 18520 10:19:04,200 --> 10:19:05,200 controller so here it is we've got our 18521 10:19:06,060 --> 10:19:07,060 number pop-up and we basically just want 18522 10:19:08,460 --> 10:19:09,460 to play this animation whenever we want 18523 10:19:10,256 --> 10:19:11,256 so let's put it and make a transition 18524 10:19:12,540 --> 10:19:13,540 from the any state onto the number 18525 10:19:14,340 --> 10:19:15,340 pop-up on this transition let's make 18526 10:19:16,740 --> 10:19:17,740 sure we have no exit time and for the 18527 10:19:18,540 --> 10:19:19,540 settings over here for the duration 18528 10:19:19,620 --> 10:19:20,620 let's put it on zero so that it's 18529 10:19:21,060 --> 10:19:22,060 instant okay great now obviously we need 18530 10:19:23,460 --> 10:19:24,460 a condition so on the parameters let's 18531 10:19:25,680 --> 10:19:26,680 create a brand new trigger call this the 18532 10:19:28,140 --> 10:19:29,140 number pop-up let's select that one and 18533 10:19:30,776 --> 10:19:31,776 Trigger it on this trigger okay great so 18534 10:19:33,720 --> 10:19:34,720 now for handling this logic here we have 18535 10:19:36,120 --> 10:19:37,120 the usual question 18536 10:19:37,560 --> 10:19:38,560 so do we put this visual Logic on the 18537 10:19:39,660 --> 10:19:40,660 same UI script or do we separate the 18538 10:19:41,640 --> 10:19:42,640 animations from the UI for me I find 18539 10:19:43,980 --> 10:19:44,980 that UI is usually part of the visual so 18540 10:19:46,436 --> 10:19:47,436 sometimes I like to mix the two and 18541 10:19:48,360 --> 10:19:49,360 sometimes I keep them separate it really 18542 10:19:50,096 --> 10:19:51,096 depends on a case-by-case basis this 18543 10:19:52,380 --> 10:19:53,380 visual is so simple and so connected to 18544 10:19:54,596 --> 10:19:55,596 the actual UI Logics over here let's put 18545 10:19:56,640 --> 10:19:57,640 them together so let's open up the game 18546 10:19:58,680 --> 10:19:59,680 start countdown script and over here 18547 10:20:00,480 --> 10:20:01,480 let's first grab the animator so private 18548 10:20:02,400 --> 10:20:03,400 animator for the animator and on private 18549 10:20:05,040 --> 10:20:06,040 void awake let's just get the animator 18550 10:20:06,720 --> 10:20:07,720 and just get the component of type 18551 10:20:08,220 --> 10:20:09,220 animator okay so we have the animator 18552 10:20:10,800 --> 10:20:11,800 now we basically just need to keep track 18553 10:20:13,020 --> 10:20:14,020 down here where we're modifying the text 18554 10:20:14,936 --> 10:20:15,936 we're doing this on every update but now 18555 10:20:17,160 --> 10:20:18,160 we need to know when this number changes 18556 10:20:18,720 --> 10:20:19,720 so let's basically just keep track of 18557 10:20:20,880 --> 10:20:21,880 the current number and the previous 18558 10:20:22,200 --> 10:20:23,200 number so first of all over here an end 18559 10:20:24,840 --> 10:20:25,840 for the countdown number 18560 10:20:27,060 --> 10:20:28,060 and we're going to get this so this is 18561 10:20:29,520 --> 10:20:30,520 our countdown number and over here we 18562 10:20:31,860 --> 10:20:32,860 set it to string 18563 10:20:33,180 --> 10:20:34,180 okay and we just need to use a different 18564 10:20:35,220 --> 10:20:36,220 function so instead of Cl lets you cl2n 18565 10:20:37,560 --> 10:20:38,560 just to convert the output into an 18566 10:20:39,060 --> 10:20:40,060 integer okay great 18567 10:20:40,680 --> 10:20:41,680 so we have the countdown number now we 18568 10:20:42,840 --> 10:20:43,840 just need to know if this one is 18569 10:20:43,980 --> 10:20:44,980 different from the previous one so let's 18570 10:20:45,900 --> 10:20:46,900 go up here let's define a private tint 18571 10:20:48,060 --> 10:20:49,060 for the previous countdown number 18572 10:20:51,060 --> 10:20:52,060 then when we go down here we've got the 18573 10:20:53,820 --> 10:20:54,820 current countdown number okay then just 18574 10:20:55,680 --> 10:20:56,680 check if it's different 18575 10:20:58,320 --> 10:20:59,320 if it is different from the current 18576 10:21:00,120 --> 10:21:01,120 countdown number if so then let's update 18577 10:21:02,520 --> 10:21:03,520 it so the previous one becomes this one 18578 10:21:04,200 --> 10:21:05,200 and now let's fire off the animation so 18579 10:21:06,000 --> 10:21:07,000 let's go into the animator and set the 18580 10:21:07,800 --> 10:21:08,800 trigger and again we don't want these 18581 10:21:09,840 --> 10:21:10,840 strings so let's go up to the top of the 18582 10:21:11,520 --> 10:21:12,520 file make a private cons string let's 18583 10:21:14,936 --> 10:21:15,936 call this the number pop-up 18584 10:21:17,520 --> 10:21:18,520 and number pop-up 18585 10:21:20,820 --> 10:21:21,820 okay so we have this end down here we 18586 10:21:22,980 --> 10:21:23,980 just set this trigger okay so that's it 18587 10:21:25,436 --> 10:21:26,436 pretty simple and just for fun let's 18588 10:21:27,480 --> 10:21:28,480 also add a nice sound effect so let's go 18589 10:21:29,820 --> 10:21:30,820 over here onto The Sound Manager and 18590 10:21:31,436 --> 10:21:32,436 let's make a function to play sound so 18591 10:21:33,416 --> 10:21:34,416 just like we did over here for the play 18592 10:21:35,040 --> 10:21:36,040 footstep sound let's make another one 18593 10:21:37,620 --> 10:21:38,620 for this one let's go and play countdown 18594 10:21:40,200 --> 10:21:41,200 sound and for this one let's not receive 18595 10:21:42,900 --> 10:21:43,900 a volume or position and we just play 18596 10:21:45,480 --> 10:21:46,480 let's say just the warning sound so just 18597 10:21:47,880 --> 10:21:48,880 down on Vector 3.0 and with the current 18598 10:21:50,820 --> 10:21:51,820 volume 18599 10:21:52,200 --> 10:21:53,200 okay so we have this function and then 18600 10:21:54,416 --> 10:21:55,416 down here just going to sound manager 18601 10:21:56,040 --> 10:21:57,040 instance and play the countdown sound 18602 10:21:58,020 --> 10:21:59,020 again we could refactor this code to 18603 10:22:00,480 --> 10:22:01,480 separate the Yuan logic from the 18604 10:22:02,276 --> 10:22:03,276 animation from the sound that is one 18605 10:22:04,140 --> 10:22:05,140 approach and sectionally one thing that 18606 10:22:06,240 --> 10:22:07,240 we're going to do in the next polish 18607 10:22:07,800 --> 10:22:08,800 stage but this one is also a possible 18608 10:22:09,900 --> 10:22:10,900 thing since the UI is only so directly 18609 10:22:12,480 --> 10:22:13,480 connected to visuals okay so with this 18610 10:22:14,700 --> 10:22:15,700 let's test so here in the options let's 18611 10:22:16,860 --> 10:22:17,860 just make sure that we have our sound 18612 10:22:18,480 --> 10:22:19,480 effects so let's make sure they are 18613 10:22:19,740 --> 10:22:20,740 playing okay great now let's go ahead 18614 10:22:21,900 --> 10:22:22,900 and play and there you go we have our 18615 10:22:24,180 --> 10:22:25,180 nice countdown number and there you go 18616 10:22:26,096 --> 10:22:27,096 it looks great so it looks great and 18617 10:22:27,776 --> 10:22:28,776 sounds great alright awesome as you can 18618 10:22:30,300 --> 10:22:31,300 see just by adding a simple animation 18619 10:22:31,860 --> 10:22:32,860 and some simple sounds that already 18620 10:22:33,300 --> 10:22:34,300 looks so much better now the next thing 18621 10:22:35,580 --> 10:22:36,580 we want to publish is on the stove so 18622 10:22:37,916 --> 10:22:38,916 let's go into our stove back into our 18623 10:22:39,776 --> 10:22:40,776 counters back into 3D and zoom in over 18624 10:22:42,300 --> 10:22:43,300 here okay let's also make sure that we 18625 10:22:44,820 --> 10:22:45,820 hide the canvas just so we can play 18626 10:22:46,500 --> 10:22:47,500 around this all right great so there's 18627 10:22:48,596 --> 10:22:49,596 our stove and for this we want to add 18628 10:22:51,000 --> 10:22:52,000 basically a warning icon on any nice 18629 10:22:53,276 --> 10:22:54,276 sound when the meat is about to burn so 18630 10:22:55,436 --> 10:22:56,436 let's go inside the stove counter prefab 18631 10:22:57,360 --> 10:22:58,360 okay so now inside of this we already 18632 10:22:59,340 --> 10:23:00,340 have a nice generic progress bar UI and 18633 10:23:02,460 --> 10:23:03,460 like I mentioned if you want to get some 18634 10:23:04,200 --> 10:23:05,200 more custom Behavior you can combine a 18635 10:23:06,360 --> 10:23:07,360 generic bar like this one with some 18636 10:23:08,400 --> 10:23:09,400 specific components so that's exactly 18637 10:23:09,960 --> 10:23:10,960 what we're going to do right now so over 18638 10:23:11,880 --> 10:23:12,880 here let's create a brand new canvas as 18639 10:23:14,700 --> 10:23:15,700 usual let's make it a world space canvas 18640 10:23:16,800 --> 10:23:17,800 for position let's put all of this on 18641 10:23:19,080 --> 10:23:20,080 zero 18642 10:23:20,096 --> 10:23:21,096 let's just lift it up by a bit so set it 18643 10:23:22,140 --> 10:23:23,140 on a y of three okay great then let's 18644 10:23:25,080 --> 10:23:26,080 add our super useful look at camera 18645 10:23:26,820 --> 10:23:27,820 component and make it camera phone okay 18646 10:23:29,400 --> 10:23:30,400 now inside let's go ahead create a new 18647 10:23:31,860 --> 10:23:32,860 image let's put it on a size of 0.5 by 18648 10:23:34,800 --> 10:23:35,800 0.5 okay just a nice square and for the 18649 10:23:37,620 --> 10:23:38,620 Sprite there's a nice warning image in 18650 10:23:39,840 --> 10:23:40,840 the asset so it's this one here we have 18651 10:23:41,700 --> 10:23:42,700 the warning okay great basically we want 18652 10:23:44,640 --> 10:23:45,640 to show this when the meter is about to 18653 10:23:46,020 --> 10:23:47,020 burn so let's make a screen to run this 18654 10:23:48,120 --> 10:23:49,120 and on the canvas let's give it a proper 18655 10:23:49,860 --> 10:23:50,860 name so let's call this the stove burn 18656 10:23:52,080 --> 10:23:53,080 warning UI 18657 10:23:53,580 --> 10:23:54,580 okay so let's make this crypto render so 18658 10:23:55,916 --> 10:23:56,916 when you c-sharp script with the exact 18659 10:23:57,596 --> 10:23:58,596 same name and over here let's attach a 18660 10:23:59,820 --> 10:24:00,820 script okay great so now the first thing 18661 10:24:02,160 --> 10:24:03,160 that we need is obviously a reference to 18662 10:24:03,900 --> 10:24:04,900 the stove so let's make a serialized 18663 10:24:05,640 --> 10:24:06,640 film private for the stove counter for 18664 10:24:08,340 --> 10:24:09,340 the stove counter 18665 10:24:10,256 --> 10:24:11,256 okay here in the editor let's drag the 18666 10:24:12,660 --> 10:24:13,660 reference of the sub counter okay great 18667 10:24:14,276 --> 10:24:15,276 so now we basically just need to know 18668 10:24:17,096 --> 10:24:18,096 when the food is about to burn and for 18669 10:24:19,020 --> 10:24:20,020 that we can actually listen to the on 18670 10:24:20,520 --> 10:24:21,520 progress event so let's do a private 18671 10:24:23,580 --> 10:24:24,580 void start and on start let's go into 18672 10:24:25,620 --> 10:24:26,620 the stove counter and let's listen into 18673 10:24:28,020 --> 10:24:29,020 the on progress change event okay so we 18674 10:24:30,900 --> 10:24:31,900 have this one 18675 10:24:32,276 --> 10:24:33,276 and recently we're going to want to show 18676 10:24:34,140 --> 10:24:35,140 this element so let's find a bone show 18677 10:24:36,180 --> 10:24:37,180 we're going to want to show this when 18678 10:24:38,040 --> 10:24:39,040 the progress normalized is above a 18679 10:24:40,080 --> 10:24:41,080 certain amount so let's define a float 18680 10:24:42,300 --> 10:24:43,300 for the burn show progress amount and 18681 10:24:45,240 --> 10:24:46,240 let's say 1.5 18682 10:24:46,860 --> 10:24:47,860 so on this one we show it except 18683 10:24:49,256 --> 10:24:50,256 obviously we don't want it to be shown 18684 10:24:50,936 --> 10:24:51,936 when the food is just cooking we only 18685 10:24:53,096 --> 10:24:54,096 want it to show when it's about to burn 18686 10:24:54,720 --> 10:24:55,720 so that means we also need to check the 18687 10:24:56,756 --> 10:24:57,756 state on the stove counter so let's make 18688 10:24:58,680 --> 10:24:59,680 a function to check if we are in the 18689 10:25:00,060 --> 10:25:01,060 state that we want so we're here on the 18690 10:25:01,740 --> 10:25:02,740 stove counter let's go down to the 18691 10:25:03,240 --> 10:25:04,240 bottom 18692 10:25:03,960 --> 10:25:04,960 and let's make a public bowl is fried 18693 10:25:07,620 --> 10:25:08,620 and over here we just return if the 18694 10:25:09,660 --> 10:25:10,660 state equals state DOT frame 18695 10:25:11,880 --> 10:25:12,880 okay that's great so now here we're 18696 10:25:14,160 --> 10:25:15,160 going to show if the progress is above 18697 10:25:15,540 --> 10:25:16,540 0.5 and the stove counter is on the 18698 10:25:18,960 --> 10:25:19,960 Fright state 18699 10:25:20,160 --> 10:25:21,160 all right so that's the logic that we 18700 10:25:22,080 --> 10:25:23,080 want then we just want to show our 18701 10:25:23,640 --> 10:25:24,640 height so let's make the original 18702 10:25:24,540 --> 10:25:25,540 functions private show and a private 18703 10:25:27,240 --> 10:25:28,240 void hide 18704 10:25:28,740 --> 10:25:29,740 and just do game objects and active into 18705 10:25:31,140 --> 10:25:32,140 either true or false 18706 10:25:36,900 --> 10:25:37,900 and over here if show then let's call 18707 10:25:39,900 --> 10:25:40,900 the show function and if not let's call 18708 10:25:42,360 --> 10:25:43,360 the Hide function and of course on start 18709 10:25:44,880 --> 10:25:45,880 let's start off as hidden okay that's it 18710 10:25:47,880 --> 10:25:48,880 let's test just over here in the editor 18711 10:25:50,340 --> 10:25:51,340 make sure the reference is right and 18712 10:25:52,380 --> 10:25:53,380 let's save the prefab go outside and hit 18713 10:25:54,120 --> 10:25:55,120 on point and yep right away there's no 18714 10:25:56,160 --> 10:25:57,160 element okay great now I place it and it 18715 10:25:58,436 --> 10:25:59,436 won't cooking there's no element and now 18716 10:26:00,596 --> 10:26:01,596 once it's on the halfway point for 18717 10:26:02,160 --> 10:26:03,160 burning and if there you go we've got a 18718 10:26:03,900 --> 10:26:04,900 nice warning okay awesome so now that 18719 10:26:06,120 --> 10:26:07,120 this is working let's just add a nice 18720 10:26:07,680 --> 10:26:08,680 animation so once again let's go inside 18721 10:26:09,960 --> 10:26:10,960 the stove counter and on the burn 18722 10:26:11,820 --> 10:26:12,820 warning UI let's add an animator 18723 10:26:14,640 --> 10:26:15,640 controller 18724 10:26:16,020 --> 10:26:17,020 then let's actually create the animated 18725 10:26:18,000 --> 10:26:19,000 controller so let's create a brand new 18726 10:26:19,256 --> 10:26:20,256 animated controller 18727 10:26:20,640 --> 10:26:21,640 for the stove burn warning UI 18728 10:26:23,700 --> 10:26:24,700 then let's assign it okay and over here 18729 10:26:26,460 --> 10:26:27,460 on the animation window let's create an 18730 10:26:27,840 --> 10:26:28,840 animation 18731 10:26:29,040 --> 10:26:30,040 let's put it on the same folder and call 18732 10:26:31,256 --> 10:26:32,256 it 18733 10:26:32,400 --> 10:26:33,400 for this one let's say flash we're going 18734 10:26:34,140 --> 10:26:35,140 to make it Flash and then again for 18735 10:26:36,180 --> 10:26:37,180 making it flash let's use the same 18736 10:26:37,620 --> 10:26:38,620 component that we used a while ago so 18737 10:26:39,060 --> 10:26:40,060 let's add a canvas group so here it is 18738 10:26:41,520 --> 10:26:42,520 now we can play around the alpha so 18739 10:26:43,140 --> 10:26:44,140 super useful although I should say that 18740 10:26:45,360 --> 10:26:46,360 at this point since we just have a 18741 10:26:46,980 --> 10:26:47,980 single image we could just record a 18742 10:26:49,320 --> 10:26:50,320 change over here on the alpha for the 18743 10:26:50,640 --> 10:26:51,640 image itself however one place where 18744 10:26:52,800 --> 10:26:53,800 this component is super useful is if you 18745 10:26:54,596 --> 10:26:55,596 have multiple images so if over here I 18746 10:26:57,000 --> 10:26:58,000 duplicate this one and I put it off to 18747 10:26:58,620 --> 10:26:59,620 the side if I change the alpha on one of 18748 10:27:00,660 --> 10:27:01,660 them then obviously it only affects that 18749 10:27:02,460 --> 10:27:03,460 one but if I go over here and I modify 18750 10:27:04,740 --> 10:27:05,740 the canvas group that changes the amp 18751 10:27:06,180 --> 10:27:07,180 for both of them so if you have a group 18752 10:27:07,860 --> 10:27:08,860 of images then using the canvas group 18753 10:27:10,080 --> 10:27:11,080 makes it super simple so anyway so here 18754 10:27:12,660 --> 10:27:13,660 we have just our image let's go ahead 18755 10:27:15,240 --> 10:27:16,240 and record and let's say we start off on 18756 10:27:17,580 --> 10:27:18,580 Alpha zero then after 10 frames going to 18757 10:27:19,980 --> 10:27:20,980 Alpha One and after 20 frames back into 18758 10:27:22,680 --> 10:27:23,680 an alpha of zero okay so that's it a 18759 10:27:25,436 --> 10:27:26,436 super simple very basic animation we 18760 10:27:27,416 --> 10:27:28,416 don't even need analogic since we just 18761 10:27:29,220 --> 10:27:30,220 want this animation to play Non-Stop so 18762 10:27:31,916 --> 10:27:32,916 that's great that should be working now 18763 10:27:33,960 --> 10:27:34,960 let's add some sound so for that we 18764 10:27:36,060 --> 10:27:37,060 could make another script but already on 18765 10:27:37,620 --> 10:27:38,620 the stove counter we already have a nice 18766 10:27:39,960 --> 10:27:40,960 sound component so let's open up this 18767 10:27:41,936 --> 10:27:42,936 grip the stove counter sound so this is 18768 10:27:44,040 --> 10:27:45,040 basically where we're playing or 18769 10:27:45,360 --> 10:27:46,360 stopping the sizzling sound so over here 18770 10:27:47,580 --> 10:27:48,580 we can just add the warning sound we're 18771 10:27:50,276 --> 10:27:51,276 going to play the sound just like we 18772 10:27:52,020 --> 10:27:53,020 have over here for the burning UI so 18773 10:27:54,240 --> 10:27:55,240 let's actually copy these same 18774 10:27:55,916 --> 10:27:56,916 components and over here let's face it 18775 10:27:58,380 --> 10:27:59,380 so for this one instead of show let's 18776 10:28:00,360 --> 10:28:01,360 give it a proper name so play warning 18777 10:28:03,000 --> 10:28:04,000 sound except it's not on say change so 18778 10:28:05,400 --> 10:28:06,400 let's actually listen to the other one 18779 10:28:06,596 --> 10:28:07,596 so still counter on progress change 18780 10:28:08,700 --> 10:28:09,700 let's listen down and it's on that one 18781 10:28:11,096 --> 10:28:12,096 that we use this 18782 10:28:12,776 --> 10:28:13,776 Okay so we've got that one and then for 18783 10:28:15,660 --> 10:28:16,660 playing the warning sound we're going to 18784 10:28:17,400 --> 10:28:18,400 want to basically play it every certain 18785 10:28:19,020 --> 10:28:20,020 amount of time 18786 10:28:20,220 --> 10:28:21,220 so let's make over here a private void 18787 10:28:22,320 --> 10:28:23,320 update and an update let's just Define a 18788 10:28:25,680 --> 10:28:26,680 private float for the warning sound 18789 10:28:28,080 --> 10:28:29,080 timer 18790 10:28:29,820 --> 10:28:30,820 and so down here we just count down as 18791 10:28:32,160 --> 10:28:33,160 usual time dot Delta time 18792 10:28:34,620 --> 10:28:35,620 and if this one is under zero 18793 10:28:38,756 --> 10:28:39,756 if so then let's reset it so Define a 18794 10:28:41,520 --> 10:28:42,520 certain maximum 18795 10:28:42,960 --> 10:28:43,960 let's say 10 times or maybe just five 18796 10:28:45,540 --> 10:28:46,540 times per second that should be good so 18797 10:28:47,640 --> 10:28:48,640 we have this but obviously we only want 18798 10:28:49,256 --> 10:28:50,256 this to run if we should be playing the 18799 10:28:50,880 --> 10:28:51,880 warning sound so let's actually save 18800 10:28:52,200 --> 10:28:53,200 this one up here so probably won't for 18801 10:28:54,240 --> 10:28:55,240 these play the warning sound and then we 18802 10:28:56,640 --> 10:28:57,640 set it on this one 18803 10:28:58,380 --> 10:28:59,380 and down here let's just go and we're 18804 10:29:00,776 --> 10:29:01,776 only going to run this if play the 18805 10:29:02,880 --> 10:29:03,880 warning sound then we're going to run 18806 10:29:04,256 --> 10:29:05,256 our timer logic all right and then over 18807 10:29:06,180 --> 10:29:07,180 here all we need is to play that warning 18808 10:29:08,040 --> 10:29:09,040 sound 18809 10:29:08,700 --> 10:29:09,700 so let's actually go into The Sound 18810 10:29:10,380 --> 10:29:11,380 Manager and just like we added the 18811 10:29:12,540 --> 10:29:13,540 countdown sound let's add another one so 18812 10:29:14,756 --> 10:29:15,756 let's say the play warning sound and for 18813 10:29:16,980 --> 10:29:17,980 this one let's receive a vector 3 for 18814 10:29:18,540 --> 10:29:19,540 the position and we're going to play the 18815 10:29:20,520 --> 10:29:21,520 warning sound on this position so now 18816 10:29:22,680 --> 10:29:23,680 over here on the stove counter let's go 18817 10:29:24,060 --> 10:29:25,060 into The Sound Manager the instance and 18818 10:29:26,400 --> 10:29:27,400 let's play the warning sound and pass in 18819 10:29:29,220 --> 10:29:30,220 the stove dot transform that position 18820 10:29:31,380 --> 10:29:32,380 okay that should do it so we now should 18821 10:29:34,200 --> 10:29:35,200 have a nice warning sound and over here 18822 10:29:36,120 --> 10:29:37,120 we should have a nice animation on the 18823 10:29:37,740 --> 10:29:38,740 burn warning UI so let's see both those 18824 10:29:40,080 --> 10:29:41,080 okay so let's pick up some meat and drop 18825 10:29:42,416 --> 10:29:43,416 it and right now it's cooking okay great 18826 10:29:44,700 --> 10:29:45,700 and once it gets a halfway point 18827 10:29:47,700 --> 10:29:48,700 if there go now we have a nice warning 18828 10:29:49,860 --> 10:29:50,860 sound all right awesome let's just add 18829 10:29:52,560 --> 10:29:53,560 one more tiny thing let's make the bar 18830 10:29:54,960 --> 10:29:55,960 itself also flash red when we're about 18831 10:29:56,936 --> 10:29:57,936 to burn so once again let's go inside 18832 10:29:59,220 --> 10:30:00,220 the stove counter and on the progress 18833 10:30:01,680 --> 10:30:02,680 bar UI let's add a nice animator and 18834 10:30:04,916 --> 10:30:05,916 let's go ahead and make one so let's 18835 10:30:06,540 --> 10:30:07,540 create a new animated controller for the 18836 10:30:09,000 --> 10:30:10,000 stove burn flashing bar 18837 10:30:11,520 --> 10:30:12,520 let's go ahead and assign it so it's the 18838 10:30:13,500 --> 10:30:14,500 one on the progress bar let's add the 18839 10:30:16,020 --> 10:30:17,020 stove burn flashing bar then on this one 18840 10:30:18,540 --> 10:30:19,540 let's create new animation let's go 18841 10:30:20,220 --> 10:30:21,220 inside the assets animations let's make 18842 10:30:21,960 --> 10:30:22,960 one and just call it idle for this one 18843 10:30:24,416 --> 10:30:25,416 we're going to want the exact same color 18844 10:30:25,860 --> 10:30:26,860 as the normal color so let's go into the 18845 10:30:28,320 --> 10:30:29,320 bar and set the color just save a 18846 10:30:30,776 --> 10:30:31,776 keyframe over there okay so that's what 18847 10:30:32,580 --> 10:30:33,580 we want now let's make another animation 18848 10:30:34,560 --> 10:30:35,560 so let's stop recording and let's 18849 10:30:36,000 --> 10:30:37,000 actually duplicate this one so duplicate 18850 10:30:38,040 --> 10:30:39,040 it and for this one name it flash now of 18851 10:30:41,276 --> 10:30:42,276 course we need to add it to the animated 18852 10:30:42,660 --> 10:30:43,660 controller so let's go over here and 18853 10:30:44,820 --> 10:30:45,820 drag it on top okay now for the 18854 10:30:46,916 --> 10:30:47,916 animation let's select the Flash and for 18855 10:30:49,020 --> 10:30:50,020 this one let's go ahead click on record 18856 10:30:50,756 --> 10:30:51,756 let's start off on this one and after a 18857 10:30:53,220 --> 10:30:54,220 few frames so let's say maybe after 10 18858 10:30:55,500 --> 10:30:56,500 frames let's Flash in red and after 20 18859 10:30:58,500 --> 10:30:59,500 frames let's copy paste the same frame 18860 10:31:00,360 --> 10:31:01,360 okay so that's our nice flashing bar now 18861 10:31:02,880 --> 10:31:03,880 let's just set it up so let's go into 18862 10:31:04,140 --> 10:31:05,140 the animator and over here we're going 18863 10:31:05,880 --> 10:31:06,880 to have a transition from that 18864 10:31:07,140 --> 10:31:08,140 deformation form flashback now all we 18865 10:31:10,140 --> 10:31:11,140 need of course is an animator to control 18866 10:31:11,460 --> 10:31:12,460 this so let's make a new animator 18867 10:31:13,320 --> 10:31:14,320 parameter let's make it a Boolean and 18868 10:31:15,596 --> 10:31:16,596 call it is flashing and again make sure 18869 10:31:18,300 --> 10:31:19,300 to be careful with cane sensitive 18870 10:31:20,400 --> 10:31:21,400 okay so from idle into flash let's go 18871 10:31:23,640 --> 10:31:24,640 ahead remove the exit time for the 18872 10:31:25,560 --> 10:31:26,560 duration make it instant so zero and for 18873 10:31:27,900 --> 10:31:28,900 the conditions when that one is true 18874 10:31:28,980 --> 10:31:29,980 okay great and for going back once again 18875 10:31:31,620 --> 10:31:32,620 same thing so instant and let's make the 18876 10:31:34,020 --> 10:31:35,020 condition when it's false okay that's it 18877 10:31:36,360 --> 10:31:37,360 super simple now let's make a script to 18878 10:31:38,640 --> 10:31:39,640 run this so let's go ahead create a 18879 10:31:40,916 --> 10:31:41,916 brainy sharp script for the stove burn 18880 10:31:43,320 --> 10:31:44,320 flashing bar UI let's go ahead and add 18881 10:31:46,140 --> 10:31:47,140 it to the bar so that's the flashing bar 18882 10:31:47,880 --> 10:31:48,880 UI okay over here let's do pretty much 18883 10:31:50,096 --> 10:31:51,096 the same thing that we did on the other 18884 10:31:51,840 --> 10:31:52,840 one 18885 10:31:52,740 --> 10:31:53,740 so let's go over here onto the stove 18886 10:31:54,480 --> 10:31:55,480 burn warning UI I might actually copy 18887 10:31:56,460 --> 10:31:57,460 exactly this so let's go on this one and 18888 10:31:58,680 --> 10:31:59,680 paste this one then back here in the 18889 10:32:00,720 --> 10:32:01,720 editor let's drag the reference to the 18890 10:32:02,220 --> 10:32:03,220 self counter and over here the logic is 18891 10:32:04,436 --> 10:32:05,436 going to be very very similar so the 18892 10:32:06,660 --> 10:32:07,660 only difference is we have an animator 18893 10:32:08,400 --> 10:32:09,400 so the animator and we're going to grab 18894 10:32:11,276 --> 10:32:12,276 it on private wide awake and later get 18895 10:32:13,256 --> 10:32:14,256 component of type animator 18896 10:32:16,020 --> 10:32:17,020 so we have the animator then let's 18897 10:32:17,936 --> 10:32:18,936 define the parameter so private con 18898 10:32:20,700 --> 10:32:21,700 string 18899 10:32:21,900 --> 10:32:22,900 for the is flashing 18900 10:32:24,416 --> 10:32:25,416 and let's set it is flashing okay we 18901 10:32:27,360 --> 10:32:28,360 have our parameter and now down here 18902 10:32:29,520 --> 10:32:30,520 instead of showing and hiding we'll just 18903 10:32:31,560 --> 10:32:32,560 go into the animator in order to set a 18904 10:32:33,360 --> 10:32:34,360 ball 18905 10:32:34,436 --> 10:32:35,436 and the bone will be the is flashing and 18906 10:32:37,500 --> 10:32:38,500 let's set it based on show so either we 18907 10:32:39,596 --> 10:32:40,596 show or hide and we actually don't need 18908 10:32:41,096 --> 10:32:42,096 these functions and by default of course 18909 10:32:43,436 --> 10:32:44,436 let's leave it on false okay so that's 18910 10:32:45,900 --> 10:32:46,900 it super simple Let's test just make 18911 10:32:48,840 --> 10:32:49,840 sure to save the prefab and hit on play 18912 10:32:50,820 --> 10:32:51,820 okay let's go ahead and cook so let's 18913 10:32:52,916 --> 10:32:53,916 pick it up and drop it alright so it's 18914 10:32:54,596 --> 10:32:55,596 cooking let's wait for it to be burning 18915 10:32:56,700 --> 10:32:57,700 and as soon as it gets there yeah there 18916 10:32:59,580 --> 10:33:00,580 you go we've got a nice warning a nice 18917 10:33:01,256 --> 10:33:02,256 flashing bar and a nice sound effect so 18918 10:33:03,540 --> 10:33:04,540 all three warnings making ourselves much 18919 10:33:05,520 --> 10:33:06,520 more polished alright awesome now just 18920 10:33:08,340 --> 10:33:09,340 for balancing let's play around the 18921 10:33:09,900 --> 10:33:10,900 timers so let's go into our script ball 18922 10:33:12,540 --> 10:33:13,540 objects on the frying rest BSO let's 18923 10:33:14,880 --> 10:33:15,880 make this one take five seconds 18924 10:33:17,460 --> 10:33:18,460 then on the burning recipe for this one 18925 10:33:19,560 --> 10:33:20,560 let's make it take six 18926 10:33:21,360 --> 10:33:22,360 and finally let's also add another stove 18927 10:33:23,276 --> 10:33:24,276 so let's take our self counter duplicate 18928 10:33:26,040 --> 10:33:27,040 the prefab let's put it over here so 18929 10:33:28,380 --> 10:33:29,380 rotate it to the side and let's get rid 18930 10:33:29,880 --> 10:33:30,880 of this one and put this one right in 18931 10:33:32,640 --> 10:33:33,640 there so on 7.5 0 and minus 1. all right 18932 10:33:36,720 --> 10:33:37,720 so we now have two stoves I can put one 18933 10:33:38,820 --> 10:33:39,820 cooking put another one and I can start 18934 10:33:41,340 --> 10:33:42,340 cutting down some cheese start cutting 18935 10:33:43,916 --> 10:33:44,916 and before they start to burn what's 18936 10:33:45,840 --> 10:33:46,840 actually here there you go that one is 18937 10:33:47,460 --> 10:33:48,460 about to burn so let's pick it up 18938 10:33:48,720 --> 10:33:49,720 quickly and that one is actually gonna 18939 10:33:50,460 --> 10:33:51,460 burn but I got it okay great all right 18940 10:33:53,040 --> 10:33:54,040 awesome everything's working great now 18941 10:33:55,200 --> 10:33:56,200 for one more polish element let's make a 18942 10:33:57,300 --> 10:33:58,300 nice visual when we deliver either a 18943 10:33:59,160 --> 10:34:00,160 correct or incorrect recipe I think it 18944 10:34:01,436 --> 10:34:02,436 wouldn't look good as a warm canvas on 18945 10:34:03,180 --> 10:34:04,180 top of the delivery counter so let's do 18946 10:34:04,680 --> 10:34:05,680 that let's over here find the delivery 18947 10:34:07,020 --> 10:34:08,020 counter let's go inside the prefab and 18948 10:34:09,180 --> 10:34:10,180 now in here let's create a new UI canvas 18949 10:34:11,340 --> 10:34:12,340 let's name this the delivery result UI 18950 10:34:14,040 --> 10:34:15,040 and as usual let's make this a worm 18951 10:34:16,916 --> 10:34:17,916 space canvas so put it on worst face 18952 10:34:19,680 --> 10:34:20,680 and for the position let's actually lift 18953 10:34:22,560 --> 10:34:23,560 it up and then we're going to make it 18954 10:34:23,880 --> 10:34:24,880 look at the camera but just like this it 18955 10:34:26,160 --> 10:34:27,160 might actually go inside the wall so 18956 10:34:27,596 --> 10:34:28,596 let's put it over here to the side a 18957 10:34:29,160 --> 10:34:30,160 little bit so let's put it on this 18958 10:34:30,776 --> 10:34:31,776 position so on the X of minus 1.6 on a y 18959 10:34:33,596 --> 10:34:34,596 of three and on a z of 1.2 okay that's 18960 10:34:37,380 --> 10:34:38,380 the position so right there that is 18961 10:34:39,840 --> 10:34:40,840 going to be unlocking at the camera now 18962 10:34:41,820 --> 10:34:42,820 inside let's create a new UI image it's 18963 10:34:44,756 --> 10:34:45,756 going to be our background and for the 18964 10:34:47,400 --> 10:34:48,400 size the width and height let's put it 18965 10:34:48,840 --> 10:34:49,840 on 2.2 by 0.9 18966 10:34:51,060 --> 10:34:52,060 okay that's our background for the 18967 10:34:53,340 --> 10:34:54,340 Hunger let's tinted in a nice green so 18968 10:34:55,740 --> 10:34:56,740 let's put it something like this 18969 10:34:58,020 --> 10:34:59,020 then let's also add a nice outline let's 18970 10:35:01,200 --> 10:35:02,200 put it on full Alpha and for the size 18971 10:35:04,080 --> 10:35:05,080 let's put it on 0.1.1 then let's also 18972 10:35:07,200 --> 10:35:08,200 add a nice shadow component for this one 18973 10:35:09,596 --> 10:35:10,596 leave it on half Alpha and let's put it 18974 10:35:12,000 --> 10:35:13,000 on 0.2 and minus 0.2 18975 10:35:14,220 --> 10:35:15,220 okay so that's a nice visual now on top 18976 10:35:17,096 --> 10:35:18,096 of it let's create a new UI text let's 18977 10:35:19,680 --> 10:35:20,680 call it the message text and for the 18978 10:35:22,140 --> 10:35:23,140 message we're going to say something 18979 10:35:23,220 --> 10:35:24,220 like delivery and then underneath 18980 10:35:25,200 --> 10:35:26,200 success let's put it on a width and 18981 10:35:27,776 --> 10:35:28,776 height of zero let's put it on a super 18982 10:35:29,936 --> 10:35:30,936 tiny font so let's say just 0.25 let's 18983 10:35:32,700 --> 10:35:33,700 put it in bold and put it down Center 18984 10:35:34,860 --> 10:35:35,860 and get rid of wrapping okay that's it 18985 10:35:37,140 --> 10:35:38,140 let's just push it a little bit on the 18986 10:35:38,700 --> 10:35:39,700 left side so on minus 0.32 on the X okay 18987 10:35:41,820 --> 10:35:42,820 and now next to it let's make another UI 18988 10:35:44,520 --> 10:35:45,520 image for this one call it the icon 18989 10:35:46,916 --> 10:35:47,916 image let's put it with a size of 0.5 by 18990 10:35:49,800 --> 10:35:50,800 0.5 and put it over to the right side so 18991 10:35:52,200 --> 10:35:53,200 on an X of 0.7 okay and now for these 18992 10:35:55,080 --> 10:35:56,080 Sprites including the assets are too 18993 10:35:56,936 --> 10:35:57,936 nice sprites so there's a nice cross for 18994 10:35:58,860 --> 10:35:59,860 when we get it wrong and there's a nice 18995 10:36:00,660 --> 10:36:01,660 tick okay so that's the setup that we 18996 10:36:03,000 --> 10:36:04,000 want now on the delivery result UI let's 18997 10:36:05,340 --> 10:36:06,340 go ahead add our own look at the camera 18998 10:36:06,900 --> 10:36:07,900 component and for this one let's go 18999 10:36:08,756 --> 10:36:09,756 different so instead of the camera four 19000 10:36:10,320 --> 10:36:11,320 let's go ahead with the unlock at 19001 10:36:12,180 --> 10:36:13,180 inverting so there it is this is our 19002 10:36:14,160 --> 10:36:15,160 setup now let's make the script run this 19003 10:36:16,320 --> 10:36:17,320 so let's go ahead create the new UI new 19004 10:36:19,500 --> 10:36:20,500 c-sharp script for the delivery result 19005 10:36:21,540 --> 10:36:22,540 UI let's attach the script and open okay 19006 10:36:24,776 --> 10:36:25,776 so now here on let's make serialized 19007 10:36:26,276 --> 10:36:27,276 films for our elements so a serialized 19008 10:36:28,740 --> 10:36:29,740 film 19009 10:36:29,936 --> 10:36:30,936 first of all for the background image 19010 10:36:31,860 --> 10:36:32,860 and this is actually going to be a Type 19011 10:36:33,660 --> 10:36:34,660 image image inside in the engine.ui okay 19012 10:36:36,660 --> 10:36:37,660 our background image then we're going to 19013 10:36:38,756 --> 10:36:39,756 have another one for the icon image and 19014 10:36:41,096 --> 10:36:42,096 we're going to have another one this one 19015 10:36:42,480 --> 10:36:43,480 is a text mesh Pro e GUI for the message 19016 10:36:44,580 --> 10:36:45,580 text 19017 10:36:45,900 --> 10:36:46,900 okay let's save okay so let's drag the 19018 10:36:48,900 --> 10:36:49,900 references to the background the message 19019 10:36:51,120 --> 10:36:52,120 text and the icon image okay great and 19020 10:36:53,936 --> 10:36:54,936 over here let's listen when a delivery 19021 10:36:55,800 --> 10:36:56,800 is delivered so let's make a private 19022 10:36:57,660 --> 10:36:58,660 start let's go into the delivery manager 19023 10:37:00,540 --> 10:37:01,540 the instance and we have all of our next 19024 10:37:03,300 --> 10:37:04,300 events so we've got a success and a 19025 10:37:05,520 --> 10:37:06,520 field so let's listen into both them 19026 10:37:07,980 --> 10:37:08,980 so both the success and on the recipe 19027 10:37:10,200 --> 10:37:11,200 failed let's listen to all these and as 19028 10:37:13,020 --> 10:37:14,020 always let's write good point code and 19029 10:37:14,756 --> 10:37:15,756 rename this so the delivery manager on 19030 10:37:17,160 --> 10:37:18,160 recipe success and for this one is the 19031 10:37:19,916 --> 10:37:20,916 on recipe failed 19032 10:37:22,560 --> 10:37:23,560 okay we have both of our events 19033 10:37:25,436 --> 10:37:26,436 so over here it's actually going to be 19034 10:37:27,000 --> 10:37:28,000 very simple we just want to play around 19035 10:37:28,916 --> 10:37:29,916 the text the icon and the background 19036 10:37:30,776 --> 10:37:31,776 color so for example when we fail let's 19037 10:37:33,300 --> 10:37:34,300 go 19038 10:37:34,256 --> 10:37:35,256 and we want to set the background image 19039 10:37:36,360 --> 10:37:37,360 to about a red so for defining the 19040 10:37:38,276 --> 10:37:39,276 column let's actually go here and Define 19041 10:37:40,380 --> 10:37:41,380 a color for the success color and we're 19042 10:37:44,096 --> 10:37:45,096 going to have another one for the failed 19043 10:37:46,020 --> 10:37:47,020 color 19044 10:37:47,040 --> 10:37:48,040 and then for the Sprites let's also have 19045 10:37:48,960 --> 10:37:49,960 that so Sprite for the success Sprite 19046 10:37:51,240 --> 10:37:52,240 and another one for the failed Sprite 19047 10:37:54,240 --> 10:37:55,240 okay those are on the elements so we're 19048 10:37:56,640 --> 10:37:57,640 here in the editor let's just set them 19049 10:37:58,020 --> 10:37:59,020 so for the success column let's actually 19050 10:37:59,640 --> 10:38:00,640 use the exact same color by the way 19051 10:38:01,916 --> 10:38:02,916 here's a quick tip if you go up to film 19052 10:38:04,020 --> 10:38:05,020 for example like this one on the color 19053 10:38:05,340 --> 10:38:06,340 you can right click and copy and then go 19054 10:38:08,040 --> 10:38:09,040 into delivery results and over here 19055 10:38:09,596 --> 10:38:10,596 right click and paste there go the 19056 10:38:11,220 --> 10:38:12,220 perfect color then for the final color 19057 10:38:13,320 --> 10:38:14,320 let's go with the red maybe a bit darker 19058 10:38:15,660 --> 10:38:16,660 and also importantly make sure you set 19059 10:38:17,460 --> 10:38:18,460 the alpha to phone okay so we have a red 19060 10:38:19,800 --> 10:38:20,800 nice and like that okay then the success 19061 10:38:22,380 --> 10:38:23,380 Sprite this one is going to be the tech 19062 10:38:24,060 --> 10:38:25,060 and for the fail this is going to be the 19063 10:38:26,220 --> 10:38:27,220 cross okay those are all of our elements 19064 10:38:28,620 --> 10:38:29,620 so over here when we fail let's go into 19065 10:38:30,900 --> 10:38:31,900 the background image and set the color 19066 10:38:32,880 --> 10:38:33,880 and let's put the fan color then for the 19067 10:38:36,000 --> 10:38:37,000 icon image let's set the Sprite to the 19068 10:38:37,980 --> 10:38:38,980 Fey on Sprite 19069 10:38:39,660 --> 10:38:40,660 and for the message text let's set this 19070 10:38:42,720 --> 10:38:43,720 one for delivery and then failed 19071 10:38:46,680 --> 10:38:47,680 by the way this backward slash n this 19072 10:38:48,660 --> 10:38:49,660 means a new line so we're going to let 19073 10:38:50,096 --> 10:38:51,096 you set the text on this one so it 19074 10:38:51,960 --> 10:38:52,960 essentially means that it won't write 19075 10:38:53,160 --> 10:38:54,160 delivery then new line and then failed 19076 10:38:55,256 --> 10:38:56,256 underneath just make sure you're using 19077 10:38:57,300 --> 10:38:58,300 the Packer slash and not the forward 19078 10:38:58,860 --> 10:38:59,860 slash so use the backwards one there you 19079 10:39:01,140 --> 10:39:02,140 go there's a new line okay so that's the 19080 10:39:03,060 --> 10:39:04,060 on recipe film and now on the recipe 19081 10:39:04,800 --> 10:39:05,800 success let's use the success color the 19082 10:39:07,740 --> 10:39:08,740 success Sprite and over here the 19083 10:39:10,320 --> 10:39:11,320 delivery success okay so that's great 19084 10:39:12,960 --> 10:39:13,960 that should be working now just one more 19085 10:39:15,000 --> 10:39:16,000 visual thing let's add a nice animation 19086 10:39:17,520 --> 10:39:18,520 so just like we did previously let's go 19087 10:39:19,980 --> 10:39:20,980 over here over here and let's add an 19088 10:39:21,660 --> 10:39:22,660 animator component 19089 10:39:23,460 --> 10:39:24,460 let's create an animation for this one 19090 10:39:25,320 --> 10:39:26,320 for delivery result UI so let's go up 19091 10:39:27,360 --> 10:39:28,360 here create a brand new animated 19092 10:39:29,340 --> 10:39:30,340 controller for this and let's go ahead 19093 10:39:31,500 --> 10:39:32,500 and assign it so delivery result UI all 19094 10:39:34,256 --> 10:39:35,256 right now let's make an animation so 19095 10:39:36,416 --> 10:39:37,416 this delivery result UI let's call it 19096 10:39:38,400 --> 10:39:39,400 just pop-up and for this one let's do 19097 10:39:40,380 --> 10:39:41,380 just like we did for numbers so let's 19098 10:39:42,360 --> 10:39:43,360 scale and rotate it however if we rotate 19099 10:39:45,120 --> 10:39:46,120 that's actually not going to work that 19100 10:39:47,160 --> 10:39:48,160 is because we have the unlocked camera 19101 10:39:48,540 --> 10:39:49,540 and this one is already going to be 19102 10:39:49,740 --> 10:39:50,740 setting the rotation so we would end up 19103 10:39:52,080 --> 10:39:53,080 with this script finding the animator 19104 10:39:53,520 --> 10:39:54,520 for the rotation so that would mess 19105 10:39:55,680 --> 10:39:56,680 things up however one nice and simple 19106 10:39:57,776 --> 10:39:58,776 solution to this 19107 10:39:59,220 --> 10:40:00,220 basically we just put this inside 19108 10:40:00,776 --> 10:40:01,776 another game object so let's create a 19109 10:40:03,180 --> 10:40:04,180 new game object and let's put it inside 19110 10:40:04,800 --> 10:40:05,800 what's an empty game object for the 19111 10:40:06,840 --> 10:40:07,840 delivery result rewind then look at the 19112 10:40:08,936 --> 10:40:09,936 camera 19113 10:40:09,900 --> 10:40:10,900 so we have this one now the reason why I 19114 10:40:11,880 --> 10:40:12,880 created it inside is that so over here 19115 10:40:13,860 --> 10:40:14,860 we can set everything to zero and now 19116 10:40:16,140 --> 10:40:17,140 with that one on zero we can go ahead 19117 10:40:18,060 --> 10:40:19,060 and drag this outside of this object and 19118 10:40:20,220 --> 10:40:21,220 there you go that one keeps the exact 19119 10:40:21,596 --> 10:40:22,596 same settings and on this one we can add 19120 10:40:23,756 --> 10:40:24,756 the unlocked camera component and set it 19121 10:40:25,916 --> 10:40:26,916 up just like we had so then we'll look 19122 10:40:27,300 --> 10:40:28,300 at inverting and on this one we're going 19123 10:40:29,580 --> 10:40:30,580 to make a channel live down and there 19124 10:40:31,140 --> 10:40:32,140 you go now everything is on zero exactly 19125 10:40:32,756 --> 10:40:33,756 as it should be and on this one we can 19126 10:40:34,560 --> 10:40:35,560 get rid of the unlocked camera and now 19127 10:40:36,480 --> 10:40:37,480 we can indeed play around the rotation 19128 10:40:38,040 --> 10:40:39,040 so for the animation let's just go ahead 19129 10:40:39,776 --> 10:40:40,776 and set it so for this one let's go up 19130 10:40:42,060 --> 10:40:43,060 to one second 19131 10:40:43,380 --> 10:40:44,380 and let's record a keyframe on a scale 19132 10:40:45,840 --> 10:40:46,840 of one and on a rotation of zero then 19133 10:40:49,200 --> 10:40:50,200 let's go back into the beginning and for 19134 10:40:51,300 --> 10:40:52,300 this one let's scale it backwards so 19135 10:40:53,700 --> 10:40:54,700 maybe something like this maybe a 15 19136 10:40:56,160 --> 10:40:57,160 let's put it quite a bit smaller then 19137 10:40:58,500 --> 10:40:59,500 let's go up by three frames let's put 19138 10:41:00,776 --> 10:41:01,776 that one on -15 so rotation on the other 19139 10:41:02,880 --> 10:41:03,880 side and put it quite a bit bigger and 19140 10:41:05,700 --> 10:41:06,700 then on frame 10 put it on say 1.1 19141 10:41:09,360 --> 10:41:10,360 with a rotation of zero just like that 19142 10:41:11,756 --> 10:41:12,756 so there you go there's a nice pop-up 19143 10:41:13,860 --> 10:41:14,860 and for the alpha let's also go over 19144 10:41:16,740 --> 10:41:17,740 here into the 50 and let's just add the 19145 10:41:19,500 --> 10:41:20,500 canvas group let's set this one over 19146 10:41:21,720 --> 10:41:22,720 here is on one and then we scroll it 19147 10:41:24,120 --> 10:41:25,120 down to zero okay so that's our nice 19148 10:41:26,400 --> 10:41:27,400 animation let's stop recording let's 19149 10:41:29,160 --> 10:41:30,160 open up the animated controller and over 19150 10:41:31,140 --> 10:41:32,140 here let's make our nice animations 19151 10:41:33,360 --> 10:41:34,360 transition so transition from any state 19152 10:41:35,700 --> 10:41:36,700 into that one let's make it based on a 19153 10:41:37,740 --> 10:41:38,740 trigger let's call it just pop-up 19154 10:41:40,200 --> 10:41:41,200 and for this one this says no exit time 19155 10:41:43,020 --> 10:41:44,020 duration of zero and let's go when the 19156 10:41:46,080 --> 10:41:47,080 condition when we have this trigger okay 19157 10:41:47,936 --> 10:41:48,936 so that's it although one thing by 19158 10:41:49,800 --> 10:41:50,800 default this animation is going to Loop 19159 10:41:51,480 --> 10:41:52,480 so let's just go ahead we can select the 19160 10:41:53,700 --> 10:41:54,700 animation and over here let's just 19161 10:41:55,800 --> 10:41:56,800 untick Loop time so that way the 19162 10:41:57,480 --> 10:41:58,480 animation will not Loop okay so that's 19163 10:41:59,640 --> 10:42:00,640 great now let's go into the script and 19164 10:42:01,560 --> 10:42:02,560 over here let's get our animator so 19165 10:42:03,360 --> 10:42:04,360 private animator animator 19166 10:42:06,200 --> 10:42:07,200 let's get the animator just get 19167 10:42:08,460 --> 10:42:09,460 component of type animator 19168 10:42:12,960 --> 10:42:13,960 and let's define over here the private 19169 10:42:15,300 --> 10:42:16,300 constring for the pop-up 19170 10:42:22,560 --> 10:42:23,560 so we have this and then when we have 19171 10:42:24,480 --> 10:42:25,480 either fail or success let's just go 19172 10:42:26,820 --> 10:42:27,820 into the animator 19173 10:42:28,740 --> 10:42:29,740 and let's set the trigger for our pop-up 19174 10:42:31,380 --> 10:42:32,380 both up here and over here now we just 19175 10:42:34,436 --> 10:42:35,436 have obviously one issue which is that 19176 10:42:36,120 --> 10:42:37,120 it starts off as visible we don't want 19177 10:42:37,800 --> 10:42:38,800 that so over here we can just do game 19178 10:42:40,080 --> 10:42:41,080 objects set active into false in order 19179 10:42:42,360 --> 10:42:43,360 to hide it and when we get either of 19180 10:42:44,276 --> 10:42:45,276 these let's set it both to true 19181 10:42:46,860 --> 10:42:47,860 then afterwards the animation won't make 19182 10:42:48,900 --> 10:42:49,900 it invisible so it will still be active 19183 10:42:50,580 --> 10:42:51,580 but it won't be invisible so that's fine 19184 10:42:52,140 --> 10:42:53,140 so just with this everything should be 19185 10:42:53,880 --> 10:42:54,880 working as we want so let's test let's 19186 10:42:55,916 --> 10:42:56,916 just make sure to save it and go back 19187 10:42:57,480 --> 10:42:58,480 okay so here we are let's try delivering 19188 10:42:59,756 --> 10:43:00,756 an incorrect plate and there you go 19189 10:43:01,380 --> 10:43:02,380 Gotta delivery film okay great now let's 19190 10:43:03,360 --> 10:43:04,360 try delivering a correct one so someone 19191 10:43:05,460 --> 10:43:06,460 wants a cheeseburger so let's cook it 19192 10:43:07,740 --> 10:43:08,740 slice some cheese let's get some bread 19193 10:43:10,800 --> 10:43:11,800 so bread cheese and pick up the burger 19194 10:43:13,020 --> 10:43:14,020 and deliver and there you go a nice 19195 10:43:14,936 --> 10:43:15,936 delivery success all right awesome 19196 10:43:17,520 --> 10:43:18,520 okay so with these handphone changes you 19197 10:43:19,740 --> 10:43:20,740 can already see how we made quite a big 19198 10:43:21,240 --> 10:43:22,240 difference in our game we didn't do 19199 10:43:23,040 --> 10:43:24,040 anything to change any core mechanics we 19200 10:43:25,140 --> 10:43:26,140 just made what was already there pop out 19201 10:43:26,880 --> 10:43:27,880 we added a nice visual boundary to make 19202 10:43:29,096 --> 10:43:30,096 the map look nice we added some nice 19203 10:43:31,320 --> 10:43:32,320 particles when the character is moving 19204 10:43:32,756 --> 10:43:33,756 then we added a nice tutorial and 19205 10:43:34,740 --> 10:43:35,740 controls right as the game starts we 19206 10:43:36,900 --> 10:43:37,900 also added a bunch of effects on the 19207 10:43:38,340 --> 10:43:39,340 stove so it flashes has a warning and 19208 10:43:40,256 --> 10:43:41,256 some sound and lastly we also added a 19209 10:43:42,480 --> 10:43:43,480 nice pop-up when delivery is delivered 19210 10:43:44,276 --> 10:43:45,276 whether correctly or incorrectly 19211 10:43:46,500 --> 10:43:47,500 now of course we can always keep 19212 10:43:47,936 --> 10:43:48,936 publishing the game until Infinity 19213 10:43:49,080 --> 10:43:50,080 there's always more small things you can 19214 10:43:51,240 --> 10:43:52,240 add to punish the game just a little bit 19215 10:43:52,800 --> 10:43:53,800 more but at this point I'm very happy 19216 10:43:54,776 --> 10:43:55,776 with what the game looks like so after 19217 10:43:56,640 --> 10:43:57,640 all this work let's go into the next 19218 10:43:58,020 --> 10:43:59,020 lecture where we're going to play our 19219 10:43:59,460 --> 10:44:00,460 game from start to finish and see what 19220 10:44:00,960 --> 10:44:01,960 we've done 19221 10:44:02,520 --> 10:44:03,520 hello and welcome I'm your kudmaki in 19222 10:44:05,460 --> 10:44:06,460 this lecture we're going to look at all 19223 10:44:06,900 --> 10:44:07,900 the work that we've done and have some 19224 10:44:08,580 --> 10:44:09,580 fun playing the final game okay so here 19225 10:44:11,160 --> 10:44:12,160 we are in our nice starting main menu 19226 10:44:13,020 --> 10:44:14,020 it's simple but it works I actually 19227 10:44:14,880 --> 10:44:15,880 thinking looks pretty good so we have 19228 10:44:16,980 --> 10:44:17,980 our main menu working and we also have 19229 10:44:18,720 --> 10:44:19,720 the unloading system that we made so as 19230 10:44:20,700 --> 10:44:21,700 soon as I click on Play There You Go 19231 10:44:22,140 --> 10:44:23,140 loads in loading scene and here we are 19232 10:44:23,880 --> 10:44:24,880 on the game scene so we start off with 19233 10:44:25,680 --> 10:44:26,680 our really nice tutorial window and down 19234 10:44:27,720 --> 10:44:28,720 here we have the controls of course some 19235 10:44:29,400 --> 10:44:30,400 of these are dynamics so depending on if 19236 10:44:31,200 --> 10:44:32,200 the player rebinds or something this one 19237 10:44:32,936 --> 10:44:33,936 is going to update so we can look at 19238 10:44:34,916 --> 10:44:35,916 this window for as long as we want the 19239 10:44:36,416 --> 10:44:37,416 game is paused in the background so it's 19240 10:44:38,160 --> 10:44:39,160 on a paused game state 19241 10:44:39,776 --> 10:44:40,776 then whenever ready we can interact 19242 10:44:42,540 --> 10:44:43,540 so again that's the game input class 19243 10:44:44,400 --> 10:44:45,400 listening to the input and again all of 19244 10:44:46,436 --> 10:44:47,436 the code in here is really nice and 19245 10:44:47,820 --> 10:44:48,820 clean so when we press enter key the 19246 10:44:50,640 --> 10:44:51,640 tutorial isn't directly listening to 19247 10:44:52,200 --> 10:44:53,200 that but rather the general kitchen game 19248 10:44:54,000 --> 10:44:55,000 manager that main State machine is the 19249 10:44:55,980 --> 10:44:56,980 one listening to the input and this one 19250 10:44:57,416 --> 10:44:58,416 is listening to that state 19251 10:44:58,980 --> 10:44:59,980 so our logic is very well organized all 19252 10:45:01,980 --> 10:45:02,980 of the elements only listen to the 19253 10:45:03,540 --> 10:45:04,540 things that make sense to them so 19254 10:45:05,096 --> 10:45:06,096 anyways here we have tutorial let's 19255 10:45:06,660 --> 10:45:07,660 interact and there you go we've got our 19256 10:45:08,220 --> 10:45:09,220 nice game start countdown some really 19257 10:45:10,140 --> 10:45:11,140 nice animation really nice sound and yep 19258 10:45:12,000 --> 10:45:13,000 here we are then we've got our clock 19259 10:45:14,096 --> 10:45:15,096 showing the game time and on the left 19260 10:45:15,900 --> 10:45:16,900 side we can see our recipes once again 19261 10:45:18,180 --> 10:45:19,180 all of the elements they're all Dynamic 19262 10:45:19,916 --> 10:45:20,916 they're all spawn randomly and the icons 19263 10:45:22,560 --> 10:45:23,560 for all of the recipes they're also all 19264 10:45:24,900 --> 10:45:25,900 Dynamic so over here we have the 19265 10:45:26,820 --> 10:45:27,820 character control that we built we have 19266 10:45:28,560 --> 10:45:29,560 the collisions that we implemented and 19267 10:45:30,416 --> 10:45:31,416 of course we have the raycast testing 19268 10:45:32,276 --> 10:45:33,276 for interaction so we can identify all 19269 10:45:33,960 --> 10:45:34,960 the objects in front 19270 10:45:35,340 --> 10:45:36,340 let's begin delivering some recipes so 19271 10:45:37,320 --> 10:45:38,320 for example we need to cook some meat so 19272 10:45:39,240 --> 10:45:40,240 let's go ahead put it on the stove so 19273 10:45:40,860 --> 10:45:41,860 here is the really nice tape machine 19274 10:45:42,240 --> 10:45:43,240 that we built so we've got all the 19275 10:45:44,400 --> 10:45:45,400 various States we've got the visual 19276 10:45:45,776 --> 10:45:46,776 completely separated from the logic so 19277 10:45:47,276 --> 10:45:48,276 everything is really nice and of course 19278 10:45:48,900 --> 10:45:49,900 here we have the nice burning elements 19279 10:45:50,700 --> 10:45:51,700 that we added in the Polish lecture so 19280 10:45:52,800 --> 10:45:53,800 that one is burned so let's go ahead and 19281 10:45:54,240 --> 10:45:55,240 use the trash bin to get rid of that 19282 10:45:56,276 --> 10:45:57,276 so let's go ahead cook another one and 19283 10:45:58,500 --> 10:45:59,500 let's make a cheeseburger so let's put 19284 10:46:00,000 --> 10:46:01,000 some cheese let's listen to the aunt 19285 10:46:01,620 --> 10:46:02,620 interaction key and we can slice the 19286 10:46:03,416 --> 10:46:04,416 cheese we can pick up the meat pick up 19287 10:46:05,756 --> 10:46:06,756 the cheese then also pick up some bread 19288 10:46:07,740 --> 10:46:08,740 and deliver the recipe and there you go 19289 10:46:09,720 --> 10:46:10,720 our nice polish visual all right awesome 19290 10:46:12,120 --> 10:46:13,120 so here you can already see everything 19291 10:46:13,740 --> 10:46:14,740 that we've built the character the 19292 10:46:15,840 --> 10:46:16,840 physics the logic the input all of the 19293 10:46:17,820 --> 10:46:18,820 UI elements all of the worm UI elements 19294 10:46:19,860 --> 10:46:20,860 of the various counters and how they are 19295 10:46:21,776 --> 10:46:22,776 on prefab variants of the plates the 19296 10:46:24,360 --> 10:46:25,360 separation between the visuals and logic 19297 10:46:26,160 --> 10:46:27,160 separation between the sounds and logic 19298 10:46:28,740 --> 10:46:29,740 of the Polish elements that we made over 19299 10:46:30,900 --> 10:46:31,900 there the nice shadow graph that we made 19300 10:46:32,640 --> 10:46:33,640 then of course some of the basic things 19301 10:46:34,500 --> 10:46:35,500 that a lot of tutorials won't teach you 19302 10:46:35,880 --> 10:46:36,880 like for example how to make a pause 19303 10:46:37,256 --> 10:46:38,256 menu how to make the options 19304 10:46:39,060 --> 10:46:40,060 how to modify the Sound and Music Volume 19305 10:46:41,096 --> 10:46:42,096 how to rebind the Keys and so on 19306 10:46:43,436 --> 10:46:44,436 so with all that here throughout this 19307 10:46:44,880 --> 10:46:45,880 course we'll learn how to make a really 19308 10:46:46,256 --> 10:46:47,256 nice game with lots of interesting 19309 10:46:48,000 --> 10:46:49,000 interactions which you can now apply to 19310 10:46:49,860 --> 10:46:50,860 any kind of game any kind of genre you 19311 10:46:51,480 --> 10:46:52,480 want so like I mentioned in the very 19312 10:46:53,276 --> 10:46:54,276 beginning 19313 10:46:54,360 --> 10:46:55,360 you can take pretty much what we've made 19314 10:46:55,980 --> 10:46:56,980 here which is really just a character 19315 10:46:57,596 --> 10:46:58,596 controller and a bunch of interesting 19316 10:46:59,276 --> 10:47:00,276 interactions you can take everything 19317 10:47:00,960 --> 10:47:01,960 that you've learned here and make 19318 10:47:02,400 --> 10:47:03,400 something on a Sci-Fi space like for 19319 10:47:04,380 --> 10:47:05,380 example make something like Among Us you 19320 10:47:06,180 --> 10:47:07,180 can make something like FTL or perhaps 19321 10:47:08,340 --> 10:47:09,340 make some kind of survival crafting game 19322 10:47:10,740 --> 10:47:11,740 some of the interactions you would have 19323 10:47:12,416 --> 10:47:13,416 like resource nodes in the world then 19324 10:47:14,340 --> 10:47:15,340 you can interact together those 19325 10:47:15,596 --> 10:47:16,596 resources so with that you could build 19326 10:47:17,520 --> 10:47:18,520 something like rust or Minecraft or 19327 10:47:19,500 --> 10:47:20,500 Don't Starve so hopefully in this course 19328 10:47:21,596 --> 10:47:22,596 you'll learn a ton that you can now 19329 10:47:22,916 --> 10:47:23,916 apply to your own custom original 19330 10:47:24,300 --> 10:47:25,300 projects and if you've made it this far 19331 10:47:26,220 --> 10:47:27,220 then congratulations let's go into the 19332 10:47:28,256 --> 10:47:29,256 next lecture where I'll give you my 19333 10:47:29,756 --> 10:47:30,756 closing thoughts 19334 10:47:31,380 --> 10:47:32,380 hello and welcome I'm your code monkey 19335 10:47:33,300 --> 10:47:34,300 and congratulations you have completed 19336 10:47:35,640 --> 10:47:36,640 this course awesome seriously congrats 19337 10:47:38,340 --> 10:47:39,340 looking at the stats on my courses very 19338 10:47:40,560 --> 10:47:41,560 few people stick with it until the very 19339 10:47:42,180 --> 10:47:43,180 end so if you're hearing this then 19340 10:47:44,040 --> 10:47:45,040 that's excellent you're on the top 10 19341 10:47:45,660 --> 10:47:46,660 percent it means you are serious about 19342 10:47:47,756 --> 10:47:48,756 learning game development and I 19343 10:47:49,320 --> 10:47:50,320 generally hope this course has helped 19344 10:47:50,640 --> 10:47:51,640 you on your own Game Dev Journey 19345 10:47:51,900 --> 10:47:52,900 throughout this course you'll learn 19346 10:47:53,580 --> 10:47:54,580 about the basics of unity and c-sharp 19347 10:47:55,860 --> 10:47:56,860 you'll learn how to make a character 19348 10:47:57,120 --> 10:47:58,120 controller how to do a physics raycast 19349 10:47:59,160 --> 10:48:00,160 and use that for both Collision 19350 10:48:00,540 --> 10:48:01,540 detection and identifying objects to 19351 10:48:02,580 --> 10:48:03,580 interact with you'll learn about c-sharp 19352 10:48:04,860 --> 10:48:05,860 interface and events two extremely 19353 10:48:06,596 --> 10:48:07,596 useful c-sharp features you'll learn 19354 10:48:08,936 --> 10:48:09,936 about script mode objects how to use the 19355 10:48:10,800 --> 10:48:11,800 new input system should graph and tons 19356 10:48:12,720 --> 10:48:13,720 tons more and the most important thing 19357 10:48:14,880 --> 10:48:15,880 of all you'll learn how to build a 19358 10:48:16,320 --> 10:48:17,320 relatively complex game while writing 19359 10:48:18,180 --> 10:48:19,180 good clean code I really hope that's the 19360 10:48:20,700 --> 10:48:21,700 main takeaway you'll learn from this 19361 10:48:22,020 --> 10:48:23,020 course learning how to write better high 19362 10:48:24,300 --> 10:48:25,300 quality code learning how to refactor 19363 10:48:26,340 --> 10:48:27,340 how to keep the visuals and logic 19364 10:48:28,020 --> 10:48:29,020 separate keep the UI the couple from 19365 10:48:29,700 --> 10:48:30,700 logic learning all those things has now 19366 10:48:31,800 --> 10:48:32,800 made you a 10 times better developer 19367 10:48:33,540 --> 10:48:34,540 than when you started 19368 10:48:34,916 --> 10:48:35,916 so I really hope you enjoyed learning 19369 10:48:36,720 --> 10:48:37,720 all that let me know in the comments 19370 10:48:38,276 --> 10:48:39,276 what was the most important thing you'll 19371 10:48:39,660 --> 10:48:40,660 learn throughout this course I really 19372 10:48:41,340 --> 10:48:42,340 hope this was very fun and very 19373 10:48:43,140 --> 10:48:44,140 educational if you enjoyed my teaching 19374 10:48:45,240 --> 10:48:46,240 style check out my other courses I 19375 10:48:47,096 --> 10:48:48,096 really think the turn-based strategy 19376 10:48:48,480 --> 10:48:49,480 course would be excellent for you right 19377 10:48:49,916 --> 10:48:50,916 now it Dives even deeper into some 19378 10:48:52,200 --> 10:48:53,200 Advanced topics and since you've watched 19379 10:48:53,880 --> 10:48:54,880 this entire course all the way you now 19380 10:48:55,620 --> 10:48:56,620 have all the knowledge needed to follow 19381 10:48:57,000 --> 10:48:58,000 that course it will help you really 19382 10:48:58,740 --> 10:48:59,740 simply the final knowledge you gained 19383 10:49:00,360 --> 10:49:01,360 especially everything related to writing 19384 10:49:02,276 --> 10:49:03,276 good high quality clean code and since 19385 10:49:04,380 --> 10:49:05,380 you use Unity check out my ultimate DND 19386 10:49:06,480 --> 10:49:07,480 overview course it covers lots of tools 19387 10:49:08,640 --> 10:49:09,640 and features of the engine so you can 19388 10:49:10,140 --> 10:49:11,140 really use all the tones at your 19389 10:49:11,580 --> 10:49:12,580 disposal to make any game you can think 19390 10:49:13,320 --> 10:49:14,320 of alternatively if you like visual 19391 10:49:15,776 --> 10:49:16,776 scripting I have course on that or learn 19392 10:49:17,936 --> 10:49:18,936 how to make a really nice Builder 19393 10:49:19,380 --> 10:49:20,380 Defender game and definitely make sure 19394 10:49:21,120 --> 10:49:22,120 that you wishlist my upcoming steam game 19395 10:49:22,916 --> 10:49:23,916 total one Liberation I won't be posting 19396 10:49:25,256 --> 10:49:26,256 devlogs and in those you will see how 19397 10:49:27,120 --> 10:49:28,120 the code that I use in my own steam game 19398 10:49:28,740 --> 10:49:29,740 is on the same level of quality as what 19399 10:49:30,840 --> 10:49:31,840 you learned in this course okay so 19400 10:49:32,820 --> 10:49:33,820 that's it for me this course was a ton 19401 10:49:34,740 --> 10:49:35,740 of work so I generally hope it helped 19402 10:49:36,360 --> 10:49:37,360 you a ton on your gamedev journey thank 19403 10:49:38,520 --> 10:49:39,520 you so much for watching and I'll see 19404 10:49:40,080 --> 10:49:41,080 you next time1495568

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.