All language subtitles for [English (auto-generated)] Learn Unity Beginner_Intermediate 2023 (FREE COMPLETE Course - Unity Tutorial) [DownSub.com]

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:02,100 hello and welcome I'm your code monkey 2 00:00:02,100 --> 00:00:04,620 and here is a free complete course on 3 00:00:04,620 --> 00:00:06,839 making a game from start to finish if 4 00:00:06,839 --> 00:00:08,220 you've always wanted to learn how to 5 00:00:08,220 --> 00:00:10,019 make a game or if you already know the 6 00:00:10,019 --> 00:00:11,880 basics but want to see how to organize a 7 00:00:11,880 --> 00:00:13,620 more complex project then this video is 8 00:00:13,620 --> 00:00:16,020 for you it's perfect for both beginners 9 00:00:16,020 --> 00:00:18,720 and more intermediate users this is a 10 00:00:18,720 --> 00:00:20,699 completely free course video but it has 11 00:00:20,699 --> 00:00:22,500 the same level of quality as my paid 12 00:00:22,500 --> 00:00:24,600 courses or my Steam games you can 13 00:00:24,600 --> 00:00:26,039 download the project files to follow 14 00:00:26,039 --> 00:00:28,260 along or inspect the funnel game you can 15 00:00:28,260 --> 00:00:29,820 even play the final game directly on 16 00:00:29,820 --> 00:00:31,679 scene we're going to start commonly from 17 00:00:31,679 --> 00:00:33,420 scratch and build a really awesome game 18 00:00:33,420 --> 00:00:35,160 with tons of systems and mechanics 19 00:00:35,160 --> 00:00:37,380 building this design requires working 20 00:00:37,380 --> 00:00:39,300 with lots of unity and c-sharp features 21 00:00:39,300 --> 00:00:40,980 so this is a really awesome project for 22 00:00:40,980 --> 00:00:42,960 you to learn after following this course 23 00:00:42,960 --> 00:00:44,579 and learning all of these techniques you 24 00:00:44,579 --> 00:00:46,079 won't be able to build all kinds of 25 00:00:46,079 --> 00:00:48,480 games in all kinds of genres this is 26 00:00:48,480 --> 00:00:49,860 going to involve learning about the 27 00:00:49,860 --> 00:00:51,899 basics of unity and c-sharp learning how 28 00:00:51,899 --> 00:00:53,460 to make a character controller physics 29 00:00:53,460 --> 00:00:55,680 raycast learn all about c-sharp 30 00:00:55,680 --> 00:00:57,480 interface and events using script more 31 00:00:57,480 --> 00:00:59,520 objects handling UI the new input system 32 00:00:59,520 --> 00:01:00,840 and lots more 33 00:01:00,840 --> 00:01:02,579 very importantly everything that we're 34 00:01:02,579 --> 00:01:04,199 going to do here is going to be focused 35 00:01:04,199 --> 00:01:06,000 on writing good easy to understand clean 36 00:01:06,000 --> 00:01:08,580 code meaning that I will not be teaching 37 00:01:08,580 --> 00:01:10,140 you bad practices that some beginner 38 00:01:10,140 --> 00:01:12,180 tutorials teach the code that we're 39 00:01:12,180 --> 00:01:13,439 going to write here is production 40 00:01:13,439 --> 00:01:15,659 quality code this is not a throwaway 41 00:01:15,659 --> 00:01:17,880 demo the quality of the code and the 42 00:01:17,880 --> 00:01:18,960 structure of the game that we're going 43 00:01:18,960 --> 00:01:20,640 to build is on the same level of quality 44 00:01:20,640 --> 00:01:22,799 as my own Steam games as you can see 45 00:01:22,799 --> 00:01:24,540 from the video link this is indeed a 46 00:01:24,540 --> 00:01:27,119 complete very thorough course so don't 47 00:01:27,119 --> 00:01:28,619 try to watch this whole thing in one 48 00:01:28,619 --> 00:01:30,900 sitting take your time take it slow and 49 00:01:30,900 --> 00:01:33,000 just focus on learning there are 50 00:01:33,000 --> 00:01:34,740 chapters for every single lecture in the 51 00:01:34,740 --> 00:01:36,840 video here's a quick overview of the 52 00:01:36,840 --> 00:01:38,280 entire course all the steps that we're 53 00:01:38,280 --> 00:01:39,360 going to take to reach the final 54 00:01:39,360 --> 00:01:41,759 published game so first of all we're 55 00:01:41,759 --> 00:01:43,740 going to start commonly from scratch by 56 00:01:43,740 --> 00:01:46,020 selecting a Unity version and creating a 57 00:01:46,020 --> 00:01:48,119 brand new project with that new project 58 00:01:48,119 --> 00:01:50,280 we will then learn all about the basics 59 00:01:50,280 --> 00:01:52,140 of the UNT interface and setup plane 60 00:01:52,140 --> 00:01:53,040 layout 61 00:01:53,040 --> 00:01:55,079 then the other important part is Visual 62 00:01:55,079 --> 00:01:56,460 Studio which is where we're going to be 63 00:01:56,460 --> 00:01:58,020 writing all of our code 64 00:01:58,020 --> 00:01:59,939 after that comes an extremely important 65 00:01:59,939 --> 00:02:01,619 lecture all about coding style and 66 00:02:01,619 --> 00:02:03,720 naming rules like I said the code in 67 00:02:03,720 --> 00:02:05,100 this course is on the same level of 68 00:02:05,100 --> 00:02:06,840 quality as my Steam games so having 69 00:02:06,840 --> 00:02:08,639 proper naming rules and good code sound 70 00:02:08,639 --> 00:02:10,679 is Paramount next we're going to 71 00:02:10,679 --> 00:02:12,660 download and import all the assets that 72 00:02:12,660 --> 00:02:13,560 we're going to use in the course 73 00:02:13,560 --> 00:02:15,660 everything is included so you can follow 74 00:02:15,660 --> 00:02:17,580 along with every step of the way 75 00:02:17,580 --> 00:02:19,260 with yes it's important we're going to 76 00:02:19,260 --> 00:02:20,940 set up some quick post processing just 77 00:02:20,940 --> 00:02:23,280 to make the game look good then for our 78 00:02:23,280 --> 00:02:24,720 first piece of logic we're going to make 79 00:02:24,720 --> 00:02:27,300 a simple character controller with that 80 00:02:27,300 --> 00:02:29,340 logic working we will then Implement a 81 00:02:29,340 --> 00:02:30,660 proper character visual with the 82 00:02:30,660 --> 00:02:31,980 included assets 83 00:02:31,980 --> 00:02:34,080 next we're going to learn the basics of 84 00:02:34,080 --> 00:02:36,300 animation and the animator component and 85 00:02:36,300 --> 00:02:37,800 with that we're going to make our player 86 00:02:37,800 --> 00:02:39,720 really Common live with some simple but 87 00:02:39,720 --> 00:02:42,000 really nice animations then we're going 88 00:02:42,000 --> 00:02:44,280 to install the send machine package this 89 00:02:44,280 --> 00:02:45,720 isn't actually used too much in this 90 00:02:45,720 --> 00:02:47,400 course but I still wanted to include it 91 00:02:47,400 --> 00:02:49,560 because it is such a useful tool so I do 92 00:02:49,560 --> 00:02:51,300 want you to know about it after that 93 00:02:51,300 --> 00:02:53,099 comes another extremely extremely 94 00:02:53,099 --> 00:02:54,480 important lecture with regards to 95 00:02:54,480 --> 00:02:56,519 writing some good link code we're going 96 00:02:56,519 --> 00:02:58,860 to do a nice refactor to replace the 97 00:02:58,860 --> 00:03:00,660 Legacy input Venture with the brand new 98 00:03:00,660 --> 00:03:01,800 input system 99 00:03:01,800 --> 00:03:04,080 learning how to refactor is an extremely 100 00:03:04,080 --> 00:03:05,879 important and very valuable skill that 101 00:03:05,879 --> 00:03:07,500 will massively improve the quality of 102 00:03:07,500 --> 00:03:09,540 your code with that then we're going to 103 00:03:09,540 --> 00:03:11,280 implement some nice Collision detection 104 00:03:11,280 --> 00:03:12,900 to make sure our character doesn't want 105 00:03:12,900 --> 00:03:14,159 through walls 106 00:03:14,159 --> 00:03:16,080 next we're going to create the very 107 00:03:16,080 --> 00:03:18,000 first kitchen counter and make a script 108 00:03:18,000 --> 00:03:20,340 to handle how to interact with it then 109 00:03:20,340 --> 00:03:22,260 we're going to learn all about c-sharp 110 00:03:22,260 --> 00:03:24,180 events and create a proper interact 111 00:03:24,180 --> 00:03:26,580 input next we're going to build a 112 00:03:26,580 --> 00:03:28,140 selected counter visual which will 113 00:03:28,140 --> 00:03:30,060 require us to learn about the extremely 114 00:03:30,060 --> 00:03:32,280 useful Singleton pattern with the 115 00:03:32,280 --> 00:03:33,780 counters working we're going to start 116 00:03:33,780 --> 00:03:35,099 working on the kitchen objects 117 00:03:35,099 --> 00:03:37,080 themselves so these are going to be the 118 00:03:37,080 --> 00:03:38,819 ingredients and the plates we're going 119 00:03:38,819 --> 00:03:40,739 to use scriptable objects to Define all 120 00:03:40,739 --> 00:03:41,940 of the types 121 00:03:41,940 --> 00:03:43,920 then a very important part of our design 122 00:03:43,920 --> 00:03:46,019 is each kitchen object will have to be 123 00:03:46,019 --> 00:03:48,180 placed somewhere so we're going to take 124 00:03:48,180 --> 00:03:49,920 some time to really think about the best 125 00:03:49,920 --> 00:03:51,599 way to achieve that all while riding 126 00:03:51,599 --> 00:03:53,580 some good clean code next we're going to 127 00:03:53,580 --> 00:03:55,440 enable the player to pick up an object 128 00:03:55,440 --> 00:03:57,299 in doing so we're going to learn about 129 00:03:57,299 --> 00:03:59,640 c-sharp interfaces then we're going to 130 00:03:59,640 --> 00:04:01,680 make a container counter this is from 131 00:04:01,680 --> 00:04:03,780 where we can spawn new objects 132 00:04:03,780 --> 00:04:05,700 with that we will enable the player to 133 00:04:05,700 --> 00:04:07,560 pick up objects and drop them anywhere 134 00:04:07,560 --> 00:04:09,060 where there's space 135 00:04:09,060 --> 00:04:10,739 then we're going to make the cutting 136 00:04:10,739 --> 00:04:12,959 counter this one enables the player to 137 00:04:12,959 --> 00:04:15,780 cut an ingredient into slices so to do 138 00:04:15,780 --> 00:04:17,459 that we're going to make an alternate 139 00:04:17,459 --> 00:04:18,779 interaction 140 00:04:18,779 --> 00:04:20,760 and for handling the cutting we're going 141 00:04:20,760 --> 00:04:22,740 to once again use script more objects to 142 00:04:22,740 --> 00:04:24,720 define a proper cutting recipe 143 00:04:24,720 --> 00:04:26,400 then we're going to learn about a really 144 00:04:26,400 --> 00:04:28,440 awesome Unity feature we're on canvases 145 00:04:28,440 --> 00:04:30,419 and use that to display a nice progress 146 00:04:30,419 --> 00:04:32,699 Bar for our cutting progress after that 147 00:04:32,699 --> 00:04:35,160 is a quick lecture just going to make a 148 00:04:35,160 --> 00:04:36,840 very useful generic script to make any 149 00:04:36,840 --> 00:04:38,580 object look at the camera 150 00:04:38,580 --> 00:04:40,560 next for another counter we're going to 151 00:04:40,560 --> 00:04:42,419 build a trash bin this is where the 152 00:04:42,419 --> 00:04:45,000 player can drop objects to destroy them 153 00:04:45,000 --> 00:04:47,400 then the stove counter this one is going 154 00:04:47,400 --> 00:04:49,560 to be quite a bit complex we're going to 155 00:04:49,560 --> 00:04:51,660 create recipes for cooking and for 156 00:04:51,660 --> 00:04:53,580 burning we're going to learn how to make 157 00:04:53,580 --> 00:04:55,680 a basic state machine and handle timers 158 00:04:55,680 --> 00:04:57,660 next we're going to make the plates 159 00:04:57,660 --> 00:04:59,699 counter this is a simple encounter that 160 00:04:59,699 --> 00:05:01,440 just spawns a bunch of plates 161 00:05:01,440 --> 00:05:03,060 after that we're going to make some 162 00:05:03,060 --> 00:05:04,740 custom Logic on the plate to be able to 163 00:05:04,740 --> 00:05:06,479 hold other objects 164 00:05:06,479 --> 00:05:08,100 with that logic working we're going to 165 00:05:08,100 --> 00:05:09,840 build a complete visual for all the 166 00:05:09,840 --> 00:05:11,759 objects that can exist on the plate 167 00:05:11,759 --> 00:05:14,220 then make a nice UI element on the plane 168 00:05:14,220 --> 00:05:16,440 itself to showcase the icons of what 169 00:05:16,440 --> 00:05:18,900 exactly is on that plate afterwards 170 00:05:18,900 --> 00:05:20,160 we're going to make the very last 171 00:05:20,160 --> 00:05:22,320 counter the delivery counter this is 172 00:05:22,320 --> 00:05:24,780 where we drop the completed plates and 173 00:05:24,780 --> 00:05:26,100 in this lecture we're also going to 174 00:05:26,100 --> 00:05:27,840 learn about the unity share graph and 175 00:05:27,840 --> 00:05:30,120 make a quick simple custom Shader 176 00:05:30,120 --> 00:05:31,919 then we're going to build the delivering 177 00:05:31,919 --> 00:05:33,600 manager class that generates the recipes 178 00:05:33,600 --> 00:05:36,060 that the customers are requesting next 179 00:05:36,060 --> 00:05:38,220 we're going to build a UI to showcase 180 00:05:38,220 --> 00:05:40,680 the wedding recipes after that comes 181 00:05:40,680 --> 00:05:42,060 something pretty crucial we're going to 182 00:05:42,060 --> 00:05:44,460 add some music and then add some sound 183 00:05:44,460 --> 00:05:47,100 effects for all kinds of game actions 184 00:05:47,100 --> 00:05:49,500 without the game won't be almost done so 185 00:05:49,500 --> 00:05:51,240 next we're going to build a proper game 186 00:05:51,240 --> 00:05:52,800 start and a game end 187 00:05:52,800 --> 00:05:55,259 then make a simple main menu and handle 188 00:05:55,259 --> 00:05:57,539 scene loading after that hand on 189 00:05:57,539 --> 00:05:59,699 creating a basic pause window 190 00:05:59,699 --> 00:06:02,039 then make an options menu enable the 191 00:06:02,039 --> 00:06:03,900 player to modify the audio levels and 192 00:06:03,900 --> 00:06:05,280 rebound keys 193 00:06:05,280 --> 00:06:07,080 after that we're going to enable menu 194 00:06:07,080 --> 00:06:09,539 navigation with a controller and in the 195 00:06:09,539 --> 00:06:11,639 end as usual comes the Polish stage so 196 00:06:11,639 --> 00:06:13,080 we're going to add all kinds of small 197 00:06:13,080 --> 00:06:14,880 tweaks and effects to make the game feel 198 00:06:14,880 --> 00:06:16,800 really great like I've said many times 199 00:06:16,800 --> 00:06:18,600 polish is what separates good games from 200 00:06:18,600 --> 00:06:20,759 great games after all of that we will 201 00:06:20,759 --> 00:06:22,979 have our final completed project so as 202 00:06:22,979 --> 00:06:24,720 you can see you will learn about tons of 203 00:06:24,720 --> 00:06:27,180 Topics by following this course also let 204 00:06:27,180 --> 00:06:28,979 me point out one of the reasons why I 205 00:06:28,979 --> 00:06:31,319 chose this specific design is because my 206 00:06:31,319 --> 00:06:33,000 next free course won't be on taking the 207 00:06:33,000 --> 00:06:34,319 game that we're going to build here and 208 00:06:34,319 --> 00:06:36,300 make it multiplayer so if you've ever 209 00:06:36,300 --> 00:06:37,800 wanted to make multiplayer games then 210 00:06:37,800 --> 00:06:39,360 that course will be excellent for you 211 00:06:39,360 --> 00:06:41,400 definitely take your time following this 212 00:06:41,400 --> 00:06:42,840 course the multiplayer free course 213 00:06:42,840 --> 00:06:44,940 should hopefully be out next month or if 214 00:06:44,940 --> 00:06:46,319 you're watching this in the future check 215 00:06:46,319 --> 00:06:48,240 the links in description although that 216 00:06:48,240 --> 00:06:49,800 multiplayer video won't be starting from 217 00:06:49,800 --> 00:06:51,360 where this course ends so definitely 218 00:06:51,360 --> 00:06:53,520 make sure you watch this one now if you 219 00:06:53,520 --> 00:06:55,440 are new to the channel then welcome and 220 00:06:55,440 --> 00:06:57,300 here's a bit about me and my credentials 221 00:06:57,300 --> 00:06:59,160 or why you shouldn't listen to what I 222 00:06:59,160 --> 00:07:00,180 have to teach 223 00:07:00,180 --> 00:07:01,860 my name is Hugo and I've been running 224 00:07:01,860 --> 00:07:03,539 this Code Monkey YouTube channel for 225 00:07:03,539 --> 00:07:06,180 five years now in total almost 700 226 00:07:06,180 --> 00:07:08,340 videos on all kinds of topics including 227 00:07:08,340 --> 00:07:10,080 tons of tutorials sharing my knowledge 228 00:07:10,080 --> 00:07:12,479 to help you on your Game Dev Journey I'm 229 00:07:12,479 --> 00:07:14,100 also a professional indie game developer 230 00:07:14,100 --> 00:07:16,139 making games for over 10 years with 8 231 00:07:16,139 --> 00:07:18,419 successful Games published on scene so 232 00:07:18,419 --> 00:07:19,979 what I'm teaching here is based on a lot 233 00:07:19,979 --> 00:07:21,599 of years of experience making a lot of 234 00:07:21,599 --> 00:07:23,940 games just like with my paid courses I'm 235 00:07:23,940 --> 00:07:24,840 always going to be in the common 236 00:07:24,840 --> 00:07:27,000 censoring questions so if you get stuck 237 00:07:27,000 --> 00:07:28,680 at a particular point or need extra 238 00:07:28,680 --> 00:07:31,139 clarification on something go ahead post 239 00:07:31,139 --> 00:07:33,000 a comment and I'll do my best to help do 240 00:07:33,000 --> 00:07:34,740 make sure you include a timestamp of 241 00:07:34,740 --> 00:07:36,840 what you're referring to I will also be 242 00:07:36,840 --> 00:07:38,580 updating the pin comment with any 243 00:07:38,580 --> 00:07:40,800 frequently asked questions that I see so 244 00:07:40,800 --> 00:07:42,240 actually right now go ahead pause the 245 00:07:42,240 --> 00:07:43,620 video and scroll down a bit just to look 246 00:07:43,620 --> 00:07:45,780 at that comment since on YouTube I 247 00:07:45,780 --> 00:07:47,160 cannot update the video after it's 248 00:07:47,160 --> 00:07:48,720 published I will be updating that 249 00:07:48,720 --> 00:07:50,039 comment over the next months and years 250 00:07:50,039 --> 00:07:52,259 with anything that comes up also I've 251 00:07:52,259 --> 00:07:53,880 been running this channel for five years 252 00:07:53,880 --> 00:07:55,860 and in that time I've made almost 700 253 00:07:55,860 --> 00:07:58,259 videos so there's lots of topics that 254 00:07:58,259 --> 00:07:59,759 I've covered separately in more detail 255 00:07:59,759 --> 00:08:01,680 all of those videos are linked in the 256 00:08:01,680 --> 00:08:03,599 description throughout this course I 257 00:08:03,599 --> 00:08:04,919 will be focused on building this 258 00:08:04,919 --> 00:08:06,720 specific game using whatever it takes to 259 00:08:06,720 --> 00:08:08,880 build it meaning for example when we get 260 00:08:08,880 --> 00:08:10,620 to using c-sharp events I won't teach 261 00:08:10,620 --> 00:08:12,360 the basics about how they work in order 262 00:08:12,360 --> 00:08:14,340 to achieve what we want to build but if 263 00:08:14,340 --> 00:08:15,900 you then want to learn about c-sharp 264 00:08:15,900 --> 00:08:17,520 events in more detail definitely go 265 00:08:17,520 --> 00:08:19,680 watch a dedicated video and I also made 266 00:08:19,680 --> 00:08:22,199 a page on my website for this course it 267 00:08:22,199 --> 00:08:23,819 contains a link to download all of the 268 00:08:23,819 --> 00:08:26,160 project assets you can also download the 269 00:08:26,160 --> 00:08:27,960 complete project files for every single 270 00:08:27,960 --> 00:08:30,240 lecture so if you get stuck at any point 271 00:08:30,240 --> 00:08:31,860 you can download the code at that 272 00:08:31,860 --> 00:08:33,419 lecture and compare with your own 273 00:08:33,419 --> 00:08:35,580 there's also references to all of the 274 00:08:35,580 --> 00:08:37,320 videos and I will also be including 275 00:08:37,320 --> 00:08:38,820 frequently asked questions for each 276 00:08:38,820 --> 00:08:41,219 lecture so definitely keep that page 277 00:08:41,219 --> 00:08:43,080 open in a second tab as you follow along 278 00:08:43,080 --> 00:08:45,600 this course now this free course Took a 279 00:08:45,600 --> 00:08:47,160 ton of work to make so I really hope you 280 00:08:47,160 --> 00:08:49,140 find this video helpful go ahead and hit 281 00:08:49,140 --> 00:08:51,300 the like button if it helps you it's a 282 00:08:51,300 --> 00:08:52,740 small thing but it generally does help 283 00:08:52,740 --> 00:08:54,240 this video on the YouTube algorithm 284 00:08:54,240 --> 00:08:56,459 making this course was a ton of work and 285 00:08:56,459 --> 00:08:58,320 by making it commonly free it means it 286 00:08:58,320 --> 00:08:59,820 will obviously never make as much money 287 00:08:59,820 --> 00:09:01,920 as if I had just made this a paid course 288 00:09:01,920 --> 00:09:03,959 I'm personally okay with that decision 289 00:09:03,959 --> 00:09:05,700 with the hopes that by making it free it 290 00:09:05,700 --> 00:09:07,320 won't reach and help many more people 291 00:09:07,320 --> 00:09:09,839 I'm also a big believer that education 292 00:09:09,839 --> 00:09:11,820 should be free so if you can't afford 293 00:09:11,820 --> 00:09:13,680 one of my paid courses like if you're 294 00:09:13,680 --> 00:09:15,300 just a kid or going through a rough time 295 00:09:15,300 --> 00:09:17,339 I still want you to have access to high 296 00:09:17,339 --> 00:09:19,019 quality education so you can achieve 297 00:09:19,019 --> 00:09:21,120 your Game Dev dreams one easy way you 298 00:09:21,120 --> 00:09:23,100 can help me for free is simply by liking 299 00:09:23,100 --> 00:09:24,480 this video subscribing to the channel 300 00:09:24,480 --> 00:09:26,279 and just watching this course 301 00:09:26,279 --> 00:09:28,200 that will hopefully help push this video 302 00:09:28,200 --> 00:09:29,880 on the YouTube algorithm and help it 303 00:09:29,880 --> 00:09:32,220 reach many more people another free way 304 00:09:32,220 --> 00:09:33,959 to support what I do is I'm currently 305 00:09:33,959 --> 00:09:35,640 working on my next team game called turn 306 00:09:35,640 --> 00:09:37,920 one Liberation you can wish list the 307 00:09:37,920 --> 00:09:40,140 game on Steam wishlists matter a lot for 308 00:09:40,140 --> 00:09:42,000 steam visibility so just by doing that 309 00:09:42,000 --> 00:09:44,279 you won't be helping me and just in case 310 00:09:44,279 --> 00:09:46,080 you can't afford it and you find this 311 00:09:46,080 --> 00:09:47,760 free course useful you can also support 312 00:09:47,760 --> 00:09:50,220 what I do in a few other ways I spent a 313 00:09:50,220 --> 00:09:51,660 bunch of money making this course I 314 00:09:51,660 --> 00:09:53,640 hired an artist for the 3D assets so 315 00:09:53,640 --> 00:09:55,080 that I had the right to distribute them 316 00:09:55,080 --> 00:09:56,580 so that you can download it and follow 317 00:09:56,580 --> 00:09:57,420 along 318 00:09:57,420 --> 00:09:59,040 same thing for the music and sound 319 00:09:59,040 --> 00:10:01,200 effects the logo and the cost to upload 320 00:10:01,200 --> 00:10:03,420 the game to seem so I would like to at 321 00:10:03,420 --> 00:10:04,760 least not lose money on this project 322 00:10:04,760 --> 00:10:06,959 hopefully there's enough of you who 323 00:10:06,959 --> 00:10:08,459 can't afford to help me so that I can at 324 00:10:08,459 --> 00:10:09,660 least break even 325 00:10:09,660 --> 00:10:11,760 and for one way you can support is I 326 00:10:11,760 --> 00:10:13,560 added this exact same course on my 327 00:10:13,560 --> 00:10:15,000 website as a regular paid course 328 00:10:15,000 --> 00:10:17,279 although I want to be very very clear 329 00:10:17,279 --> 00:10:19,200 there is absolutely no difference 330 00:10:19,200 --> 00:10:20,940 between this free video and the paid 331 00:10:20,940 --> 00:10:22,860 course there is absolutely nothing 332 00:10:22,860 --> 00:10:25,320 behind any kind of payroll all of the 333 00:10:25,320 --> 00:10:27,000 lectures are free all of the apps are 334 00:10:27,000 --> 00:10:28,980 free everything is free you don't have 335 00:10:28,980 --> 00:10:30,839 to pay for anything if you can't afford 336 00:10:30,839 --> 00:10:32,940 it or you just don't want to the paid 337 00:10:32,940 --> 00:10:35,160 version is essentially a donation the 338 00:10:35,160 --> 00:10:36,480 only difference is this free YouTube 339 00:10:36,480 --> 00:10:38,580 video has regular YouTube ads whereas 340 00:10:38,580 --> 00:10:40,019 the paid version on the website doesn't 341 00:10:40,019 --> 00:10:42,240 have any ads that's it that's the only 342 00:10:42,240 --> 00:10:44,399 thing so the only reason why I made that 343 00:10:44,399 --> 00:10:46,500 paid version is just in case some of you 344 00:10:46,500 --> 00:10:48,060 can't afford it and you want to support 345 00:10:48,060 --> 00:10:49,860 what I do and want to help me break even 346 00:10:49,860 --> 00:10:52,200 on this project but again only do that 347 00:10:52,200 --> 00:10:53,940 if you can't afford them if you can't 348 00:10:53,940 --> 00:10:55,860 that's personally fine I hope you'll 349 00:10:55,860 --> 00:10:57,540 learn a ton from watching and following 350 00:10:57,540 --> 00:10:59,640 this free course beyond that if you 351 00:10:59,640 --> 00:11:01,019 follow this course and you enjoy my 352 00:11:01,019 --> 00:11:02,700 teaching sound perhaps look into my 353 00:11:02,700 --> 00:11:04,560 other courses if you like this video 354 00:11:04,560 --> 00:11:06,180 then I think you won't really like my 355 00:11:06,180 --> 00:11:08,399 turn-based strategy course that is the 356 00:11:08,399 --> 00:11:09,540 perfect course to follow up on this one 357 00:11:09,540 --> 00:11:12,300 one it Dives even deeper into some of 358 00:11:12,300 --> 00:11:13,980 the concepts used here and it will help 359 00:11:13,980 --> 00:11:15,300 you make the jump from beginner to 360 00:11:15,300 --> 00:11:17,459 Advanced and since you're interested in 361 00:11:17,459 --> 00:11:19,560 unity I think my ultimate unity overview 362 00:11:19,560 --> 00:11:21,839 course would also be very useful to you 363 00:11:21,839 --> 00:11:23,640 each lecture on that course is focused 364 00:11:23,640 --> 00:11:25,980 on teaching one entitled feature there's 365 00:11:25,980 --> 00:11:27,899 already over 15 lectures including 366 00:11:27,899 --> 00:11:29,640 plenty of small but very important 367 00:11:29,640 --> 00:11:31,320 things that you just wouldn't see in a 368 00:11:31,320 --> 00:11:32,880 regular YouTube video if you're 369 00:11:32,880 --> 00:11:34,260 interested in visual scripting I have 370 00:11:34,260 --> 00:11:35,700 course on making three unique games 371 00:11:35,700 --> 00:11:37,500 internally with visual scripting and no 372 00:11:37,500 --> 00:11:40,019 code at all or if you prefer code you 373 00:11:40,019 --> 00:11:41,459 can learn how to build a nice Builder 374 00:11:41,459 --> 00:11:43,200 Defender game so if you enjoy my 375 00:11:43,200 --> 00:11:44,700 teaching Style on this free course then 376 00:11:44,700 --> 00:11:46,620 check out my other ones then of course 377 00:11:46,620 --> 00:11:48,420 YouTube has Channel memberships and 378 00:11:48,420 --> 00:11:50,279 super thanks so you can use those if you 379 00:11:50,279 --> 00:11:52,500 want I also have my patreon if you 380 00:11:52,500 --> 00:11:55,079 prefer that and in a lot of my videos I 381 00:11:55,079 --> 00:11:56,640 have some affiliate links if you ever 382 00:11:56,640 --> 00:11:58,320 pick up anything through those I get a 383 00:11:58,320 --> 00:12:00,420 nice commission and I also have some of 384 00:12:00,420 --> 00:12:02,820 my own assets on the unity Astor so if 385 00:12:02,820 --> 00:12:04,320 you enjoy this free course and you want 386 00:12:04,320 --> 00:12:05,760 to support what I do there's plenty of 387 00:12:05,760 --> 00:12:08,459 ways but again don't feel obligated if 388 00:12:08,459 --> 00:12:09,839 you can't afford it or you just don't 389 00:12:09,839 --> 00:12:11,940 want to that's perfectly fine I hope 390 00:12:11,940 --> 00:12:13,440 you'll learn a ton from watching and 391 00:12:13,440 --> 00:12:15,420 following this recourse alright so 392 00:12:15,420 --> 00:12:16,800 that's enough talk of that for now 393 00:12:16,800 --> 00:12:19,019 before we begin building the game from 394 00:12:19,019 --> 00:12:21,300 scratch let's inspect the final polish 395 00:12:21,300 --> 00:12:22,860 game that we're going to build so let's 396 00:12:22,860 --> 00:12:25,019 see that in the next lecture 397 00:12:25,019 --> 00:12:27,019 hello and welcome I'm your code monkey 398 00:12:27,019 --> 00:12:29,640 here let's take a look at the final game 399 00:12:29,640 --> 00:12:31,380 that we're going to build so we start 400 00:12:31,380 --> 00:12:33,120 off on a simple but really nice main 401 00:12:33,120 --> 00:12:35,579 menu so we've got a nice visual a nice 402 00:12:35,579 --> 00:12:37,920 logo and a bunch of useful buttons then 403 00:12:37,920 --> 00:12:39,480 of course the game has a nice loading 404 00:12:39,480 --> 00:12:40,920 system so when I click on play it's 405 00:12:40,920 --> 00:12:42,660 going to load into a unloading scene and 406 00:12:42,660 --> 00:12:44,639 then funnel into the final game scene so 407 00:12:44,639 --> 00:12:46,500 let's go ahead and play and if there we 408 00:12:46,500 --> 00:12:48,360 go here we do see the game scene and 409 00:12:48,360 --> 00:12:50,160 right away we see a nice internal window 410 00:12:50,160 --> 00:12:52,200 so it's telling us how to play the game 411 00:12:52,200 --> 00:12:54,120 so the basic interactions and then over 412 00:12:54,120 --> 00:12:56,339 here the controls importantly these are 413 00:12:56,339 --> 00:12:58,139 all rebindable so over here this element 414 00:12:58,139 --> 00:13:00,540 is all Dynamic then we can look at this 415 00:13:00,540 --> 00:13:02,100 tutorial for as long as we want and we 416 00:13:02,100 --> 00:13:03,480 are waiting for the interact to continue 417 00:13:03,480 --> 00:13:05,459 there's also a really nice song playing 418 00:13:05,459 --> 00:13:07,019 in the background so the game has music 419 00:13:07,019 --> 00:13:09,000 now we can look at this tutorial for as 420 00:13:09,000 --> 00:13:10,620 long as we want and when we're ready we 421 00:13:10,620 --> 00:13:12,660 can interact and continue and as soon as 422 00:13:12,660 --> 00:13:14,760 we do if there you go we've got a nice 423 00:13:14,760 --> 00:13:16,380 countdown some nice animations a nice 424 00:13:16,380 --> 00:13:17,760 sound effect and there you go now we are 425 00:13:17,760 --> 00:13:19,980 playing okay so here I am controlling a 426 00:13:19,980 --> 00:13:21,959 nice character I can move in any 427 00:13:21,959 --> 00:13:23,100 direction 428 00:13:23,100 --> 00:13:24,660 there is Collision detection so 429 00:13:24,660 --> 00:13:26,399 obviously I cannot go inside solid 430 00:13:26,399 --> 00:13:28,560 objects so I can walk around and for the 431 00:13:28,560 --> 00:13:29,820 goal of the game over here on the left 432 00:13:29,820 --> 00:13:31,200 side we've got recipes that the 433 00:13:31,200 --> 00:13:33,060 customers are waiting for so for example 434 00:13:33,060 --> 00:13:35,399 One customer wants a simple Burger so 435 00:13:35,399 --> 00:13:37,620 for that we gonna need to pick up a nice 436 00:13:37,620 --> 00:13:39,720 bun so let's pick it up then the burger 437 00:13:39,720 --> 00:13:41,579 obviously requires a meat Patty so let's 438 00:13:41,579 --> 00:13:43,139 go ahead we can pick one up from here 439 00:13:43,139 --> 00:13:45,060 but this one is an uncooked meat padding 440 00:13:45,060 --> 00:13:46,740 so we need to drop it over here on the 441 00:13:46,740 --> 00:13:48,540 stove and there you go it starts cooking 442 00:13:48,540 --> 00:13:50,339 we've got a nice timer we've got a nice 443 00:13:50,339 --> 00:13:51,839 warm bar UI 444 00:13:51,839 --> 00:13:53,940 and there you go it keeps counting and 445 00:13:53,940 --> 00:13:55,380 we've got some nice park on some nice 446 00:13:55,380 --> 00:13:56,820 visuals and over there even a nice 447 00:13:56,820 --> 00:13:58,260 indicator telling us the meat is about 448 00:13:58,260 --> 00:13:59,940 to burn and there you go the meat has 449 00:13:59,940 --> 00:14:02,339 burned so now I can pick this up and I'm 450 00:14:02,339 --> 00:14:03,959 holding some burnt meat so the customer 451 00:14:03,959 --> 00:14:06,060 probably doesn't want to eat this so we 452 00:14:06,060 --> 00:14:07,740 can go over here to the trash or trash 453 00:14:07,740 --> 00:14:09,779 it let's try doing another one and do it 454 00:14:09,779 --> 00:14:11,459 properly so let's wait for it to cook 455 00:14:11,459 --> 00:14:13,380 pick up a plate so we can pick it up 456 00:14:13,380 --> 00:14:14,940 directly onto the plate there you go to 457 00:14:14,940 --> 00:14:16,139 the meat is cooked so let's pick it up 458 00:14:16,139 --> 00:14:18,360 then go pick up some bread and there you 459 00:14:18,360 --> 00:14:20,579 go here we have our camelli recipe so 460 00:14:20,579 --> 00:14:21,839 let's go into the delivery counter 461 00:14:21,839 --> 00:14:23,519 deliver it and there you go a nice 462 00:14:23,519 --> 00:14:26,040 delivery success all right awesome we've 463 00:14:26,040 --> 00:14:28,560 just delivered our first recipe so then 464 00:14:28,560 --> 00:14:30,240 someone else wants a salad so let's go 465 00:14:30,240 --> 00:14:32,459 ahead pick up a tomato here we have a 466 00:14:32,459 --> 00:14:34,860 big uncut tomato so let's drop it onto a 467 00:14:34,860 --> 00:14:37,019 cutting board and now we can interact 468 00:14:37,019 --> 00:14:38,700 with it so we can interact with a 469 00:14:38,700 --> 00:14:40,380 secondary interaction key 470 00:14:40,380 --> 00:14:42,779 and by interacting we cut the tomatoes 471 00:14:42,779 --> 00:14:44,220 so it takes a few cuts and there you go 472 00:14:44,220 --> 00:14:46,019 with slices and it's sliced into tomato 473 00:14:46,019 --> 00:14:48,000 slices so let's do the same thing for 474 00:14:48,000 --> 00:14:50,160 the Cabbage here we are holding a 475 00:14:50,160 --> 00:14:52,019 regular cabbage then slice it and this 476 00:14:52,019 --> 00:14:53,820 one actually takes a bunch more and 477 00:14:53,820 --> 00:14:55,860 there you go got both slices okay great 478 00:14:55,860 --> 00:14:58,019 so now let's pick up the plate pick up 479 00:14:58,019 --> 00:14:59,639 both slices and deliver to the customer 480 00:14:59,639 --> 00:15:01,860 and there you go got a nice success all 481 00:15:01,860 --> 00:15:04,139 right awesome and of course we have a 482 00:15:04,139 --> 00:15:06,360 correct identification of if we have a 483 00:15:06,360 --> 00:15:07,860 crack recipe or not 484 00:15:07,860 --> 00:15:10,079 so if I just pick up an empty plate and 485 00:15:10,079 --> 00:15:11,639 deliver it there you go got a film 486 00:15:11,639 --> 00:15:13,199 delivery because nobody wants just an 487 00:15:13,199 --> 00:15:15,060 empty plate alright so here you can 488 00:15:15,060 --> 00:15:16,500 already see quite a lot of interactions 489 00:15:16,500 --> 00:15:18,600 quite a lot of systems at work so the 490 00:15:18,600 --> 00:15:19,920 character has a nice character 491 00:15:19,920 --> 00:15:21,660 controller it has physics interaction 492 00:15:21,660 --> 00:15:23,579 you can see how it identifies the 493 00:15:23,579 --> 00:15:25,440 counter that is in from the character I 494 00:15:25,440 --> 00:15:26,880 can press a button to interact with the 495 00:15:26,880 --> 00:15:28,199 counter and interacting with different 496 00:15:28,199 --> 00:15:30,240 counters does different things so if I 497 00:15:30,240 --> 00:15:31,680 interact with a clear counter I can pick 498 00:15:31,680 --> 00:15:33,779 up or drop things over here I can pick 499 00:15:33,779 --> 00:15:35,820 up drop it with an alternate interaction 500 00:15:35,820 --> 00:15:38,279 I can do the second action then there's 501 00:15:38,279 --> 00:15:40,380 the stove machine so that one has a nice 502 00:15:40,380 --> 00:15:42,540 State machine so it counts up over here 503 00:15:42,540 --> 00:15:44,100 we've got some nice particles we've got 504 00:15:44,100 --> 00:15:45,779 a nice Bloom so all the Visions look 505 00:15:45,779 --> 00:15:46,920 really great so we've got some post 506 00:15:46,920 --> 00:15:48,959 processing we have a bunch of UI 507 00:15:48,959 --> 00:15:50,880 elements directly on the world and 508 00:15:50,880 --> 00:15:52,320 outside of here we've got some regular 509 00:15:52,320 --> 00:15:53,639 UI elements 510 00:15:53,639 --> 00:15:55,560 so we've got the recipes with Dynamic 511 00:15:55,560 --> 00:15:57,839 icons for all of them we've got a timer 512 00:15:57,839 --> 00:15:59,279 over there on the top right corner 513 00:15:59,279 --> 00:16:01,019 showing how long we have to deliver on 514 00:16:01,019 --> 00:16:03,060 our recipes and on the kitchen counter 515 00:16:03,060 --> 00:16:04,740 we're also using a custom Shader so this 516 00:16:04,740 --> 00:16:06,959 was built using shade wrap so as you can 517 00:16:06,959 --> 00:16:09,120 see lots of internalized systems then 518 00:16:09,120 --> 00:16:10,680 the game also has of course the basics 519 00:16:10,680 --> 00:16:13,019 that any game should have so I can pause 520 00:16:13,019 --> 00:16:14,639 the game and there you go we've got a 521 00:16:14,639 --> 00:16:16,500 nice pause menu so we can resume to go 522 00:16:16,500 --> 00:16:18,120 back or pause it again and of course 523 00:16:18,120 --> 00:16:19,440 while pause everything is possible 524 00:16:19,440 --> 00:16:21,660 that's great we can go back into the 525 00:16:21,660 --> 00:16:24,000 main menu or we can go into options and 526 00:16:24,000 --> 00:16:25,560 over here we can play around the sound 527 00:16:25,560 --> 00:16:27,660 effects volume the Music Volume we've 528 00:16:27,660 --> 00:16:29,639 got all of our controls importantly 529 00:16:29,639 --> 00:16:31,260 these are the controls for the keyboard 530 00:16:31,260 --> 00:16:33,360 and also the GamePad 531 00:16:33,360 --> 00:16:35,040 so the game can be played with any 532 00:16:35,040 --> 00:16:37,139 Gamepad so it can be an Xbox controller 533 00:16:37,139 --> 00:16:38,820 PlayStation switch controller it doesn't 534 00:16:38,820 --> 00:16:41,279 matter all of them work and we can also 535 00:16:41,279 --> 00:16:43,620 rebind all these Keys both the keys as 536 00:16:43,620 --> 00:16:45,899 well as the GamePad inputs so let's go 537 00:16:45,899 --> 00:16:47,220 ahead and deliver a cheeseburger so 538 00:16:47,220 --> 00:16:48,899 here's some burn meat so let's toss this 539 00:16:48,899 --> 00:16:51,360 then pick up some more meat pick up a 540 00:16:51,360 --> 00:16:53,639 plate here we've got some cheese we've 541 00:16:53,639 --> 00:16:55,920 got some bread pick up the meat and 542 00:16:55,920 --> 00:16:58,380 deliver it all right awesome and of 543 00:16:58,380 --> 00:17:00,000 course finally at the end when our 544 00:17:00,000 --> 00:17:01,920 timers left here we have a nice game 545 00:17:01,920 --> 00:17:03,899 over window showing how many recipes we 546 00:17:03,899 --> 00:17:06,179 delivered alright so this is the final 547 00:17:06,179 --> 00:17:07,799 game that we're going to build as you 548 00:17:07,799 --> 00:17:09,359 can see it involves lots of interesting 549 00:17:09,359 --> 00:17:11,220 interactions which require learning lots 550 00:17:11,220 --> 00:17:13,020 of different skills we're going to be 551 00:17:13,020 --> 00:17:15,179 using c-sharp interfaces c-sharp events 552 00:17:15,179 --> 00:17:16,919 the new input system shade graphs 553 00:17:16,919 --> 00:17:18,959 critical objects we're going to learn 554 00:17:18,959 --> 00:17:20,400 about c-sharp events making character 555 00:17:20,400 --> 00:17:22,319 controller handle collisions and so on 556 00:17:22,319 --> 00:17:24,119 like I said one thing that we're going 557 00:17:24,119 --> 00:17:25,559 to focus heavily throughout the making 558 00:17:25,559 --> 00:17:27,179 of this game is on writing good clean 559 00:17:27,179 --> 00:17:29,400 code meaning that the final game that 560 00:17:29,400 --> 00:17:30,780 we're going to build won't be very easy 561 00:17:30,780 --> 00:17:33,480 to expand upon thanks to how long the 562 00:17:33,480 --> 00:17:35,160 code is very clean it will be very easy 563 00:17:35,160 --> 00:17:37,200 to add more recipes maybe more counters 564 00:17:37,200 --> 00:17:38,940 with more actions maybe things like 565 00:17:38,940 --> 00:17:40,620 perhaps washing dishes adding an oven 566 00:17:40,620 --> 00:17:42,660 and so on or really you could make 567 00:17:42,660 --> 00:17:44,220 something completely different 568 00:17:44,220 --> 00:17:46,020 this game is all about character and 569 00:17:46,020 --> 00:17:47,220 interactions 570 00:17:47,220 --> 00:17:49,320 so that could be whatever you want you 571 00:17:49,320 --> 00:17:51,120 could take this as a base and build some 572 00:17:51,120 --> 00:17:53,160 kind of sci-fi game something like Among 573 00:17:53,160 --> 00:17:55,559 Us or FTL you could make a survival 574 00:17:55,559 --> 00:17:57,960 crafting game like rust or Minecraft or 575 00:17:57,960 --> 00:18:00,120 Don't Starve really fun learning how to 576 00:18:00,120 --> 00:18:01,559 build this game by the end you won't 577 00:18:01,559 --> 00:18:03,000 have gained the knowledge required to 578 00:18:03,000 --> 00:18:04,260 build all kinds of unique and 579 00:18:04,260 --> 00:18:06,240 interesting games alright so now that 580 00:18:06,240 --> 00:18:07,679 we've seen the final game Let's actually 581 00:18:07,679 --> 00:18:09,900 build it just before we do let's get a 582 00:18:09,900 --> 00:18:11,520 quick refresher of the absolute Basics 583 00:18:11,520 --> 00:18:13,980 you should know in the next lecture 584 00:18:13,980 --> 00:18:15,900 hello and welcome I'm your code monkey 585 00:18:15,900 --> 00:18:18,299 in this lecture we're going to just get 586 00:18:18,299 --> 00:18:20,220 a quick refresher of the absolute Basics 587 00:18:20,220 --> 00:18:21,660 you should know in order to be able to 588 00:18:21,660 --> 00:18:24,240 follow everything in this course okay so 589 00:18:24,240 --> 00:18:26,160 like I said this free course is targeted 590 00:18:26,160 --> 00:18:28,080 at both beginners and more intermediate 591 00:18:28,080 --> 00:18:30,120 users in order to start following the 592 00:18:30,120 --> 00:18:31,559 course you really only need to know the 593 00:18:31,559 --> 00:18:33,900 absolute Basics I've made three useful 594 00:18:33,900 --> 00:18:35,520 videos with all of the basic knowledge 595 00:18:35,520 --> 00:18:37,380 required to follow this course 596 00:18:37,380 --> 00:18:39,179 watch the video on how to download 597 00:18:39,179 --> 00:18:41,940 install and set up Unity then the quick 598 00:18:41,940 --> 00:18:44,000 Unity Basics and the c-sharp basics 599 00:18:44,000 --> 00:18:46,620 those three Quick videos contain all of 600 00:18:46,620 --> 00:18:48,660 the absolute basic knowledge you need so 601 00:18:48,660 --> 00:18:50,220 if you're a complete beginner go ahead 602 00:18:50,220 --> 00:18:51,960 pause this video and go quickly watch 603 00:18:51,960 --> 00:18:53,880 those and even if you are already 604 00:18:53,880 --> 00:18:55,799 somewhat familiar with unity still go 605 00:18:55,799 --> 00:18:57,000 ahead and give those videos a watch 606 00:18:57,000 --> 00:18:59,160 perhaps in a faster speed just so you 607 00:18:59,160 --> 00:19:00,780 know everything that this course assumes 608 00:19:00,780 --> 00:19:02,940 that you know here I will assume that 609 00:19:02,940 --> 00:19:04,380 you know the basics covered in those 610 00:19:04,380 --> 00:19:06,419 videos like what is a game object what 611 00:19:06,419 --> 00:19:08,220 is a transform what is a mono Behavior 612 00:19:08,220 --> 00:19:10,740 how scripts have a start and update and 613 00:19:10,740 --> 00:19:12,840 some c-sharp Basics as long as you know 614 00:19:12,840 --> 00:19:14,580 those absolute Basics you should be able 615 00:19:14,580 --> 00:19:16,440 to follow everything in this course I 616 00:19:16,440 --> 00:19:17,940 won't teach everything above the 617 00:19:17,940 --> 00:19:20,160 absolute Basics and if you are a more 618 00:19:20,160 --> 00:19:21,840 advanced users definitely keep watching 619 00:19:21,840 --> 00:19:23,760 the beginning of this course might not 620 00:19:23,760 --> 00:19:25,860 have much that is new to you but as we 621 00:19:25,860 --> 00:19:27,299 build the game and start using more 622 00:19:27,299 --> 00:19:29,160 advanced tools like script of objects 623 00:19:29,160 --> 00:19:30,679 c-sharp events and interfaces 624 00:19:30,679 --> 00:19:32,880 refactoring code and focusing on Project 625 00:19:32,880 --> 00:19:34,679 architecture and writing some good clean 626 00:19:34,679 --> 00:19:35,580 code 627 00:19:35,580 --> 00:19:37,440 if you are not a complete beginner you 628 00:19:37,440 --> 00:19:38,940 will still learn quite a lot from seeing 629 00:19:38,940 --> 00:19:41,220 how this project is built and again like 630 00:19:41,220 --> 00:19:42,900 I said I answer comments every single 631 00:19:42,900 --> 00:19:45,179 day so any questions you have just post 632 00:19:45,179 --> 00:19:46,740 them there and I'll do my best to help 633 00:19:46,740 --> 00:19:49,140 this course is split into lectures they 634 00:19:49,140 --> 00:19:51,000 are all as chapters on videos so you can 635 00:19:51,000 --> 00:19:53,340 navigate around let me also take this 636 00:19:53,340 --> 00:19:54,840 time to point out that you are not 637 00:19:54,840 --> 00:19:56,340 expected to follow this course in one 638 00:19:56,340 --> 00:19:58,380 sitting go ahead and take your time 639 00:19:58,380 --> 00:20:00,539 focus on actually learning remember 640 00:20:00,539 --> 00:20:02,760 that's the only goal you're not 641 00:20:02,760 --> 00:20:04,380 competing with anyone you're gaining 642 00:20:04,380 --> 00:20:05,940 knowledge just for yourself 643 00:20:05,940 --> 00:20:07,740 so take as much time as you need 644 00:20:07,740 --> 00:20:09,720 re-watch some lectures if you feel you 645 00:20:09,720 --> 00:20:11,340 didn't fully get it or just ask some 646 00:20:11,340 --> 00:20:13,559 questions whatever you do take your time 647 00:20:13,559 --> 00:20:15,960 and just focus on actually learning so 648 00:20:15,960 --> 00:20:17,580 again if you haven't done so go ahead 649 00:20:17,580 --> 00:20:19,200 pause this video and go watch those 650 00:20:19,200 --> 00:20:21,419 three Basics videos with that we're 651 00:20:21,419 --> 00:20:22,860 going to have everything we need to get 652 00:20:22,860 --> 00:20:25,020 started we're going to start only from 653 00:20:25,020 --> 00:20:26,880 scratch so let's begin creating a brand 654 00:20:26,880 --> 00:20:29,340 new project in the next lecture 655 00:20:29,340 --> 00:20:31,140 hello and welcome I'm your code monkey 656 00:20:31,140 --> 00:20:32,880 in this lecture we're going to begin 657 00:20:32,880 --> 00:20:34,740 actually building our game so let's 658 00:20:34,740 --> 00:20:36,660 create a chameleon 2 project and start 659 00:20:36,660 --> 00:20:38,820 building it on from scratch okay so the 660 00:20:38,820 --> 00:20:39,900 first thing that we need is to install 661 00:20:39,900 --> 00:20:41,940 Unity now I cover this in detail on that 662 00:20:41,940 --> 00:20:44,160 other Basics video so here I will assume 663 00:20:44,160 --> 00:20:45,480 that you already have Unity Hub 664 00:20:45,480 --> 00:20:47,220 installed the first decision we really 665 00:20:47,220 --> 00:20:48,780 need to make is choosing a Unity version 666 00:20:48,780 --> 00:20:51,059 Sony Hub you go into installs and 667 00:20:51,059 --> 00:20:53,039 install an editor and now Unity 668 00:20:53,039 --> 00:20:54,780 recommends that you use the LTS version 669 00:20:54,780 --> 00:20:56,940 or long term sport you should be using 670 00:20:56,940 --> 00:20:58,740 that one in most cases it's what it 671 00:20:58,740 --> 00:21:00,780 installs by default which as the time of 672 00:21:00,780 --> 00:21:02,520 this recording the latest one the latest 673 00:21:02,520 --> 00:21:05,820 LTS one is 2021.3 however I want this 674 00:21:05,820 --> 00:21:07,320 video to stay up to date for as long as 675 00:21:07,320 --> 00:21:09,120 possible so for making this game I will 676 00:21:09,120 --> 00:21:11,520 actually be using version 2022.2 if 677 00:21:11,520 --> 00:21:12,960 you're watching this video where it is 678 00:21:12,960 --> 00:21:15,000 came out then download this version and 679 00:21:15,000 --> 00:21:16,260 if you're watching this months in the 680 00:21:16,260 --> 00:21:18,419 future after version 22 on TS is out 681 00:21:18,419 --> 00:21:19,740 then you can use that one it won't 682 00:21:19,740 --> 00:21:21,240 probably be the exact same thing as 683 00:21:21,240 --> 00:21:23,340 version 22.2 so you should be able to 684 00:21:23,340 --> 00:21:24,780 follow everything exactly for any 685 00:21:24,780 --> 00:21:26,520 changes I will Point them out in the 686 00:21:26,520 --> 00:21:28,260 updated pin comment and if you're 687 00:21:28,260 --> 00:21:29,640 watching this years in the future and 688 00:21:29,640 --> 00:21:31,500 there's an even newer LTS version I 689 00:21:31,500 --> 00:21:32,880 would still recommend you follow using 690 00:21:32,880 --> 00:21:35,220 the 22 LTS don't worry about using a 691 00:21:35,220 --> 00:21:36,780 quote unquote older version everything 692 00:21:36,780 --> 00:21:38,400 you'll learn here in this version will 693 00:21:38,400 --> 00:21:40,080 still be applicable even 10 years from 694 00:21:40,080 --> 00:21:41,580 now so I said I'm going to be installing 695 00:21:41,580 --> 00:21:43,380 this one in terms of modulus doesn't 696 00:21:43,380 --> 00:21:45,059 really need anything I already have 697 00:21:45,059 --> 00:21:46,799 Visual Studio Community installed and 698 00:21:46,799 --> 00:21:48,360 all the other ones are unticked so 699 00:21:48,360 --> 00:21:50,659 install 700 00:21:52,620 --> 00:21:54,600 okay so the version is installed now 701 00:21:54,600 --> 00:21:56,039 let's create a new project let's go into 702 00:21:56,039 --> 00:21:57,960 the projects tab then create a new 703 00:21:57,960 --> 00:22:00,179 project and now first up up here make 704 00:22:00,179 --> 00:22:01,799 sure to select the right version so 705 00:22:01,799 --> 00:22:04,620 again I'm going to be using 22.2 then 706 00:22:04,620 --> 00:22:06,659 for the templates this has mainly to do 707 00:22:06,659 --> 00:22:08,640 with the UNT render pipelines now if 708 00:22:08,640 --> 00:22:09,960 you're a beginner don't worry about that 709 00:22:09,960 --> 00:22:12,299 too much just go ahead and select the 3D 710 00:22:12,299 --> 00:22:14,460 urp template so scroll down this one 711 00:22:14,460 --> 00:22:16,980 right here 3D urp make sure to select 712 00:22:16,980 --> 00:22:18,299 this one and not the one that says just 713 00:22:18,299 --> 00:22:20,520 reading the urp here stands for the 714 00:22:20,520 --> 00:22:22,200 universal render pipeline which means 715 00:22:22,200 --> 00:22:23,760 our game will be playable on literally 716 00:22:23,760 --> 00:22:25,980 any platform so we can make the funnel 717 00:22:25,980 --> 00:22:27,900 game and put it on steam or consoles are 718 00:22:27,900 --> 00:22:30,059 mobile it won't run on everything then 719 00:22:30,059 --> 00:22:31,140 over here on the right side let's 720 00:22:31,140 --> 00:22:33,000 quickly just download the template there 721 00:22:33,000 --> 00:22:34,320 it is it's done 722 00:22:34,320 --> 00:22:36,960 now select the name for your project so 723 00:22:36,960 --> 00:22:39,539 I'm going to call this kitchen chaos and 724 00:22:39,539 --> 00:22:41,400 then select the founder for it all right 725 00:22:41,400 --> 00:22:42,960 so that's it again make sure you're 726 00:22:42,960 --> 00:22:44,700 using the exact right version make sure 727 00:22:44,700 --> 00:22:46,799 you're using the 3D urp template give it 728 00:22:46,799 --> 00:22:50,299 a name a folder and let's head on create 729 00:22:53,640 --> 00:22:55,559 all right so it's open and right away 730 00:22:55,559 --> 00:22:57,179 you might or might not see a window 731 00:22:57,179 --> 00:22:59,400 talking about urp material upgrades I 732 00:22:59,400 --> 00:23:00,659 think this has to do with the template 733 00:23:00,659 --> 00:23:02,460 not having the default materials updated 734 00:23:02,460 --> 00:23:04,320 to the latest Erp version so if you're 735 00:23:04,320 --> 00:23:05,700 watching this in the future chances are 736 00:23:05,700 --> 00:23:07,440 you might not see this one at all but if 737 00:23:07,440 --> 00:23:09,120 you do then just go ahead click on OK 738 00:23:09,120 --> 00:23:10,860 and it will automatically upgrade all of 739 00:23:10,860 --> 00:23:13,260 the default materials alright so here we 740 00:23:13,260 --> 00:23:15,840 have our basic unity window now since we 741 00:23:15,840 --> 00:23:17,520 started a project starting from the RP 742 00:23:17,520 --> 00:23:19,320 template we have down here A bunch of 743 00:23:19,320 --> 00:23:21,240 Erp helper files so you can click to 744 00:23:21,240 --> 00:23:22,740 select the readme file and you can see 745 00:23:22,740 --> 00:23:24,299 it over here on the right side on the 746 00:23:24,299 --> 00:23:25,799 inspector if you want you can browse 747 00:23:25,799 --> 00:23:27,299 around these links in order to learn 748 00:23:27,299 --> 00:23:28,919 more about urp but in our case we're 749 00:23:28,919 --> 00:23:30,240 building the our game we really don't 750 00:23:30,240 --> 00:23:31,740 need this so we're here on the 751 00:23:31,740 --> 00:23:33,120 inspection let's just click this button 752 00:23:33,120 --> 00:23:35,159 to clean up these readme files just go 753 00:23:35,159 --> 00:23:37,919 ahead click on yes and okay that's it so 754 00:23:37,919 --> 00:23:39,419 basically you should only have these 755 00:23:39,419 --> 00:23:41,159 files in your project window so there's 756 00:23:41,159 --> 00:23:43,020 a scene folder and inside we've got the 757 00:23:43,020 --> 00:23:44,580 simple scene then we've got the settings 758 00:23:44,580 --> 00:23:47,220 and inside a bunch of urp assets while 759 00:23:47,220 --> 00:23:48,179 this should have been set up 760 00:23:48,179 --> 00:23:49,620 automatically since we use the 3D 761 00:23:49,620 --> 00:23:51,360 template and then finally we just have 762 00:23:51,360 --> 00:23:53,159 the urp equivalent settings asset now 763 00:23:53,159 --> 00:23:54,600 let's just verify find everything worked 764 00:23:54,600 --> 00:23:56,640 correctly so let's go to the top left go 765 00:23:56,640 --> 00:23:58,440 into edit then go down into project 766 00:23:58,440 --> 00:24:00,539 settings then over here let's go into 767 00:24:00,539 --> 00:24:02,520 the graphics Tab and you should see the 768 00:24:02,520 --> 00:24:04,440 urp High Fidelity asset assigned by 769 00:24:04,440 --> 00:24:06,000 default if not you can click on the 770 00:24:06,000 --> 00:24:07,860 circle icon and assign it then the other 771 00:24:07,860 --> 00:24:09,659 menus over here the urp mobile settings 772 00:24:09,659 --> 00:24:11,520 again this one should be set by default 773 00:24:11,520 --> 00:24:13,740 then down here on the quality tab on 774 00:24:13,740 --> 00:24:15,299 this one make sure High Fidelity is 775 00:24:15,299 --> 00:24:16,980 selected basically whatever you select 776 00:24:16,980 --> 00:24:18,480 here is the quality that we'll be using 777 00:24:18,480 --> 00:24:20,280 in the editor and in turn the selected 778 00:24:20,280 --> 00:24:21,780 quality over here also has a render 779 00:24:21,780 --> 00:24:23,640 pipeline Ascent now in order to avoid 780 00:24:23,640 --> 00:24:25,200 any confusion let's actually get rid of 781 00:24:25,200 --> 00:24:26,760 the other ones so let's just click on 782 00:24:26,760 --> 00:24:28,080 the trash icon to get rid of the 783 00:24:28,080 --> 00:24:29,520 performance and the bounce quality so 784 00:24:29,520 --> 00:24:31,260 just click and click okay so we only 785 00:24:31,260 --> 00:24:33,120 have this one then let's close the 786 00:24:33,120 --> 00:24:34,860 project settings and let's go into the 787 00:24:34,860 --> 00:24:36,299 settings folder and over here let's 788 00:24:36,299 --> 00:24:38,159 select the urp balance there are two 789 00:24:38,159 --> 00:24:39,960 assets for each quality so select those 790 00:24:39,960 --> 00:24:41,460 leave the High Fidelity and the 791 00:24:41,460 --> 00:24:42,900 performance and let's delete these 792 00:24:42,900 --> 00:24:44,640 alright that's it by the way if you made 793 00:24:44,640 --> 00:24:46,020 a mistake and accidentally deleted 794 00:24:46,020 --> 00:24:47,280 something don't worry you can always 795 00:24:47,280 --> 00:24:48,960 just click over here on the plus icon on 796 00:24:48,960 --> 00:24:50,580 the project window and then go over here 797 00:24:50,580 --> 00:24:52,440 under rendering and you can create a new 798 00:24:52,440 --> 00:24:53,820 urp asset with the universe personal 799 00:24:53,820 --> 00:24:56,220 render okay so just like this so we only 800 00:24:56,220 --> 00:24:58,140 have one quality setting we have high 801 00:24:58,140 --> 00:25:00,000 fidelity the quality setting is using 802 00:25:00,000 --> 00:25:01,679 this random pipeline asset which is also 803 00:25:01,679 --> 00:25:03,539 using this renderer so that's really it 804 00:25:03,539 --> 00:25:05,039 with this we have the absolute bare 805 00:25:05,039 --> 00:25:06,780 minimum we need if in the end after 806 00:25:06,780 --> 00:25:08,100 building the whole game you want to 807 00:25:08,100 --> 00:25:09,659 provide multiple quality settings then 808 00:25:09,659 --> 00:25:11,100 you can come back to this menu and 809 00:25:11,100 --> 00:25:12,539 recreate them but in order to avoid 810 00:25:12,539 --> 00:25:13,799 confusion while building the game let's 811 00:25:13,799 --> 00:25:15,240 keep things like this as simple as 812 00:25:15,240 --> 00:25:17,159 possible okay so that's the basic setup 813 00:25:17,159 --> 00:25:19,200 done next we want to prepare our layout 814 00:25:19,200 --> 00:25:22,380 so let's continue on to the next lecture 815 00:25:22,380 --> 00:25:24,299 hello and welcome I'm your code monkey 816 00:25:24,299 --> 00:25:26,039 in this lecture we're going to learn 817 00:25:26,039 --> 00:25:28,200 about the union layout and set it up so 818 00:25:28,200 --> 00:25:30,000 first things first let's familiarize 819 00:25:30,000 --> 00:25:31,980 ourselves with the various NT Windows to 820 00:25:31,980 --> 00:25:33,360 create our own layout it's very 821 00:25:33,360 --> 00:25:34,440 important that you feel uncomfortable 822 00:25:34,440 --> 00:25:36,059 with your layout that you have easy 823 00:25:36,059 --> 00:25:37,380 access to all the things that you need 824 00:25:37,380 --> 00:25:38,940 then you know where everything is you 825 00:25:38,940 --> 00:25:40,260 can see that there's lots of tabs 826 00:25:40,260 --> 00:25:41,640 everywhere over here on the NT window 827 00:25:41,640 --> 00:25:43,200 all of them can be dragged and dropped 828 00:25:43,200 --> 00:25:45,240 in any different position so you can 829 00:25:45,240 --> 00:25:46,740 customize your layout to get it looking 830 00:25:46,740 --> 00:25:48,840 exactly as you want you can set it up in 831 00:25:48,840 --> 00:25:50,460 any way but it will be easier to follow 832 00:25:50,460 --> 00:25:51,960 this course if you're following the same 833 00:25:51,960 --> 00:25:53,880 layout as me I'm assuming you've seen my 834 00:25:53,880 --> 00:25:55,679 quick Basics video so I'm assuming you 835 00:25:55,679 --> 00:25:57,299 know what is the inspector what is a 836 00:25:57,299 --> 00:25:59,159 game object what is a transform what is 837 00:25:59,159 --> 00:26:00,600 the console where is the hierarchy and 838 00:26:00,600 --> 00:26:02,220 so on if this is the very first time 839 00:26:02,220 --> 00:26:03,720 you're seeing the UNT interface go watch 840 00:26:03,720 --> 00:26:05,400 that other quick video first just learn 841 00:26:05,400 --> 00:26:07,380 the absolute Basics now for me I've been 842 00:26:07,380 --> 00:26:09,240 using Unity for over 10 years now so 843 00:26:09,240 --> 00:26:10,620 let's see the layout that I've developed 844 00:26:10,620 --> 00:26:12,419 over the years first the inspector on 845 00:26:12,419 --> 00:26:14,220 the right side just like default that 846 00:26:14,220 --> 00:26:15,840 way we always have a nice view of the 847 00:26:15,840 --> 00:26:17,520 selected object and whatever scripts and 848 00:26:17,520 --> 00:26:19,320 components it has then for the hierarchy 849 00:26:19,320 --> 00:26:21,240 I like to put it down here only on left 850 00:26:21,240 --> 00:26:22,679 side we're going to make sure that in 851 00:26:22,679 --> 00:26:24,120 our scene is always organized so we 852 00:26:24,120 --> 00:26:25,679 don't need the hierarchy to take up tons 853 00:26:25,679 --> 00:26:27,659 of space then with the project files 854 00:26:27,659 --> 00:26:29,279 next to it this corner is enough to 855 00:26:29,279 --> 00:26:31,080 really browse all of the files we want 856 00:26:31,080 --> 00:26:32,880 the console to be on the tab right next 857 00:26:32,880 --> 00:26:34,500 to it usually I find that when making 858 00:26:34,500 --> 00:26:36,000 the game I want to look at the project 859 00:26:36,000 --> 00:26:37,860 window but when playing the game I just 860 00:26:37,860 --> 00:26:39,539 want to look at the console so keeping 861 00:26:39,539 --> 00:26:40,860 them in the same place but on different 862 00:26:40,860 --> 00:26:42,659 tabs works great then over here on the 863 00:26:42,659 --> 00:26:44,279 center of the scene View and again with 864 00:26:44,279 --> 00:26:46,020 the game view right next to it okay so 865 00:26:46,020 --> 00:26:47,820 this is the basic layout that I normally 866 00:26:47,820 --> 00:26:50,159 use now for a couple more options let's 867 00:26:50,159 --> 00:26:52,679 go into the project window and on the 868 00:26:52,679 --> 00:26:53,880 top right corner you can see over here 869 00:26:53,880 --> 00:26:55,980 these little three dots by default it 870 00:26:55,980 --> 00:26:57,419 shows you a two column layout so there's 871 00:26:57,419 --> 00:26:59,039 a column here and a column here but 872 00:26:59,039 --> 00:27:00,419 personally I prefer the one column 873 00:27:00,419 --> 00:27:02,340 layout this shock is one of the project 874 00:27:02,340 --> 00:27:04,440 files in a nice compact list view the 875 00:27:04,440 --> 00:27:05,760 one thing where I prefer the other one 876 00:27:05,760 --> 00:27:07,260 is if you're browsing for some visual 877 00:27:07,260 --> 00:27:08,760 assets over here you can increase the 878 00:27:08,760 --> 00:27:10,740 thumbnail size but for most times I 879 00:27:10,740 --> 00:27:12,240 really like to use the one com layout 880 00:27:12,240 --> 00:27:14,159 much more compact also since we're 881 00:27:14,159 --> 00:27:15,840 talking about the project window just in 882 00:27:15,840 --> 00:27:17,159 case you don't know there's over here 883 00:27:17,159 --> 00:27:19,200 this little button with the eye this one 884 00:27:19,200 --> 00:27:21,120 has to do with package visibility if you 885 00:27:21,120 --> 00:27:22,260 toggle it then some of the inside 886 00:27:22,260 --> 00:27:24,059 compacts are hidden whereas if you 887 00:27:24,059 --> 00:27:25,980 untangle it then you can see all the 888 00:27:25,980 --> 00:27:27,539 various packages with all the source 889 00:27:27,539 --> 00:27:29,159 code and so on you can expand over here 890 00:27:29,159 --> 00:27:30,960 the packages and right now it is showing 891 00:27:30,960 --> 00:27:32,940 all of them all of them with source code 892 00:27:32,940 --> 00:27:34,620 the things everything in there and if 893 00:27:34,620 --> 00:27:36,000 you click on this then it hides it only 894 00:27:36,000 --> 00:27:37,919 shows a bunch of core ones but for most 895 00:27:37,919 --> 00:27:39,299 part you really want to leave this text 896 00:27:39,299 --> 00:27:41,100 and leave this one collapse nice and 897 00:27:41,100 --> 00:27:43,500 clean okay so then on the console over 898 00:27:43,500 --> 00:27:44,940 here once again let's go into the three 899 00:27:44,940 --> 00:27:47,400 dots and for the unlock entry for this 900 00:27:47,400 --> 00:27:49,380 one I like to select one line this makes 901 00:27:49,380 --> 00:27:51,120 the console nice and compact which I 902 00:27:51,120 --> 00:27:53,460 personally prefer you can see more logs 903 00:27:53,460 --> 00:27:55,140 without taking up more space and if you 904 00:27:55,140 --> 00:27:56,520 want to read the home log you can always 905 00:27:56,520 --> 00:27:58,320 just click on it to see the home stack 906 00:27:58,320 --> 00:27:59,580 Trace now there are also some more 907 00:27:59,580 --> 00:28:01,080 options over here if you want for 908 00:28:01,080 --> 00:28:02,880 example show the timestamp this will 909 00:28:02,880 --> 00:28:04,140 show the timestamp when each message 910 00:28:04,140 --> 00:28:06,240 were sent you can use a mono space font 911 00:28:06,240 --> 00:28:08,460 meaning a font where every character has 912 00:28:08,460 --> 00:28:09,960 the exact same width so a bunch of 913 00:28:09,960 --> 00:28:11,520 options but for me leaving it just like 914 00:28:11,520 --> 00:28:13,559 this works perfectly fine then also 915 00:28:13,559 --> 00:28:14,760 importantly over here these three 916 00:28:14,760 --> 00:28:17,100 buttons these toggle the visibility for 917 00:28:17,100 --> 00:28:18,480 the type of messages that appear in the 918 00:28:18,480 --> 00:28:20,340 console the unlocked one this one is for 919 00:28:20,340 --> 00:28:21,840 regular messages we're going to use this 920 00:28:21,840 --> 00:28:23,760 a lot then we've got warnings and 921 00:28:23,760 --> 00:28:25,980 finally errors if you untangle them then 922 00:28:25,980 --> 00:28:27,659 the messages of that type will not show 923 00:28:27,659 --> 00:28:29,100 up on the console so if you ever come 924 00:28:29,100 --> 00:28:30,779 across an issue where nothing is showing 925 00:28:30,779 --> 00:28:32,400 up on the console make sure all three of 926 00:28:32,400 --> 00:28:33,900 these buttons are ticked then on left 927 00:28:33,900 --> 00:28:35,520 side on clear you can click on the Arrow 928 00:28:35,520 --> 00:28:37,140 to see more options I like to set it to 929 00:28:37,140 --> 00:28:39,360 clear on play then collapse this one 930 00:28:39,360 --> 00:28:40,980 basically collapses messages that are 931 00:28:40,980 --> 00:28:42,960 the same all of them into one entry 932 00:28:42,960 --> 00:28:45,059 personally I do nothing like this I want 933 00:28:45,059 --> 00:28:46,740 to see every single message as it comes 934 00:28:46,740 --> 00:28:48,600 out even if it's repeated I've also seen 935 00:28:48,600 --> 00:28:50,279 this lead to a lot of confusion for some 936 00:28:50,279 --> 00:28:52,140 people they think their code is firing 937 00:28:52,140 --> 00:28:53,279 just one message when it's actually 938 00:28:53,279 --> 00:28:54,960 firing hundreds So to avoid any 939 00:28:54,960 --> 00:28:56,340 confusion make sure you leave this 940 00:28:56,340 --> 00:28:58,500 Untitled then for airpods this will 941 00:28:58,500 --> 00:28:59,880 automatically pause the game when there 942 00:28:59,880 --> 00:29:01,440 occurs you should definitely have this 943 00:29:01,440 --> 00:29:03,120 one toggled if there is an area you 944 00:29:03,120 --> 00:29:04,500 definitely want to know about it you 945 00:29:04,500 --> 00:29:05,880 want to know when it happens so you can 946 00:29:05,880 --> 00:29:07,799 fix it whereas if you untuckle this you 947 00:29:07,799 --> 00:29:09,360 might get some errors and the game might 948 00:29:09,360 --> 00:29:10,860 keep playing which will then lead to 949 00:29:10,860 --> 00:29:12,539 lots of confusion when something starts 950 00:29:12,539 --> 00:29:14,400 behaving weirdly so always leave this 951 00:29:14,400 --> 00:29:16,080 one toggled and then the editor button 952 00:29:16,080 --> 00:29:17,520 this one is for more advanced use case 953 00:29:17,520 --> 00:29:19,380 so don't worry about it okay so that's 954 00:29:19,380 --> 00:29:21,240 the console then over here for the game 955 00:29:21,240 --> 00:29:23,520 view we've got a button here to select 956 00:29:23,520 --> 00:29:25,380 the aspect ratio let's go ahead and 957 00:29:25,380 --> 00:29:27,899 select fully Gene this one is a 16x9 958 00:29:27,899 --> 00:29:29,460 aspect ratio so everything is pretty 959 00:29:29,460 --> 00:29:31,380 normal this will really only matter when 960 00:29:31,380 --> 00:29:33,299 we start working on the UI but so I like 961 00:29:33,299 --> 00:29:35,580 to keep it at 16x9 always then on this 962 00:29:35,580 --> 00:29:37,200 button that says play Focus we can 963 00:29:37,200 --> 00:29:39,059 modify some options basically Focus 964 00:29:39,059 --> 00:29:40,919 won't play exam like this on this small 965 00:29:40,919 --> 00:29:42,720 window if you choose maximize then it 966 00:29:42,720 --> 00:29:44,279 will maximize this one when playing the 967 00:29:44,279 --> 00:29:46,140 game and play in Focus won't play the 968 00:29:46,140 --> 00:29:47,760 game even when the window is not in 969 00:29:47,760 --> 00:29:49,320 Focus then another important one is 970 00:29:49,320 --> 00:29:50,880 actually on the same one as the aspect 971 00:29:50,880 --> 00:29:52,500 ratio here we've got a button to turn on 972 00:29:52,500 --> 00:29:54,299 vsync usually When developing the game 973 00:29:54,299 --> 00:29:55,679 you really want to toggle this that's 974 00:29:55,679 --> 00:29:57,000 because right in the beginning when the 975 00:29:57,000 --> 00:29:58,380 game doesn't really have anything you 976 00:29:58,380 --> 00:29:59,820 can leave it on Talent then this might 977 00:29:59,820 --> 00:30:01,500 run at like a thousand frames per second 978 00:30:01,500 --> 00:30:03,480 and that will pretty much drive your GPU 979 00:30:03,480 --> 00:30:05,159 crazy finally if your game view is 980 00:30:05,159 --> 00:30:06,779 looking a bit too pixelated make sure 981 00:30:06,779 --> 00:30:08,580 over here on the scale slider make sure 982 00:30:08,580 --> 00:30:10,320 this one is not zoomed in this one 983 00:30:10,320 --> 00:30:11,880 should always be pushed straight to the 984 00:30:11,880 --> 00:30:13,440 left as much as possible okay so that's 985 00:30:13,440 --> 00:30:15,179 the game view then over here on the 986 00:30:15,179 --> 00:30:16,860 scene view for this one default should 987 00:30:16,860 --> 00:30:18,840 be good these two buttons are extremely 988 00:30:18,840 --> 00:30:20,520 important pretty much all the time you 989 00:30:20,520 --> 00:30:21,899 want to keep the tone handles on the 990 00:30:21,899 --> 00:30:23,700 pivot it and not on the center if you 991 00:30:23,700 --> 00:30:25,140 ever see your handles on weird places 992 00:30:25,140 --> 00:30:26,760 always come back to this you want to 993 00:30:26,760 --> 00:30:28,080 sound pivot pretty much all the time 994 00:30:28,080 --> 00:30:30,299 then for rotation sometimes local is 995 00:30:30,299 --> 00:30:31,919 useful but for the most part you should 996 00:30:31,919 --> 00:30:33,539 probably be keeping in and Global then 997 00:30:33,539 --> 00:30:35,279 for the great showing the reason why yep 998 00:30:35,279 --> 00:30:36,480 down looks pretty good a nice little 999 00:30:36,480 --> 00:30:38,039 visual grid then you've got a bunch more 1000 00:30:38,039 --> 00:30:39,840 options if you want then next to it 1001 00:30:39,840 --> 00:30:42,299 we've got snapping this one we also 1002 00:30:42,299 --> 00:30:44,220 don't need this for now and finally same 1003 00:30:44,220 --> 00:30:45,899 thing for increment also don't need this 1004 00:30:45,899 --> 00:30:47,580 okay then on the right for the drum mode 1005 00:30:47,580 --> 00:30:49,320 let's leave it on Shaden for two then 1006 00:30:49,320 --> 00:30:50,700 let's leave this disabled since we're 1007 00:30:50,700 --> 00:30:52,620 working on a 3D game for lights let's 1008 00:30:52,620 --> 00:30:54,480 make sure this one is enabled for sound 1009 00:30:54,480 --> 00:30:55,799 we're only going to add this in the end 1010 00:30:55,799 --> 00:30:57,299 so it doesn't really matter for now then 1011 00:30:57,299 --> 00:30:59,220 for special effects usually you want 1012 00:30:59,220 --> 00:31:00,779 this one to be enabled so it shows 1013 00:31:00,779 --> 00:31:02,279 everything you can click on the arrow 1014 00:31:02,279 --> 00:31:03,600 and make sure all of them are toggled 1015 00:31:03,600 --> 00:31:05,700 the only exception is always refresh you 1016 00:31:05,700 --> 00:31:07,260 probably don't need this little scene 1017 00:31:07,260 --> 00:31:09,299 window to be refreshing at 60 frames per 1018 00:31:09,299 --> 00:31:10,500 second so you can leave that one 1019 00:31:10,500 --> 00:31:12,179 unticked and take on the others then 1020 00:31:12,179 --> 00:31:13,980 these are for the hidden objects so 1021 00:31:13,980 --> 00:31:15,480 let's leave them toggled for the camera 1022 00:31:15,480 --> 00:31:17,820 here are the defaults and finally gizmos 1023 00:31:17,820 --> 00:31:19,799 leave them all enabled as the defaults 1024 00:31:19,799 --> 00:31:21,659 alright so down that's end here is in 1025 00:31:21,659 --> 00:31:23,159 layout and going to be using throughout 1026 00:31:23,159 --> 00:31:24,840 the course it will be easier to follow 1027 00:31:24,840 --> 00:31:26,100 the course if you're using the exact 1028 00:31:26,100 --> 00:31:27,899 same layout as me so ideally you should 1029 00:31:27,899 --> 00:31:29,580 be using this but again like I mentioned 1030 00:31:29,580 --> 00:31:31,380 all the windows are customizable so if 1031 00:31:31,380 --> 00:31:32,580 there's something that you absolutely 1032 00:31:32,580 --> 00:31:34,559 prefer differently then go ahead you can 1033 00:31:34,559 --> 00:31:36,000 drag and drop and place any Windows 1034 00:31:36,000 --> 00:31:37,380 anywhere you want so once you have 1035 00:31:37,380 --> 00:31:39,299 layout your happy win you can go up here 1036 00:31:39,299 --> 00:31:40,860 to the top right corner where it says 1037 00:31:40,860 --> 00:31:42,480 default you can click on it and here 1038 00:31:42,480 --> 00:31:43,860 you've got a bunch of layouts so you can 1039 00:31:43,860 --> 00:31:45,480 save your new layout so I'm going to 1040 00:31:45,480 --> 00:31:47,640 save this one as kitchen chaos and then 1041 00:31:47,640 --> 00:31:49,200 over here you can select anyone you want 1042 00:31:49,200 --> 00:31:51,000 for example if you ever have some issues 1043 00:31:51,000 --> 00:31:52,860 with any kind of weird editor Windows 1044 00:31:52,860 --> 00:31:54,840 you can load back the default layout and 1045 00:31:54,840 --> 00:31:56,340 then go back and load your own layout 1046 00:31:56,340 --> 00:31:58,260 okay so with that our layout is set up 1047 00:31:58,260 --> 00:32:00,000 the next important thing is setting up 1048 00:32:00,000 --> 00:32:01,679 visual studio so let's do that in the 1049 00:32:01,679 --> 00:32:03,179 next lecture 1050 00:32:03,179 --> 00:32:05,159 hello and welcome I'm your code monkey 1051 00:32:05,159 --> 00:32:07,140 in this lecture we're going to set up 1052 00:32:07,140 --> 00:32:09,539 our Visual Studio alright so with the 1053 00:32:09,539 --> 00:32:11,100 Intel layout setup let's make sure 1054 00:32:11,100 --> 00:32:12,840 Visual Studio is also set up correctly 1055 00:32:12,840 --> 00:32:14,940 I'm going to be using version 22 1056 00:32:14,940 --> 00:32:16,679 Community this one is the free version 1057 00:32:16,679 --> 00:32:18,659 you don't absolutely have to use the 1058 00:32:18,659 --> 00:32:20,520 same code ID that I'm using you can use 1059 00:32:20,520 --> 00:32:22,620 writer or vs code or whatever you want 1060 00:32:22,620 --> 00:32:24,419 so let's see my setup for visual studio 1061 00:32:24,419 --> 00:32:25,980 but first let's actually set up 1062 00:32:25,980 --> 00:32:28,200 something over here in unity so let's go 1063 00:32:28,200 --> 00:32:30,480 up top into window and then let's open 1064 00:32:30,480 --> 00:32:32,760 up the package manager then over here on 1065 00:32:32,760 --> 00:32:34,620 the drop down menu let's select the 1066 00:32:34,620 --> 00:32:36,600 packages and select the ones from DNT 1067 00:32:36,600 --> 00:32:38,760 registry then let's scroll down to find 1068 00:32:38,760 --> 00:32:41,039 the visual studio editor package so here 1069 00:32:41,039 --> 00:32:42,659 it is this one this package basically 1070 00:32:42,659 --> 00:32:44,159 handles the integration with visual 1071 00:32:44,159 --> 00:32:46,080 studio so you can use the debugger and a 1072 00:32:46,080 --> 00:32:47,640 bunch of things alternatively there's 1073 00:32:47,640 --> 00:32:49,140 also a package over here for visual 1074 00:32:49,140 --> 00:32:50,940 studio code and there's also one over 1075 00:32:50,940 --> 00:32:52,799 here for jetbrains Rider so if you're 1076 00:32:52,799 --> 00:32:54,539 using a different IDE go ahead and 1077 00:32:54,539 --> 00:32:56,039 install the package for me I'm going to 1078 00:32:56,039 --> 00:32:57,899 install the visual City one so this one 1079 00:32:57,899 --> 00:32:59,880 just go ahead and install okay it's done 1080 00:32:59,880 --> 00:33:02,640 so next let's go up into edit and let's 1081 00:33:02,640 --> 00:33:04,320 open up the print preferences then over 1082 00:33:04,320 --> 00:33:06,240 here let's go down into external tools 1083 00:33:06,240 --> 00:33:08,100 and on the external script editor make 1084 00:33:08,100 --> 00:33:09,539 sure you select the one you're using so 1085 00:33:09,539 --> 00:33:11,520 again for me I'm using visual studio 22 1086 00:33:11,520 --> 00:33:13,200 and also over here you've got a bunch of 1087 00:33:13,200 --> 00:33:14,940 extra options now if you want to play 1088 00:33:14,940 --> 00:33:16,500 around with reading the source code for 1089 00:33:16,500 --> 00:33:18,240 the very CNT packages then you can tick 1090 00:33:18,240 --> 00:33:19,980 on these boxes but in our case for this 1091 00:33:19,980 --> 00:33:21,840 simple game we don't need that so go 1092 00:33:21,840 --> 00:33:23,100 ahead and leave everything just like 1093 00:33:23,100 --> 00:33:24,840 this with defaults okay so with this 1094 00:33:24,840 --> 00:33:26,399 setup now we can go over here into 1095 00:33:26,399 --> 00:33:28,080 assets and open up the c-sharp project 1096 00:33:28,080 --> 00:33:29,760 and this should open up visual studio 1097 00:33:29,760 --> 00:33:32,220 and alright so here it is now for some 1098 00:33:32,220 --> 00:33:33,960 more settings inside of here in my 1099 00:33:33,960 --> 00:33:35,519 visual studio I have a really nice 1100 00:33:35,519 --> 00:33:37,440 extension that adds a bit more colors to 1101 00:33:37,440 --> 00:33:39,000 my code which makes it easier to read 1102 00:33:39,000 --> 00:33:40,980 and write so up top let's go into the 1103 00:33:40,980 --> 00:33:42,779 extensions menu and manage extensions 1104 00:33:42,779 --> 00:33:44,100 and the important one that I've 1105 00:33:44,100 --> 00:33:45,960 installed is this one vs4 if you want 1106 00:33:45,960 --> 00:33:47,820 you can go into the online Tab and over 1107 00:33:47,820 --> 00:33:49,559 here search for it any Apple that show 1108 00:33:49,559 --> 00:33:51,539 up in here then for the settings on that 1109 00:33:51,539 --> 00:33:53,580 extension let's go up here into tools 1110 00:33:53,580 --> 00:33:55,440 and let's open up the options then over 1111 00:33:55,440 --> 00:33:57,779 here let's scroll down and find vs4 Yep 1112 00:33:57,779 --> 00:33:59,159 this one and here are all the settings 1113 00:33:59,159 --> 00:34:00,600 and expand this and a bunch more 1114 00:34:00,600 --> 00:34:02,399 settings now for me I think these are on 1115 00:34:02,399 --> 00:34:04,019 the defaults I don't remember if I 1116 00:34:04,019 --> 00:34:05,940 changed anything the important one is 1117 00:34:05,940 --> 00:34:08,820 over here the rainbow braces so these 1118 00:34:08,820 --> 00:34:10,260 have a bunch of Commerce which make it a 1119 00:34:10,260 --> 00:34:12,060 bit easier to read the code so let's 1120 00:34:12,060 --> 00:34:13,800 create a simple script just to see this 1121 00:34:13,800 --> 00:34:15,839 so back in until let's go into the 1122 00:34:15,839 --> 00:34:17,760 project window let's click the plus icon 1123 00:34:17,760 --> 00:34:19,320 and let's create the brand new c-sharp 1124 00:34:19,320 --> 00:34:21,060 script let's call it just testing wait 1125 00:34:21,060 --> 00:34:23,280 for it to compile and now let's open now 1126 00:34:23,280 --> 00:34:24,780 over here I'm just going to write a 1127 00:34:24,780 --> 00:34:26,520 bunch of simple code just to test it out 1128 00:34:26,520 --> 00:34:28,440 you don't have to follow this alright so 1129 00:34:28,440 --> 00:34:30,540 here's a bunch of sample code these are 1130 00:34:30,540 --> 00:34:31,800 the colors you can see it makes 1131 00:34:31,800 --> 00:34:33,659 everything a bit easier to read although 1132 00:34:33,659 --> 00:34:35,099 again this is not a requirement you 1133 00:34:35,099 --> 00:34:36,719 don't absolutely need this extension but 1134 00:34:36,719 --> 00:34:38,520 personally I do find it quite useful I 1135 00:34:38,520 --> 00:34:39,780 find that it helps make the code more 1136 00:34:39,780 --> 00:34:41,460 readable than having everything be gray 1137 00:34:41,460 --> 00:34:43,320 okay so that's the setup for this 1138 00:34:43,320 --> 00:34:45,480 extension next for the text formatting 1139 00:34:45,480 --> 00:34:47,219 options so once again let's go into two 1140 00:34:47,219 --> 00:34:49,139 holes go into options and then over here 1141 00:34:49,139 --> 00:34:51,179 let's go into the text editor then over 1142 00:34:51,179 --> 00:34:52,800 here I think I've got pretty much all 1143 00:34:52,800 --> 00:34:54,839 the same defaults then we can go into 1144 00:34:54,839 --> 00:34:57,359 the c-sharp rules so here are all the 1145 00:34:57,359 --> 00:34:58,560 settings if you notice something 1146 00:34:58,560 --> 00:35:00,119 different on your end go ahead and pause 1147 00:35:00,119 --> 00:35:01,619 the video and compare the settings but 1148 00:35:01,619 --> 00:35:03,000 again I think everything here is pretty 1149 00:35:03,000 --> 00:35:04,859 much defaults I believe the only 1150 00:35:04,859 --> 00:35:06,480 difference that I did was over here on 1151 00:35:06,480 --> 00:35:08,640 the code style over here for new lines 1152 00:35:08,640 --> 00:35:10,619 personally I like to have the currently 1153 00:35:10,619 --> 00:35:12,599 brackets on the same line but if you 1154 00:35:12,599 --> 00:35:13,920 want you can also change it and put it 1155 00:35:13,920 --> 00:35:15,420 on the second leg I think that's pretty 1156 00:35:15,420 --> 00:35:16,500 much the only difference that I did 1157 00:35:16,500 --> 00:35:17,940 everything else should be exactly the 1158 00:35:17,940 --> 00:35:19,500 same as defaults so that's the code 1159 00:35:19,500 --> 00:35:21,420 sound settings and speaking of that the 1160 00:35:21,420 --> 00:35:22,980 next lecture is very important we're 1161 00:35:22,980 --> 00:35:24,900 going to talk a bit about naming rules 1162 00:35:24,900 --> 00:35:26,700 although just before we go let's just 1163 00:35:26,700 --> 00:35:28,380 clean up our testing script so let's 1164 00:35:28,380 --> 00:35:30,300 close this one click on the X then back 1165 00:35:30,300 --> 00:35:32,040 into Unity we don't need the script so 1166 00:35:32,040 --> 00:35:33,720 let's just delete it okay so with that 1167 00:35:33,720 --> 00:35:35,700 we have Visual Studio setup and ready to 1168 00:35:35,700 --> 00:35:37,260 go now let's continue in the next 1169 00:35:37,260 --> 00:35:40,020 lecture to learn about some naming rules 1170 00:35:40,020 --> 00:35:42,060 hello and welcome I'm your code monkey 1171 00:35:42,060 --> 00:35:43,680 in this lecture we're going to learn 1172 00:35:43,680 --> 00:35:45,359 something extremely important let's 1173 00:35:45,359 --> 00:35:47,339 learn about naming world this one is a 1174 00:35:47,339 --> 00:35:48,720 very important lecture that you should 1175 00:35:48,720 --> 00:35:50,339 definitely refer back to whenever you 1176 00:35:50,339 --> 00:35:52,140 have some questions so first what 1177 00:35:52,140 --> 00:35:54,060 exactly are naming rules these are 1178 00:35:54,060 --> 00:35:55,380 really just rules you follow when 1179 00:35:55,380 --> 00:35:57,180 writing your code it is extremely 1180 00:35:57,180 --> 00:35:58,740 important that you are consistent in 1181 00:35:58,740 --> 00:36:00,599 applying your own rules you don't want 1182 00:36:00,599 --> 00:36:02,400 one class in your game to be written a 1183 00:36:02,400 --> 00:36:04,020 certain way and then a different class 1184 00:36:04,020 --> 00:36:06,240 using a completely different style that 1185 00:36:06,240 --> 00:36:08,640 would create tons of confusion so naming 1186 00:36:08,640 --> 00:36:10,560 rules and writing the code correctly is 1187 00:36:10,560 --> 00:36:12,660 very very important one mistake that I 1188 00:36:12,660 --> 00:36:14,280 see a lot of beginners do is they send 1189 00:36:14,280 --> 00:36:15,660 me some code and ask why it's not 1190 00:36:15,660 --> 00:36:17,760 working then I take a quick look and I 1191 00:36:17,760 --> 00:36:19,320 see that all of the code is written in a 1192 00:36:19,320 --> 00:36:21,119 very messy way some functions are on 1193 00:36:21,119 --> 00:36:23,099 lowercase others using snake case some 1194 00:36:23,099 --> 00:36:25,020 films are in personal case some in camel 1195 00:36:25,020 --> 00:36:27,180 case and so on remember that code is 1196 00:36:27,180 --> 00:36:29,160 case sensitive so it is extremely 1197 00:36:29,160 --> 00:36:30,420 important that you write the code 1198 00:36:30,420 --> 00:36:32,280 correctly if you change a character from 1199 00:36:32,280 --> 00:36:34,020 lowercase to uppercase then you are 1200 00:36:34,020 --> 00:36:35,160 suddenly referring to something 1201 00:36:35,160 --> 00:36:36,660 completely different if you're a 1202 00:36:36,660 --> 00:36:38,220 beginner keep that always in your mind 1203 00:36:38,220 --> 00:36:40,859 code is case sensitive so don't just 1204 00:36:40,859 --> 00:36:42,839 write code semi-randomly write it 1205 00:36:42,839 --> 00:36:44,579 properly as if you were doing an English 1206 00:36:44,579 --> 00:36:46,440 literature test now with that said when 1207 00:36:46,440 --> 00:36:48,240 it comes to naming roles you can use 1208 00:36:48,240 --> 00:36:49,859 whatever name neurons you want different 1209 00:36:49,859 --> 00:36:51,720 people like different rules for example 1210 00:36:51,720 --> 00:36:53,640 you can use a prefix in your variables 1211 00:36:53,640 --> 00:36:55,440 you can use a postpick you can use 1212 00:36:55,440 --> 00:36:57,300 capitals for consonants chemical case 1213 00:36:57,300 --> 00:36:59,220 for properties snake case for Fields by 1214 00:36:59,220 --> 00:37:00,780 the way here are the definitions of what 1215 00:37:00,780 --> 00:37:02,640 those terms actually mean Pascal K 1216 00:37:02,640 --> 00:37:04,440 starts with a capital and every word is 1217 00:37:04,440 --> 00:37:06,720 capitalized camel case starts lowercase 1218 00:37:06,720 --> 00:37:08,160 and then uppercase for the first 1219 00:37:08,160 --> 00:37:10,260 selector of every other word kind of 1220 00:37:10,260 --> 00:37:11,880 like a camel hump in the middle and 1221 00:37:11,880 --> 00:37:13,260 snake Haze is where you add an 1222 00:37:13,260 --> 00:37:15,119 underscore in between the words I send 1223 00:37:15,119 --> 00:37:17,160 every rule can be valid the important 1224 00:37:17,160 --> 00:37:18,720 thing is that you are consistent in 1225 00:37:18,720 --> 00:37:20,160 always following through with your rules 1226 00:37:20,160 --> 00:37:21,900 as you might know Unity mono behaviors 1227 00:37:21,900 --> 00:37:23,339 have some deformed functions you can 1228 00:37:23,339 --> 00:37:25,260 Implement things like start and update 1229 00:37:25,260 --> 00:37:27,000 which are written using pastel case 1230 00:37:27,000 --> 00:37:28,859 since you can't really change in these 1231 00:37:28,859 --> 00:37:30,660 rules at least on function names I would 1232 00:37:30,660 --> 00:37:32,220 say you should base your rules off of 1233 00:37:32,220 --> 00:37:33,720 theirs so for functions you should 1234 00:37:33,720 --> 00:37:35,579 probably be using Pascal case for the 1235 00:37:35,579 --> 00:37:37,320 rules like I said choose whatever makes 1236 00:37:37,320 --> 00:37:39,000 sense to you here are some of my own 1237 00:37:39,000 --> 00:37:39,900 personal rooms that have developed 1238 00:37:39,900 --> 00:37:41,880 jumped over the last 10 years and the 1239 00:37:41,880 --> 00:37:43,260 code sound that I won't be following in 1240 00:37:43,260 --> 00:37:45,540 this course for functions I use Pascal 1241 00:37:45,540 --> 00:37:47,460 case just like unity and just like the 1242 00:37:47,460 --> 00:37:49,680 c-sharp standard for function parameters 1243 00:37:49,680 --> 00:37:52,560 I use camel case for Fields also camel 1244 00:37:52,560 --> 00:37:54,480 case properties are in personal case 1245 00:37:54,480 --> 00:37:56,820 constants are in uppercase snake case 1246 00:37:56,820 --> 00:37:58,980 then another rule is that I like to add 1247 00:37:58,980 --> 00:38:01,200 the top of the variable as a postfix so 1248 00:38:01,200 --> 00:38:02,880 if it's a list type in the list if it's 1249 00:38:02,880 --> 00:38:04,800 an array open array and now you might be 1250 00:38:04,800 --> 00:38:06,240 thinking with this wouldn't it be an 1251 00:38:06,240 --> 00:38:07,859 issue if we change the type then the 1252 00:38:07,859 --> 00:38:09,300 name is suddenly wrong and the simple 1253 00:38:09,300 --> 00:38:10,980 solution for that is that if I change 1254 00:38:10,980 --> 00:38:12,660 the type then I just use Visual Studio 1255 00:38:12,660 --> 00:38:14,339 to quickly change the name that's it 1256 00:38:14,339 --> 00:38:16,020 then for the currently brackets like I 1257 00:38:16,020 --> 00:38:17,460 mentioned in previous lecture I like 1258 00:38:17,460 --> 00:38:19,200 them on the same line some people have 1259 00:38:19,200 --> 00:38:20,820 some very strong opinions about this 1260 00:38:20,820 --> 00:38:22,920 really it's just a visual style and this 1261 00:38:22,920 --> 00:38:24,420 is the one that I personally prefer if 1262 00:38:24,420 --> 00:38:25,800 you like new online then go ahead and 1263 00:38:25,800 --> 00:38:27,359 use that it doesn't change how the code 1264 00:38:27,359 --> 00:38:29,880 Works in any way in a final rule spend 1265 00:38:29,880 --> 00:38:31,619 some time deciding on a proper name and 1266 00:38:31,619 --> 00:38:33,240 don't be afraid to rename things you 1267 00:38:33,240 --> 00:38:34,619 will note how all the code that we're 1268 00:38:34,619 --> 00:38:36,240 going to write in this course has proper 1269 00:38:36,240 --> 00:38:37,800 names for everything you should never 1270 00:38:37,800 --> 00:38:39,660 use a variable with a single letter like 1271 00:38:39,660 --> 00:38:41,940 X X or k the exception of course would 1272 00:38:41,940 --> 00:38:44,339 be iterated in a for Loop also don't use 1273 00:38:44,339 --> 00:38:46,680 acronyms or abbreviations those might 1274 00:38:46,680 --> 00:38:48,420 seem player right now but in a few weeks 1275 00:38:48,420 --> 00:38:49,740 you might not remember what they mean 1276 00:38:49,740 --> 00:38:51,660 remember you don't get bonus points for 1277 00:38:51,660 --> 00:38:53,579 writing extremely compact code so 1278 00:38:53,579 --> 00:38:55,619 prioritize making your code readable and 1279 00:38:55,619 --> 00:38:57,540 understandable even if it requires 1280 00:38:57,540 --> 00:38:59,220 variables and functions with long names 1281 00:38:59,220 --> 00:39:01,320 so these are my general rules and the 1282 00:39:01,320 --> 00:39:02,579 code style that I personally follow 1283 00:39:02,579 --> 00:39:04,500 figure out what works for you and follow 1284 00:39:04,500 --> 00:39:06,240 your own naming rules but naturally in 1285 00:39:06,240 --> 00:39:07,800 this course I will be using my own code 1286 00:39:07,800 --> 00:39:09,780 cell so if when following the course you 1287 00:39:09,780 --> 00:39:11,220 are not sure how to write some type of 1288 00:39:11,220 --> 00:39:13,140 code you can refer back to this lecture 1289 00:39:13,140 --> 00:39:14,400 and watch it again like I've mentioned 1290 00:39:14,400 --> 00:39:15,660 many times the code that I won't teach 1291 00:39:15,660 --> 00:39:17,220 you how to write in this course is on 1292 00:39:17,220 --> 00:39:18,839 the exact same level of quality as my 1293 00:39:18,839 --> 00:39:20,880 paid courses and my Steam games so as 1294 00:39:20,880 --> 00:39:22,800 such because that this lecture these 1295 00:39:22,800 --> 00:39:24,480 naming rules are all extremely important 1296 00:39:24,480 --> 00:39:26,400 okay so with this very important lecture 1297 00:39:26,400 --> 00:39:27,839 out of the way now let's start playing 1298 00:39:27,839 --> 00:39:29,460 with some visuals by importing some 1299 00:39:29,460 --> 00:39:32,099 Assets in the next lecture hello and 1300 00:39:32,099 --> 00:39:34,079 welcome I'm your code monkey in this 1301 00:39:34,079 --> 00:39:35,280 lecture we're going to import the 1302 00:39:35,280 --> 00:39:36,900 project files with all the assets that 1303 00:39:36,900 --> 00:39:38,339 we're going to use by the way remember 1304 00:39:38,339 --> 00:39:39,960 that if you have any questions go ahead 1305 00:39:39,960 --> 00:39:41,460 and post them in the comments I go 1306 00:39:41,460 --> 00:39:42,960 through those every day and I'll do my 1307 00:39:42,960 --> 00:39:44,640 best to help okay so with the project 1308 00:39:44,640 --> 00:39:46,200 created the next thing we want is to 1309 00:39:46,200 --> 00:39:47,520 import the assets that we're going to 1310 00:39:47,520 --> 00:39:49,320 use to make this game you can download 1311 00:39:49,320 --> 00:39:50,700 all of the assets with the link in the 1312 00:39:50,700 --> 00:39:52,140 description which by the way like I 1313 00:39:52,140 --> 00:39:53,640 mentioned a while ago that link contains 1314 00:39:53,640 --> 00:39:55,500 a Unity package that contains both the 1315 00:39:55,500 --> 00:39:57,599 assets and the final game so when you 1316 00:39:57,599 --> 00:39:59,579 download that you get ENT package just 1317 00:39:59,579 --> 00:40:01,380 go ahead and double click or click and 1318 00:40:01,380 --> 00:40:02,940 drag and drop it on the projects window 1319 00:40:02,940 --> 00:40:04,859 here is the asset import window just 1320 00:40:04,859 --> 00:40:06,359 make sure you select all and let's 1321 00:40:06,359 --> 00:40:08,400 import okay so here it is let's import 1322 00:40:08,400 --> 00:40:10,680 the assets folder and inside comes all 1323 00:40:10,680 --> 00:40:12,660 of the assets meshes textures and so on 1324 00:40:12,660 --> 00:40:14,820 so everything we're going to need and 1325 00:40:14,820 --> 00:40:16,619 then it also imported inside of it 1326 00:40:16,619 --> 00:40:18,960 another ENT package so if you want to 1327 00:40:18,960 --> 00:40:20,640 import the final project with all of the 1328 00:40:20,640 --> 00:40:22,619 code already written it's also here if 1329 00:40:22,619 --> 00:40:24,060 you extract this one you're going to get 1330 00:40:24,060 --> 00:40:26,040 the complete project files now of course 1331 00:40:26,040 --> 00:40:27,540 don't do that if you want to follow 1332 00:40:27,540 --> 00:40:29,520 along with the course and be aware that 1333 00:40:29,520 --> 00:40:30,780 if you're following along and you 1334 00:40:30,780 --> 00:40:32,520 accidentally end unpack this one it will 1335 00:40:32,520 --> 00:40:34,859 override all of your own files so if you 1336 00:40:34,859 --> 00:40:36,240 want to inspect the final project files 1337 00:40:36,240 --> 00:40:37,859 go ahead and do that but do that in a 1338 00:40:37,859 --> 00:40:39,720 separate project in order to make sure 1339 00:40:39,720 --> 00:40:41,640 that we have no accidents I'm going to 1340 00:40:41,640 --> 00:40:42,960 delete this one from the current project 1341 00:40:42,960 --> 00:40:45,119 so just go ahead and delete okay so 1342 00:40:45,119 --> 00:40:46,980 that's it and over here we've got all of 1343 00:40:46,980 --> 00:40:49,140 our really nice visuals we can look in 1344 00:40:49,140 --> 00:40:50,880 the prefabs visuals and over here we've 1345 00:40:50,880 --> 00:40:53,400 got a visual for a container Sergo 1346 00:40:53,400 --> 00:40:55,500 that's a container counter then we have 1347 00:40:55,500 --> 00:40:57,660 a cutting counter we've got a trash bin 1348 00:40:57,660 --> 00:41:00,000 then on the kitchen object visuals we've 1349 00:41:00,000 --> 00:41:01,800 got all the visuals so a block of cheese 1350 00:41:01,800 --> 00:41:03,780 we've got some burned meat we've got a 1351 00:41:03,780 --> 00:41:05,700 plate and so on these are all the nice 1352 00:41:05,700 --> 00:41:07,560 3D models that we're going to use in our 1353 00:41:07,560 --> 00:41:09,420 game and then over here on the textures 1354 00:41:09,420 --> 00:41:11,040 folder we also got a bunch of General 1355 00:41:11,040 --> 00:41:13,680 icons as well as actual icons for all of 1356 00:41:13,680 --> 00:41:15,960 the various parts okay so all of the 1357 00:41:15,960 --> 00:41:17,460 assets have been important now let's 1358 00:41:17,460 --> 00:41:19,740 continue on to the next lecture 1359 00:41:19,740 --> 00:41:21,720 hello and welcome I'm your code monkey 1360 00:41:21,720 --> 00:41:23,579 in this lecture we're going to set up 1361 00:41:23,579 --> 00:41:25,740 post processing now here let me make a 1362 00:41:25,740 --> 00:41:27,660 quick note usually when making your 1363 00:41:27,660 --> 00:41:29,220 games you probably don't want to hand on 1364 00:41:29,220 --> 00:41:30,839 post-processing right way you should 1365 00:41:30,839 --> 00:41:32,400 first get an ugly prototype up and 1366 00:41:32,400 --> 00:41:34,020 working before worrying about any 1367 00:41:34,020 --> 00:41:36,240 visuals so normally I would only add 1368 00:41:36,240 --> 00:41:38,040 post-processing much later on in the dev 1369 00:41:38,040 --> 00:41:40,260 process but since this is a course in 1370 00:41:40,260 --> 00:41:42,000 video format in order for the video to 1371 00:41:42,000 --> 00:41:43,560 look a bit more appealing let's set a 1372 00:41:43,560 --> 00:41:45,000 post processing right away now we 1373 00:41:45,000 --> 00:41:46,500 already have the project set up to use 1374 00:41:46,500 --> 00:41:48,480 urp so adding post-processing is 1375 00:41:48,480 --> 00:41:50,099 actually super simple it's actually 1376 00:41:50,099 --> 00:41:52,380 already added by default first before we 1377 00:41:52,380 --> 00:41:54,000 do that let's rename our scene with a 1378 00:41:54,000 --> 00:41:55,740 proper name so inside the scenes folder 1379 00:41:55,740 --> 00:41:57,420 it starts off with sample scene this 1380 00:41:57,420 --> 00:41:58,800 will be our main game scene so let's 1381 00:41:58,800 --> 00:42:01,260 just rename this to game scene okay and 1382 00:42:01,260 --> 00:42:03,240 now here on the hierarchy we can see by 1383 00:42:03,240 --> 00:42:05,220 default this scene already contains a 1384 00:42:05,220 --> 00:42:07,200 global volume game object this is how 1385 00:42:07,200 --> 00:42:09,000 you actually add post-processing and by 1386 00:42:09,000 --> 00:42:10,619 default you can see that it also already 1387 00:42:10,619 --> 00:42:13,020 has a sample and profile attached this 1388 00:42:13,020 --> 00:42:14,099 is how you add all of the various 1389 00:42:14,099 --> 00:42:16,140 effects you can click on this link and 1390 00:42:16,140 --> 00:42:17,700 it will show it over here on the project 1391 00:42:17,700 --> 00:42:19,320 window now let's film this from scratch 1392 00:42:19,320 --> 00:42:20,820 instead of starting from this one so 1393 00:42:20,820 --> 00:42:22,800 let's go into that file into that asset 1394 00:42:22,800 --> 00:42:24,900 and just delete it okay so now we have 1395 00:42:24,900 --> 00:42:26,640 no value profile now let's go ahead and 1396 00:42:26,640 --> 00:42:28,200 click on new to create a brand new one 1397 00:42:28,200 --> 00:42:30,180 okay so now here we can add overrides 1398 00:42:30,180 --> 00:42:31,680 add all of the effects that we want 1399 00:42:31,680 --> 00:42:33,720 let's drag some visual meshes that we 1400 00:42:33,720 --> 00:42:35,160 imported in the last lecture to get a 1401 00:42:35,160 --> 00:42:36,599 better look at all these effects and 1402 00:42:36,599 --> 00:42:38,640 what they do so first let's make some 1403 00:42:38,640 --> 00:42:40,440 kind of more so let's make a 3D object 1404 00:42:40,440 --> 00:42:42,839 let's make it a plane let's name this D4 1405 00:42:42,839 --> 00:42:44,520 also one extremely important thing 1406 00:42:44,520 --> 00:42:46,020 whenever you create a brand new object 1407 00:42:46,020 --> 00:42:47,820 always check the object's transform 1408 00:42:47,820 --> 00:42:49,680 position by default when you create an 1409 00:42:49,680 --> 00:42:51,180 object it appears in front of the scene 1410 00:42:51,180 --> 00:42:53,280 camera which will probably not be on 1411 00:42:53,280 --> 00:42:55,020 zero zero zero you always want to be 1412 00:42:55,020 --> 00:42:56,400 very careful with the position of your 1413 00:42:56,400 --> 00:42:58,619 actual objects so for a plane we do want 1414 00:42:58,619 --> 00:43:01,079 this to be on the origin so on zero zero 1415 00:43:01,079 --> 00:43:02,760 zero so make sure you always do that 1416 00:43:02,760 --> 00:43:04,440 then let's scale it up a bit so on the 1417 00:43:04,440 --> 00:43:06,780 scale let's put it on 555 which by the 1418 00:43:06,780 --> 00:43:08,520 way you've got this nice little icon 1419 00:43:08,520 --> 00:43:10,260 this was added in a recent Indie version 1420 00:43:10,260 --> 00:43:12,060 basically if you enable this and matches 1421 00:43:12,060 --> 00:43:13,500 all of these values so if you just 1422 00:43:13,500 --> 00:43:14,760 change one of them it changes all of 1423 00:43:14,760 --> 00:43:16,079 them so let's put this on Five okay 1424 00:43:16,079 --> 00:43:18,060 great now for the visual let's go ahead 1425 00:43:18,060 --> 00:43:19,680 into the mesh render on the materials 1426 00:43:19,680 --> 00:43:21,300 and let's select the brand new material 1427 00:43:21,300 --> 00:43:23,040 so let's click on the circle icon and 1428 00:43:23,040 --> 00:43:24,599 over here let's find the floor material 1429 00:43:24,599 --> 00:43:26,400 so here it is it's the one included in 1430 00:43:26,400 --> 00:43:28,319 the assets there you go we've got a nice 1431 00:43:28,319 --> 00:43:30,300 basic form material now let's also drag 1432 00:43:30,300 --> 00:43:32,040 the player visual so let's go inside the 1433 00:43:32,040 --> 00:43:33,720 assets folder and over here let's go 1434 00:43:33,720 --> 00:43:35,940 inside the prefabs visuals and down here 1435 00:43:35,940 --> 00:43:37,680 we find the player visual so let's just 1436 00:43:37,680 --> 00:43:39,180 go ahead and drag this one so there it 1437 00:43:39,180 --> 00:43:41,280 is a nice player visual let's also drag 1438 00:43:41,280 --> 00:43:43,440 a counter so let's find let's say the 1439 00:43:43,440 --> 00:43:45,780 Clear counter let's drag this one let's 1440 00:43:45,780 --> 00:43:47,280 rotate it to face the camera something 1441 00:43:47,280 --> 00:43:49,079 like this and let's also put a cutting 1442 00:43:49,079 --> 00:43:50,640 counter again we're just placing some 1443 00:43:50,640 --> 00:43:52,380 visuals just so we can see what the post 1444 00:43:52,380 --> 00:43:54,240 processing will do and let's also place 1445 00:43:54,240 --> 00:43:55,920 a bunch more things so let's say a 1446 00:43:55,920 --> 00:43:57,660 tomato let's place a tomato over there 1447 00:43:57,660 --> 00:43:59,640 and maybe cabbage all the way over here 1448 00:43:59,640 --> 00:44:01,380 okay so we've got a handful of nice 1449 00:44:01,380 --> 00:44:03,000 visual elements so we can test out our 1450 00:44:03,000 --> 00:44:04,740 post pressing by the way here's a quick 1451 00:44:04,740 --> 00:44:06,780 empty tip on scene controls whenever you 1452 00:44:06,780 --> 00:44:08,040 are on the scene view which make sure 1453 00:44:08,040 --> 00:44:09,420 you're on scene View and not game view 1454 00:44:09,420 --> 00:44:10,980 those are different so on the scene view 1455 00:44:10,980 --> 00:44:12,660 you can move the camera with a mouse you 1456 00:44:12,660 --> 00:44:14,520 can pan with mouse 3 so the middle Mouse 1457 00:44:14,520 --> 00:44:16,859 button so hold that and pan around we 1458 00:44:16,859 --> 00:44:18,660 can rotate with the right Mouse button 1459 00:44:18,660 --> 00:44:20,819 you can rotate around Point by holding 1460 00:44:20,819 --> 00:44:22,800 down left alt and left click and just 1461 00:44:22,800 --> 00:44:24,540 drag it around to rotate around an 1462 00:44:24,540 --> 00:44:26,099 object you can select an object like for 1463 00:44:26,099 --> 00:44:27,780 example player visual then you can press 1464 00:44:27,780 --> 00:44:29,819 on F to select that object and now if 1465 00:44:29,819 --> 00:44:31,560 you hold alt and click it will rotate 1466 00:44:31,560 --> 00:44:33,180 around that object also another method 1467 00:44:33,180 --> 00:44:34,740 is you can hold the right Mouse button 1468 00:44:34,740 --> 00:44:36,180 to move it around and then you can use 1469 00:44:36,180 --> 00:44:39,599 was to move so d a and so on then you 1470 00:44:39,599 --> 00:44:41,400 can even press shift to move in faster 1471 00:44:41,400 --> 00:44:43,200 and you can use the scroll wheel while 1472 00:44:43,200 --> 00:44:44,640 holding down the right Mouse button or 1473 00:44:44,640 --> 00:44:46,440 to modify the speed at which you move so 1474 00:44:46,440 --> 00:44:48,240 there are plenty of camera controls to 1475 00:44:48,240 --> 00:44:50,280 really get you seeing exactly what you 1476 00:44:50,280 --> 00:44:52,319 want to see now for another quick empty 1477 00:44:52,319 --> 00:44:53,880 tip you can move the scene camera to 1478 00:44:53,880 --> 00:44:55,319 where you want the game camera to be so 1479 00:44:55,319 --> 00:44:56,700 let's say I want the game camera to see 1480 00:44:56,700 --> 00:44:58,740 things from about this angle so you just 1481 00:44:58,740 --> 00:45:00,599 position the scene camera then on the 1482 00:45:00,599 --> 00:45:02,220 hierarchy select the camera game object 1483 00:45:02,220 --> 00:45:03,839 so the main camera right here and with 1484 00:45:03,839 --> 00:45:05,520 that object selected you press Ctrl 1485 00:45:05,520 --> 00:45:07,560 shift and F and if there you go you can 1486 00:45:07,560 --> 00:45:09,180 see over here on the camera preview let 1487 00:45:09,180 --> 00:45:10,800 it position the main camera looking on 1488 00:45:10,800 --> 00:45:12,359 the exact same position at the exact 1489 00:45:12,359 --> 00:45:14,099 same direction as the scene camera set 1490 00:45:14,099 --> 00:45:15,660 the shortcut Ctrl shift F or 1491 00:45:15,660 --> 00:45:17,700 alternatively go up into game object and 1492 00:45:17,700 --> 00:45:19,380 over here on line with view now if you 1493 00:45:19,380 --> 00:45:20,940 look here is the scene View and over 1494 00:45:20,940 --> 00:45:22,500 here we've got a nice camera view so 1495 00:45:22,500 --> 00:45:24,359 just position the camera somewhere where 1496 00:45:24,359 --> 00:45:26,160 we can view all of the Assets Now with 1497 00:45:26,160 --> 00:45:27,480 this let's add some post processing 1498 00:45:27,480 --> 00:45:29,520 effects so first let's select the global 1499 00:45:29,520 --> 00:45:31,260 volume game object and over here we can 1500 00:45:31,260 --> 00:45:33,540 add all of our effect overrides first up 1501 00:45:33,540 --> 00:45:35,700 let's begin by adding tone mapping so 1502 00:45:35,700 --> 00:45:37,079 there you go we've got the effect and 1503 00:45:37,079 --> 00:45:38,220 over here we've got a nice little 1504 00:45:38,220 --> 00:45:40,319 checkbox so you can enable it in order 1505 00:45:40,319 --> 00:45:42,240 to enable this effect and set one of the 1506 00:45:42,240 --> 00:45:43,980 options now for this one I'm not too 1507 00:45:43,980 --> 00:45:45,540 familiar with color correction but I 1508 00:45:45,540 --> 00:45:47,099 find that usually adding a neutral tone 1509 00:45:47,099 --> 00:45:48,900 map usually that helps also make sure 1510 00:45:48,900 --> 00:45:50,579 you're looking at the game View and not 1511 00:45:50,579 --> 00:45:52,079 the scene view if you're looking in the 1512 00:45:52,079 --> 00:45:53,460 game View and you enable and disable 1513 00:45:53,460 --> 00:45:54,660 this effect you should see a difference 1514 00:45:54,660 --> 00:45:56,640 whereas on the scene view if you enable 1515 00:45:56,640 --> 00:45:57,839 and disable it doesn't actually show 1516 00:45:57,839 --> 00:45:59,220 that even if you're on the scene view 1517 00:45:59,220 --> 00:46:00,720 over here you have all the effects 1518 00:46:00,720 --> 00:46:02,579 enabled even with that some effects for 1519 00:46:02,579 --> 00:46:04,079 some reason don't show up on the scene 1520 00:46:04,079 --> 00:46:05,700 view so when playing around these 1521 00:46:05,700 --> 00:46:06,660 effects almost make sure you're 1522 00:46:06,660 --> 00:46:08,099 unlocking through the game view so like 1523 00:46:08,099 --> 00:46:09,660 I said you should be able to toggle this 1524 00:46:09,660 --> 00:46:11,280 and see a visual difference on the game 1525 00:46:11,280 --> 00:46:13,020 view if you don't then make sure the 1526 00:46:13,020 --> 00:46:14,760 camera has post processing enabled so 1527 00:46:14,760 --> 00:46:16,319 let's select the main camera game object 1528 00:46:16,319 --> 00:46:17,940 and down here there's a tongue for post 1529 00:46:17,940 --> 00:46:19,319 Crossing make sure this one is enabled 1530 00:46:19,319 --> 00:46:21,300 and then also on the render pipeline 1531 00:46:21,300 --> 00:46:23,099 assets so let's find that one on the 1532 00:46:23,099 --> 00:46:24,599 project window over here we've got the 1533 00:46:24,599 --> 00:46:26,099 settings and we've got the urp High 1534 00:46:26,099 --> 00:46:27,960 Fidelity this one should be using a 1535 00:46:27,960 --> 00:46:29,760 renderer so if you click on the renderer 1536 00:46:29,760 --> 00:46:31,440 over here you should have post-rossing 1537 00:46:31,440 --> 00:46:33,060 enabled again all of this should already 1538 00:46:33,060 --> 00:46:35,280 be correctly set up by default so if 1539 00:46:35,280 --> 00:46:36,240 you're going to take a global volume 1540 00:46:36,240 --> 00:46:37,920 enable our disabled you should see a 1541 00:46:37,920 --> 00:46:39,839 visual difference okay so next Effect 1542 00:46:39,839 --> 00:46:41,819 one that I always like to add is a bit 1543 00:46:41,819 --> 00:46:43,800 of saturation so let's add an override 1544 00:46:43,800 --> 00:46:45,960 post processing and let's add a brand 1545 00:46:45,960 --> 00:46:48,119 new here it is color adjustments then 1546 00:46:48,119 --> 00:46:49,500 over here you've got plenty of things to 1547 00:46:49,500 --> 00:46:51,420 play around with for me I like to add a 1548 00:46:51,420 --> 00:46:53,220 bit of saturation so just lift it up a 1549 00:46:53,220 --> 00:46:55,740 little bit let's say just about 20 and I 1550 00:46:55,740 --> 00:46:56,940 also like to add a little bit of 1551 00:46:56,940 --> 00:46:58,560 contrast over here and let's also add 1552 00:46:58,560 --> 00:47:00,540 20. and there you go it makes the colors 1553 00:47:00,540 --> 00:47:02,099 pop a little bit more so personally I 1554 00:47:02,099 --> 00:47:03,780 don't like this effect then later on 1555 00:47:03,780 --> 00:47:05,400 we're going to have some glowing objects 1556 00:47:05,400 --> 00:47:07,500 for example the stove let's actually try 1557 00:47:07,500 --> 00:47:09,060 dragging that into the scene so let's go 1558 00:47:09,060 --> 00:47:11,280 into scene View and in the assets let's 1559 00:47:11,280 --> 00:47:13,920 find the stove counter so here it is and 1560 00:47:13,920 --> 00:47:16,319 inside the stove counter there are some 1561 00:47:16,319 --> 00:47:18,300 things so here it is the stove on visual 1562 00:47:18,300 --> 00:47:20,220 this one is disabled by default also on 1563 00:47:20,220 --> 00:47:21,480 the inspector let's just enable on this 1564 00:47:21,480 --> 00:47:22,920 game object to make it visible again 1565 00:47:22,920 --> 00:47:24,480 don't worry about the positioning of the 1566 00:47:24,480 --> 00:47:25,619 objects on the scene view right now 1567 00:47:25,619 --> 00:47:27,180 we're only positioning them just to set 1568 00:47:27,180 --> 00:47:28,440 up the post pressing we're going to 1569 00:47:28,440 --> 00:47:29,579 delete them all at the end of this 1570 00:47:29,579 --> 00:47:31,680 lecture okay so now in enable let's go 1571 00:47:31,680 --> 00:47:33,000 into the game View and over here we see 1572 00:47:33,000 --> 00:47:35,040 the stove enabled so now let's go into 1573 00:47:35,040 --> 00:47:36,780 the local volume let's add an override 1574 00:47:36,780 --> 00:47:38,460 go into post pressing let's add a volume 1575 00:47:38,460 --> 00:47:40,440 effect so right now notice how that one 1576 00:47:40,440 --> 00:47:42,660 is not glowing red hot for that work we 1577 00:47:42,660 --> 00:47:44,220 need to have Bloom and we need to enable 1578 00:47:44,220 --> 00:47:46,380 the threshold and the intensity if we 1579 00:47:46,380 --> 00:47:48,180 raise the intensity we do see yep there 1580 00:47:48,180 --> 00:47:49,859 we go a really nice low there by the way 1581 00:47:49,859 --> 00:47:51,540 here's a quick visual attempt if you 1582 00:47:51,540 --> 00:47:52,859 want to make your game feel a bit more 1583 00:47:52,859 --> 00:47:54,780 ethereal and magical one good way is to 1584 00:47:54,780 --> 00:47:56,099 put the threshold that on low value 1585 00:47:56,099 --> 00:47:58,680 below one so something like 0.5 and then 1586 00:47:58,680 --> 00:48:00,480 put the intensity as a little bit and 1587 00:48:00,480 --> 00:48:02,220 with this notice how everything has a 1588 00:48:02,220 --> 00:48:03,960 slight low even colors that don't have 1589 00:48:03,960 --> 00:48:05,640 any extra intensity so the floor is 1590 00:48:05,640 --> 00:48:06,839 glowing the character is going so 1591 00:48:06,839 --> 00:48:08,280 everything looks quite a bit ethereum 1592 00:48:08,280 --> 00:48:09,960 this is a bit extreme but it is an 1593 00:48:09,960 --> 00:48:11,400 interesting effect also another quick 1594 00:48:11,400 --> 00:48:12,780 note here in case you're not seeing 1595 00:48:12,780 --> 00:48:14,520 anything change make sure you go into 1596 00:48:14,520 --> 00:48:16,200 the render prop online assets so the urp 1597 00:48:16,200 --> 00:48:17,760 High Fidelity and over here make sure 1598 00:48:17,760 --> 00:48:20,520 AGR is enabled you can look at so low if 1599 00:48:20,520 --> 00:48:22,260 I disable it yep that one stops glowing 1600 00:48:22,260 --> 00:48:23,579 and with that enabled it does start 1601 00:48:23,579 --> 00:48:25,560 glowing AGR stands for high dynamic 1602 00:48:25,560 --> 00:48:27,300 range so that is how you can have a 1603 00:48:27,300 --> 00:48:29,220 color go with an intensity above one 1604 00:48:29,220 --> 00:48:30,780 which actually makes it low when you 1605 00:48:30,780 --> 00:48:32,099 have the balloon post pressing if even 1606 00:48:32,099 --> 00:48:33,359 with that you're still seeing issues 1607 00:48:33,359 --> 00:48:34,740 then make sure you go into the renderer 1608 00:48:34,740 --> 00:48:36,240 and over here for the post processing 1609 00:48:36,240 --> 00:48:38,160 sometimes Unity has a weird bug and 1610 00:48:38,160 --> 00:48:39,960 doesn't generate this post-process data 1611 00:48:39,960 --> 00:48:41,579 file so if that does happen just go 1612 00:48:41,579 --> 00:48:43,440 ahead untoggle and toggle this and it 1613 00:48:43,440 --> 00:48:45,060 should work and finally like I said on 1614 00:48:45,060 --> 00:48:46,319 the camera make sure you have post 1615 00:48:46,319 --> 00:48:48,060 Crossing in Arrow so with all that you 1616 00:48:48,060 --> 00:48:49,500 should be able to see the game view glow 1617 00:48:49,500 --> 00:48:51,359 okay back into our effects with our 1618 00:48:51,359 --> 00:48:52,920 balloon working like I said you can 1619 00:48:52,920 --> 00:48:54,480 lower this below one to get a nice 1620 00:48:54,480 --> 00:48:56,040 ethereum look but this is a bit too 1621 00:48:56,040 --> 00:48:57,780 intensive on what we want so let's make 1622 00:48:57,780 --> 00:48:59,220 it a bit more subtle so on the threshold 1623 00:48:59,220 --> 00:49:01,680 let's put it at 0.95 so there's a slight 1624 00:49:01,680 --> 00:49:03,240 low on the white Parts but nothing too 1625 00:49:03,240 --> 00:49:05,099 intense and for intensity let's put it 1626 00:49:05,099 --> 00:49:06,839 at a wrong number one okay so I think 1627 00:49:06,839 --> 00:49:08,400 that's a nice amount of Bloom all the 1628 00:49:08,400 --> 00:49:10,319 colors glow a little bit and we can see 1629 00:49:10,319 --> 00:49:11,700 over there the stove it is indeed 1630 00:49:11,700 --> 00:49:13,680 glowing okay great now if you ever 1631 00:49:13,680 --> 00:49:15,359 forget all these steps and you can get 1632 00:49:15,359 --> 00:49:17,220 your project to Glow I made a nice video 1633 00:49:17,220 --> 00:49:18,660 with a nice checklist of everything 1634 00:49:18,660 --> 00:49:20,819 needed for you low definitely go ahead 1635 00:49:20,819 --> 00:49:22,020 and watch that video whenever you have 1636 00:49:22,020 --> 00:49:24,359 issues then for another fun effect we 1637 00:49:24,359 --> 00:49:26,280 have yet so let's go into ad override 1638 00:49:26,280 --> 00:49:27,839 post Crossing and let's find the 1639 00:49:27,839 --> 00:49:29,700 vignette what this one does is adds a 1640 00:49:29,700 --> 00:49:31,380 bit of Darkness to the colors so if we 1641 00:49:31,380 --> 00:49:33,119 enable the intensity and we increase it 1642 00:49:33,119 --> 00:49:34,740 you can see what it does so it adds 1643 00:49:34,740 --> 00:49:35,940 Darkness around the corners there 1644 00:49:35,940 --> 00:49:37,380 personally I find this one looks good 1645 00:49:37,380 --> 00:49:38,940 when it's quite a bit subtle so let's 1646 00:49:38,940 --> 00:49:41,700 put the intensity at some like 0.25 and 1647 00:49:41,700 --> 00:49:43,380 then for the smoothness let's also put 1648 00:49:43,380 --> 00:49:45,720 it on 0.4 so just like that just a 1649 00:49:45,720 --> 00:49:46,980 slight Darkness on the edges so 1650 00:49:46,980 --> 00:49:48,300 personally I think it looks pretty good 1651 00:49:48,300 --> 00:49:50,280 and that's pretty much it for the Post 1652 00:49:50,280 --> 00:49:52,260 Crossing on the volume component I like 1653 00:49:52,260 --> 00:49:53,400 how this looks you can see difference 1654 00:49:53,400 --> 00:49:55,319 with the volume enabled or disabled 1655 00:49:55,319 --> 00:49:56,880 quite a big difference looks pretty nice 1656 00:49:56,880 --> 00:49:59,160 but again these are just visuals so feel 1657 00:49:59,160 --> 00:50:00,960 free to play around maybe add some more 1658 00:50:00,960 --> 00:50:03,000 effects using different settings these 1659 00:50:03,000 --> 00:50:04,500 are just visuals they don't impact the 1660 00:50:04,500 --> 00:50:06,119 game logic at all so feel free to make 1661 00:50:06,119 --> 00:50:08,520 it work exactly as you wanted then yet 1662 00:50:08,520 --> 00:50:10,140 another thing related to post processing 1663 00:50:10,140 --> 00:50:11,520 but not in this component it's some 1664 00:50:11,520 --> 00:50:13,560 anti-aliasing for that one place where 1665 00:50:13,560 --> 00:50:15,000 you can change it is on the main camera 1666 00:50:15,000 --> 00:50:16,740 over here you see a film for post 1667 00:50:16,740 --> 00:50:18,420 Crossing and you have a bunch of types 1668 00:50:18,420 --> 00:50:21,960 so fxa a or smaa or if you want some 1669 00:50:21,960 --> 00:50:23,520 more higher end post processing you can 1670 00:50:23,520 --> 00:50:24,900 go into the render prop online Essence 1671 00:50:24,900 --> 00:50:26,880 so urp and hyphenoly and over here we 1672 00:50:26,880 --> 00:50:29,400 see anti-analyzing msai this one is a 1673 00:50:29,400 --> 00:50:30,780 bit more expensive but looks a bit 1674 00:50:30,780 --> 00:50:32,280 better if you want to see difference you 1675 00:50:32,280 --> 00:50:34,140 can go over here into the aim View and 1676 00:50:34,140 --> 00:50:35,880 on the slider up top on the scale you 1677 00:50:35,880 --> 00:50:37,680 can increase this quite a bit so with 1678 00:50:37,680 --> 00:50:39,359 this we can now see the pixelation and 1679 00:50:39,359 --> 00:50:40,980 you can see over here if I switch at the 1680 00:50:40,980 --> 00:50:42,540 only thing from 4X back into the table 1681 00:50:42,540 --> 00:50:45,000 you can see lots of jagged edges and if 1682 00:50:45,000 --> 00:50:46,859 I put it on 2x Yep looks a bit more 1683 00:50:46,859 --> 00:50:49,140 smooth 4X a bit more smooth and 8x even 1684 00:50:49,140 --> 00:50:51,000 more smooth so with that you can see 1685 00:50:51,000 --> 00:50:52,559 difference on all the edges on the 1686 00:50:52,559 --> 00:50:54,599 things by default this renderer has on 1687 00:50:54,599 --> 00:50:56,400 4X and nothing on the camera this 1688 00:50:56,400 --> 00:50:57,780 already unlocks pretty good but to make 1689 00:50:57,780 --> 00:50:59,099 the video look even better I'm going to 1690 00:50:59,099 --> 00:51:01,619 put it on 8X and on the main camera I'm 1691 00:51:01,619 --> 00:51:02,700 also going to leave it with no 1692 00:51:02,700 --> 00:51:04,319 anti-alency you can combine them but if 1693 00:51:04,319 --> 00:51:05,700 you do then everything looks a bit too 1694 00:51:05,700 --> 00:51:07,800 wiry so I don't quite like that effect 1695 00:51:07,800 --> 00:51:09,540 so put this one on none and the other 1696 00:51:09,540 --> 00:51:11,880 one on 8X although again this is just a 1697 00:51:11,880 --> 00:51:13,980 visual so if you have a low end PC feel 1698 00:51:13,980 --> 00:51:16,260 free to go into the urp and over here 1699 00:51:16,260 --> 00:51:18,359 disable anti-alizing so the game looks a 1700 00:51:18,359 --> 00:51:19,920 bit worse but it won't run much better 1701 00:51:19,920 --> 00:51:22,260 okay let's drag the scale back down okay 1702 00:51:22,260 --> 00:51:25,079 now one final thing we can add is some 1703 00:51:25,079 --> 00:51:26,400 really nice screen space ambient 1704 00:51:26,400 --> 00:51:28,140 conclusion for that let's go into the 1705 00:51:28,140 --> 00:51:29,880 render so not the render pipeline asset 1706 00:51:29,880 --> 00:51:31,680 the renderer and over here by default it 1707 00:51:31,680 --> 00:51:33,180 already added screen space ambient 1708 00:51:33,180 --> 00:51:34,680 Collision if it didn't add you can click 1709 00:51:34,680 --> 00:51:36,420 on ADD render feature and over here you 1710 00:51:36,420 --> 00:51:37,980 won't be able to see it I don't see it 1711 00:51:37,980 --> 00:51:39,480 because I already have it okay so here 1712 00:51:39,480 --> 00:51:41,520 it is basically what this effect does is 1713 00:51:41,520 --> 00:51:43,559 it adds some tiny Shadows where geometry 1714 00:51:43,559 --> 00:51:45,599 intersect if we enable and disable it 1715 00:51:45,599 --> 00:51:47,040 quickly we can see the effect over there 1716 00:51:47,040 --> 00:51:48,780 on the counters so you can see with 1717 00:51:48,780 --> 00:51:50,700 default effects it already Works quite 1718 00:51:50,700 --> 00:51:52,619 nicely for example look there on the 1719 00:51:52,619 --> 00:51:54,059 player we can barely see the difference 1720 00:51:54,059 --> 00:51:55,500 between the head and body but if we 1721 00:51:55,500 --> 00:51:56,760 enable this it has that nice little 1722 00:51:56,760 --> 00:51:58,680 Shadow I think it looks really nice but 1723 00:51:58,680 --> 00:52:00,119 then we've got a bunch of settings we 1724 00:52:00,119 --> 00:52:01,500 can play around increase the intensity 1725 00:52:01,500 --> 00:52:03,420 the radius and so on Now One important 1726 00:52:03,420 --> 00:52:05,099 thing when setting all these effects is 1727 00:52:05,099 --> 00:52:06,720 to remember the point of view of the 1728 00:52:06,720 --> 00:52:08,220 camera in this case we're making a 1729 00:52:08,220 --> 00:52:10,200 top-down game so before we play around 1730 00:52:10,200 --> 00:52:11,579 these settings let's actually position 1731 00:52:11,579 --> 00:52:13,680 the camera in a correct position so 1732 00:52:13,680 --> 00:52:15,180 let's go ahead select the main camera 1733 00:52:15,180 --> 00:52:17,339 and let's position it above pointing 1734 00:52:17,339 --> 00:52:20,940 down so let's put it on an X of 0 on a y 1735 00:52:20,940 --> 00:52:24,900 of 21.5 on his head of minus 21.3 then 1736 00:52:24,900 --> 00:52:27,660 for the rotation on the X 46 then 0 and 1737 00:52:27,660 --> 00:52:29,339 0. and finally on the camera over here 1738 00:52:29,339 --> 00:52:30,599 on the field of view instead of 16 1739 00:52:30,599 --> 00:52:32,460 that's really wine for this game let's 1740 00:52:32,460 --> 00:52:34,079 go with 20. okay so this is the view 1741 00:52:34,079 --> 00:52:35,700 that we're going to use for our game let 1742 00:52:35,700 --> 00:52:37,500 me just rotate the object so they 1743 00:52:37,500 --> 00:52:39,420 actually face the camera so on the 1744 00:52:39,420 --> 00:52:41,040 hierarchy let's just select all the 1745 00:52:41,040 --> 00:52:43,619 objects let's rotate them all around and 1746 00:52:43,619 --> 00:52:45,359 just position them again we're only 1747 00:52:45,359 --> 00:52:47,099 using these just to see what they look 1748 00:52:47,099 --> 00:52:48,839 like we're going to delete all of these 1749 00:52:48,839 --> 00:52:50,819 objects in a bit okay so yep that's the 1750 00:52:50,819 --> 00:52:52,440 game view now that we have the camera 1751 00:52:52,440 --> 00:52:54,180 set up let's work on the settings for 1752 00:52:54,180 --> 00:52:55,920 the eminent conclusion so let's go down 1753 00:52:55,920 --> 00:52:57,540 select the renderer and over here for 1754 00:52:57,540 --> 00:52:59,160 the settings for the intensity and let's 1755 00:52:59,160 --> 00:53:01,079 put it on four for the radiance let's 1756 00:53:01,079 --> 00:53:02,940 put it at 0.3 and direct lighting 1757 00:53:02,940 --> 00:53:04,440 strength let's put it all the way up to 1758 00:53:04,440 --> 00:53:06,480 one okay so you can toggle this enable 1759 00:53:06,480 --> 00:53:08,339 and disable to see difference and yep I 1760 00:53:08,339 --> 00:53:09,780 do think these settings look pretty good 1761 00:53:09,780 --> 00:53:11,220 finally the last thing we need to check 1762 00:53:11,220 --> 00:53:13,200 is in lightning window so let's go into 1763 00:53:13,200 --> 00:53:14,819 window then down into rendering and 1764 00:53:14,819 --> 00:53:16,440 let's go into lighting how it pops up 1765 00:53:16,440 --> 00:53:18,180 the unlighting window personally I like 1766 00:53:18,180 --> 00:53:19,200 to Anchor it over there next thing 1767 00:53:19,200 --> 00:53:20,940 inspector and over here we're really 1768 00:53:20,940 --> 00:53:22,980 going to leave everything on defaults so 1769 00:53:22,980 --> 00:53:24,119 you can leave it as the lighting 1770 00:53:24,119 --> 00:53:26,339 settings assets and nothing assigned and 1771 00:53:26,339 --> 00:53:28,140 then on the environment tab over here 1772 00:53:28,140 --> 00:53:29,700 again all of the defaults I didn't touch 1773 00:53:29,700 --> 00:53:31,319 any of these so we've got environment 1774 00:53:31,319 --> 00:53:32,819 lighting from the Skybox and then some 1775 00:53:32,819 --> 00:53:34,619 multiplier of one so everything pretty 1776 00:53:34,619 --> 00:53:36,480 much on defaults although again like I 1777 00:53:36,480 --> 00:53:37,920 said most of these visual effects are 1778 00:53:37,920 --> 00:53:39,720 very much personal preference so if you 1779 00:53:39,720 --> 00:53:40,859 want to make your game look a bit 1780 00:53:40,859 --> 00:53:42,540 different than mine then go ahead you 1781 00:53:42,540 --> 00:53:44,040 can play around with lighting over here 1782 00:53:44,040 --> 00:53:46,200 you can change Skybox gradient color and 1783 00:53:46,200 --> 00:53:48,119 so on if you want you can use some bake 1784 00:53:48,119 --> 00:53:49,740 lighting then if you want you can add 1785 00:53:49,740 --> 00:53:51,839 all kinds of extra effects and also by 1786 00:53:51,839 --> 00:53:53,280 the way remember that the effects are 1787 00:53:53,280 --> 00:53:55,380 stored on this profile over here so for 1788 00:53:55,380 --> 00:53:56,880 example you can click over here on the 1789 00:53:56,880 --> 00:53:58,619 Clone button and it will include the 1790 00:53:58,619 --> 00:53:59,819 effects and let's click on it to find it 1791 00:53:59,819 --> 00:54:01,319 yep there you go so that's the one that 1792 00:54:01,319 --> 00:54:02,940 I've built and here's a clone one so if 1793 00:54:02,940 --> 00:54:04,319 you want you can make a clone one and 1794 00:54:04,319 --> 00:54:05,760 then make it look very different for 1795 00:54:05,760 --> 00:54:06,900 example let's go into chromatic 1796 00:54:06,900 --> 00:54:09,000 aberration make it really intense and 1797 00:54:09,000 --> 00:54:11,160 for example let's go into the counter 1798 00:54:11,160 --> 00:54:12,960 curves and over here for some reason 1799 00:54:12,960 --> 00:54:14,819 let's drag the green up and so on so 1800 00:54:14,819 --> 00:54:16,380 there you go completely different visual 1801 00:54:16,380 --> 00:54:17,760 so if you want to play around make some 1802 00:54:17,760 --> 00:54:19,020 weird effects and if you want to go back 1803 00:54:19,020 --> 00:54:20,520 to just revert back into the original 1804 00:54:20,520 --> 00:54:22,200 profile personally I'm quite happy with 1805 00:54:22,200 --> 00:54:23,579 how this looks so I'm going to be using 1806 00:54:23,579 --> 00:54:25,559 this one okay again you can enable and 1807 00:54:25,559 --> 00:54:27,359 disable the volume game object to see 1808 00:54:27,359 --> 00:54:28,500 quite the big difference that 1809 00:54:28,500 --> 00:54:30,240 post-processing makes if you ever want 1810 00:54:30,240 --> 00:54:31,559 to make your game look quite a lot 1811 00:54:31,559 --> 00:54:33,180 better always make sure that some post 1812 00:54:33,180 --> 00:54:34,859 processing alright so like I said this 1813 00:54:34,859 --> 00:54:36,839 looks really good I like it now before 1814 00:54:36,839 --> 00:54:38,339 we go to the next lecture let's just 1815 00:54:38,339 --> 00:54:40,140 clean this up so let's get rid of all of 1816 00:54:40,140 --> 00:54:41,700 these objects so the counter cabbage 1817 00:54:41,700 --> 00:54:43,319 tomato and so on let's get rid of all of 1818 00:54:43,319 --> 00:54:44,700 them except the four so let's leave the 1819 00:54:44,700 --> 00:54:46,800 four and get rid of all these alright so 1820 00:54:46,800 --> 00:54:48,540 here we have our nice empty scene let's 1821 00:54:48,540 --> 00:54:50,520 just save our scene and let's get ready 1822 00:54:50,520 --> 00:54:52,740 for the next lecture 1823 00:54:52,740 --> 00:54:55,500 hi there this is a quick intermission so 1824 00:54:55,500 --> 00:54:57,000 how are you doing are you enjoying the 1825 00:54:57,000 --> 00:54:58,800 course so far are you having any trouble 1826 00:54:58,800 --> 00:55:00,480 with anything is there something you 1827 00:55:00,480 --> 00:55:02,579 didn't understand if so remember I'm 1828 00:55:02,579 --> 00:55:04,079 always active in the comments answering 1829 00:55:04,079 --> 00:55:05,940 all the questions so if there's anything 1830 00:55:05,940 --> 00:55:07,920 you need some extra clarification go 1831 00:55:07,920 --> 00:55:09,300 ahead and ask and I'll do my best to 1832 00:55:09,300 --> 00:55:11,579 help also remember to check out the pin 1833 00:55:11,579 --> 00:55:14,040 comment YouTube videos cannot be updated 1834 00:55:14,040 --> 00:55:16,079 so for any notes or comments I'll put 1835 00:55:16,079 --> 00:55:18,059 them in the pin comment and definitely 1836 00:55:18,059 --> 00:55:19,680 check out the website page for this 1837 00:55:19,680 --> 00:55:21,780 course as people ask more and more 1838 00:55:21,780 --> 00:55:23,339 questions I will keep that page updated 1839 00:55:23,339 --> 00:55:25,140 with any frequently asked questions for 1840 00:55:25,140 --> 00:55:26,940 every single lecture so that way you can 1841 00:55:26,940 --> 00:55:28,260 see what others have asked and learn 1842 00:55:28,260 --> 00:55:30,420 from them and you can also download the 1843 00:55:30,420 --> 00:55:32,700 project files for each lecture so keep 1844 00:55:32,700 --> 00:55:34,619 that page open on a second Tab and check 1845 00:55:34,619 --> 00:55:36,119 it every time you start watching a new 1846 00:55:36,119 --> 00:55:38,280 lecture I really hope you're enjoying 1847 00:55:38,280 --> 00:55:39,420 the course and I hope you've already 1848 00:55:39,420 --> 00:55:41,700 learned quite a few things go ahead and 1849 00:55:41,700 --> 00:55:43,140 hit the like button and subscribe to the 1850 00:55:43,140 --> 00:55:44,579 channel if you haven't already 1851 00:55:44,579 --> 00:55:47,940 okay so let's go to the next lecture 1852 00:55:47,940 --> 00:55:50,400 hello and welcome I'm your kudmaki in 1853 00:55:50,400 --> 00:55:51,420 this lecture we're going to begin 1854 00:55:51,420 --> 00:55:53,579 creating our character let's make a nice 1855 00:55:53,579 --> 00:55:55,200 character controller so we can move our 1856 00:55:55,200 --> 00:55:56,819 character in the world 1857 00:55:56,819 --> 00:55:58,859 okay so first let's begin by creating 1858 00:55:58,859 --> 00:56:00,420 the character game object 1859 00:56:00,420 --> 00:56:02,940 and now usually most beginner tutorials 1860 00:56:02,940 --> 00:56:04,800 will tell you to just right click go 1861 00:56:04,800 --> 00:56:06,660 into 3D object and create something like 1862 00:56:06,660 --> 00:56:09,059 a capsule that way you would have the 1863 00:56:09,059 --> 00:56:11,520 game object with the visual included 1864 00:56:11,520 --> 00:56:14,040 however for a good project structure and 1865 00:56:14,040 --> 00:56:15,660 good organization you should only 1866 00:56:15,660 --> 00:56:18,119 separate the visuals from the logic for 1867 00:56:18,119 --> 00:56:19,619 example here in let's say that I don't 1868 00:56:19,619 --> 00:56:21,900 want my capsule exam like this let's say 1869 00:56:21,900 --> 00:56:23,460 that I want my player to be a little bit 1870 00:56:23,460 --> 00:56:25,559 more skinny to do that I would have to 1871 00:56:25,559 --> 00:56:27,240 modify on the scale on this game object 1872 00:56:27,240 --> 00:56:30,180 so put it maybe on 0.7.7 so something 1873 00:56:30,180 --> 00:56:32,040 like this basically by doing that by 1874 00:56:32,040 --> 00:56:34,140 modifying the visual I also modified the 1875 00:56:34,140 --> 00:56:36,000 scale on the actual player game object 1876 00:56:36,000 --> 00:56:38,880 having a non-uniform scale on a logic 1877 00:56:38,880 --> 00:56:40,680 game object that can cause all kind of 1878 00:56:40,680 --> 00:56:42,540 problems with any kind of logic 1879 00:56:42,540 --> 00:56:44,640 component also I would prefer to have my 1880 00:56:44,640 --> 00:56:46,200 character on the floor but if I put it 1881 00:56:46,200 --> 00:56:48,599 on yf0 notice how the character is half 1882 00:56:48,599 --> 00:56:50,760 underneath the floor so if I were to use 1883 00:56:50,760 --> 00:56:52,619 this method I would have to apply some 1884 00:56:52,619 --> 00:56:53,880 kind of offset in order to make the 1885 00:56:53,880 --> 00:56:55,800 visual above the floor so that would 1886 00:56:55,800 --> 00:56:57,540 require rearranging all the logic to 1887 00:56:57,540 --> 00:57:00,059 work with an offset on the Y position so 1888 00:57:00,059 --> 00:57:01,680 because of those reasons and many more 1889 00:57:01,680 --> 00:57:03,900 you should not Place both the logic and 1890 00:57:03,900 --> 00:57:05,280 the visual on the same game object 1891 00:57:05,280 --> 00:57:07,800 instead you should separate them so 1892 00:57:07,800 --> 00:57:09,660 let's get rid of this and instead let's 1893 00:57:09,660 --> 00:57:11,940 create an empty game object let's name 1894 00:57:11,940 --> 00:57:13,319 this the player 1895 00:57:13,319 --> 00:57:16,559 let's put it on zero zero zero okay and 1896 00:57:16,559 --> 00:57:19,140 now inside of it now inside let's create 1897 00:57:19,140 --> 00:57:21,540 let's say a capsule now in this one we 1898 00:57:21,540 --> 00:57:23,040 can easily scale this to get any size 1899 00:57:23,040 --> 00:57:25,859 and shape you want so for example 0.7.7 1900 00:57:25,859 --> 00:57:28,380 then since the visual is a child of the 1901 00:57:28,380 --> 00:57:30,059 game object we can also easily offset 1902 00:57:30,059 --> 00:57:31,680 this so let's say you put it up by about 1903 00:57:31,680 --> 00:57:34,079 one unit so with this we can position 1904 00:57:34,079 --> 00:57:36,059 the visual so that basically the player 1905 00:57:36,059 --> 00:57:37,740 game object is over here on zero zero 1906 00:57:37,740 --> 00:57:39,300 and the character is above the floor so 1907 00:57:39,300 --> 00:57:41,700 we don't have any weird offsets this 1908 00:57:41,700 --> 00:57:43,319 will make all of our logic much more 1909 00:57:43,319 --> 00:57:44,280 simplified 1910 00:57:44,280 --> 00:57:46,740 and on this empty Parent Game object we 1911 00:57:46,740 --> 00:57:48,300 can attach all of the logic components 1912 00:57:48,300 --> 00:57:51,000 we want and then in the child visual we 1913 00:57:51,000 --> 00:57:52,859 can either replace whatever visuals we 1914 00:57:52,859 --> 00:57:55,020 want so as a general rule you should 1915 00:57:55,020 --> 00:57:57,000 always try to do this only separate the 1916 00:57:57,000 --> 00:57:58,440 logic from the Visions in your game 1917 00:57:58,440 --> 00:57:59,700 objects 1918 00:57:59,700 --> 00:58:01,559 okay so with that we have the player 1919 00:58:01,559 --> 00:58:03,420 game object now let's make our character 1920 00:58:03,420 --> 00:58:04,800 controller script 1921 00:58:04,800 --> 00:58:06,900 and before we do let's keep things once 1922 00:58:06,900 --> 00:58:09,359 again organized so before we do let's 1923 00:58:09,359 --> 00:58:10,680 create a brand new folder so let's right 1924 00:58:10,680 --> 00:58:12,420 click on the assets create a brand new 1925 00:58:12,420 --> 00:58:15,059 folder call it scripts and now inside 1926 00:58:15,059 --> 00:58:17,099 let's right click and create new c-sharp 1927 00:58:17,099 --> 00:58:19,559 script called the player wait for the 1928 00:58:19,559 --> 00:58:21,480 code to compound then select the player 1929 00:58:21,480 --> 00:58:23,339 game object and attach the script again 1930 00:58:23,339 --> 00:58:25,200 remember logic components go on the 1931 00:58:25,200 --> 00:58:26,640 parent game object not the channel 1932 00:58:26,640 --> 00:58:28,859 vision so the challenge visual this one 1933 00:58:28,859 --> 00:58:30,359 only has visual components and the 1934 00:58:30,359 --> 00:58:31,859 player this is the one that actually has 1935 00:58:31,859 --> 00:58:33,780 the logic components so let's open up 1936 00:58:33,780 --> 00:58:34,859 this script 1937 00:58:34,859 --> 00:58:37,079 okay so here's our first c-sharp script 1938 00:58:37,079 --> 00:58:39,059 like I said I'm going to assume you know 1939 00:58:39,059 --> 00:58:41,400 the absolute Basics go watch the c-sharp 1940 00:58:41,400 --> 00:58:43,319 basics video If you haven't seen it yet 1941 00:58:43,319 --> 00:58:45,240 so I won't assume that you know what is 1942 00:58:45,240 --> 00:58:47,040 a function what is a variable what is 1943 00:58:47,040 --> 00:58:48,900 start and update so pretty much the 1944 00:58:48,900 --> 00:58:50,760 absolute basics for a character 1945 00:58:50,760 --> 00:58:52,799 controller we first need some input from 1946 00:58:52,799 --> 00:58:55,020 the player and for that EMT actually has 1947 00:58:55,020 --> 00:58:57,059 two methods you have the Legacy input 1948 00:58:57,059 --> 00:58:58,520 manager and the new input system 1949 00:58:58,520 --> 00:59:01,020 basically the Legacy input manager is 1950 00:59:01,020 --> 00:59:02,819 super simple and very easy to use so 1951 00:59:02,819 --> 00:59:04,200 this one is perfect for quickly 1952 00:59:04,200 --> 00:59:06,720 prototyping and the new input system is 1953 00:59:06,720 --> 00:59:08,339 extremely capable with tons of features 1954 00:59:08,339 --> 00:59:10,799 but it's also a bit more complex so what 1955 00:59:10,799 --> 00:59:12,839 I do is while I'm doing a simple demo or 1956 00:59:12,839 --> 00:59:14,400 testing out a new prototype by just 1957 00:59:14,400 --> 00:59:16,200 using Legacy input manager but when 1958 00:59:16,200 --> 00:59:18,000 making a more complex project like for 1959 00:59:18,000 --> 00:59:19,500 example my sim game then at a certain 1960 00:59:19,500 --> 00:59:21,299 point I refactor my code to use the new 1961 00:59:21,299 --> 00:59:23,400 input system so here I'm going to teach 1962 00:59:23,400 --> 00:59:25,260 you both as well as teaching you how to 1963 00:59:25,260 --> 00:59:26,819 refactor code which is an extremely 1964 00:59:26,819 --> 00:59:28,920 useful skill so let's first begin by 1965 00:59:28,920 --> 00:59:31,440 using the Simpson Legacy input manager 1966 00:59:31,440 --> 00:59:33,660 we want some basic was movement to move 1967 00:59:33,660 --> 00:59:35,579 our character and we're going to need to 1968 00:59:35,579 --> 00:59:37,559 run that logic on every single frame so 1969 00:59:37,559 --> 00:59:39,720 let's do it on update and let's actually 1970 00:59:39,720 --> 00:59:41,700 get rid of the code that Unity writes by 1971 00:59:41,700 --> 00:59:43,440 default let's start coming from scratch 1972 00:59:43,440 --> 00:59:45,059 and let's get rid of this just close 1973 00:59:45,059 --> 00:59:47,460 okay so here let's start by writing 1974 00:59:47,460 --> 00:59:49,980 private void update and now here very 1975 00:59:49,980 --> 00:59:51,480 important if you're a beginner make sure 1976 00:59:51,480 --> 00:59:53,339 that update is written exactly like this 1977 00:59:53,339 --> 00:59:55,799 if you write update with lowercase if 1978 00:59:55,799 --> 00:59:57,240 you do this then it won't work the 1979 00:59:57,240 --> 00:59:58,380 function will not be calmed 1980 00:59:58,380 --> 01:00:00,240 automatically I'm pointing this out 1981 01:00:00,240 --> 01:00:01,680 because I have seen a bunch of comments 1982 01:00:01,680 --> 01:00:03,119 from beginners wondering why their code 1983 01:00:03,119 --> 01:00:04,500 doesn't work and it's as simple as this 1984 01:00:04,500 --> 01:00:06,720 with a lowercase Unity will not call 1985 01:00:06,720 --> 01:00:08,040 this automatically it needs to be 1986 01:00:08,040 --> 01:00:10,020 exactly perfect so again if you're a 1987 01:00:10,020 --> 01:00:11,160 beginner make sure you write the code 1988 01:00:11,160 --> 01:00:13,380 exactly the code is case sensitive so 1989 01:00:13,380 --> 01:00:14,760 this is very important 1990 01:00:14,760 --> 01:00:16,980 also another note you saw that the code 1991 01:00:16,980 --> 01:00:18,900 that Unity wrote by default when we made 1992 01:00:18,900 --> 01:00:21,480 a new script it just had void update it 1993 01:00:21,480 --> 01:00:23,700 did not have the private keyword private 1994 01:00:23,700 --> 01:00:25,859 is what is called an accessor you have 1995 01:00:25,859 --> 01:00:27,599 private then you have public and then 1996 01:00:27,599 --> 01:00:29,339 there are some more advanced ones 1997 01:00:29,339 --> 01:00:32,099 secondly you can omit the accessor and 1998 01:00:32,099 --> 01:00:33,960 in most cases it will default to private 1999 01:00:33,960 --> 01:00:36,540 however in writing good clean code you 2000 01:00:36,540 --> 01:00:38,400 should be as explicit as possible there 2001 01:00:38,400 --> 01:00:40,140 should be no room for misunderstandings 2002 01:00:40,140 --> 01:00:42,359 so while technically you could emit the 2003 01:00:42,359 --> 01:00:44,760 private you should always include it to 2004 01:00:44,760 --> 01:00:46,619 make your code easy to read and easy to 2005 01:00:46,619 --> 01:00:47,400 understand 2006 01:00:47,400 --> 01:00:49,680 this one is the first of many clean code 2007 01:00:49,680 --> 01:00:51,059 rules that I will teach you during this 2008 01:00:51,059 --> 01:00:53,040 course like I said all of the code that 2009 01:00:53,040 --> 01:00:54,660 I'm writing here is on the same level of 2010 01:00:54,660 --> 01:00:55,859 quality that I use in my own 2011 01:00:55,859 --> 01:00:57,660 professional games I'm not going to 2012 01:00:57,660 --> 01:00:59,280 teach you bad practices like so many 2013 01:00:59,280 --> 01:01:01,619 beginner tutorials do so always be 2014 01:01:01,619 --> 01:01:03,299 explicit always include the accessor 2015 01:01:03,299 --> 01:01:05,640 okay so we have our update Running code 2016 01:01:05,640 --> 01:01:08,160 on every single frame then to test if a 2017 01:01:08,160 --> 01:01:09,839 key is being pressed we just go inside 2018 01:01:09,839 --> 01:01:12,359 input then over here we've got two 2019 01:01:12,359 --> 01:01:14,700 functions so we have get key and get key 2020 01:01:14,700 --> 01:01:15,480 down 2021 01:01:15,480 --> 01:01:17,460 both these functions were turning Boeing 2022 01:01:17,460 --> 01:01:19,440 so that's how the true or false the 2023 01:01:19,440 --> 01:01:21,119 difference between them is that get key 2024 01:01:21,119 --> 01:01:23,160 down this one only returns true for a 2025 01:01:23,160 --> 01:01:24,780 single frame when the key is pressed 2026 01:01:24,780 --> 01:01:27,119 whereas get key this one stays true for 2027 01:01:27,119 --> 01:01:28,859 as long as the key is held down for 2028 01:01:28,859 --> 01:01:30,839 example for an action like jumping you 2029 01:01:30,839 --> 01:01:31,920 just want to know when the player 2030 01:01:31,920 --> 01:01:34,020 presses the button so for that one you 2031 01:01:34,020 --> 01:01:36,359 would use get key down however in our 2032 01:01:36,359 --> 01:01:37,920 case for a character controller we want 2033 01:01:37,920 --> 01:01:39,900 to know if the key is being held down we 2034 01:01:39,900 --> 01:01:42,180 don't want just one frame but always 2035 01:01:42,180 --> 01:01:44,160 so for movement let's make sure we go 2036 01:01:44,160 --> 01:01:45,480 with get game 2037 01:01:45,480 --> 01:01:47,520 then requires a key so let's write our 2038 01:01:47,520 --> 01:01:49,140 key code and then choose the key let's 2039 01:01:49,140 --> 01:01:50,640 say we want w 2040 01:01:50,640 --> 01:01:52,859 and then let's just put this inside and 2041 01:01:52,859 --> 01:01:55,559 if just like this okay so here we have 2042 01:01:55,559 --> 01:01:57,180 code we want to run while holding down 2043 01:01:57,180 --> 01:01:59,400 the down key let's do a quick test just 2044 01:01:59,400 --> 01:02:00,480 to verify everything is working 2045 01:02:00,480 --> 01:02:02,940 perfectly and for testing we can use a 2046 01:02:02,940 --> 01:02:05,940 super useful debug.log this one lets us 2047 01:02:05,940 --> 01:02:07,500 print a message in the console someone 2048 01:02:07,500 --> 01:02:09,180 said One log here just say something 2049 01:02:09,180 --> 01:02:11,640 like pressing and then let's also do an 2050 01:02:11,640 --> 01:02:14,040 else and if else let's do a debug.log 2051 01:02:14,040 --> 01:02:16,680 and just do a dash okay so here is our 2052 01:02:16,680 --> 01:02:18,420 very basic script let's make sure to 2053 01:02:18,420 --> 01:02:21,359 save it so Ctrl s then back in unity 2054 01:02:21,359 --> 01:02:23,640 over here make sure you have the script 2055 01:02:23,640 --> 01:02:25,920 attached to the player game object and 2056 01:02:25,920 --> 01:02:28,260 now we can test and now down here on the 2057 01:02:28,260 --> 01:02:29,940 console we can already see dashes so I'm 2058 01:02:29,940 --> 01:02:32,040 not pressing anything also like I 2059 01:02:32,040 --> 01:02:33,660 mentioned in the setup lecture if you're 2060 01:02:33,660 --> 01:02:35,460 seeing just one message then maybe that 2061 01:02:35,460 --> 01:02:36,960 means you have over here the collapse 2062 01:02:36,960 --> 01:02:38,880 Target if you talk on it and look how it 2063 01:02:38,880 --> 01:02:40,500 only shows one message but then over 2064 01:02:40,500 --> 01:02:41,700 here on the right side it says the 2065 01:02:41,700 --> 01:02:43,859 number of messages personally I prefer 2066 01:02:43,859 --> 01:02:45,660 to always keep it untoggle so I can see 2067 01:02:45,660 --> 01:02:47,819 every single message also over here on 2068 01:02:47,819 --> 01:02:49,260 the right make sure you have info 2069 01:02:49,260 --> 01:02:51,720 messages visible if you untangle this 2070 01:02:51,720 --> 01:02:53,040 and you don't see it so make sure this 2071 01:02:53,040 --> 01:02:54,660 one and actually both of them make sure 2072 01:02:54,660 --> 01:02:56,579 all of them are enabled okay so we're 2073 01:02:56,579 --> 01:02:58,500 seeing a whole bunch of dashes and one 2074 01:02:58,500 --> 01:03:00,240 more note if over here these chromebars 2075 01:03:00,240 --> 01:03:01,799 stop scrolling so right now you can see 2076 01:03:01,799 --> 01:03:03,180 it's stuck up instead of being down 2077 01:03:03,180 --> 01:03:05,520 there so if that happens one is easy way 2078 01:03:05,520 --> 01:03:07,200 to reset that is just click over here on 2079 01:03:07,200 --> 01:03:08,520 clear and it goes back into AutoZone 2080 01:03:08,520 --> 01:03:11,099 okay so we have the dashes I am not 2081 01:03:11,099 --> 01:03:13,440 pressing anything now as I press yep 2082 01:03:13,440 --> 01:03:15,000 there you go there's a message if you 2083 01:03:15,000 --> 01:03:16,500 don't see it make sure the game window 2084 01:03:16,500 --> 01:03:17,700 is in focus 2085 01:03:17,700 --> 01:03:19,740 so selective game View and click right 2086 01:03:19,740 --> 01:03:21,059 here on the middle to make this one the 2087 01:03:21,059 --> 01:03:23,220 focused window then if you press the 2088 01:03:23,220 --> 01:03:24,960 down key you should see the message and 2089 01:03:24,960 --> 01:03:26,880 if I Let Go yep there it is and I stash 2090 01:03:26,880 --> 01:03:28,859 okay great so all the basic logic is 2091 01:03:28,859 --> 01:03:31,140 working back in the code here now that 2092 01:03:31,140 --> 01:03:32,880 logic is working let's get rid of the 2093 01:03:32,880 --> 01:03:34,140 else here 2094 01:03:34,140 --> 01:03:36,000 and let's set this for all the other 2095 01:03:36,000 --> 01:03:38,520 keys so let's copy paste this so we're 2096 01:03:38,520 --> 01:03:41,940 going to need w a s and D so let's make 2097 01:03:41,940 --> 01:03:44,640 all of these 2098 01:03:44,640 --> 01:03:46,740 okay so we have our inputs let's also 2099 01:03:46,740 --> 01:03:49,079 get rid of the logs we don't need this 2100 01:03:49,079 --> 01:03:50,819 all right so we have all of our key 2101 01:03:50,819 --> 01:03:52,859 presses now let's construct a vector 2102 01:03:52,859 --> 01:03:55,020 with our inputs and since we're just 2103 01:03:55,020 --> 01:03:56,760 going to have two axes 2104 01:03:56,760 --> 01:03:58,440 the double s that is forward and 2105 01:03:58,440 --> 01:03:59,640 backwards and this one is left and right 2106 01:03:59,640 --> 01:04:01,260 so just two axis 2107 01:04:01,260 --> 01:04:03,359 so because we have just two let's use a 2108 01:04:03,359 --> 01:04:05,400 vector two and let's call it the input 2109 01:04:05,400 --> 01:04:07,260 vector 2110 01:04:07,260 --> 01:04:09,420 let's construct it so we'll do a new one 2111 01:04:09,420 --> 01:04:12,119 and start off at zero zero okay 2112 01:04:12,119 --> 01:04:13,559 then over here the logic is pretty 2113 01:04:13,559 --> 01:04:15,780 simple so when we press W then let's go 2114 01:04:15,780 --> 01:04:17,579 into the input vector and set the Y to 2115 01:04:17,579 --> 01:04:19,260 pause one 2116 01:04:19,260 --> 01:04:21,240 then when we have an S we want to go 2117 01:04:21,240 --> 01:04:23,700 backwards so put the Y on -1 for the a 2118 01:04:23,700 --> 01:04:26,280 we want to go left so that's an x on the 2119 01:04:26,280 --> 01:04:28,980 minus one and finally for the D that is 2120 01:04:28,980 --> 01:04:31,500 an x on plus one okay so with this we 2121 01:04:31,500 --> 01:04:33,780 have our correct input Vector let's do a 2122 01:04:33,780 --> 01:04:35,819 quick log just to test so debug down log 2123 01:04:35,819 --> 01:04:37,680 on the input vector 2124 01:04:37,680 --> 01:04:39,960 okay so let's test all right so we can 2125 01:04:39,960 --> 01:04:41,579 see in log zero zero okay makes sense 2126 01:04:41,579 --> 01:04:44,400 now if I press W yep we've got an 1 on 2127 01:04:44,400 --> 01:04:46,740 the Y if I press a we got minus one in 2128 01:04:46,740 --> 01:04:49,260 the X press D plus one press s and minus 2129 01:04:49,260 --> 01:04:51,440 one okay great so everything works 2130 01:04:51,440 --> 01:04:53,819 except we also need to be careful about 2131 01:04:53,819 --> 01:04:57,359 one other thing if I press both W and D 2132 01:04:57,359 --> 01:04:59,880 with this look at that the vector is 1 1 2133 01:04:59,880 --> 01:05:01,440 which is correct that's exactly what it 2134 01:05:01,440 --> 01:05:03,240 is then except the factor one one 2135 01:05:03,240 --> 01:05:05,160 actually has a bigger magnitude than 2136 01:05:05,160 --> 01:05:07,200 just one vector if we leave it like this 2137 01:05:07,200 --> 01:05:08,760 then the character will move faster when 2138 01:05:08,760 --> 01:05:10,619 moving diagonally versus when moving in 2139 01:05:10,619 --> 01:05:12,839 just one direction for our input Vector 2140 01:05:12,839 --> 01:05:14,339 we really want it to be normalized 2141 01:05:14,339 --> 01:05:16,140 meaning we wanted to have the same size 2142 01:05:16,140 --> 01:05:17,819 regardless of the combination of keys 2143 01:05:17,819 --> 01:05:19,440 that we're pressing so back in the code 2144 01:05:19,440 --> 01:05:21,299 here after calculating the input vector 2145 01:05:21,299 --> 01:05:23,819 and let's simply normalize it so we go 2146 01:05:23,819 --> 01:05:25,559 into the input vector and we set it 2147 01:05:25,559 --> 01:05:28,380 equals to input Vector Dot normalized 2148 01:05:28,380 --> 01:05:30,420 so this will normalize our input Vector 2149 01:05:30,420 --> 01:05:32,520 let's see and over here if I press 2150 01:05:32,520 --> 01:05:34,619 doubly you've got one press s minus one 2151 01:05:34,619 --> 01:05:36,480 okay so all those work now if I press 2152 01:05:36,480 --> 01:05:38,940 both W and D if there go now it says 2153 01:05:38,940 --> 01:05:41,280 0.71 when you combine both these I need 2154 01:05:41,280 --> 01:05:43,079 the math these do end up with a 2155 01:05:43,079 --> 01:05:45,119 magnitude of one so with this our 2156 01:05:45,119 --> 01:05:46,740 character will move at the same speed on 2157 01:05:46,740 --> 01:05:49,319 both diagonals and straights okay so we 2158 01:05:49,319 --> 01:05:51,059 have the input Vector on correct now 2159 01:05:51,059 --> 01:05:53,099 let's actually apply some movement for 2160 01:05:53,099 --> 01:05:54,599 that there are many ways of making a 2161 01:05:54,599 --> 01:05:56,339 character controller for example you can 2162 01:05:56,339 --> 01:05:58,619 decide to use physics or not over here I 2163 01:05:58,619 --> 01:05:59,940 want to keep the game simple so let's 2164 01:05:59,940 --> 01:06:02,040 not use physics instead let's just move 2165 01:06:02,040 --> 01:06:04,079 the player transform directly over here 2166 01:06:04,079 --> 01:06:06,299 we have our input Vector okay great now 2167 01:06:06,299 --> 01:06:07,859 we want to apply this to our character 2168 01:06:07,859 --> 01:06:09,780 position so first we access the 2169 01:06:09,780 --> 01:06:10,920 transform 2170 01:06:10,920 --> 01:06:12,900 this one refers to the transform where 2171 01:06:12,900 --> 01:06:14,579 this script is attached to 2172 01:06:14,579 --> 01:06:16,440 this script was attached to the player 2173 01:06:16,440 --> 01:06:18,180 so this is going to refer to the player 2174 01:06:18,180 --> 01:06:20,040 transform then we want to modify the 2175 01:06:20,040 --> 01:06:21,660 position so let's access the position 2176 01:06:21,660 --> 01:06:23,940 and now for moving we don't want to just 2177 01:06:23,940 --> 01:06:28,079 assign it if we do something like this 2178 01:06:28,079 --> 01:06:29,819 like this the player would never leave 2179 01:06:29,819 --> 01:06:31,260 the center of the world he would always 2180 01:06:31,260 --> 01:06:33,780 be near zero zero so instead we don't 2181 01:06:33,780 --> 01:06:35,819 want to just assign it but instead we 2182 01:06:35,819 --> 01:06:37,680 want to add onto it now if you're a 2183 01:06:37,680 --> 01:06:38,940 complete beginner and you don't know 2184 01:06:38,940 --> 01:06:40,980 this syntax then this one is exactly the 2185 01:06:40,980 --> 01:06:43,680 same as this so transform dot position 2186 01:06:43,680 --> 01:06:46,440 equals transform dot position plus input 2187 01:06:46,440 --> 01:06:48,960 vector so both these little lines are 2188 01:06:48,960 --> 01:06:50,760 doing the exact same thing personally I 2189 01:06:50,760 --> 01:06:53,039 prefer to use the shorthand I find that 2190 01:06:53,039 --> 01:06:55,380 equally readable and more compact okay 2191 01:06:55,380 --> 01:06:57,599 so we have this and we add our input 2192 01:06:57,599 --> 01:06:59,520 Vector to the transform position except 2193 01:06:59,520 --> 01:07:01,319 we can also see a really nice error 2194 01:07:01,319 --> 01:07:03,059 basically it's telling us that we are 2195 01:07:03,059 --> 01:07:05,640 mixing two types our input is a vector 2196 01:07:05,640 --> 01:07:08,280 two where we only have an X and Y but 2197 01:07:08,280 --> 01:07:10,260 transform that position is a vector 3 2198 01:07:10,260 --> 01:07:13,319 meaning it has an X Y and Z one simple 2199 01:07:13,319 --> 01:07:15,359 solution is to cast our input Vector 2200 01:07:15,359 --> 01:07:18,119 onto a vector three so we just convert 2201 01:07:18,119 --> 01:07:19,859 this from one type into the other one 2202 01:07:19,859 --> 01:07:21,780 and yep we don't have the error so let's 2203 01:07:21,780 --> 01:07:24,359 test and now if I press W any of the 2204 01:07:24,359 --> 01:07:26,339 character does move Let's ignore the 2205 01:07:26,339 --> 01:07:28,740 massive speed for now so it does move it 2206 01:07:28,740 --> 01:07:31,200 does seem slightly correct except you 2207 01:07:31,200 --> 01:07:32,640 can obviously notice that it's not 2208 01:07:32,640 --> 01:07:35,099 correct we are moving on the x-axis on 2209 01:07:35,099 --> 01:07:36,299 left and right that is correct but then 2210 01:07:36,299 --> 01:07:37,859 we are moving up and down instead of 2211 01:07:37,859 --> 01:07:40,260 fourth and back basically we convert the 2212 01:07:40,260 --> 01:07:41,940 effector 2 directly into a vector three 2213 01:07:41,940 --> 01:07:44,460 so we are moving on the X and Y axes but 2214 01:07:44,460 --> 01:07:46,140 in our 3D game we really don't want the 2215 01:07:46,140 --> 01:07:48,059 characters to fly so instead we want to 2216 01:07:48,059 --> 01:07:50,880 move on the XZ axis so back in code here 2217 01:07:50,880 --> 01:07:52,680 instead of directly casting this down 2218 01:07:52,680 --> 01:07:55,200 into a vector 3. let's construct a move 2219 01:07:55,200 --> 01:07:57,740 to your vector similar to Vector three 2220 01:07:57,740 --> 01:08:00,119 let's call it our move there for our 2221 01:08:00,119 --> 01:08:02,280 move Direction and over here we 2222 01:08:02,280 --> 01:08:04,260 construct a new vector3 2223 01:08:04,260 --> 01:08:05,819 and basically we're just going to assign 2224 01:08:05,819 --> 01:08:08,160 the input y to the Zenon here so first 2225 01:08:08,160 --> 01:08:09,900 of all for the X7 is correct so input 2226 01:08:09,900 --> 01:08:12,539 vector.x then for the Y let's leave this 2227 01:08:12,539 --> 01:08:14,880 one on zero and finally let's use the 2228 01:08:14,880 --> 01:08:16,979 input vector.y as I said on the Move 2229 01:08:16,979 --> 01:08:19,080 direction also now at this point you 2230 01:08:19,080 --> 01:08:21,179 might be questioning if we're using a 2231 01:08:21,179 --> 01:08:23,580 vector 3 here why don't we also use a 2232 01:08:23,580 --> 01:08:25,560 vector 3 appear and then just assign the 2233 01:08:25,560 --> 01:08:27,420 Z directly that's certainly a 2234 01:08:27,420 --> 01:08:29,100 possibility and for making a super quick 2235 01:08:29,100 --> 01:08:31,439 prototype I might even do that myself 2236 01:08:31,439 --> 01:08:33,600 but the proper answer to that is once 2237 01:08:33,600 --> 01:08:35,160 again all about writing good clean code 2238 01:08:35,160 --> 01:08:37,979 the input logically only has two axes 2239 01:08:37,979 --> 01:08:40,979 there's no z-axis on your keyboard so 2240 01:08:40,979 --> 01:08:42,540 logically it makes no sense for the 2241 01:08:42,540 --> 01:08:45,000 input to have three axes and beyond that 2242 01:08:45,000 --> 01:08:46,920 you should keep the logic separate so 2243 01:08:46,920 --> 01:08:48,719 you should first get the input and then 2244 01:08:48,719 --> 01:08:50,698 actually move the object we're going to 2245 01:08:50,698 --> 01:08:52,198 see the benefit of that separation when 2246 01:08:52,198 --> 01:08:53,939 we refactor this code to work with the 2247 01:08:53,939 --> 01:08:56,339 new input system doing that will in turn 2248 01:08:56,339 --> 01:08:58,198 make enabling Gamepad joystick support 2249 01:08:58,198 --> 01:09:00,179 super easy because we have the input 2250 01:09:00,179 --> 01:09:01,799 Vector separated from the actual 2251 01:09:01,799 --> 01:09:03,719 movement some of that to say and let's 2252 01:09:03,719 --> 01:09:06,120 do things properly let's keep the input 2253 01:09:06,120 --> 01:09:07,920 Vector separate from the movement Vector 2254 01:09:07,920 --> 01:09:10,679 so we just translate the X Y onto X end 2255 01:09:10,679 --> 01:09:12,899 and then we just apply this into our 2256 01:09:12,899 --> 01:09:14,399 transform position 2257 01:09:14,399 --> 01:09:17,339 okay so let's test so now if I press the 2258 01:09:17,339 --> 01:09:19,799 right turn left and press W and S and 2259 01:09:19,799 --> 01:09:21,540 there you go okay great so it is indeed 2260 01:09:21,540 --> 01:09:23,160 moving Left Right forward and back okay 2261 01:09:23,160 --> 01:09:25,439 great so it is working but as you can 2262 01:09:25,439 --> 01:09:27,660 see it's moving insanely fast you might 2263 01:09:27,660 --> 01:09:29,279 think the issue here is just applying 2264 01:09:29,279 --> 01:09:30,839 some sort of movement speed multiplier 2265 01:09:30,839 --> 01:09:33,238 except there's actually one sneaky issue 2266 01:09:33,238 --> 01:09:35,520 here on the game view on the top right 2267 01:09:35,520 --> 01:09:37,319 corner we've got a stats button and over 2268 01:09:37,319 --> 01:09:38,839 here we can see a whole bunch of things 2269 01:09:38,839 --> 01:09:40,920 specifically we can look at the frame 2270 01:09:40,920 --> 01:09:43,380 rate we can see that it's running at 144 2271 01:09:43,380 --> 01:09:45,779 frames per second over here on the left 2272 01:09:45,779 --> 01:09:48,420 side on this button I have vsync enabled 2273 01:09:48,420 --> 01:09:50,219 this will cap the frame rate to the 2274 01:09:50,219 --> 01:09:52,500 monitor's refresh rate so that is why 2275 01:09:52,500 --> 01:09:54,900 I'm seeing 144 Hertz I can overhear 2276 01:09:54,900 --> 01:09:56,940 disable vsync and the upload that goes 2277 01:09:56,940 --> 01:09:59,100 all the way up to 700. basically now the 2278 01:09:59,100 --> 01:10:00,300 game is running as fast as my computer 2279 01:10:00,300 --> 01:10:02,580 can run it and if I press the movement 2280 01:10:02,580 --> 01:10:04,320 keys and look at that now it's moving 2281 01:10:04,320 --> 01:10:05,580 even faster 2282 01:10:05,580 --> 01:10:07,440 now I've completely lost track of where 2283 01:10:07,440 --> 01:10:10,440 my player is this is not what we want we 2284 01:10:10,440 --> 01:10:11,640 don't want the player to move at 2285 01:10:11,640 --> 01:10:12,960 different speeds depending on the frame 2286 01:10:12,960 --> 01:10:15,060 rate we want it to always move at the 2287 01:10:15,060 --> 01:10:17,219 same speed regardless of frame rate so 2288 01:10:17,219 --> 01:10:18,900 when you do any kind of movement Logic 2289 01:10:18,900 --> 01:10:21,120 on an update you always need to make 2290 01:10:21,120 --> 01:10:23,340 sure to multiply by time dot Delta time 2291 01:10:23,340 --> 01:10:25,440 what this variable contains is the 2292 01:10:25,440 --> 01:10:27,000 number of seconds in Labs since the last 2293 01:10:27,000 --> 01:10:29,280 frame for example let's unlock to this 2294 01:10:29,280 --> 01:10:30,840 we no longer need the input Vector so 2295 01:10:30,840 --> 01:10:32,400 let's unlock just the time that down to 2296 01:10:32,400 --> 01:10:35,040 time okay so we can see there there's 2297 01:10:35,040 --> 01:10:36,960 basically telling us how many seconds it 2298 01:10:36,960 --> 01:10:39,420 is taking to render a single frame once 2299 01:10:39,420 --> 01:10:41,219 again note how I have vsync enabled so 2300 01:10:41,219 --> 01:10:43,980 I'm running at 144 frames per second and 2301 01:10:43,980 --> 01:10:45,239 now if I disable it let's see what 2302 01:10:45,239 --> 01:10:46,679 happens to that number so if I disable 2303 01:10:46,679 --> 01:10:48,179 and you have a look at that that number 2304 01:10:48,179 --> 01:10:49,980 is now much much smaller and the game is 2305 01:10:49,980 --> 01:10:52,080 now running much much faster so by 2306 01:10:52,080 --> 01:10:53,520 incorporating this value into our 2307 01:10:53,520 --> 01:10:55,020 calculation we are going to be taking 2308 01:10:55,020 --> 01:10:56,699 into account the frame rate 2309 01:10:56,699 --> 01:10:58,500 thus making sure that movement is always 2310 01:10:58,500 --> 01:11:00,719 frame rate independent right now with 2311 01:11:00,719 --> 01:11:02,159 this frame rate if I move you can see 2312 01:11:02,159 --> 01:11:04,199 I'm moving at this speed and now if I 2313 01:11:04,199 --> 01:11:06,060 enable vsync change the frame rate and I 2314 01:11:06,060 --> 01:11:07,500 move and I'm still moving at the exact 2315 01:11:07,500 --> 01:11:08,460 same speed 2316 01:11:08,460 --> 01:11:10,800 okay that's great except obviously it's 2317 01:11:10,800 --> 01:11:12,480 not exactly great it's moving way too 2318 01:11:12,480 --> 01:11:14,159 slow so let's also incorporate a 2319 01:11:14,159 --> 01:11:16,080 movement speed now for this once again 2320 01:11:16,080 --> 01:11:17,640 most beginner tutorials will teach you 2321 01:11:17,640 --> 01:11:19,500 to go all the way up here and find a 2322 01:11:19,500 --> 01:11:22,800 public float move speed 2323 01:11:22,800 --> 01:11:24,540 maybe they found it to some villain like 2324 01:11:24,540 --> 01:11:26,580 7f something like that 2325 01:11:26,580 --> 01:11:28,739 then you have this field and then down 2326 01:11:28,739 --> 01:11:30,000 here you simply use it in the 2327 01:11:30,000 --> 01:11:32,040 calculation so movement here move 2328 01:11:32,040 --> 01:11:34,140 multiply it by move speed and by time 2329 01:11:34,140 --> 01:11:36,719 dot time so this is what most tutorials 2330 01:11:36,719 --> 01:11:39,060 will teach you by making it public up 2331 01:11:39,060 --> 01:11:40,260 here what you're doing is you're 2332 01:11:40,260 --> 01:11:42,480 enabling access from the editor so if 2333 01:11:42,480 --> 01:11:43,800 you go over here in the editor over 2334 01:11:43,800 --> 01:11:45,360 there on the player we can see the move 2335 01:11:45,360 --> 01:11:47,280 speed variable we can see this exposed 2336 01:11:47,280 --> 01:11:49,380 and we can modify it this makes it 2337 01:11:49,380 --> 01:11:50,699 really easy for testing and for 2338 01:11:50,699 --> 01:11:52,320 iterating upon the value even while the 2339 01:11:52,320 --> 01:11:53,460 game is running 2340 01:11:53,460 --> 01:11:55,440 so the game is playing I can move and I 2341 01:11:55,440 --> 01:11:57,420 have this move speed now I can modify 2342 01:11:57,420 --> 01:11:59,219 this and yep now I got a different move 2343 01:11:59,219 --> 01:12:00,900 speed so I can use this to quickly to 2344 01:12:00,900 --> 01:12:02,820 rate and find the perfect value 2345 01:12:02,820 --> 01:12:04,620 so it's great to have this variable 2346 01:12:04,620 --> 01:12:06,960 exposed in the editor and this feature 2347 01:12:06,960 --> 01:12:08,520 is indeed the reason why most beginner 2348 01:12:08,520 --> 01:12:09,840 tutorials will teach you to make it 2349 01:12:09,840 --> 01:12:11,340 public it's so you can see it in the 2350 01:12:11,340 --> 01:12:13,620 editor that is indeed a very valuable 2351 01:12:13,620 --> 01:12:15,719 thing being able to easily iterate upon 2352 01:12:15,719 --> 01:12:17,540 important values is always very useful 2353 01:12:17,540 --> 01:12:19,980 however when you make something public 2354 01:12:19,980 --> 01:12:22,260 when you do that you don't just expose 2355 01:12:22,260 --> 01:12:24,179 the film to the editor you are exposing 2356 01:12:24,179 --> 01:12:25,860 it to every other class in your entire 2357 01:12:25,860 --> 01:12:28,320 code base so some other class could 2358 01:12:28,320 --> 01:12:30,000 access this field and set the player's 2359 01:12:30,000 --> 01:12:31,380 movement speed to something like zero 2360 01:12:31,380 --> 01:12:33,120 and you would have no idea that was 2361 01:12:33,120 --> 01:12:34,620 happening because the issue would not be 2362 01:12:34,620 --> 01:12:36,960 on this code right here I have an entire 2363 01:12:36,960 --> 01:12:39,000 video on this subject why you should not 2364 01:12:39,000 --> 01:12:41,219 make everything public this is an 2365 01:12:41,219 --> 01:12:42,659 extremely important topic to know about 2366 01:12:42,659 --> 01:12:45,120 this one tiny change will massively 2367 01:12:45,120 --> 01:12:46,739 improve the quality of your code 2368 01:12:46,739 --> 01:12:48,600 definitely go ahead and watch that video 2369 01:12:48,600 --> 01:12:50,640 to learn why such a bad thing and make 2370 01:12:50,640 --> 01:12:52,920 sure you don't do it so to avoid all 2371 01:12:52,920 --> 01:12:54,420 kinds of problems you should never make 2372 01:12:54,420 --> 01:12:56,880 films public so very quickly the obvious 2373 01:12:56,880 --> 01:12:59,520 alternative is make it private making it 2374 01:12:59,520 --> 01:13:01,080 private means that only this class only 2375 01:13:01,080 --> 01:13:03,060 the code in here only this can modify 2376 01:13:03,060 --> 01:13:04,920 this film so you know for certain that 2377 01:13:04,920 --> 01:13:06,659 no other class can ever modify this 2378 01:13:06,659 --> 01:13:08,640 however making it private also means the 2379 01:13:08,640 --> 01:13:10,980 editor cannot modify this film so we've 2380 01:13:10,980 --> 01:13:13,020 lost our very useful iteration approach 2381 01:13:13,020 --> 01:13:15,420 so what we can do to expose it just to 2382 01:13:15,420 --> 01:13:16,980 the editor is to keep it private and 2383 01:13:16,980 --> 01:13:18,900 then we add the attribute serialize 2384 01:13:18,900 --> 01:13:19,860 field 2385 01:13:19,860 --> 01:13:21,900 this way this field is still private 2386 01:13:21,900 --> 01:13:23,880 meaning that it can only be modified by 2387 01:13:23,880 --> 01:13:26,159 the code inside the player class but 2388 01:13:26,159 --> 01:13:28,260 with this attribute over here in the 2389 01:13:28,260 --> 01:13:30,300 editor yep we do have an editable field 2390 01:13:30,300 --> 01:13:32,340 so only the code in that class in the 2391 01:13:32,340 --> 01:13:34,620 editor can modify it nothing else can 2392 01:13:34,620 --> 01:13:36,540 touch it nothing else can read or write 2393 01:13:36,540 --> 01:13:38,760 which is exactly what we want one of the 2394 01:13:38,760 --> 01:13:40,560 main rules in writing good clean code is 2395 01:13:40,560 --> 01:13:42,360 minimizing complexity and one of the 2396 01:13:42,360 --> 01:13:43,980 easier ways to minimize complexity is 2397 01:13:43,980 --> 01:13:46,620 simply to minimize axis by making this 2398 01:13:46,620 --> 01:13:48,120 feel private we are minimizing 2399 01:13:48,120 --> 01:13:49,860 complexity because it doesn't matter how 2400 01:13:49,860 --> 01:13:52,080 complex our game is maybe our code base 2401 01:13:52,080 --> 01:13:53,880 is a thousand classes long it doesn't 2402 01:13:53,880 --> 01:13:55,560 really matter because only this class 2403 01:13:55,560 --> 01:13:57,900 can never touch this field so if we have 2404 01:13:57,900 --> 01:13:59,880 a bug related movement speed we know for 2405 01:13:59,880 --> 01:14:01,620 certain it has to be inside this code 2406 01:14:01,620 --> 01:14:03,900 and nothing else so we minimize the 2407 01:14:03,900 --> 01:14:05,340 things we need to keep in our head which 2408 01:14:05,340 --> 01:14:07,380 is always a very good thing okay so with 2409 01:14:07,380 --> 01:14:08,940 all that said we have our movement speed 2410 01:14:08,940 --> 01:14:10,679 and down here we are incorporating it 2411 01:14:10,679 --> 01:14:13,080 into our calculation just with this we 2412 01:14:13,080 --> 01:14:14,340 have our character working with a 2413 01:14:14,340 --> 01:14:16,560 variable movement speed and by using 2414 01:14:16,560 --> 01:14:17,940 Delta time we have our movement 2415 01:14:17,940 --> 01:14:19,920 correctly being frame rate independent 2416 01:14:19,920 --> 01:14:21,719 so here's our character and using the 2417 01:14:21,719 --> 01:14:23,340 keys I can walk around and yep the 2418 01:14:23,340 --> 01:14:24,960 character moves in any direction so we 2419 01:14:24,960 --> 01:14:26,880 have movement only working while using 2420 01:14:26,880 --> 01:14:29,159 the Legacy input manager like I said 2421 01:14:29,159 --> 01:14:30,659 we're going to learn how to refactor our 2422 01:14:30,659 --> 01:14:31,920 code to use the new input system 2423 01:14:31,920 --> 01:14:34,080 learning how to refactor is an extremely 2424 01:14:34,080 --> 01:14:35,400 important skill to improve your own 2425 01:14:35,400 --> 01:14:37,679 programming skills it is something that 2426 01:14:37,679 --> 01:14:39,480 you should always do when necessary it 2427 01:14:39,480 --> 01:14:40,800 will massively help you improve the 2428 01:14:40,800 --> 01:14:42,300 quality of your code 2429 01:14:42,300 --> 01:14:44,280 so we're going to do that but before we 2430 01:14:44,280 --> 01:14:45,659 get to that let's actually do something 2431 01:14:45,659 --> 01:14:47,219 a bit more fun and add some proper 2432 01:14:47,219 --> 01:14:49,080 visuals and animations to our player in 2433 01:14:49,080 --> 01:14:51,120 the next lecture 2434 01:14:51,120 --> 01:14:53,100 hello and welcome I'm your code monkey 2435 01:14:53,100 --> 01:14:54,840 in this lecture we're going to replace 2436 01:14:54,840 --> 01:14:57,060 our boring capsule visual with a nice 2437 01:14:57,060 --> 01:14:59,340 proper character mesh okay so in the 2438 01:14:59,340 --> 01:15:01,560 included assets project files over here 2439 01:15:01,560 --> 01:15:03,960 if we go inside the prefab visuals we 2440 01:15:03,960 --> 01:15:06,000 see a nice player visual let's position 2441 01:15:06,000 --> 01:15:08,219 it inside the player game object so 2442 01:15:08,219 --> 01:15:10,440 let's drag it inside again because we 2443 01:15:10,440 --> 01:15:12,060 separate the logic and visuals this is 2444 01:15:12,060 --> 01:15:13,860 going to be pretty easy we don't need to 2445 01:15:13,860 --> 01:15:15,780 modify the parent game object at all we 2446 01:15:15,780 --> 01:15:17,040 just dropped the visualize this channel 2447 01:15:17,040 --> 01:15:19,140 that's it also again very important make 2448 01:15:19,140 --> 01:15:20,580 sure the visual is over here on low 2449 01:15:20,580 --> 01:15:22,440 composition zero zero zero only the 2450 01:15:22,440 --> 01:15:24,179 parent game object should move the 2451 01:15:24,179 --> 01:15:25,860 visual itself should never move if you 2452 01:15:25,860 --> 01:15:27,360 notice some weird positions as your 2453 01:15:27,360 --> 01:15:29,340 player moves and rotates always check to 2454 01:15:29,340 --> 01:15:31,140 make sure that the channel visual is on 2455 01:15:31,140 --> 01:15:33,060 zero zero zero okay so with this let's 2456 01:15:33,060 --> 01:15:35,880 delete the old capsule delete it okay so 2457 01:15:35,880 --> 01:15:37,800 here we have a pretty simple but really 2458 01:15:37,800 --> 01:15:39,659 nice character visual it's really just 2459 01:15:39,659 --> 01:15:41,159 two spheres stacked on top of one 2460 01:15:41,159 --> 01:15:42,840 another with a bunch of eyes very simple 2461 01:15:42,840 --> 01:15:45,179 for the visual itself the material is 2462 01:15:45,179 --> 01:15:47,580 using just a solid color so here it is 2463 01:15:47,580 --> 01:15:49,679 inside the assets material you can see a 2464 01:15:49,679 --> 01:15:50,820 bunch of player bodies with different 2465 01:15:50,820 --> 01:15:52,739 color these different colors they won't 2466 01:15:52,739 --> 01:15:54,420 be used in the upcoming multiplayer 2467 01:15:54,420 --> 01:15:56,040 video basically each player will have a 2468 01:15:56,040 --> 01:15:57,420 different color also by the way if 2469 01:15:57,420 --> 01:15:58,800 you're a complete beginner here's a 2470 01:15:58,800 --> 01:16:00,480 quick lecture on materials these are 2471 01:16:00,480 --> 01:16:02,040 materials and if we call it select we 2472 01:16:02,040 --> 01:16:03,540 can see a bunch of sets related to that 2473 01:16:03,540 --> 01:16:05,400 material basically the materials have a 2474 01:16:05,400 --> 01:16:06,900 Shader and then a bunch of properties 2475 01:16:06,900 --> 01:16:09,300 now the Shader is the actual code that 2476 01:16:09,300 --> 01:16:11,100 runs on the graphics card that says how 2477 01:16:11,100 --> 01:16:13,080 an object should be rendered by default 2478 01:16:13,080 --> 01:16:14,640 you have a whole bunch of included 2479 01:16:14,640 --> 01:16:16,560 shaders we're using the universal render 2480 01:16:16,560 --> 01:16:18,060 pipeline so you should mostly be using 2481 01:16:18,060 --> 01:16:20,340 the ones inside the urp and by default 2482 01:16:20,340 --> 01:16:21,540 you probably want to be using the 2483 01:16:21,540 --> 01:16:22,980 standard light Shader then of course you 2484 01:16:22,980 --> 01:16:24,600 can also build your own custom shaders 2485 01:16:24,600 --> 01:16:26,400 one excellent tool for doing that is 2486 01:16:26,400 --> 01:16:27,960 shade graph which I have covered in 2487 01:16:27,960 --> 01:16:29,760 detail in a previous video it's a fully 2488 01:16:29,760 --> 01:16:31,140 visual tool that you can use to make 2489 01:16:31,140 --> 01:16:32,699 shaders without having to write any 2490 01:16:32,699 --> 01:16:34,739 shutter code it's a great tool I've also 2491 01:16:34,739 --> 01:16:36,480 made a bunch of tutorials on all kinds 2492 01:16:36,480 --> 01:16:37,980 of effects you can make although right 2493 01:16:37,980 --> 01:16:39,300 now we're not going to be using custom 2494 01:16:39,300 --> 01:16:41,100 shaders we're going to do that later on 2495 01:16:41,100 --> 01:16:42,300 the course but for now we're going to 2496 01:16:42,300 --> 01:16:43,860 stick with default light Shader so 2497 01:16:43,860 --> 01:16:45,659 materials have a combination of shaders 2498 01:16:45,659 --> 01:16:47,400 and the properties on that Shader for 2499 01:16:47,400 --> 01:16:48,900 example over here for the phone light 2500 01:16:48,900 --> 01:16:50,580 sharing you can see that it has over 2501 01:16:50,580 --> 01:16:52,739 here based map that has a counter field 2502 01:16:52,739 --> 01:16:54,540 this is what you can change to apply a 2503 01:16:54,540 --> 01:16:56,100 different color to your player also as 2504 01:16:56,100 --> 01:16:57,960 to how you apply a material to an object 2505 01:16:57,960 --> 01:16:59,699 over here on the player visual you can 2506 01:16:59,699 --> 01:17:01,679 see the objects are made up of a sphere 2507 01:17:01,679 --> 01:17:03,179 so this is the mesh and then the mesh 2508 01:17:03,179 --> 01:17:04,860 render this is the one that has the 2509 01:17:04,860 --> 01:17:07,080 material so both these are what stores 2510 01:17:07,080 --> 01:17:09,000 the shape as well as the visual for the 2511 01:17:09,000 --> 01:17:11,100 object the mesh is just a 3D shape but 2512 01:17:11,100 --> 01:17:12,600 just by some of the mesh filter doesn't 2513 01:17:12,600 --> 01:17:14,219 actually render anything so it needs a 2514 01:17:14,219 --> 01:17:15,780 mesh render which needs a material 2515 01:17:15,780 --> 01:17:17,580 attached to it so for example over here 2516 01:17:17,580 --> 01:17:19,080 on the hierarching let's right click on 2517 01:17:19,080 --> 01:17:20,640 empty space and let's create a brand new 2518 01:17:20,640 --> 01:17:22,500 Cube just to see it so if there you go 2519 01:17:22,500 --> 01:17:24,179 it does create an object and as you can 2520 01:17:24,179 --> 01:17:25,920 see it has a mesh filter and a mesh 2521 01:17:25,920 --> 01:17:27,540 render now to apply a different material 2522 01:17:27,540 --> 01:17:29,580 you can click on this little circle icon 2523 01:17:29,580 --> 01:17:31,320 and it shows you all the materials in 2524 01:17:31,320 --> 01:17:33,239 that project alternatively you can grab 2525 01:17:33,239 --> 01:17:34,679 the material directly from the project 2526 01:17:34,679 --> 01:17:36,420 window so for example the player body 2527 01:17:36,420 --> 01:17:38,640 just grab it and drop it in there or you 2528 01:17:38,640 --> 01:17:40,380 can also drop the material over here on 2529 01:17:40,380 --> 01:17:41,760 scene view as you can see as I Mouse 2530 01:17:41,760 --> 01:17:43,560 over different objects it applies that 2531 01:17:43,560 --> 01:17:45,360 material to a different object although 2532 01:17:45,360 --> 01:17:47,159 note that only works over here on scene 2533 01:17:47,159 --> 01:17:48,900 view it does not work on game view so 2534 01:17:48,900 --> 01:17:50,400 this basically sets the material over 2535 01:17:50,400 --> 01:17:52,380 there on the object right now one more 2536 01:17:52,380 --> 01:17:54,360 very important thing on materials if you 2537 01:17:54,360 --> 01:17:56,159 have multiple meshes only using the 2538 01:17:56,159 --> 01:17:57,960 exact same material and then you modify 2539 01:17:57,960 --> 01:17:59,340 the material it won't change the vision 2540 01:17:59,340 --> 01:18:01,440 while all meshes using that material so 2541 01:18:01,440 --> 01:18:03,360 for example if I modify the color here 2542 01:18:03,360 --> 01:18:05,159 put it on something different there you 2543 01:18:05,159 --> 01:18:07,320 go all three instances all three objects 2544 01:18:07,320 --> 01:18:08,699 that are all using the exact same 2545 01:18:08,699 --> 01:18:10,380 material they all update to the new 2546 01:18:10,380 --> 01:18:12,300 color if for example you wanted the head 2547 01:18:12,300 --> 01:18:13,800 to be a different color from the rest 2548 01:18:13,800 --> 01:18:15,659 then you would just create new material 2549 01:18:15,659 --> 01:18:17,159 so you can right click on the project 2550 01:18:17,159 --> 01:18:19,440 window let's create a new material then 2551 01:18:19,440 --> 01:18:21,000 you can give it a name give it colors 2552 01:18:21,000 --> 01:18:22,560 use a different shade or whatever and 2553 01:18:22,560 --> 01:18:23,580 then use this one for something 2554 01:18:23,580 --> 01:18:24,960 different so that's pretty much the 2555 01:18:24,960 --> 01:18:26,820 basics for materials and by the way if 2556 01:18:26,820 --> 01:18:28,080 you're a complete beginner and you have 2557 01:18:28,080 --> 01:18:29,580 questions remember to post them in the 2558 01:18:29,580 --> 01:18:30,900 comments and I'll do my best to help 2559 01:18:30,900 --> 01:18:32,280 like I said I want to keep this video 2560 01:18:32,280 --> 01:18:33,960 moving I'm trying to teach as much as 2561 01:18:33,960 --> 01:18:35,460 possible while still keeping the video 2562 01:18:35,460 --> 01:18:37,020 reasonable length so if you need any 2563 01:18:37,020 --> 01:18:38,460 further clarification on anything 2564 01:18:38,460 --> 01:18:40,140 specific just go ahead and ask in the 2565 01:18:40,140 --> 01:18:41,760 comments okay so when materials are out 2566 01:18:41,760 --> 01:18:43,020 of the way here we have our player with 2567 01:18:43,020 --> 01:18:44,880 visual let's just get rid of our Cube 2568 01:18:44,880 --> 01:18:47,100 okay and just with this if we test and 2569 01:18:47,100 --> 01:18:48,840 yep over here we already have a nice 2570 01:18:48,840 --> 01:18:51,179 player visual walking around okay great 2571 01:18:51,179 --> 01:18:52,860 except the player isn't actually 2572 01:18:52,860 --> 01:18:55,080 rotating ideally the visual should be 2573 01:18:55,080 --> 01:18:57,060 facing the walking direction so if I 2574 01:18:57,060 --> 01:18:58,739 walk down it should be rotated to face 2575 01:18:58,739 --> 01:19:00,659 down so let's have that doing that is 2576 01:19:00,659 --> 01:19:02,460 actually going to be pretty simple let's 2577 01:19:02,460 --> 01:19:04,140 go into our script here we are on the 2578 01:19:04,140 --> 01:19:05,820 player script and over here we already 2579 01:19:05,820 --> 01:19:07,980 have the movement Direction so we're 2580 01:19:07,980 --> 01:19:09,300 going to use this in order to make sure 2581 01:19:09,300 --> 01:19:11,580 to rotate the game object to face this 2582 01:19:11,580 --> 01:19:13,440 move Direction and for rotating and 2583 01:19:13,440 --> 01:19:15,120 transform there are many many ways to do 2584 01:19:15,120 --> 01:19:17,400 it one obvious one is to modify the 2585 01:19:17,400 --> 01:19:19,860 transform dot rotation however this one 2586 01:19:19,860 --> 01:19:21,360 as you can see works with quaternions 2587 01:19:21,360 --> 01:19:22,980 for me even though I've been doing Game 2588 01:19:22,980 --> 01:19:24,540 Dev for over 10 years I still find 2589 01:19:24,540 --> 01:19:26,520 quaternions quite a bit confusing so I 2590 01:19:26,520 --> 01:19:28,440 normally don't use this method another 2591 01:19:28,440 --> 01:19:30,659 method is to modify the transform dot 2592 01:19:30,659 --> 01:19:32,640 Euler angles this one is much more 2593 01:19:32,640 --> 01:19:34,560 intuitive and makes more sense to me it 2594 01:19:34,560 --> 01:19:36,480 works with regular Euler angles which is 2595 01:19:36,480 --> 01:19:38,040 much easier to understand if you don't 2596 01:19:38,040 --> 01:19:39,600 know that name it really just means the 2597 01:19:39,600 --> 01:19:42,120 angles that go from 0 to 360. then for 2598 01:19:42,120 --> 01:19:43,380 another method you can also use the 2599 01:19:43,380 --> 01:19:45,719 function transform Dot and look at this 2600 01:19:45,719 --> 01:19:47,280 one makes a transform look at a certain 2601 01:19:47,280 --> 01:19:49,080 point so it can be a transform Target 2602 01:19:49,080 --> 01:19:50,820 can be a vector three for one position 2603 01:19:50,820 --> 01:19:52,800 and anything like that so this is a very 2604 01:19:52,800 --> 01:19:54,600 useful function we could calculate a 2605 01:19:54,600 --> 01:19:55,980 point right in front of our move 2606 01:19:55,980 --> 01:19:58,260 Direction and look at it or finally the 2607 01:19:58,260 --> 01:19:59,820 method that I personally like to use for 2608 01:19:59,820 --> 01:20:01,560 this specific purpose which is just 2609 01:20:01,560 --> 01:20:03,600 modify the transform dot forward this 2610 01:20:03,600 --> 01:20:05,100 one has the normalized vector 2611 01:20:05,100 --> 01:20:06,900 representing the foreign axes and 2612 01:20:06,900 --> 01:20:08,520 importantly you can get it and you can 2613 01:20:08,520 --> 01:20:10,440 also set it so you have both read and 2614 01:20:10,440 --> 01:20:12,120 write you can read it to get the current 2615 01:20:12,120 --> 01:20:13,920 transform for it but you can also write 2616 01:20:13,920 --> 01:20:15,420 to it to essentially rotate the 2617 01:20:15,420 --> 01:20:17,340 transform so we can just assign this to 2618 01:20:17,340 --> 01:20:19,380 our forward Vector also by the way you 2619 01:20:19,380 --> 01:20:21,719 also have transform dot up and transform 2620 01:20:21,719 --> 01:20:23,699 dot right both these work exactly the 2621 01:20:23,699 --> 01:20:25,320 same way for example transforms are 2622 01:20:25,320 --> 01:20:26,940 right this one is extremely useful for 2623 01:20:26,940 --> 01:20:28,739 2D games but over here we're working in 2624 01:20:28,739 --> 01:20:30,480 3D so we want to transform that forward 2625 01:20:30,480 --> 01:20:32,159 and all we need is the forward Vector 2626 01:20:32,159 --> 01:20:33,420 which is really just in move Direction 2627 01:20:33,420 --> 01:20:35,280 so let's set this one equal Z move there 2628 01:20:35,280 --> 01:20:37,260 okay so just like this it shouldn't 2629 01:20:37,260 --> 01:20:38,820 really work let's also just clean up the 2630 01:20:38,820 --> 01:20:40,679 log we already need to see the Delta 2631 01:20:40,679 --> 01:20:42,420 time okay so let's see like this okay 2632 01:20:42,420 --> 01:20:44,219 here we are and as I move and you better 2633 01:20:44,219 --> 01:20:45,780 go and look at that the player object 2634 01:20:45,780 --> 01:20:47,400 does indeed rotate to face the move 2635 01:20:47,400 --> 01:20:48,960 Direction okay so it's already looking 2636 01:20:48,960 --> 01:20:51,060 great all right awesome however it also 2637 01:20:51,060 --> 01:20:53,280 looks a bit odd with how it's instant so 2638 01:20:53,280 --> 01:20:54,900 I move left and right look at that it 2639 01:20:54,900 --> 01:20:56,820 instantly rotates so there's no 2640 01:20:56,820 --> 01:20:59,159 smoothing nothing it's way too janky so 2641 01:20:59,159 --> 01:21:01,020 let's add some nice simple smoothing and 2642 01:21:01,020 --> 01:21:02,460 for that let's use a really awesome 2643 01:21:02,460 --> 01:21:04,679 really useful math function called lerp 2644 01:21:04,679 --> 01:21:06,360 it helps you interpolate between two 2645 01:21:06,360 --> 01:21:08,699 values I made a quick video showcasing a 2646 01:21:08,699 --> 01:21:10,380 bunch of uses for it you can alert 2647 01:21:10,380 --> 01:21:12,420 floats Vector 3s quaternions or just 2648 01:21:12,420 --> 01:21:14,100 about anything it's really perfect for 2649 01:21:14,100 --> 01:21:15,840 making some smooth movement or smooth 2650 01:21:15,840 --> 01:21:18,060 rotation so for that we can access the 2651 01:21:18,060 --> 01:21:20,400 function inside the vector 3 class so we 2652 01:21:20,400 --> 01:21:22,620 can find an alert then here we actually 2653 01:21:22,620 --> 01:21:26,100 have two options we've got learn this 2654 01:21:26,100 --> 01:21:28,440 one interpolates and we've got slurp 2655 01:21:28,440 --> 01:21:30,179 this one interpolates but with a 2656 01:21:30,179 --> 01:21:31,800 spherical interpolation basically if 2657 01:21:31,800 --> 01:21:33,360 you're dealing with rotations like what 2658 01:21:33,360 --> 01:21:34,920 we have here then we want to be using 2659 01:21:34,920 --> 01:21:36,480 slurp whereas if you're dealing with 2660 01:21:36,480 --> 01:21:38,340 just positions and you want to use so 2661 01:21:38,340 --> 01:21:41,100 here let's use slurp this one as you can 2662 01:21:41,100 --> 01:21:43,679 see takes an a a b and a t like I said 2663 01:21:43,679 --> 01:21:45,600 this interpolates between A and B based 2664 01:21:45,600 --> 01:21:48,300 on T so for example if T is zero then it 2665 01:21:48,300 --> 01:21:50,580 won't return the value a if T is one 2666 01:21:50,580 --> 01:21:52,860 then it won't return to Value B if C is 2667 01:21:52,860 --> 01:21:54,719 0.5 then it won't return the point in 2668 01:21:54,719 --> 01:21:56,520 between A and B if you want to learn 2669 01:21:56,520 --> 01:21:58,080 some more about interpolation and the 2670 01:21:58,080 --> 01:21:59,699 math behind this then I highly recommend 2671 01:21:59,699 --> 01:22:01,739 you look at my video on splines splines 2672 01:22:01,739 --> 01:22:03,179 are basically just a whole bunch of 2673 01:22:03,179 --> 01:22:05,040 merps put together so anyways over here 2674 01:22:05,040 --> 01:22:06,239 we can add some smoothing to our 2675 01:22:06,239 --> 01:22:07,820 Rotation by just using the current 2676 01:22:07,820 --> 01:22:10,679 transform.ford as our a 2677 01:22:10,679 --> 01:22:12,780 then for the B this one is our Target so 2678 01:22:12,780 --> 01:22:15,000 let's use the move there and finally 14 2679 01:22:15,000 --> 01:22:17,520 let's use time dot Delta time meaning 2680 01:22:17,520 --> 01:22:19,199 that with this over time the character 2681 01:22:19,199 --> 01:22:21,179 won't rotate towards our Target movement 2682 01:22:21,179 --> 01:22:23,100 Direction so just with this let's test 2683 01:22:23,100 --> 01:22:25,080 so here if I move to the right and you 2684 01:22:25,080 --> 01:22:26,400 have a look at that it is indeed 2685 01:22:26,400 --> 01:22:28,739 rotating it's way too slow but yep it is 2686 01:22:28,739 --> 01:22:30,420 rotating smoothly all right so let's 2687 01:22:30,420 --> 01:22:32,520 just add a bit more speed so over here 2688 01:22:32,520 --> 01:22:34,500 let's just find a float for the rotate 2689 01:22:34,500 --> 01:22:37,320 spin let's put it at some like 10f then 2690 01:22:37,320 --> 01:22:39,000 we just multiply it to times that down 2691 01:22:39,000 --> 01:22:40,860 time multiplied by our speed let's see 2692 01:22:40,860 --> 01:22:42,659 and move any up there you go look at 2693 01:22:42,659 --> 01:22:45,420 that much much better okay great so as 2694 01:22:45,420 --> 01:22:47,280 you can see everything works as I move 2695 01:22:47,280 --> 01:22:48,900 the character does rotate to face the 2696 01:22:48,900 --> 01:22:50,760 move Direction all right great so here 2697 01:22:50,760 --> 01:22:52,500 we have our character with a nice visual 2698 01:22:52,500 --> 01:22:54,300 all rotating to face the move Direction 2699 01:22:54,300 --> 01:22:56,460 now next step is we want to add some 2700 01:22:56,460 --> 01:22:58,440 nice animation so let's do that in the 2701 01:22:58,440 --> 01:23:00,179 next lecture 2702 01:23:00,179 --> 01:23:02,159 hello and welcome I'm your code monkey 2703 01:23:02,159 --> 01:23:04,199 in this lecture we're going to add some 2704 01:23:04,199 --> 01:23:06,360 animations to our player character now I 2705 01:23:06,360 --> 01:23:07,860 have already included some pre-made 2706 01:23:07,860 --> 01:23:09,900 animations with a pre-made animator over 2707 01:23:09,900 --> 01:23:11,699 here inside the Asus folder but let's 2708 01:23:11,699 --> 01:23:13,500 first do it from scratch so you'll learn 2709 01:23:13,500 --> 01:23:15,179 how to do it first to animate we're 2710 01:23:15,179 --> 01:23:17,100 going to need the animator component if 2711 01:23:17,100 --> 01:23:18,780 we go inside the player visual game 2712 01:23:18,780 --> 01:23:20,460 object once again remember all the 2713 01:23:20,460 --> 01:23:22,320 visuals go on the visual game object so 2714 01:23:22,320 --> 01:23:24,000 for adding the animator component we 2715 01:23:24,000 --> 01:23:25,560 want it on the visual and not on the 2716 01:23:25,560 --> 01:23:27,360 logic component so anyways over here as 2717 01:23:27,360 --> 01:23:29,280 you can see by default I already attach 2718 01:23:29,280 --> 01:23:31,560 it with the assets included but let's do 2719 01:23:31,560 --> 01:23:33,300 it from scratch so let's remove this by 2720 01:23:33,300 --> 01:23:35,159 default now let's add a new component 2721 01:23:35,159 --> 01:23:37,800 let's go on an animator also one very 2722 01:23:37,800 --> 01:23:39,659 very important thing here it's the 2723 01:23:39,659 --> 01:23:41,880 animator component not the animation 2724 01:23:41,880 --> 01:23:44,040 component these QR can only difference 2725 01:23:44,040 --> 01:23:46,320 the animation component this one is 2726 01:23:46,320 --> 01:23:48,120 actually related to unity's Legacy 2727 01:23:48,120 --> 01:23:49,980 animation system from a very long time 2728 01:23:49,980 --> 01:23:51,719 ago it's only here pretty much for a 2729 01:23:51,719 --> 01:23:53,340 backwards compatibility and for super 2730 01:23:53,340 --> 01:23:55,080 simple use cases so most of the time 2731 01:23:55,080 --> 01:23:56,699 make sure you're using the anime tour 2732 01:23:56,699 --> 01:23:58,860 component okay so to drive this animator 2733 01:23:58,860 --> 01:24:01,320 component we need an NM troller let's go 2734 01:24:01,320 --> 01:24:02,880 into our project files and let's create 2735 01:24:02,880 --> 01:24:04,679 and create a brand new animated control 2736 01:24:04,679 --> 01:24:07,560 let's call this my player animator then 2737 01:24:07,560 --> 01:24:09,239 let's select the player Visual and just 2738 01:24:09,239 --> 01:24:11,040 drag the controller on there okay again 2739 01:24:11,040 --> 01:24:12,840 if you have issues then you cannot drag 2740 01:24:12,840 --> 01:24:14,699 the animator onto the film make sure 2741 01:24:14,699 --> 01:24:16,560 you're using the animator and not the 2742 01:24:16,560 --> 01:24:18,300 animation component okay so with this we 2743 01:24:18,300 --> 01:24:20,040 have assigned our animator controller 2744 01:24:20,040 --> 01:24:22,080 now let's double click on it to open the 2745 01:24:22,080 --> 01:24:23,699 animated window and if you don't see it 2746 01:24:23,699 --> 01:24:25,380 then go into window then go into 2747 01:24:25,380 --> 01:24:27,000 animation and open up the animator 2748 01:24:27,000 --> 01:24:28,739 window and also if you still don't see 2749 01:24:28,739 --> 01:24:30,420 anything that maybe you might have some 2750 01:24:30,420 --> 01:24:32,159 issues with your layout if that's the 2751 01:24:32,159 --> 01:24:33,780 case then go on to the top right corner 2752 01:24:33,780 --> 01:24:35,520 layout and go back into the default and 2753 01:24:35,520 --> 01:24:36,960 then back into your own layout and 2754 01:24:36,960 --> 01:24:38,280 finally if you still don't see anything 2755 01:24:38,280 --> 01:24:40,140 on this window if you don't see defontes 2756 01:24:40,140 --> 01:24:42,480 make sure you have the object selected 2757 01:24:42,480 --> 01:24:43,980 in the hierarchy so with that you should 2758 01:24:43,980 --> 01:24:45,540 be able to see these states so this is 2759 01:24:45,540 --> 01:24:47,340 our animator controller now I have a 2760 01:24:47,340 --> 01:24:49,080 really detailed overview of the animator 2761 01:24:49,080 --> 01:24:50,940 and the animation windows in my ultimate 2762 01:24:50,940 --> 01:24:52,500 unity overview course so you can go 2763 01:24:52,500 --> 01:24:54,000 watch those lectures for some really 2764 01:24:54,000 --> 01:24:55,679 in-depth explanations about everything 2765 01:24:55,679 --> 01:24:57,780 this does basically the animator is a 2766 01:24:57,780 --> 01:24:59,640 state machine so you have various States 2767 01:24:59,640 --> 01:25:01,380 and you can create transitions between 2768 01:25:01,380 --> 01:25:03,360 each state by default you have these 2769 01:25:03,360 --> 01:25:05,040 three special States there's the entry 2770 01:25:05,040 --> 01:25:07,140 State exit and any state these are used 2771 01:25:07,140 --> 01:25:08,520 for making transitions but we don't 2772 01:25:08,520 --> 01:25:09,900 really need to worry about them just for 2773 01:25:09,900 --> 01:25:11,940 now first let's just make a basic new 2774 01:25:11,940 --> 01:25:13,739 animation and for that the easy way to 2775 01:25:13,739 --> 01:25:15,360 do it is to open up the animation window 2776 01:25:15,360 --> 01:25:17,699 so let's go up top into window go into 2777 01:25:17,699 --> 01:25:19,380 animation and open up the animation 2778 01:25:19,380 --> 01:25:21,420 window so here it is again that's a 2779 01:25:21,420 --> 01:25:23,400 different window that's animation not 2780 01:25:23,400 --> 01:25:25,199 anywhere and for me for this window I 2781 01:25:25,199 --> 01:25:26,760 like to dock it down here so there's a 2782 01:25:26,760 --> 01:25:28,140 nice timeline so I think this is good 2783 01:25:28,140 --> 01:25:30,239 okay and now if we select the object in 2784 01:25:30,239 --> 01:25:32,159 the hierarchy that has our animator then 2785 01:25:32,159 --> 01:25:33,659 we can see the text here so to begin 2786 01:25:33,659 --> 01:25:35,280 animating we've got a nice button to 2787 01:25:35,280 --> 01:25:37,020 create an animation so let's go ahead 2788 01:25:37,020 --> 01:25:38,760 and click on this and now let's give it 2789 01:25:38,760 --> 01:25:40,560 a name for now let's first make the 2790 01:25:40,560 --> 01:25:42,300 iPhone animation so let's just call this 2791 01:25:42,300 --> 01:25:43,980 Idol and name just like that we have 2792 01:25:43,980 --> 01:25:45,840 created an animation you can see the 2793 01:25:45,840 --> 01:25:47,520 animation window down here has changed 2794 01:25:47,520 --> 01:25:49,800 we now see a nice timeline showing the 2795 01:25:49,800 --> 01:25:51,780 time and also on the animated controller 2796 01:25:51,780 --> 01:25:53,580 you can see the new animation was added 2797 01:25:53,580 --> 01:25:55,739 as a brand new state so a new state was 2798 01:25:55,739 --> 01:25:57,840 created and if you click to select it on 2799 01:25:57,840 --> 01:25:59,280 the right side in the inspector you see 2800 01:25:59,280 --> 01:26:00,719 the motion so the actual animation 2801 01:26:00,719 --> 01:26:02,460 selected and you can also see that 2802 01:26:02,460 --> 01:26:04,139 there's an arrow pointing from the entry 2803 01:26:04,139 --> 01:26:05,699 onto the unknown state so that means 2804 01:26:05,699 --> 01:26:07,020 this one is going to be the default 2805 01:26:07,020 --> 01:26:08,699 State when the animated controller 2806 01:26:08,699 --> 01:26:10,440 starts it won't start playing right on 2807 01:26:10,440 --> 01:26:12,120 this state let me just point out one 2808 01:26:12,120 --> 01:26:14,219 more thing related to animations so on 2809 01:26:14,219 --> 01:26:16,020 the project window we can see yep here 2810 01:26:16,020 --> 01:26:17,460 is our animation that we just created 2811 01:26:17,460 --> 01:26:19,320 and you can see the inspector unlocks 2812 01:26:19,320 --> 01:26:21,000 just like this now if your inspector 2813 01:26:21,000 --> 01:26:22,500 looks differently that might be because 2814 01:26:22,500 --> 01:26:24,480 you accidentally created the Legacy 2815 01:26:24,480 --> 01:26:26,280 animation that has to do with the 2816 01:26:26,280 --> 01:26:27,780 previous animation system that I talked 2817 01:26:27,780 --> 01:26:29,400 about the one that is Legacy that should 2818 01:26:29,400 --> 01:26:31,440 really no longer be used so if you see a 2819 01:26:31,440 --> 01:26:33,060 different inspector then a quick way to 2820 01:26:33,060 --> 01:26:35,040 fix it is to click on these three dots 2821 01:26:35,040 --> 01:26:36,780 on the inspector these three dots then 2822 01:26:36,780 --> 01:26:38,340 you change the inspector into debug 2823 01:26:38,340 --> 01:26:40,260 inspector and over here you see a toggle 2824 01:26:40,260 --> 01:26:42,060 on foreign legacy so for the animations 2825 01:26:42,060 --> 01:26:43,920 that we want to use right now we do not 2826 01:26:43,920 --> 01:26:45,600 want to be using Legacy animations so 2827 01:26:45,600 --> 01:26:47,340 make sure this one is untoggled if in 2828 01:26:47,340 --> 01:26:49,199 our case is toggle just untoggle it then 2829 01:26:49,199 --> 01:26:51,300 go back into the normal inspector and 2830 01:26:51,300 --> 01:26:52,920 now yep it shouldn't look just like this 2831 01:26:52,920 --> 01:26:54,960 okay so we have our animation and now 2832 01:26:54,960 --> 01:26:56,820 it's on our animator controller now it's 2833 01:26:56,820 --> 01:26:59,040 actually make an animation so let's 2834 01:26:59,040 --> 01:27:00,900 select the animation window though and 2835 01:27:00,900 --> 01:27:02,100 again let's make sure to select the 2836 01:27:02,100 --> 01:27:03,300 objects and let's select the player 2837 01:27:03,300 --> 01:27:05,100 visual game object so here on the 2838 01:27:05,100 --> 01:27:06,600 animation window we see this nice little 2839 01:27:06,600 --> 01:27:08,760 red button this one enables or disables 2840 01:27:08,760 --> 01:27:10,679 recording so if you click on it you can 2841 01:27:10,679 --> 01:27:12,540 see yep the timeline is now red meaning 2842 01:27:12,540 --> 01:27:14,460 that we are now recording and now we can 2843 01:27:14,460 --> 01:27:16,380 do anything to any channel objects and 2844 01:27:16,380 --> 01:27:18,300 it won't record any changes we make now 2845 01:27:18,300 --> 01:27:19,860 note what I said that's very important 2846 01:27:19,860 --> 01:27:21,780 it needs to be challenged objects if you 2847 01:27:21,780 --> 01:27:23,100 select for example the apparent game 2848 01:27:23,100 --> 01:27:24,420 object then all of a sudden it stops 2849 01:27:24,420 --> 01:27:26,460 recording so you can only animate child 2850 01:27:26,460 --> 01:27:28,679 objects so let's select the player 2851 01:27:28,679 --> 01:27:30,540 visual let's enable recording then let's 2852 01:27:30,540 --> 01:27:32,159 expand the player visual let's make sure 2853 01:27:32,159 --> 01:27:33,960 that our timeline is on zero so drag it 2854 01:27:33,960 --> 01:27:35,219 all the way to the left and now for 2855 01:27:35,219 --> 01:27:37,139 example let's grab the head object and 2856 01:27:37,139 --> 01:27:39,000 let's move it just a tiny tiny bit 2857 01:27:39,000 --> 01:27:41,159 basically just move it enough in order 2858 01:27:41,159 --> 01:27:42,659 to make sure that the position over here 2859 01:27:42,659 --> 01:27:44,580 is in red meaning that we have recorded 2860 01:27:44,580 --> 01:27:46,679 a keyframe then let's drag the timeline 2861 01:27:46,679 --> 01:27:48,780 by a little bit let's go over here to 2862 01:27:48,780 --> 01:27:50,820 frame 30. this one is actually going to 2863 01:27:50,820 --> 01:27:52,500 be half a second and soon to be that 2864 01:27:52,500 --> 01:27:54,120 because over here on the samples this is 2865 01:27:54,120 --> 01:27:55,860 the frame rate for the animation so at 2866 01:27:55,860 --> 01:27:57,780 6C that means we have 60 frames this 2867 01:27:57,780 --> 01:28:00,000 makes one second so 30 frames would be 2868 01:28:00,000 --> 01:28:02,219 half a second you can also zoom out by 2869 01:28:02,219 --> 01:28:03,840 scrolling over here or dragging the 2870 01:28:03,840 --> 01:28:05,400 handles down here so let's go into 30 2871 01:28:05,400 --> 01:28:07,199 half a second and on this one let's move 2872 01:28:07,199 --> 01:28:08,639 the head by a little bit something like 2873 01:28:08,639 --> 01:28:10,080 this as you can see down there we can 2874 01:28:10,080 --> 01:28:11,760 note that I record the new keyframe and 2875 01:28:11,760 --> 01:28:13,440 now if we hit on the play button we can 2876 01:28:13,440 --> 01:28:15,000 preview the animation any upon like that 2877 01:28:15,000 --> 01:28:16,800 that does do exactly that so it starts 2878 01:28:16,800 --> 01:28:18,420 off down and then moves up okay so 2879 01:28:18,420 --> 01:28:20,219 that's great but we don't want to snap 2880 01:28:20,219 --> 01:28:21,840 back so let's actually add another 2881 01:28:21,840 --> 01:28:23,880 keyframe right at the end so let's stop 2882 01:28:23,880 --> 01:28:25,679 playing the animation and to make sure 2883 01:28:25,679 --> 01:28:27,780 we have a perfect Loop let's just click 2884 01:28:27,780 --> 01:28:29,760 to select the keyframe let's press Ctrl 2885 01:28:29,760 --> 01:28:32,100 C then let's go down into the one second 2886 01:28:32,100 --> 01:28:34,199 Mark let's press Ctrl V and there you go 2887 01:28:34,199 --> 01:28:36,000 there's the exact same keyframe so now 2888 01:28:36,000 --> 01:28:37,980 if we hit on play the other go we have 2889 01:28:37,980 --> 01:28:39,780 our nice seamless Loop so the head goes 2890 01:28:39,780 --> 01:28:41,699 up and down and repeats forever alright 2891 01:28:41,699 --> 01:28:44,159 awesome okay so that's great now let's 2892 01:28:44,159 --> 01:28:46,080 also do one thing let's also record a 2893 01:28:46,080 --> 01:28:48,540 keyframe on the body however we don't 2894 01:28:48,540 --> 01:28:50,460 want it to move at least not in this 2895 01:28:50,460 --> 01:28:52,620 idle animation we just want to have a 2896 01:28:52,620 --> 01:28:54,659 static keyframe so let's select the body 2897 01:28:54,659 --> 01:28:56,699 and let me actually move it a bit to the 2898 01:28:56,699 --> 01:28:58,260 side just to make sure to record and now 2899 01:28:58,260 --> 01:28:59,940 manually we can modify things over here 2900 01:28:59,940 --> 01:29:02,280 here to modify the actual keyframe data 2901 01:29:02,280 --> 01:29:03,719 so on this one I don't want it to move 2902 01:29:03,719 --> 01:29:05,340 so let's put it all the way back at zero 2903 01:29:05,340 --> 01:29:07,320 just make sure we have a nice keyframe 2904 01:29:07,320 --> 01:29:08,880 recording now the reason why we are 2905 01:29:08,880 --> 01:29:10,500 recording the body position even without 2906 01:29:10,500 --> 01:29:12,420 moving it is because the wonk animation 2907 01:29:12,420 --> 01:29:14,400 will indeed move the body but when we 2908 01:29:14,400 --> 01:29:16,380 get back to idle we want the body to go 2909 01:29:16,380 --> 01:29:18,239 back to this exact position so that is 2910 01:29:18,239 --> 01:29:19,860 why we need the keyframe here okay so 2911 01:29:19,860 --> 01:29:21,420 that's done so we can stop recording so 2912 01:29:21,420 --> 01:29:23,100 let's click on the red button again okay 2913 01:29:23,100 --> 01:29:25,260 great by the way one more note to make 2914 01:29:25,260 --> 01:29:27,000 sure that the animation Loops go into 2915 01:29:27,000 --> 01:29:29,100 the project window and over here select 2916 01:29:29,100 --> 01:29:30,600 the animation and make sure on Loop time 2917 01:29:30,600 --> 01:29:32,400 is enabled it should be there by default 2918 01:29:32,400 --> 01:29:34,560 okay so the animation is set up and if 2919 01:29:34,560 --> 01:29:35,940 we unlock in the animator it's already 2920 01:29:35,940 --> 01:29:38,280 the default set so if we hit point we 2921 01:29:38,280 --> 01:29:39,719 should be able to see the anal animation 2922 01:29:39,719 --> 01:29:41,639 playing non-stop so let's hit play and 2923 01:29:41,639 --> 01:29:43,139 if there it is the anal animation with 2924 01:29:43,139 --> 01:29:44,760 the head moving up and down everything 2925 01:29:44,760 --> 01:29:47,340 works perfectly alright awesome okay so 2926 01:29:47,340 --> 01:29:49,560 next up let's make a wonk animation now 2927 01:29:49,560 --> 01:29:51,360 for me when making an animation that is 2928 01:29:51,360 --> 01:29:52,860 based on another one I like to actually 2929 01:29:52,860 --> 01:29:54,480 duplicate it instead of starting from 2930 01:29:54,480 --> 01:29:55,679 scratch so over here on the project 2931 01:29:55,679 --> 01:29:57,420 window let's select the anal animation 2932 01:29:57,420 --> 01:29:59,639 and let's duplicate it so Ctrl D let's 2933 01:29:59,639 --> 01:30:01,380 learn name this one to the wonk 2934 01:30:01,380 --> 01:30:03,360 animation and now if we select the 2935 01:30:03,360 --> 01:30:05,159 player Visual and then we go into the 2936 01:30:05,159 --> 01:30:06,960 animation window over here we see a nice 2937 01:30:06,960 --> 01:30:08,639 little drop down menu for all of the 2938 01:30:08,639 --> 01:30:10,679 animations except right now we don't see 2939 01:30:10,679 --> 01:30:12,420 the wonk animation we only see the idle 2940 01:30:12,420 --> 01:30:14,340 animation that is because this menu only 2941 01:30:14,340 --> 01:30:16,020 shows animations that are attached to 2942 01:30:16,020 --> 01:30:18,060 the animator so first we need to add the 2943 01:30:18,060 --> 01:30:19,800 animation onto the animator component 2944 01:30:19,800 --> 01:30:21,239 and how we do that is actually super 2945 01:30:21,239 --> 01:30:22,739 simple let's just open up the project 2946 01:30:22,739 --> 01:30:24,360 window and just write the wonk animation 2947 01:30:24,360 --> 01:30:26,100 and drop it here that's it so with this 2948 01:30:26,100 --> 01:30:27,719 we have attached a new state to the 2949 01:30:27,719 --> 01:30:29,580 animated controller and now if once 2950 01:30:29,580 --> 01:30:30,960 again we select the object in the 2951 01:30:30,960 --> 01:30:32,580 hierarchy go into the animation click 2952 01:30:32,580 --> 01:30:34,380 the drop down menu any up now we do see 2953 01:30:34,380 --> 01:30:36,000 the wonk animation so let's click to 2954 01:30:36,000 --> 01:30:37,500 select this one and now for this one 2955 01:30:37,500 --> 01:30:38,820 let's make the animation so let's look 2956 01:30:38,820 --> 01:30:40,679 in scene View and make it bounce just up 2957 01:30:40,679 --> 01:30:42,239 and down so I'm going to enable record 2958 01:30:42,239 --> 01:30:44,820 go back here and for the body this one 2959 01:30:44,820 --> 01:30:46,199 already has a keyframe so let's go up 2960 01:30:46,199 --> 01:30:48,540 here move it a little bit and then copy 2961 01:30:48,540 --> 01:30:50,040 the keyframe put it the same one at the 2962 01:30:50,040 --> 01:30:51,719 end something like this so there you go 2963 01:30:51,719 --> 01:30:53,040 just goes up and down once actually 2964 01:30:53,040 --> 01:30:54,659 input it offsets it looks a bit better 2965 01:30:54,659 --> 01:30:56,520 so something like this by the way in a 2966 01:30:56,520 --> 01:30:57,600 bit we're going to replace these 2967 01:30:57,600 --> 01:30:58,800 animations with the ones that I made 2968 01:30:58,800 --> 01:31:00,480 previously so don't worry about making 2969 01:31:00,480 --> 01:31:02,100 the animations perfect unless you want 2970 01:31:02,100 --> 01:31:03,420 to do that okay so there you go that's 2971 01:31:03,420 --> 01:31:04,679 the animation although for walking 2972 01:31:04,679 --> 01:31:06,600 should be much faster so here's a quick 2973 01:31:06,600 --> 01:31:08,580 animated tip this top bar here lets you 2974 01:31:08,580 --> 01:31:10,260 select all of the keyframes within a 2975 01:31:10,260 --> 01:31:12,000 certain time so if I click the select 2976 01:31:12,000 --> 01:31:13,800 note how it selects both those keyframes 2977 01:31:13,800 --> 01:31:15,659 and also if you click and drag once on 2978 01:31:15,659 --> 01:31:17,100 top of here you can select multiple 2979 01:31:17,100 --> 01:31:18,719 keyframes so for example to select 2980 01:31:18,719 --> 01:31:20,460 everything just click and drag to select 2981 01:31:20,460 --> 01:31:22,020 all of them and now you see these nice 2982 01:31:22,020 --> 01:31:24,000 little vertical bars so if you click on 2983 01:31:24,000 --> 01:31:25,440 those and then you drag them you can 2984 01:31:25,440 --> 01:31:27,060 basically modify the time of all the 2985 01:31:27,060 --> 01:31:29,100 animations and everything matches up so 2986 01:31:29,100 --> 01:31:30,360 for example let's make this one super 2987 01:31:30,360 --> 01:31:32,460 fast let's put it just 20 frames there 2988 01:31:32,460 --> 01:31:33,659 you go now it's a much faster walking 2989 01:31:33,659 --> 01:31:35,639 Mission okay great let's click on the 2990 01:31:35,639 --> 01:31:37,139 right to stop recording all right and 2991 01:31:37,139 --> 01:31:39,000 back in the animator so over here we 2992 01:31:39,000 --> 01:31:40,679 have both animations and now what we 2993 01:31:40,679 --> 01:31:42,480 need is to make a transition going from 2994 01:31:42,480 --> 01:31:44,639 idle into wonk otherwise the wonk 2995 01:31:44,639 --> 01:31:46,560 animation will never play so how we make 2996 01:31:46,560 --> 01:31:48,360 a transition is also super simple let's 2997 01:31:48,360 --> 01:31:50,219 right click on the I don't say let's 2998 01:31:50,219 --> 01:31:52,620 make a transition then now we have a 2999 01:31:52,620 --> 01:31:54,179 nice little arrow under the mouse and 3000 01:31:54,179 --> 01:31:55,739 now if we go into the wonk and click on 3001 01:31:55,739 --> 01:31:57,060 it there you go we have a nice 3002 01:31:57,060 --> 01:31:58,500 transition now we can click on the 3003 01:31:58,500 --> 01:32:00,239 transition itself to select it and over 3004 01:32:00,239 --> 01:32:01,739 here in the inspector we see a bunch of 3005 01:32:01,739 --> 01:32:03,480 transition options so let's expand the 3006 01:32:03,480 --> 01:32:05,100 settings yep there you go everything now 3007 01:32:05,100 --> 01:32:06,540 like I said I covered all of these 3008 01:32:06,540 --> 01:32:08,460 options in a lot of detail in my 3009 01:32:08,460 --> 01:32:10,440 ultimate TNT of recourse so if you want 3010 01:32:10,440 --> 01:32:12,120 to learn more go watch that here on 3011 01:32:12,120 --> 01:32:13,560 let's just learn the basics for how to 3012 01:32:13,560 --> 01:32:14,940 achieve our goal and making a simple 3013 01:32:14,940 --> 01:32:16,860 player animator the important one is 3014 01:32:16,860 --> 01:32:18,900 over here the exit time basically if 3015 01:32:18,900 --> 01:32:20,400 this one is toggled then this transition 3016 01:32:20,400 --> 01:32:21,960 won't be triggered automatically meaning 3017 01:32:21,960 --> 01:32:23,639 it won't play the outline Mission and 3018 01:32:23,639 --> 01:32:25,139 immediately transition into the walk 3019 01:32:25,139 --> 01:32:26,880 animation so for example if we hit play 3020 01:32:26,880 --> 01:32:28,440 and look at it quickly if there go 3021 01:32:28,440 --> 01:32:30,000 there's the idle any of transitions into 3022 01:32:30,000 --> 01:32:31,920 wonk and now it stays there forever okay 3023 01:32:31,920 --> 01:32:33,480 so that's good but not exactly what we 3024 01:32:33,480 --> 01:32:35,639 want we want the Wonka mission to only 3025 01:32:35,639 --> 01:32:37,199 play When the character is walking and 3026 01:32:37,199 --> 01:32:38,940 when it stops we want to go back into 3027 01:32:38,940 --> 01:32:40,800 the idle animation now for that we need 3028 01:32:40,800 --> 01:32:42,960 to use animator parameters so back in 3029 01:32:42,960 --> 01:32:45,000 our animator on the top left corner we 3030 01:32:45,000 --> 01:32:46,320 see something called layers we don't 3031 01:32:46,320 --> 01:32:47,580 need to worry about that for now and 3032 01:32:47,580 --> 01:32:49,679 then next week we see parameters then we 3033 01:32:49,679 --> 01:32:51,300 can click on the plus button or to 3034 01:32:51,300 --> 01:32:52,620 create the brand new parameter and you 3035 01:32:52,620 --> 01:32:54,060 can see all the various types that we 3036 01:32:54,060 --> 01:32:55,620 can create now for wonky we want 3037 01:32:55,620 --> 01:32:57,120 something that we can set to either true 3038 01:32:57,120 --> 01:32:59,280 or false so let's go with a nice bullion 3039 01:32:59,280 --> 01:33:01,679 and for name let's go with is wonky 3040 01:33:01,679 --> 01:33:03,300 again pay very close attention to the 3041 01:33:03,300 --> 01:33:05,040 capitalization this is extremely 3042 01:33:05,040 --> 01:33:07,139 important just like code is walking is 3043 01:33:07,139 --> 01:33:09,060 different from is walking so make sure 3044 01:33:09,060 --> 01:33:11,040 the capitalization is perfect okay so 3045 01:33:11,040 --> 01:33:12,719 with that we have our nice parameter now 3046 01:33:12,719 --> 01:33:14,040 let's click on transition going from 3047 01:33:14,040 --> 01:33:16,500 idling to wonk and now let's untick exit 3048 01:33:16,500 --> 01:33:18,360 time we don't want this transition to 3049 01:33:18,360 --> 01:33:19,980 trigger automatically and as soon as we 3050 01:33:19,980 --> 01:33:21,480 do we see this nice little warning 3051 01:33:21,480 --> 01:33:22,800 basically it's telling us that this 3052 01:33:22,800 --> 01:33:25,080 transition will never happen so over 3053 01:33:25,080 --> 01:33:27,120 here we have the nice conditions if we 3054 01:33:27,120 --> 01:33:28,679 click on the plus icon we can add some 3055 01:33:28,679 --> 01:33:30,420 conditions and for this one we want this 3056 01:33:30,420 --> 01:33:32,219 transition to happen from idling to walk 3057 01:33:32,219 --> 01:33:34,380 when the parameter is walking is set to 3058 01:33:34,380 --> 01:33:36,120 true so that's it this is our transition 3059 01:33:36,120 --> 01:33:38,040 now let you see the reverse so let's 3060 01:33:38,040 --> 01:33:39,659 right click on the wall make Transition 3061 01:33:39,659 --> 01:33:41,820 go back into Idol let's click the select 3062 01:33:41,820 --> 01:33:44,040 transition get rid of the exit time and 3063 01:33:44,040 --> 01:33:45,719 conditions when is Walking is set to 3064 01:33:45,719 --> 01:33:48,120 false okay so just like this our basic 3065 01:33:48,120 --> 01:33:50,040 animation logic should be working so 3066 01:33:50,040 --> 01:33:51,719 let's test so here we are and the 3067 01:33:51,719 --> 01:33:53,159 character is playing the online Mission 3068 01:33:53,159 --> 01:33:54,600 by the way you can look at the end 3069 01:33:54,600 --> 01:33:56,400 better while the game is running so let 3070 01:33:56,400 --> 01:33:58,199 me just drag the animator window just 3071 01:33:58,199 --> 01:34:00,000 drag it and put it on the side of the 3072 01:34:00,000 --> 01:34:01,800 game view so we can see both at the same 3073 01:34:01,800 --> 01:34:04,020 time okay great and right now note how 3074 01:34:04,020 --> 01:34:05,520 it's not updating so there's nothing 3075 01:34:05,520 --> 01:34:06,780 moving over here on the animated 3076 01:34:06,780 --> 01:34:08,219 component that is because like I said 3077 01:34:08,219 --> 01:34:09,900 you must select the object so on the 3078 01:34:09,900 --> 01:34:11,159 hierarchy make sure you select the 3079 01:34:11,159 --> 01:34:12,480 player Visual and you have there go now 3080 01:34:12,480 --> 01:34:14,159 you do see that updating so make sure 3081 01:34:14,159 --> 01:34:15,840 the object is selected in the hierarchy 3082 01:34:15,840 --> 01:34:17,280 and over here we see a nice little 3083 01:34:17,280 --> 01:34:19,020 progress bar showing the Adeline Mission 3084 01:34:19,020 --> 01:34:20,820 constantly playing in looping okay great 3085 01:34:20,820 --> 01:34:22,800 another important thing is over here the 3086 01:34:22,800 --> 01:34:24,540 parameters you can manually change the 3087 01:34:24,540 --> 01:34:25,860 state of these while the game is running 3088 01:34:25,860 --> 01:34:27,780 so for example if I click it's going to 3089 01:34:27,780 --> 01:34:29,460 trigger the is walking parameter which 3090 01:34:29,460 --> 01:34:30,840 should trigger this transition and 3091 01:34:30,840 --> 01:34:32,760 should go into one so if I click and if 3092 01:34:32,760 --> 01:34:34,380 there go transitions into the wonk 3093 01:34:34,380 --> 01:34:36,060 animation and now yep it is playing The 3094 01:34:36,060 --> 01:34:37,860 Walking animation and if I click to 3095 01:34:37,860 --> 01:34:39,780 untick it look at over there what 3096 01:34:39,780 --> 01:34:41,400 happens untake and there you go 3097 01:34:41,400 --> 01:34:43,199 transitions back into idle alright 3098 01:34:43,199 --> 01:34:44,760 awesome so as you can see we have 3099 01:34:44,760 --> 01:34:46,500 overall logic working we have the 3100 01:34:46,500 --> 01:34:48,420 animator with both of our states and by 3101 01:34:48,420 --> 01:34:49,920 changing this parameter we can change 3102 01:34:49,920 --> 01:34:51,480 which animation is playing now of course 3103 01:34:51,480 --> 01:34:53,159 the goal is not to trigger this manually 3104 01:34:53,159 --> 01:34:54,900 by clicking on it but rather doing it 3105 01:34:54,900 --> 01:34:56,340 through code but at least for now we 3106 01:34:56,340 --> 01:34:58,020 know that our animator is fully set up 3107 01:34:58,020 --> 01:34:59,580 again if you want more detail on the 3108 01:34:59,580 --> 01:35:01,620 animator and animation windows and 3109 01:35:01,620 --> 01:35:03,179 everything related to animations then 3110 01:35:03,179 --> 01:35:04,800 check out those lectures in my ultimate 3111 01:35:04,800 --> 01:35:06,780 TNT overview course and also later on 3112 01:35:06,780 --> 01:35:08,460 for more advanced use cases I have video 3113 01:35:08,460 --> 01:35:10,199 on the animation rigging package this 3114 01:35:10,199 --> 01:35:11,940 one is for more advanced use cases for 3115 01:35:11,940 --> 01:35:13,679 making Dynamic procedural animations 3116 01:35:13,679 --> 01:35:15,300 it's really fun so definitely check it 3117 01:35:15,300 --> 01:35:16,860 out but only after finishing this course 3118 01:35:16,860 --> 01:35:18,540 that one is a much more advanced duel 3119 01:35:18,540 --> 01:35:20,340 for now let's continue here so we want 3120 01:35:20,340 --> 01:35:21,719 to trigger our parameter but do it 3121 01:35:21,719 --> 01:35:23,460 through code and again here we have yet 3122 01:35:23,460 --> 01:35:25,020 another clean code question technically 3123 01:35:25,020 --> 01:35:26,820 we could add that code directly over 3124 01:35:26,820 --> 01:35:28,739 here on the player script we could just 3125 01:35:28,739 --> 01:35:30,600 grab the animator component and change 3126 01:35:30,600 --> 01:35:32,460 the parameter and in this case for this 3127 01:35:32,460 --> 01:35:33,900 very simple game that would actually not 3128 01:35:33,900 --> 01:35:35,880 necessarily be a very bad approach since 3129 01:35:35,880 --> 01:35:37,500 the game is so simple with so few 3130 01:35:37,500 --> 01:35:39,300 animations but like I said I want to 3131 01:35:39,300 --> 01:35:41,340 teach you proper good practices so let's 3132 01:35:41,340 --> 01:35:43,199 make it properly and actually separate 3133 01:35:43,199 --> 01:35:44,820 the animations from the logic for then 3134 01:35:44,820 --> 01:35:46,380 let's go into our project right click in 3135 01:35:46,380 --> 01:35:48,179 our scripts folder create a new c-sharp 3136 01:35:48,179 --> 01:35:49,679 script let's come with the player 3137 01:35:49,679 --> 01:35:51,780 animator let's select the player visual 3138 01:35:51,780 --> 01:35:53,580 game object and attach the component 3139 01:35:53,580 --> 01:35:55,560 okay so now here first let's grab the 3140 01:35:55,560 --> 01:35:57,719 animator now one approach is like we've 3141 01:35:57,719 --> 01:35:59,219 seen we could just make a serialized 3142 01:35:59,219 --> 01:36:00,719 film and and drag the reference in the 3143 01:36:00,719 --> 01:36:02,340 editor that's one approach or 3144 01:36:02,340 --> 01:36:04,020 alternatively since the animator is 3145 01:36:04,020 --> 01:36:05,820 attached to the same game object as this 3146 01:36:05,820 --> 01:36:07,320 script then we can just do a get 3147 01:36:07,320 --> 01:36:08,760 component both approaches are really 3148 01:36:08,760 --> 01:36:10,679 valid so here let's use get component 3149 01:36:10,679 --> 01:36:12,540 just to see a different approach so we 3150 01:36:12,540 --> 01:36:14,880 just have a field for our animator so 3151 01:36:14,880 --> 01:36:17,100 animator and then we just do a private 3152 01:36:17,100 --> 01:36:19,080 void awake and then awake lets you get 3153 01:36:19,080 --> 01:36:21,780 component of type animator and we set 3154 01:36:21,780 --> 01:36:23,699 our animator variable again like I 3155 01:36:23,699 --> 01:36:25,139 mentioned very important make sure you 3156 01:36:25,139 --> 01:36:27,960 don't mix animator and animation these 3157 01:36:27,960 --> 01:36:29,880 are two different components we want the 3158 01:36:29,880 --> 01:36:31,860 animator okay so with this we have a 3159 01:36:31,860 --> 01:36:33,540 reference to our end meta component and 3160 01:36:33,540 --> 01:36:35,100 now how we modify the parameter is 3161 01:36:35,100 --> 01:36:37,139 actually very simple we just access the 3162 01:36:37,139 --> 01:36:38,880 animator and then we have a bunch of set 3163 01:36:38,880 --> 01:36:40,739 functions you can see we have one for 3164 01:36:40,739 --> 01:36:42,659 each type so we've got a set bone set 3165 01:36:42,659 --> 01:36:44,760 float then down here a set trigger set 3166 01:36:44,760 --> 01:36:46,980 Vector so function to set any parameter 3167 01:36:46,980 --> 01:36:48,719 type now we made the Boolean so let's 3168 01:36:48,719 --> 01:36:50,280 use the set bone and this one as you can 3169 01:36:50,280 --> 01:36:51,719 see takes the name for the animator 3170 01:36:51,719 --> 01:36:53,580 parameter by the way strings are a 3171 01:36:53,580 --> 01:36:55,440 horrible horrible way of identifying 3172 01:36:55,440 --> 01:36:57,179 things but suddenly this system really 3173 01:36:57,179 --> 01:36:58,860 does require strings to identify the 3174 01:36:58,860 --> 01:37:00,360 parameter we want to change change if 3175 01:37:00,360 --> 01:37:02,100 you're wondering why strings are bad for 3176 01:37:02,100 --> 01:37:03,719 identifying things the reason is because 3177 01:37:03,719 --> 01:37:05,520 it's very easy to make a mistake for 3178 01:37:05,520 --> 01:37:07,980 example if you use is walking here then 3179 01:37:07,980 --> 01:37:10,080 this won't work however if you instead 3180 01:37:10,080 --> 01:37:11,520 right is walking then all of a sudden 3181 01:37:11,520 --> 01:37:13,320 does not work if your right is walking 3182 01:37:13,320 --> 01:37:15,360 like this doesn't work like this doesn't 3183 01:37:15,360 --> 01:37:17,460 work and even though it doesn't work it 3184 01:37:17,460 --> 01:37:19,260 will also not throw any compiler errors 3185 01:37:19,260 --> 01:37:20,760 that is because for the compiler a 3186 01:37:20,760 --> 01:37:22,440 string is a string it's always valid but 3187 01:37:22,440 --> 01:37:24,000 then when the code runs this one is 3188 01:37:24,000 --> 01:37:25,320 going to be different than our parameter 3189 01:37:25,320 --> 01:37:26,880 which is named exam like this always 3190 01:37:26,880 --> 01:37:28,920 remember that strings are case sensitive 3191 01:37:28,920 --> 01:37:30,540 so that's one reason why you should 3192 01:37:30,540 --> 01:37:32,219 never use strings to identify things 3193 01:37:32,219 --> 01:37:34,260 it's very very easy to make tons of 3194 01:37:34,260 --> 01:37:36,000 mistakes that are then very difficult to 3195 01:37:36,000 --> 01:37:37,380 find out but like I said in this 3196 01:37:37,380 --> 01:37:39,120 animator system we have to use strings 3197 01:37:39,120 --> 01:37:40,679 there's no other way in order to 3198 01:37:40,679 --> 01:37:42,780 minimize our usage of strings one thing 3199 01:37:42,780 --> 01:37:44,699 we can do is for example let's define a 3200 01:37:44,699 --> 01:37:46,679 constant up here so let's make a private 3201 01:37:46,679 --> 01:37:48,780 make it cons for a constant meaning this 3202 01:37:48,780 --> 01:37:50,219 will never change make enough type 3203 01:37:50,219 --> 01:37:52,980 string and conlet is wonky again refer 3204 01:37:52,980 --> 01:37:54,840 back into the naming wrong section for 3205 01:37:54,840 --> 01:37:57,179 constants we always use uppercase snake 3206 01:37:57,179 --> 01:37:59,100 case so is walking and let's set it with 3207 01:37:59,100 --> 01:38:01,860 is wonky again make sure you don't make 3208 01:38:01,860 --> 01:38:03,360 a mistake here make sure you type it 3209 01:38:03,360 --> 01:38:05,280 exam like you did on the animator then 3210 01:38:05,280 --> 01:38:07,199 down here let's use is one and now if 3211 01:38:07,199 --> 01:38:08,580 you do make a mistake so if we 3212 01:38:08,580 --> 01:38:10,320 accidentally use something different now 3213 01:38:10,320 --> 01:38:12,000 we do get a compound error so at least 3214 01:38:12,000 --> 01:38:13,679 we have a little bit of protection okay 3215 01:38:13,679 --> 01:38:15,060 so this one takes a string for the name 3216 01:38:15,060 --> 01:38:16,860 and then a simple Boolean for the value 3217 01:38:16,860 --> 01:38:18,540 so this is going to be the value that we 3218 01:38:18,540 --> 01:38:20,280 want to set to our parameter now for 3219 01:38:20,280 --> 01:38:22,139 this one we want to set to True when the 3220 01:38:22,139 --> 01:38:23,639 player is walking and false when it's 3221 01:38:23,639 --> 01:38:25,199 not so for that we need to ask the 3222 01:38:25,199 --> 01:38:27,000 player what it's doing so let's go over 3223 01:38:27,000 --> 01:38:29,100 here into our player class and let's 3224 01:38:29,100 --> 01:38:31,199 make a function to return just that so 3225 01:38:31,199 --> 01:38:32,760 let's make it public because we're going 3226 01:38:32,760 --> 01:38:34,500 to access it from another script we're 3227 01:38:34,500 --> 01:38:36,300 going to return a boom and call it is 3228 01:38:36,300 --> 01:38:37,920 wonky now over here we just need to 3229 01:38:37,920 --> 01:38:40,020 return if the player is walking so let's 3230 01:38:40,020 --> 01:38:41,820 make a local field to store that saved 3231 01:38:41,820 --> 01:38:43,800 so over here private bone is walking 3232 01:38:43,800 --> 01:38:46,980 again note the capitalization for films 3233 01:38:46,980 --> 01:38:49,139 we start with camel case whereas for 3234 01:38:49,139 --> 01:38:51,060 functions we have Pascal case so these 3235 01:38:51,060 --> 01:38:52,800 are different okay so basically in order 3236 01:38:52,800 --> 01:38:54,540 to Define if we are working that's very 3237 01:38:54,540 --> 01:38:56,040 simple it's just down here we have the 3238 01:38:56,040 --> 01:38:58,139 movement Direction so we are walking if 3239 01:38:58,139 --> 01:38:59,880 the move direction is different from 3240 01:38:59,880 --> 01:39:02,880 Vector 3.0 which by the way Vector 3.0 3241 01:39:02,880 --> 01:39:04,620 is just a shorthand for writing zero 3242 01:39:04,620 --> 01:39:05,940 zero zero so if the movement direction 3243 01:39:05,940 --> 01:39:07,620 is different from zero then we are 3244 01:39:07,620 --> 01:39:09,179 indeed walking so we Define that we 3245 01:39:09,179 --> 01:39:10,860 update that film on every update and 3246 01:39:10,860 --> 01:39:12,600 then over here we just return it okay 3247 01:39:12,600 --> 01:39:14,340 just like this and now back in our 3248 01:39:14,340 --> 01:39:15,960 player animated component over here 3249 01:39:15,960 --> 01:39:17,580 first we need a reference to the player 3250 01:39:17,580 --> 01:39:19,199 so let's add it here let's add a 3251 01:39:19,199 --> 01:39:22,500 serialized film of type player and we 3252 01:39:22,500 --> 01:39:23,820 need to compound this in order to drag 3253 01:39:23,820 --> 01:39:25,440 the reference so let's just come without 3254 01:39:25,440 --> 01:39:26,639 this line just make sure the code 3255 01:39:26,639 --> 01:39:28,080 compounds now here with the code 3256 01:39:28,080 --> 01:39:29,699 compound let's write the reference of 3257 01:39:29,699 --> 01:39:31,860 our player okay that's it and then over 3258 01:39:31,860 --> 01:39:33,900 here for the animator set is wonking 3259 01:39:33,900 --> 01:39:35,820 let's go into the player and let's ask 3260 01:39:35,820 --> 01:39:37,800 is walking and of course we don't want 3261 01:39:37,800 --> 01:39:39,659 to do this just on awake we want to do 3262 01:39:39,659 --> 01:39:41,940 it on every single frame so let's do a 3263 01:39:41,940 --> 01:39:44,100 private void update and on update let's 3264 01:39:44,100 --> 01:39:46,920 do this alright that's it so this should 3265 01:39:46,920 --> 01:39:48,840 be working let's test so here we are 3266 01:39:48,840 --> 01:39:50,880 starting off as Idle and as I move yep 3267 01:39:50,880 --> 01:39:52,199 there you go it is playing The Walking 3268 01:39:52,199 --> 01:39:54,659 animation and now if I stop and if there 3269 01:39:54,659 --> 01:39:56,520 go back into idle alright Awesome 3270 01:39:56,520 --> 01:39:58,380 everything does work perfectly okay 3271 01:39:58,380 --> 01:40:00,300 great we can can even look at the 3272 01:40:00,300 --> 01:40:02,159 animator to see the state change so here 3273 01:40:02,159 --> 01:40:03,900 with both side aside and with the 3274 01:40:03,900 --> 01:40:05,580 objects selected in the hierarchy right 3275 01:40:05,580 --> 01:40:06,900 now you can see he's walking his phone 3276 01:40:06,900 --> 01:40:08,639 so it's on idle and as I move that one 3277 01:40:08,639 --> 01:40:10,440 stays true that one goes into wonk and 3278 01:40:10,440 --> 01:40:12,179 now if I don't let go if there and go 3279 01:40:12,179 --> 01:40:14,280 back into falls back into idle all right 3280 01:40:14,280 --> 01:40:16,080 awesome so with this everything is 3281 01:40:16,080 --> 01:40:17,580 working perfectly if you're having 3282 01:40:17,580 --> 01:40:19,620 issues make sure you pay attention to 3283 01:40:19,620 --> 01:40:21,960 the capitalization so make sure the name 3284 01:40:21,960 --> 01:40:24,179 you wrote here is exactly the same one 3285 01:40:24,179 --> 01:40:26,460 that you wrote here and it's exactly the 3286 01:40:26,460 --> 01:40:28,020 same that you're using here alright so 3287 01:40:28,020 --> 01:40:29,280 all of our animations are working 3288 01:40:29,280 --> 01:40:31,440 perfectly now if you want you can go 3289 01:40:31,440 --> 01:40:33,360 ahead and make your own animations or 3290 01:40:33,360 --> 01:40:34,920 you can use the ones that I pre-bumped 3291 01:40:34,920 --> 01:40:36,900 so in the included project files inside 3292 01:40:36,900 --> 01:40:38,580 the assets here we've got the animations 3293 01:40:38,580 --> 01:40:40,800 and we've got the player with the idol 3294 01:40:40,800 --> 01:40:42,600 and the wonk animations if we double 3295 01:40:42,600 --> 01:40:43,980 click on this don't look at it you can 3296 01:40:43,980 --> 01:40:46,080 see yep it looks exactly the same so 3297 01:40:46,080 --> 01:40:47,820 there's a parameter called is walking in 3298 01:40:47,820 --> 01:40:49,500 our transition so everything is exactly 3299 01:40:49,500 --> 01:40:51,179 the same just over here let's select the 3300 01:40:51,179 --> 01:40:52,920 employer Visual and on the prefab like 3301 01:40:52,920 --> 01:40:54,480 we saw we already have the animated 3302 01:40:54,480 --> 01:40:56,159 component we just removed that one from 3303 01:40:56,159 --> 01:40:57,960 the prefab in order to build it on from 3304 01:40:57,960 --> 01:40:59,219 scratch but if you want to use my image 3305 01:40:59,219 --> 01:41:01,320 then we can just go ahead remove the 3306 01:41:01,320 --> 01:41:02,880 animator that we added and then right 3307 01:41:02,880 --> 01:41:04,020 click on this one on the remove 3308 01:41:04,020 --> 01:41:05,880 component let's revert back to changes 3309 01:41:05,880 --> 01:41:07,199 and there you go here we have our 3310 01:41:07,199 --> 01:41:09,239 animator with the player controller so 3311 01:41:09,239 --> 01:41:11,280 that's the one in the animations and 3312 01:41:11,280 --> 01:41:13,139 just like this if we had on play and 3313 01:41:13,139 --> 01:41:14,580 actually over here I found an issue 3314 01:41:14,580 --> 01:41:16,080 although in your case there shouldn't be 3315 01:41:16,080 --> 01:41:17,760 any issue because I've updated the 3316 01:41:17,760 --> 01:41:19,380 assets but this is a good time to teach 3317 01:41:19,380 --> 01:41:21,600 you about any issues with animations so 3318 01:41:21,600 --> 01:41:23,040 if you select the animation and you 3319 01:41:23,040 --> 01:41:24,840 select the animation and over here you 3320 01:41:24,840 --> 01:41:26,639 might see some of them in yellow saying 3321 01:41:26,639 --> 01:41:27,900 missing basically the way that 3322 01:41:27,900 --> 01:41:29,760 animations work is based on the actual 3323 01:41:29,760 --> 01:41:31,560 name of the object if it cannot find an 3324 01:41:31,560 --> 01:41:33,120 object with the exact same name then it 3325 01:41:33,120 --> 01:41:34,980 cannot load the same animation so my 3326 01:41:34,980 --> 01:41:36,420 problem is that when I initially made 3327 01:41:36,420 --> 01:41:38,639 the assets package I made this animation 3328 01:41:38,639 --> 01:41:40,800 and the object was previously named face 3329 01:41:40,800 --> 01:41:42,659 and then I renamed it the head so now it 3330 01:41:42,659 --> 01:41:44,520 normally loads so if you ever have 3331 01:41:44,520 --> 01:41:46,080 problems with loading animations just 3332 01:41:46,080 --> 01:41:47,460 make sure the name is perfectly matched 3333 01:41:47,460 --> 01:41:49,139 so in my case I can just click in here 3334 01:41:49,139 --> 01:41:51,000 in order to rename this keyframe on the 3335 01:41:51,000 --> 01:41:52,560 animation and I'm just going to use the 3336 01:41:52,560 --> 01:41:55,020 name that I renamed it so head and just 3337 01:41:55,020 --> 01:41:56,639 like this yep the animation does play 3338 01:41:56,639 --> 01:41:58,260 correctly so it's just a nice quick tip 3339 01:41:58,260 --> 01:41:59,639 if you ever have problems with and 3340 01:41:59,639 --> 01:42:01,380 missions always remember that the stored 3341 01:42:01,380 --> 01:42:02,880 keyframes their own stored based on name 3342 01:42:02,880 --> 01:42:05,280 so if you rename the thing in here or 3343 01:42:05,280 --> 01:42:06,900 over here on the game object if you're 3344 01:42:06,900 --> 01:42:08,340 in a name you're going to have missing 3345 01:42:08,340 --> 01:42:09,900 animations but if you make sure the 3346 01:42:09,900 --> 01:42:11,460 names match and the animation shouldn't 3347 01:42:11,460 --> 01:42:13,020 work perfectly so let's hit on play and 3348 01:42:13,020 --> 01:42:14,520 if there go there's the anal animation 3349 01:42:14,520 --> 01:42:16,739 and if I move yep there's the nice wonk 3350 01:42:16,739 --> 01:42:18,360 animation so everything still works 3351 01:42:18,360 --> 01:42:19,679 perfectly because it's only using the 3352 01:42:19,679 --> 01:42:22,080 exact same parameter alright awesome so 3353 01:42:22,080 --> 01:42:23,760 like I said if you want film free to 3354 01:42:23,760 --> 01:42:25,619 make your own animations or use the ones 3355 01:42:25,619 --> 01:42:27,300 that I've included for me I'm going to 3356 01:42:27,300 --> 01:42:29,280 be using these ones so the ones that we 3357 01:42:29,280 --> 01:42:30,719 made just for learning which I created 3358 01:42:30,719 --> 01:42:32,639 down here so the multiplier animator and 3359 01:42:32,639 --> 01:42:33,719 these animations I'm just going to 3360 01:42:33,719 --> 01:42:35,100 delete these just to keep the project 3361 01:42:35,100 --> 01:42:37,500 clean so just delete and just like that 3362 01:42:37,500 --> 01:42:39,780 okay so now there we have our character 3363 01:42:39,780 --> 01:42:41,760 fully working let's quickly handle our 3364 01:42:41,760 --> 01:42:43,440 camera 3365 01:42:43,440 --> 01:42:45,600 hello and welcome I'm your code monkey 3366 01:42:45,600 --> 01:42:47,639 in this lecture we're going to quickly 3367 01:42:47,639 --> 01:42:49,860 install cinemachine this is a Unity tool 3368 01:42:49,860 --> 01:42:51,420 that makes handling cameras super easy 3369 01:42:51,420 --> 01:42:53,159 our game isn't really going to have a 3370 01:42:53,159 --> 01:42:54,780 moving camera so this part isn't 3371 01:42:54,780 --> 01:42:56,760 strictly necessary but same machine is a 3372 01:42:56,760 --> 01:42:58,260 super useful tool so I definitely want 3373 01:42:58,260 --> 01:42:59,940 you to learn about okay so let's begin 3374 01:42:59,940 --> 01:43:01,800 by installing the package let's go into 3375 01:43:01,800 --> 01:43:03,960 window open up the package manager then 3376 01:43:03,960 --> 01:43:05,580 up top let's make sure we are in the UNT 3377 01:43:05,580 --> 01:43:08,040 registry make sure you're on the all Tab 3378 01:43:08,040 --> 01:43:10,020 and now just scroll down until you find 3379 01:43:10,020 --> 01:43:11,880 yep there it is send machine okay so 3380 01:43:11,880 --> 01:43:14,159 let's go ahead and install this 3381 01:43:14,159 --> 01:43:16,440 all right Sunstone so let's close this 3382 01:43:16,440 --> 01:43:18,420 and now the way that send machine works 3383 01:43:18,420 --> 01:43:19,980 is by creating what is called a send 3384 01:43:19,980 --> 01:43:21,780 machine virtual camera so let's go up 3385 01:43:21,780 --> 01:43:23,760 top into the game object menu then 3386 01:43:23,760 --> 01:43:25,739 scroll down into cinemachine and over 3387 01:43:25,739 --> 01:43:27,360 here you can see that we can create a 3388 01:43:27,360 --> 01:43:29,219 multitude of virtual camera types now 3389 01:43:29,219 --> 01:43:30,719 just by the names you can see how this 3390 01:43:30,719 --> 01:43:32,639 tool is insanely useful for example 3391 01:43:32,639 --> 01:43:34,560 making a free download camera doing that 3392 01:43:34,560 --> 01:43:36,179 from scratch is a bit tricky but with 3393 01:43:36,179 --> 01:43:38,040 same machine it is super easy for our 3394 01:43:38,040 --> 01:43:39,960 case like I said we want the absolute 3395 01:43:39,960 --> 01:43:41,760 most basic thing possible so let's just 3396 01:43:41,760 --> 01:43:43,500 create an empty virtual camera okay 3397 01:43:43,500 --> 01:43:45,540 that's it this creates a virtual camera 3398 01:43:45,540 --> 01:43:47,580 over here in the hierarchy and turn this 3399 01:43:47,580 --> 01:43:49,080 object has the send machine virtual 3400 01:43:49,080 --> 01:43:50,760 camera component and also importantly 3401 01:43:50,760 --> 01:43:52,739 when we added this it also added over 3402 01:43:52,739 --> 01:43:54,239 here on the main camera if we scroll 3403 01:43:54,239 --> 01:43:55,679 down we can see it has a sin machine 3404 01:43:55,679 --> 01:43:57,420 brain component basically the way send 3405 01:43:57,420 --> 01:43:59,400 machine works is it works on top of the 3406 01:43:59,400 --> 01:44:01,380 main camera so it doesn't replace it it 3407 01:44:01,380 --> 01:44:03,119 works on top of it and drives the main 3408 01:44:03,119 --> 01:44:04,619 camera so now that we're using send 3409 01:44:04,619 --> 01:44:06,780 machine if we try modifying the main 3410 01:44:06,780 --> 01:44:08,340 camera game object so there's one over 3411 01:44:08,340 --> 01:44:10,139 here if I try to drag the field of view 3412 01:44:10,139 --> 01:44:12,540 nope does not work I cannot move it if I 3413 01:44:12,540 --> 01:44:14,040 try to move the position nope can't do 3414 01:44:14,040 --> 01:44:16,020 it it if I try to rotate it nope that 3415 01:44:16,020 --> 01:44:17,699 does not work like I said when working 3416 01:44:17,699 --> 01:44:19,560 with cinemachine the sin machine brain 3417 01:44:19,560 --> 01:44:21,300 is what drives the main camera so rather 3418 01:44:21,300 --> 01:44:22,860 than modifying the things over here on 3419 01:44:22,860 --> 01:44:24,600 the camera itself what we need to do is 3420 01:44:24,600 --> 01:44:26,340 change them on the virtual camera so 3421 01:44:26,340 --> 01:44:28,020 over here we have pretty much the exact 3422 01:44:28,020 --> 01:44:29,520 same options that we have on the main 3423 01:44:29,520 --> 01:44:31,860 camera for example modifying the fov 3424 01:44:31,860 --> 01:44:33,540 over here we've got the lens so we can 3425 01:44:33,540 --> 01:44:35,100 modify the fov and if we look in the 3426 01:44:35,100 --> 01:44:37,199 game scene as we modify this one yep it 3427 01:44:37,199 --> 01:44:38,880 does modify the actual properties on the 3428 01:44:38,880 --> 01:44:40,800 actual main camera now this has tons and 3429 01:44:40,800 --> 01:44:42,060 tons of options related to everything 3430 01:44:42,060 --> 01:44:44,100 the most important ones are all kinds of 3431 01:44:44,100 --> 01:44:46,080 options down here for the body and the 3432 01:44:46,080 --> 01:44:47,639 aim so this is where the camera is 3433 01:44:47,639 --> 01:44:49,080 positioned and where it's looking at 3434 01:44:49,080 --> 01:44:50,940 using this you can make a funnel camera 3435 01:44:50,940 --> 01:44:52,920 in five seconds it really is insanely 3436 01:44:52,920 --> 01:44:54,480 useful if you want to learn about Sim 3437 01:44:54,480 --> 01:44:55,920 machine in more detail I have a 3438 01:44:55,920 --> 01:44:57,719 dedicated video on it I go through what 3439 01:44:57,719 --> 01:44:59,760 all of these options do then I also have 3440 01:44:59,760 --> 01:45:01,440 another super detailed video on how to 3441 01:45:01,440 --> 01:45:03,360 make a camera system with pan Zoom 3442 01:45:03,360 --> 01:45:05,639 scroll in both 2D and 3D and a bunch 3443 01:45:05,639 --> 01:45:07,560 more features again all of it using send 3444 01:45:07,560 --> 01:45:09,239 machine but in our case we really want 3445 01:45:09,239 --> 01:45:10,860 to keep it simple so let's just position 3446 01:45:10,860 --> 01:45:12,780 our virtual camera on the same settings 3447 01:45:12,780 --> 01:45:14,520 that we had previously so for first 3448 01:45:14,520 --> 01:45:16,320 let's set the film review so for a game 3449 01:45:16,320 --> 01:45:17,699 we want something narrow so let's go 3450 01:45:17,699 --> 01:45:19,080 with just 20. then for the position 3451 01:45:19,080 --> 01:45:21,840 let's put it above so zero on the X then 3452 01:45:21,840 --> 01:45:25,199 21.5 on the Y and minus 21.3 on the Zen 3453 01:45:25,199 --> 01:45:27,719 then for the rotation 46 on the X and 3454 01:45:27,719 --> 01:45:29,400 then 0 on the others okay so our camera 3455 01:45:29,400 --> 01:45:30,840 is positioned in the exact same position 3456 01:45:30,840 --> 01:45:32,639 and if we head on 20 yep everything 3457 01:45:32,639 --> 01:45:34,080 still works the same the camera is going 3458 01:45:34,080 --> 01:45:35,340 from the same point of view and the 3459 01:45:35,340 --> 01:45:36,900 character still works everything's still 3460 01:45:36,900 --> 01:45:38,580 exactly the same now since we're using 3461 01:45:38,580 --> 01:45:40,080 cinemachine we can easily add some 3462 01:45:40,080 --> 01:45:41,820 things on top of this like for example 3463 01:45:41,820 --> 01:45:43,260 we can add some noise to our scene 3464 01:45:43,260 --> 01:45:45,000 machine camera to make it smoothly move 3465 01:45:45,000 --> 01:45:47,040 a little bit this one is a fun simple 3466 01:45:47,040 --> 01:45:48,960 effect that can make our game feel a bit 3467 01:45:48,960 --> 01:45:50,580 more Dynamic especially in games like 3468 01:45:50,580 --> 01:45:52,320 this where we have a fixed overhead view 3469 01:45:52,320 --> 01:45:53,940 how we do that is over here on the scene 3470 01:45:53,940 --> 01:45:55,199 Mission virtual camera we've got a film 3471 01:45:55,199 --> 01:45:57,119 for noise so let's click and let's 3472 01:45:57,119 --> 01:45:59,280 select basic multi-channel purlin and 3473 01:45:59,280 --> 01:46:00,360 then over here we've got the noise 3474 01:46:00,360 --> 01:46:01,980 profile so we can choose one of the 3475 01:46:01,980 --> 01:46:03,540 included ones or we can create our own 3476 01:46:03,540 --> 01:46:05,219 profile so for example let's go with 3477 01:46:05,219 --> 01:46:07,139 handheld normal mild and by the way you 3478 01:46:07,139 --> 01:46:08,340 can actually modify these settings while 3479 01:46:08,340 --> 01:46:09,900 the game is playing so here it is the 3480 01:46:09,900 --> 01:46:10,980 game playing and you can see what this 3481 01:46:10,980 --> 01:46:13,080 effect does it adds a nice little wobble 3482 01:46:13,080 --> 01:46:14,820 to the camera and then over here at my 3483 01:46:14,820 --> 01:46:16,199 student frequency so we can play around 3484 01:46:16,199 --> 01:46:17,940 these so you can make it really intense 3485 01:46:17,940 --> 01:46:19,560 so something like this that is way too 3486 01:46:19,560 --> 01:46:21,719 intense so there you go quite a lot so 3487 01:46:21,719 --> 01:46:23,400 for something more subtle maybe put 0.5 3488 01:46:23,400 --> 01:46:25,500 and 0.5 there you go just a slight 3489 01:46:25,500 --> 01:46:27,119 little movement in the camera so this 3490 01:46:27,119 --> 01:46:28,440 would help make the game a little bit 3491 01:46:28,440 --> 01:46:30,060 more Dynamic so this could be a fun 3492 01:46:30,060 --> 01:46:31,739 effect although actually in my case in 3493 01:46:31,739 --> 01:46:32,639 order to make sure that the video 3494 01:46:32,639 --> 01:46:34,260 doesn't get way too compressed I'm 3495 01:46:34,260 --> 01:46:35,820 actually going to disable this on my end 3496 01:46:35,820 --> 01:46:37,619 so just set the channel noise to none 3497 01:46:37,619 --> 01:46:39,600 but you can see how easy it is to add 3498 01:46:39,600 --> 01:46:41,280 complex camera features when using send 3499 01:46:41,280 --> 01:46:42,420 machine and of course when using 3500 01:46:42,420 --> 01:46:44,100 cinemachine if you want you can use it 3501 01:46:44,100 --> 01:46:45,659 to make your game a lot more unique now 3502 01:46:45,659 --> 01:46:47,280 for me I want to design here where the 3503 01:46:47,280 --> 01:46:48,540 camera is fixed but let's say for 3504 01:46:48,540 --> 01:46:50,159 example you wanted the camera to 3505 01:46:50,159 --> 01:46:51,719 actually follow the player like I said 3506 01:46:51,719 --> 01:46:53,280 you'll watch that dedicated video tool 3507 01:46:53,280 --> 01:46:54,900 and learn all about cinemachine but over 3508 01:46:54,900 --> 01:46:56,639 here very quickly let me just show you 3509 01:46:56,639 --> 01:46:57,960 how to do that but at the same time 3510 01:46:57,960 --> 01:46:59,340 don't bother following this part it's 3511 01:46:59,340 --> 01:47:00,659 just to show what scene machine can do 3512 01:47:00,659 --> 01:47:02,040 that I'm going to revert back to this 3513 01:47:02,040 --> 01:47:03,719 state so first of all for testing one 3514 01:47:03,719 --> 01:47:04,980 great thing about scene machine is you 3515 01:47:04,980 --> 01:47:06,780 can have multiple virtual cameras you 3516 01:47:06,780 --> 01:47:08,699 can have as many as you want and then 3517 01:47:08,699 --> 01:47:10,619 the priority and the game object enabled 3518 01:47:10,619 --> 01:47:12,179 state is what defines which camera is 3519 01:47:12,179 --> 01:47:13,739 actually being used so for example on 3520 01:47:13,739 --> 01:47:15,300 this second one let's make it follow the 3521 01:47:15,300 --> 01:47:17,040 camera and put the priority on 20 so 3522 01:47:17,040 --> 01:47:18,600 that it's above then over here for the 3523 01:47:18,600 --> 01:47:20,040 body I'm going to select transposer 3524 01:47:20,040 --> 01:47:22,500 let's put it with World space it 3525 01:47:22,500 --> 01:47:24,119 requires a funnel Target so let me drag 3526 01:47:24,119 --> 01:47:26,280 the player as the final Target and put 3527 01:47:26,280 --> 01:47:29,340 it as slightly above and behind Okay so 3528 01:47:29,340 --> 01:47:31,080 it's pretty similar as before then for 3529 01:47:31,080 --> 01:47:33,360 the aim let me also drag the aim player 3530 01:47:33,360 --> 01:47:34,679 Target and just with this it should 3531 01:47:34,679 --> 01:47:36,420 already work so if I head on play if 3532 01:47:36,420 --> 01:47:37,500 they're going to look at that the camera 3533 01:47:37,500 --> 01:47:39,480 is now moving and following the player 3534 01:47:39,480 --> 01:47:40,800 so I can move the player anywhere and 3535 01:47:40,800 --> 01:47:42,540 yep the camera follows along so as you 3536 01:47:42,540 --> 01:47:43,980 can see it's this simple to really make 3537 01:47:43,980 --> 01:47:45,840 some complex camera movement doing some 3538 01:47:45,840 --> 01:47:47,460 complex camera logic just like this 3539 01:47:47,460 --> 01:47:49,440 would require a ton of work manually but 3540 01:47:49,440 --> 01:47:51,420 with thin machine it is super easy then 3541 01:47:51,420 --> 01:47:52,679 you can even play around with either 3542 01:47:52,679 --> 01:47:55,139 priority or enable and disable and there 3543 01:47:55,139 --> 01:47:56,699 you go see the machine even transitions 3544 01:47:56,699 --> 01:47:58,260 between the state of only your virtual 3545 01:47:58,260 --> 01:47:59,820 cameras so as you can see in lots and 3546 01:47:59,820 --> 01:48:01,020 lots of things you can make with your 3547 01:48:01,020 --> 01:48:02,699 camera very easily all thanks to 3548 01:48:02,699 --> 01:48:04,560 cinemachine like I said in my case I 3549 01:48:04,560 --> 01:48:06,179 just want the fix overhead camera so I'm 3550 01:48:06,179 --> 01:48:07,500 just going to delete this secondary 3551 01:48:07,500 --> 01:48:09,000 virtual camera and there you go just 3552 01:48:09,000 --> 01:48:10,860 this one on top looking at the player 3553 01:48:10,860 --> 01:48:12,960 and looking down with a low fov and Yep 3554 01:48:12,960 --> 01:48:14,580 this is the exactly the kind of camera 3555 01:48:14,580 --> 01:48:16,500 that I want for my game okay so that's 3556 01:48:16,500 --> 01:48:18,360 in machine it's a really awesome tool 3557 01:48:18,360 --> 01:48:19,920 for making camera handling much much 3558 01:48:19,920 --> 01:48:22,020 easier so this was a quick lecture all 3559 01:48:22,020 --> 01:48:23,880 about learning about Sin machine now 3560 01:48:23,880 --> 01:48:25,139 let's handle the tests that was actually 3561 01:48:25,139 --> 01:48:26,880 left and done quite a while ago let's 3562 01:48:26,880 --> 01:48:28,739 finally learn how to refactor code and 3563 01:48:28,739 --> 01:48:30,600 implement the new input system so let's 3564 01:48:30,600 --> 01:48:33,060 do that in the next lecture 3565 01:48:33,060 --> 01:48:34,980 hello and welcome I'm your code monkey 3566 01:48:34,980 --> 01:48:37,260 in this lecture we're going to refactor 3567 01:48:37,260 --> 01:48:39,239 our code from the Legacy input manager 3568 01:48:39,239 --> 01:48:41,400 onto the new input system so the 3569 01:48:41,400 --> 01:48:42,840 simpleton character controller that we 3570 01:48:42,840 --> 01:48:44,400 made is working perfectly fine within 3571 01:48:44,400 --> 01:48:46,440 Legacy input manager like I said this 3572 01:48:46,440 --> 01:48:47,760 one is excellent for making quick 3573 01:48:47,760 --> 01:48:49,560 prototypes and demos as you can see it's 3574 01:48:49,560 --> 01:48:50,880 super easy to use 3575 01:48:50,880 --> 01:48:53,159 but now let's quickly refactor this code 3576 01:48:53,159 --> 01:48:55,260 to use the new input system instead also 3577 01:48:55,260 --> 01:48:56,400 like I said in the beginning of this 3578 01:48:56,400 --> 01:48:57,840 course here I'm going to be focused 3579 01:48:57,840 --> 01:48:59,880 primarily on building this game so for 3580 01:48:59,880 --> 01:49:01,560 example for any Unity tools that I use 3581 01:49:01,560 --> 01:49:03,360 like the new input system I'm going to 3582 01:49:03,360 --> 01:49:04,920 cover enough to be able to use a tool 3583 01:49:04,920 --> 01:49:06,480 and Achieve our goals in building this 3584 01:49:06,480 --> 01:49:07,320 game 3585 01:49:07,320 --> 01:49:08,820 of course every tool does a lot more 3586 01:49:08,820 --> 01:49:10,619 than just what we're going to use so 3587 01:49:10,619 --> 01:49:11,699 definitely make sure to watch the 3588 01:49:11,699 --> 01:49:12,960 dedicated videos Link in the description 3589 01:49:12,960 --> 01:49:15,239 for example the input system tutorial is 3590 01:49:15,239 --> 01:49:16,800 40 minutes long covering everything you 3591 01:49:16,800 --> 01:49:18,420 need to know about system whereas here 3592 01:49:18,420 --> 01:49:19,800 we're just going to learn enough to know 3593 01:49:19,800 --> 01:49:21,960 how to use it so let's refactor this 3594 01:49:21,960 --> 01:49:23,400 code to make it work with new input 3595 01:49:23,400 --> 01:49:25,739 system except before we work with new 3596 01:49:25,739 --> 01:49:27,600 input system let's just refactor this 3597 01:49:27,600 --> 01:49:29,760 code so we can completely decoup on the 3598 01:49:29,760 --> 01:49:32,040 input from the player class again we 3599 01:49:32,040 --> 01:49:33,659 want to focus on writing good clean code 3600 01:49:33,659 --> 01:49:36,179 so we should keep all of our input logic 3601 01:49:36,179 --> 01:49:37,980 in its own class that other scripts can 3602 01:49:37,980 --> 01:49:40,320 access remember the goal with clean code 3603 01:49:40,320 --> 01:49:42,900 is to minimize and manage complexity so 3604 01:49:42,900 --> 01:49:44,820 every class should do one thing and just 3605 01:49:44,820 --> 01:49:46,800 one thing meaning that the player class 3606 01:49:46,800 --> 01:49:48,480 should only handle the player and then 3607 01:49:48,480 --> 01:49:50,280 the input list should only handle the 3608 01:49:50,280 --> 01:49:52,440 input the only reason why I put this 3609 01:49:52,440 --> 01:49:53,940 over here in the beginning is exactly to 3610 01:49:53,940 --> 01:49:55,560 teach you about refactoring and how it's 3611 01:49:55,560 --> 01:49:57,000 a very common thing that you should be 3612 01:49:57,000 --> 01:49:59,340 doing all the time this is exactly how I 3613 01:49:59,340 --> 01:50:01,679 build my own games I start by making a 3614 01:50:01,679 --> 01:50:03,239 prototype and I write the input directly 3615 01:50:03,239 --> 01:50:04,920 inside the player class then at some 3616 01:50:04,920 --> 01:50:06,600 point I refactor the code to split them 3617 01:50:06,600 --> 01:50:09,000 up so don't be afraid to refactor code 3618 01:50:09,000 --> 01:50:10,860 it's a Perfectly Natural part of the 3619 01:50:10,860 --> 01:50:12,659 Game Dev process and actually a very 3620 01:50:12,659 --> 01:50:14,940 very good thing okay so let's make a 3621 01:50:14,940 --> 01:50:16,679 script just to manage our inputs let's 3622 01:50:16,679 --> 01:50:19,739 make a new c-sharp script call this game 3623 01:50:19,739 --> 01:50:22,380 input let's create an empty game object 3624 01:50:22,380 --> 01:50:24,360 give it the same name input as always 3625 01:50:24,360 --> 01:50:26,400 keep things lean so put it on zero zero 3626 01:50:26,400 --> 01:50:28,619 zero let's attach the script and open 3627 01:50:28,619 --> 01:50:30,900 okay so here's our script and let's get 3628 01:50:30,900 --> 01:50:33,179 everything related to the inputs on the 3629 01:50:33,179 --> 01:50:34,800 player for the input we are calculating 3630 01:50:34,800 --> 01:50:36,840 the input Vector then getting the actual 3631 01:50:36,840 --> 01:50:38,520 inputs from the keyboard and returning 3632 01:50:38,520 --> 01:50:39,780 the input vector 3633 01:50:39,780 --> 01:50:42,600 so let's put this on the other script so 3634 01:50:42,600 --> 01:50:44,460 over here let's make a new function 3635 01:50:44,460 --> 01:50:46,380 let's make it public since we want to 3636 01:50:46,380 --> 01:50:48,239 access it from the player we're going to 3637 01:50:48,239 --> 01:50:50,219 return a vector 2 and let's call it get 3638 01:50:50,219 --> 01:50:53,280 movement vector 3639 01:50:53,280 --> 01:50:55,080 now here let's really just copy paste 3640 01:50:55,080 --> 01:50:56,340 the exact same code that we have on 3641 01:50:56,340 --> 01:50:58,080 player so let's copy paste all of this 3642 01:50:58,080 --> 01:51:00,239 let's go and paste it here 3643 01:51:00,239 --> 01:51:02,100 okay so we get the input Vector we get 3644 01:51:02,100 --> 01:51:04,380 the inputs we normalize it and then 3645 01:51:04,380 --> 01:51:06,540 return the input vector 3646 01:51:06,540 --> 01:51:09,239 okay so that's it super simple also by 3647 01:51:09,239 --> 01:51:10,560 the way here we have an interesting 3648 01:51:10,560 --> 01:51:11,340 question 3649 01:51:11,340 --> 01:51:13,500 which is do we normalize the input over 3650 01:51:13,500 --> 01:51:15,239 here or do we do it over here on the 3651 01:51:15,239 --> 01:51:18,540 player both options can be valid you can 3652 01:51:18,540 --> 01:51:19,980 make it so that the game unplug glass 3653 01:51:19,980 --> 01:51:23,219 returns a regular input or you can make 3654 01:51:23,219 --> 01:51:25,440 it return a normalized vector you can 3655 01:51:25,440 --> 01:51:27,060 use either option but whatever you do 3656 01:51:27,060 --> 01:51:29,280 make sure you are explicit so over here 3657 01:51:29,280 --> 01:51:31,440 I am going to normalize input inside the 3658 01:51:31,440 --> 01:51:33,659 game input class however I'm also going 3659 01:51:33,659 --> 01:51:35,400 to make sure to rename this function so 3660 01:51:35,400 --> 01:51:36,960 instead of get movement Vector get 3661 01:51:36,960 --> 01:51:39,420 movement Vector normalize that way it is 3662 01:51:39,420 --> 01:51:41,820 100 clear this returns a movement Vector 3663 01:51:41,820 --> 01:51:44,460 as a normalized vector okay great 3664 01:51:44,460 --> 01:51:47,340 so now let's use this in our player over 3665 01:51:47,340 --> 01:51:49,020 here in our player class we need some 3666 01:51:49,020 --> 01:51:51,719 reference to our input class now later 3667 01:51:51,719 --> 01:51:53,219 on in this course I'm going to teach you 3668 01:51:53,219 --> 01:51:55,199 about the Singleton pattern but for now 3669 01:51:55,199 --> 01:51:57,659 let's just do a simple direct reference 3670 01:51:57,659 --> 01:52:00,179 again remember don't make it public make 3671 01:52:00,179 --> 01:52:02,520 it a serialized film private so over 3672 01:52:02,520 --> 01:52:03,600 here 3673 01:52:03,600 --> 01:52:05,760 let's make a serialized film private of 3674 01:52:05,760 --> 01:52:07,860 type game input and let's call it just 3675 01:52:07,860 --> 01:52:10,260 game input 3676 01:52:10,260 --> 01:52:12,119 okay so we have this we're going to drag 3677 01:52:12,119 --> 01:52:14,159 it in the editor then over here we 3678 01:52:14,159 --> 01:52:16,199 simply grab the vector 2 for the input 3679 01:52:16,199 --> 01:52:18,540 Vector we simply go into this one and we 3680 01:52:18,540 --> 01:52:20,880 get the movement vector normalized and 3681 01:52:20,880 --> 01:52:22,560 okay that's it no more errors let's just 3682 01:52:22,560 --> 01:52:24,780 make sure to save all of our scripts and 3683 01:52:24,780 --> 01:52:26,100 back in the editor let's go into the 3684 01:52:26,100 --> 01:52:27,840 player and just drag the reference for 3685 01:52:27,840 --> 01:52:29,940 the game input okay so just like this 3686 01:52:29,940 --> 01:52:31,500 everything should still work everything 3687 01:52:31,500 --> 01:52:33,179 should work exactly the same as 3688 01:52:33,179 --> 01:52:36,239 previously Let's test and make sure so 3689 01:52:36,239 --> 01:52:37,679 here we are moving and yep everything 3690 01:52:37,679 --> 01:52:39,239 still works I can move in any direction 3691 01:52:39,239 --> 01:52:41,159 okay so far so good 3692 01:52:41,159 --> 01:52:42,540 and what we have done here is 3693 01:52:42,540 --> 01:52:44,400 essentially we have refactor our code 3694 01:52:44,400 --> 01:52:46,440 and conveniently separate the input from 3695 01:52:46,440 --> 01:52:48,600 the player class this is an excellent 3696 01:52:48,600 --> 01:52:50,040 thing so again don't be afraid to 3697 01:52:50,040 --> 01:52:52,260 refactor code also what we did here of 3698 01:52:52,260 --> 01:52:54,360 putting the code in a separate class and 3699 01:52:54,360 --> 01:52:55,739 then doing a quick test to make sure 3700 01:52:55,739 --> 01:52:57,239 that everything soon works the same as 3701 01:52:57,239 --> 01:52:58,980 previously this is exactly what you 3702 01:52:58,980 --> 01:53:00,420 should do whenever you do some kind of 3703 01:53:00,420 --> 01:53:02,699 reorganizational refactoring in the end 3704 01:53:02,699 --> 01:53:04,500 you want to end up with the exact same 3705 01:53:04,500 --> 01:53:06,239 behaviors previously just with the code 3706 01:53:06,239 --> 01:53:08,699 organized in a different way okay so now 3707 01:53:08,699 --> 01:53:10,139 that we have this separate game input 3708 01:53:10,139 --> 01:53:12,659 class now we can very easily refactor 3709 01:53:12,659 --> 01:53:14,699 the Legacy input manager onto the new 3710 01:53:14,699 --> 01:53:16,560 input system so the first thing we need 3711 01:53:16,560 --> 01:53:18,239 is to install the package so let's open 3712 01:53:18,239 --> 01:53:20,639 up the package manager let's make sure 3713 01:53:20,639 --> 01:53:22,739 up here we are in the ENT registry make 3714 01:53:22,739 --> 01:53:25,020 sure we are in all and let's scroll down 3715 01:53:25,020 --> 01:53:27,360 to find the input system so here it is 3716 01:53:27,360 --> 01:53:30,360 let's go ahead and install 3717 01:53:30,360 --> 01:53:32,159 okay the package is installed and right 3718 01:53:32,159 --> 01:53:34,320 away we see this message basically it's 3719 01:53:34,320 --> 01:53:36,060 asking us if we want to enable the new 3720 01:53:36,060 --> 01:53:37,199 input system 3721 01:53:37,199 --> 01:53:39,239 now you could click on yes but let's 3722 01:53:39,239 --> 01:53:40,860 actually go ahead and click on no we're 3723 01:53:40,860 --> 01:53:42,719 going to enable it manually so click on 3724 01:53:42,719 --> 01:53:45,719 no then let's close this window and now 3725 01:53:45,719 --> 01:53:47,639 let's go up here into edit then let's go 3726 01:53:47,639 --> 01:53:49,739 into project settings then on the left 3727 01:53:49,739 --> 01:53:51,960 side let's go into player and now let's 3728 01:53:51,960 --> 01:53:54,119 scroll down expand over here the other 3729 01:53:54,119 --> 01:53:55,500 settings tab 3730 01:53:55,500 --> 01:53:57,840 and keep scrolling down until we see yep 3731 01:53:57,840 --> 01:54:00,060 here it is the active input Henley this 3732 01:54:00,060 --> 01:54:01,380 is where you can select which input 3733 01:54:01,380 --> 01:54:03,119 system you're using basically if you 3734 01:54:03,119 --> 01:54:04,739 click yes on that window it would 3735 01:54:04,739 --> 01:54:06,719 automatically set this option to use the 3736 01:54:06,719 --> 01:54:09,000 new input system so it would only enable 3737 01:54:09,000 --> 01:54:10,860 that one and can only disable the unless 3738 01:54:10,860 --> 01:54:13,020 input manager but like I said the lace 3739 01:54:13,020 --> 01:54:14,880 input manager is still pretty useful so 3740 01:54:14,880 --> 01:54:16,800 normally for me I prefer to enable both 3741 01:54:16,800 --> 01:54:18,780 of them so let's go ahead click on both 3742 01:54:18,780 --> 01:54:21,360 and this will restart the editor so okay 3743 01:54:21,360 --> 01:54:23,520 let's go alright the editor has 3744 01:54:23,520 --> 01:54:25,380 restarted so now the new input system is 3745 01:54:25,380 --> 01:54:27,900 now enabled okay so the way that this 3746 01:54:27,900 --> 01:54:29,580 system works is by creating something 3747 01:54:29,580 --> 01:54:32,340 called an input actions asset so on the 3748 01:54:32,340 --> 01:54:33,719 project files let's click on the plus 3749 01:54:33,719 --> 01:54:35,820 icon let's create something and let's 3750 01:54:35,820 --> 01:54:38,460 find the input actions so we need to 3751 01:54:38,460 --> 01:54:39,840 scroll down here so click on the little 3752 01:54:39,840 --> 01:54:41,460 arrow to go down and find the input 3753 01:54:41,460 --> 01:54:43,500 actions creates this file let's call 3754 01:54:43,500 --> 01:54:46,260 this the player input actions 3755 01:54:46,260 --> 01:54:48,179 okay now let's go ahead and double click 3756 01:54:48,179 --> 01:54:50,340 on it and yep there you go out pops out 3757 01:54:50,340 --> 01:54:52,679 the input system window basically this 3758 01:54:52,679 --> 01:54:54,000 one is where we're going to manage all 3759 01:54:54,000 --> 01:54:55,619 of the settings for all of our inputs 3760 01:54:55,619 --> 01:54:57,060 also by the way and like I've mentioned 3761 01:54:57,060 --> 01:54:58,260 if you're watching this in the future 3762 01:54:58,260 --> 01:55:00,360 and for some reason the input system got 3763 01:55:00,360 --> 01:55:02,400 a new update and changed this window if 3764 01:55:02,400 --> 01:55:03,719 so make sure you check the pinned 3765 01:55:03,719 --> 01:55:05,520 comment I'll keep it updated with any 3766 01:55:05,520 --> 01:55:07,679 changes on anything in this course so 3767 01:55:07,679 --> 01:55:10,199 over here we've got the action Maps then 3768 01:55:10,199 --> 01:55:12,000 we've got the actions and then we've got 3769 01:55:12,000 --> 01:55:14,340 properties now action maps are how you 3770 01:55:14,340 --> 01:55:16,920 can have different maps for example one 3771 01:55:16,920 --> 01:55:18,300 action map would be for the player 3772 01:55:18,300 --> 01:55:19,860 whilst walking normally and you could 3773 01:55:19,860 --> 01:55:21,360 have another one whilst driving a 3774 01:55:21,360 --> 01:55:23,580 vehicle then for the individual actions 3775 01:55:23,580 --> 01:55:25,800 in each action map and finally the 3776 01:55:25,800 --> 01:55:27,960 properties for each action again if you 3777 01:55:27,960 --> 01:55:29,280 want to learn about the entire input 3778 01:55:29,280 --> 01:55:31,080 system itself in more detail go ahead 3779 01:55:31,080 --> 01:55:33,060 and watch my dedicated video on it in 3780 01:55:33,060 --> 01:55:34,560 order for this course to not be 20 hours 3781 01:55:34,560 --> 01:55:36,239 long I'm really only going to use enough 3782 01:55:36,239 --> 01:55:37,920 to make sure that we can achieve our 3783 01:55:37,920 --> 01:55:39,780 goal so over here we just need one 3784 01:55:39,780 --> 01:55:41,159 action map so let's click on the plus 3785 01:55:41,159 --> 01:55:43,920 icon let's name this the player and now 3786 01:55:43,920 --> 01:55:45,659 for the actions right away we have a new 3787 01:55:45,659 --> 01:55:46,500 action 3788 01:55:46,500 --> 01:55:49,739 so let's just rename this one let's call 3789 01:55:49,739 --> 01:55:51,840 this action move then with the section 3790 01:55:51,840 --> 01:55:53,219 selected over here on the Action 3791 01:55:53,219 --> 01:55:55,080 Properties we can select the action type 3792 01:55:55,080 --> 01:55:57,360 again in the dedicated video I cover 3793 01:55:57,360 --> 01:55:58,920 what all of these mean 3794 01:55:58,920 --> 01:56:01,139 for movement we do not want a button we 3795 01:56:01,139 --> 01:56:02,940 want movement in multiple directions so 3796 01:56:02,940 --> 01:56:04,860 let's go with value then over here for 3797 01:56:04,860 --> 01:56:06,900 the control type for this one let's go 3798 01:56:06,900 --> 01:56:09,179 with the vector 2 and then let's expand 3799 01:56:09,179 --> 01:56:10,560 our action over here we can see our 3800 01:56:10,560 --> 01:56:12,719 bindings however we don't want this 3801 01:56:12,719 --> 01:56:14,580 default binding so let's actually delete 3802 01:56:14,580 --> 01:56:16,380 this one instead let's click on the plus 3803 01:56:16,380 --> 01:56:18,480 icon and over here for the type first 3804 01:56:18,480 --> 01:56:19,920 for the keyboard and let's go with this 3805 01:56:19,920 --> 01:56:21,900 one up down left right composite 3806 01:56:21,900 --> 01:56:23,699 so this one adds essentially four 3807 01:56:23,699 --> 01:56:25,739 bindings let's go ahead and name this 3808 01:56:25,739 --> 01:56:27,000 was 3809 01:56:27,000 --> 01:56:28,619 then for the up let's select the 3810 01:56:28,619 --> 01:56:30,000 bindings over here on the path let's 3811 01:56:30,000 --> 01:56:32,040 click on it then we can either find it 3812 01:56:32,040 --> 01:56:33,600 manually over here or click on the 3813 01:56:33,600 --> 01:56:35,520 listen and I'll press the W button yep 3814 01:56:35,520 --> 01:56:37,800 there you go W then for down let's go 3815 01:56:37,800 --> 01:56:40,380 ahead and listen s then for the unless 3816 01:56:40,380 --> 01:56:43,560 listen a and for the right let's listen 3817 01:56:43,560 --> 01:56:44,520 d 3818 01:56:44,520 --> 01:56:47,400 okay great so with this our input as it 3819 01:56:47,400 --> 01:56:49,679 is correctly set up one thing you must 3820 01:56:49,679 --> 01:56:51,540 never forget is up here make sure to 3821 01:56:51,540 --> 01:56:53,940 save the asset you can see this little 3822 01:56:53,940 --> 01:56:55,980 asterisk here that means we have unsafe 3823 01:56:55,980 --> 01:56:58,139 changes also alternatively there's an 3824 01:56:58,139 --> 01:57:00,119 auto save there but for now let's just 3825 01:57:00,119 --> 01:57:02,760 manually save the acid okay great 3826 01:57:02,760 --> 01:57:04,560 so now let's see how to actually use 3827 01:57:04,560 --> 01:57:06,960 this in our code there are many ways we 3828 01:57:06,960 --> 01:57:09,540 can use the input system one way is by 3829 01:57:09,540 --> 01:57:11,040 using the built-in player input 3830 01:57:11,040 --> 01:57:13,080 component so for example on the player 3831 01:57:13,080 --> 01:57:15,599 we would add the player input 3832 01:57:15,599 --> 01:57:17,400 so you could add this one attach and 3833 01:57:17,400 --> 01:57:19,080 input actions asset so this is our 3834 01:57:19,080 --> 01:57:21,300 player input actions then over here we 3835 01:57:21,300 --> 01:57:22,860 have various behaviors in order to be 3836 01:57:22,860 --> 01:57:24,960 able to trigger our actions but in this 3837 01:57:24,960 --> 01:57:26,580 course like I said I'm going to be using 3838 01:57:26,580 --> 01:57:28,139 the exact same code quality that I used 3839 01:57:28,139 --> 01:57:30,540 in my own Steam games so I will not be 3840 01:57:30,540 --> 01:57:31,860 using this component so let's remove 3841 01:57:31,860 --> 01:57:34,380 this instead I won't be using the native 3842 01:57:34,380 --> 01:57:36,960 c-sharp method so what's like the player 3843 01:57:36,960 --> 01:57:39,060 input actions and over here on the 3844 01:57:39,060 --> 01:57:40,679 inspector we see this nice toggle to 3845 01:57:40,679 --> 01:57:42,360 generate a c-sharp class 3846 01:57:42,360 --> 01:57:44,820 let's go ahead enable it and for these 3847 01:57:44,820 --> 01:57:46,320 films we can leave them all on defense 3848 01:57:46,320 --> 01:57:48,000 that's okay let's just go ahead click on 3849 01:57:48,000 --> 01:57:48,900 apply 3850 01:57:48,900 --> 01:57:50,340 and now it's going to generate those 3851 01:57:50,340 --> 01:57:51,960 scripts and compound them okay great 3852 01:57:51,960 --> 01:57:53,820 basically what this is doing is auto 3853 01:57:53,820 --> 01:57:56,219 generating some c-sharp code and on the 3854 01:57:56,219 --> 01:57:57,840 employer input actions we can see over 3855 01:57:57,840 --> 01:57:59,639 here yep we've got the generate script 3856 01:57:59,639 --> 01:58:01,800 if you want you can even open this to 3857 01:58:01,800 --> 01:58:04,199 see all of the source code now all this 3858 01:58:04,199 --> 01:58:05,639 like it says here this was all auto 3859 01:58:05,639 --> 01:58:07,260 generated so don't make any 3860 01:58:07,260 --> 01:58:08,639 modifications here 3861 01:58:08,639 --> 01:58:10,619 if you change anything any manual 3862 01:58:10,619 --> 01:58:12,300 changes won't be lost when you save some 3863 01:58:12,300 --> 01:58:14,340 changes in the input asset so if you 3864 01:58:14,340 --> 01:58:16,139 want go ahead and read through in order 3865 01:58:16,139 --> 01:58:18,300 to see how all this works but in order 3866 01:58:18,300 --> 01:58:19,860 to use it sectionally super simple you 3867 01:58:19,860 --> 01:58:21,179 don't need to worry about this script 3868 01:58:21,179 --> 01:58:23,280 first thing we need is to construct our 3869 01:58:23,280 --> 01:58:25,199 script class that was Auto General so 3870 01:58:25,199 --> 01:58:27,540 let's do it over here in our game input 3871 01:58:27,540 --> 01:58:29,820 let's make a product void awake and on 3872 01:58:29,820 --> 01:58:31,440 awake let's construct it 3873 01:58:31,440 --> 01:58:35,699 so let's do a new player input actions 3874 01:58:35,699 --> 01:58:39,800 so we construct an object of this time 3875 01:58:41,760 --> 01:58:43,560 so we have this although just like this 3876 01:58:43,560 --> 01:58:45,179 it won't be active so we need to 3877 01:58:45,179 --> 01:58:47,280 manually activate whatever action map we 3878 01:58:47,280 --> 01:58:49,380 want so let's go inside and let's go 3879 01:58:49,380 --> 01:58:50,699 inside the player so this is the action 3880 01:58:50,699 --> 01:58:52,560 map that we created and let's call 3881 01:58:52,560 --> 01:58:55,320 enable one okay so just like this it's 3882 01:58:55,320 --> 01:58:57,420 really already working all we need to do 3883 01:58:57,420 --> 01:58:59,280 is modify our code over here on the yet 3884 01:58:59,280 --> 01:59:01,020 movement Vector so for that we're going 3885 01:59:01,020 --> 01:59:02,460 to need to access this so let's actually 3886 01:59:02,460 --> 01:59:05,280 make this a member variable so private 3887 01:59:05,280 --> 01:59:07,500 let's store it up here instead of making 3888 01:59:07,500 --> 01:59:09,780 a local variable in here okay 3889 01:59:09,780 --> 01:59:11,820 so we have this one and then down here 3890 01:59:11,820 --> 01:59:13,380 on the input vector 3891 01:59:13,380 --> 01:59:15,360 let's go inside the player input actions 3892 01:59:15,360 --> 01:59:17,280 inside the player action map and then we 3893 01:59:17,280 --> 01:59:19,619 called it move so we've got this one and 3894 01:59:19,619 --> 01:59:21,480 then we defined it as a vector two so 3895 01:59:21,480 --> 01:59:23,880 over here we can call read value and 3896 01:59:23,880 --> 01:59:25,380 this one takes in the type of the value 3897 01:59:25,380 --> 01:59:27,300 now we Define it as a vector two so 3898 01:59:27,300 --> 01:59:29,820 let's read it as a vector two and just 3899 01:59:29,820 --> 01:59:31,980 like this this returns a vector 2 which 3900 01:59:31,980 --> 01:59:33,540 is really going to be our input Vector 3901 01:59:33,540 --> 01:59:36,360 so let's put it exactly like this and we 3902 01:59:36,360 --> 01:59:39,179 can now get rid of the rest of it all 3903 01:59:39,179 --> 01:59:40,739 right so that's it and just like this we 3904 01:59:40,739 --> 01:59:42,179 should already have everything working 3905 01:59:42,179 --> 01:59:44,099 exactly the same as previously 3906 01:59:44,099 --> 01:59:46,440 so let's just do a debug download just 3907 01:59:46,440 --> 01:59:49,320 to make sure so let's test so here we 3908 01:59:49,320 --> 01:59:50,940 are and the output is zero zero now I 3909 01:59:50,940 --> 01:59:53,040 press W there you go plus one minus one 3910 01:59:53,040 --> 01:59:55,139 left right and all of the ones in 3911 01:59:55,139 --> 01:59:58,320 between all right awesome so we have the 3912 01:59:58,320 --> 01:59:59,820 new input system all of it working 3913 01:59:59,820 --> 02:00:02,460 flawlessly also by the way over here we 3914 02:00:02,460 --> 02:00:03,960 can normalize the input just like we 3915 02:00:03,960 --> 02:00:05,280 were doing previously so we do it over 3916 02:00:05,280 --> 02:00:07,500 here through code or alternatively we 3917 02:00:07,500 --> 02:00:08,760 can also go into the player input 3918 02:00:08,760 --> 02:00:10,199 actions and over here there's something 3919 02:00:10,199 --> 02:00:12,480 called a processor so you can go into 3920 02:00:12,480 --> 02:00:14,580 this action add a processor and make it 3921 02:00:14,580 --> 02:00:17,159 normalized so these processes here can 3922 02:00:17,159 --> 02:00:19,380 be quite useful I cover the modeling 3923 02:00:19,380 --> 02:00:21,179 detail in the other dedicated video but 3924 02:00:21,179 --> 02:00:22,440 over here let's stick with making it 3925 02:00:22,440 --> 02:00:23,760 through code that works just as well 3926 02:00:23,760 --> 02:00:26,580 okay so that's our refactoring done with 3927 02:00:26,580 --> 02:00:28,199 that simple change we are now using the 3928 02:00:28,199 --> 02:00:29,460 new input system 3929 02:00:29,460 --> 02:00:31,380 so you can see how by refactoring our 3930 02:00:31,380 --> 02:00:33,179 code to make sure to use the game input 3931 02:00:33,179 --> 02:00:35,040 less when we change from the input 3932 02:00:35,040 --> 02:00:37,139 manager onto the new input system when 3933 02:00:37,139 --> 02:00:38,760 we made that change we did not have to 3934 02:00:38,760 --> 02:00:40,920 touch a player class at all the player 3935 02:00:40,920 --> 02:00:42,780 class just has the game input to get the 3936 02:00:42,780 --> 02:00:44,820 movement vector and does not care what 3937 02:00:44,820 --> 02:00:47,280 system he uses to get them so here we 3938 02:00:47,280 --> 02:00:49,020 have a very practical very excellent 3939 02:00:49,020 --> 02:00:50,460 example of the power of writing good 3940 02:00:50,460 --> 02:00:52,440 clean code because we separated things 3941 02:00:52,440 --> 02:00:53,940 correctly we managed to change something 3942 02:00:53,940 --> 02:00:56,040 completely and not have to make any 3943 02:00:56,040 --> 02:00:57,840 changes on any other class 3944 02:00:57,840 --> 02:00:59,580 so now that we're using the new input 3945 02:00:59,580 --> 02:01:01,739 system let's just quickly see one of the 3946 02:01:01,739 --> 02:01:03,480 main benefits of this system which is 3947 02:01:03,480 --> 02:01:05,880 easily supporting gamepads and more keys 3948 02:01:05,880 --> 02:01:08,040 for example a lot of people like using 3949 02:01:08,040 --> 02:01:09,900 ones but some people also like to use 3950 02:01:09,900 --> 02:01:12,300 the arrow keys with this system that is 3951 02:01:12,300 --> 02:01:14,340 super easy to add so let's go into the 3952 02:01:14,340 --> 02:01:15,719 move what's another one let's add 3953 02:01:15,719 --> 02:01:17,460 another one up down left right composite 3954 02:01:17,460 --> 02:01:20,699 let's call it arrow keys then let's just 3955 02:01:20,699 --> 02:01:22,920 put them so let's listen on the up Arrow 3956 02:01:22,920 --> 02:01:26,159 then over here we've got the down arrow 3957 02:01:26,159 --> 02:01:29,520 then we have the left arrow and finally 3958 02:01:29,520 --> 02:01:31,860 we have the right arrow alright so we've 3959 02:01:31,860 --> 02:01:33,840 got all the arrows and now we don't even 3960 02:01:33,840 --> 02:01:35,639 need to touch any code at all let's just 3961 02:01:35,639 --> 02:01:37,500 make sure to save the ascent which again 3962 02:01:37,500 --> 02:01:39,179 in turn that is going to Auto generate 3963 02:01:39,179 --> 02:01:40,860 the c-sharp class and go into compound 3964 02:01:40,860 --> 02:01:42,840 okay so we don't need to touch any code 3965 02:01:42,840 --> 02:01:45,060 at all let's just hit on play and now if 3966 02:01:45,060 --> 02:01:47,099 I move we're using the ones Keys yep 3967 02:01:47,099 --> 02:01:48,719 still works and if I go into the arrow 3968 02:01:48,719 --> 02:01:51,540 keys yep also still works alright great 3969 02:01:51,540 --> 02:01:53,820 now for another one let's make it for a 3970 02:01:53,820 --> 02:01:56,460 Gamepad so I just connected an Xbox 3971 02:01:56,460 --> 02:01:58,199 controller and we can see over here on 3972 02:01:58,199 --> 02:02:00,420 the log yep the game did identify it so 3973 02:02:00,420 --> 02:02:01,980 this is the new input system in action 3974 02:02:01,980 --> 02:02:04,199 let's once again open up the input 3975 02:02:04,199 --> 02:02:06,360 actions and over here on the Move let's 3976 02:02:06,360 --> 02:02:08,460 add another one and this time let's just 3977 02:02:08,460 --> 02:02:10,920 make it a regular binding and over here 3978 02:02:10,920 --> 02:02:13,320 on the path once again if we want we can 3979 02:02:13,320 --> 02:02:15,119 go down here and specifically find some 3980 02:02:15,119 --> 02:02:17,940 joysticks so you can find any of them or 3981 02:02:17,940 --> 02:02:20,159 once again let's just use in listen now 3982 02:02:20,159 --> 02:02:21,540 I'm just going to move the thumbstick on 3983 02:02:21,540 --> 02:02:23,400 the controller yep there it is I know if 3984 02:02:23,400 --> 02:02:24,780 you wanted you could go specific and 3985 02:02:24,780 --> 02:02:26,460 make it just work with Xbox controllers 3986 02:02:26,460 --> 02:02:28,440 or you can just use the generic left 3987 02:02:28,440 --> 02:02:30,060 stick this will make it work with an 3988 02:02:30,060 --> 02:02:31,980 Xbox controller or a PlayStation or 3989 02:02:31,980 --> 02:02:33,420 really anything so let's go with this 3990 02:02:33,420 --> 02:02:35,280 one and that's it nothing else we need 3991 02:02:35,280 --> 02:02:37,320 to do let's just save the asset and 3992 02:02:37,320 --> 02:02:39,239 that's it we don't need to touch any of 3993 02:02:39,239 --> 02:02:40,920 our code to make our game playable with 3994 02:02:40,920 --> 02:02:43,440 a controller so let's go ahead and test 3995 02:02:43,440 --> 02:02:45,420 so here we are and first of all if I 3996 02:02:45,420 --> 02:02:46,980 move the keys yep song Works move the 3997 02:02:46,980 --> 02:02:48,960 arrow keys yep both of them works and 3998 02:02:48,960 --> 02:02:51,000 now if I use my Gamepad any up there you 3999 02:02:51,000 --> 02:02:53,219 go everything works perfectly alright 4000 02:02:53,219 --> 02:02:55,440 awesome so as you can see this is one of 4001 02:02:55,440 --> 02:02:57,060 the main benefits of the new input 4002 02:02:57,060 --> 02:02:58,800 system it makes handling different 4003 02:02:58,800 --> 02:03:01,739 inputs really super easily as you saw we 4004 02:03:01,739 --> 02:03:03,900 didn't have to touch our code at all we 4005 02:03:03,900 --> 02:03:05,520 just had new bindings and just like that 4006 02:03:05,520 --> 02:03:07,500 our game is playable with all kinds of 4007 02:03:07,500 --> 02:03:08,580 inputs 4008 02:03:08,580 --> 02:03:10,380 so here you can really see just how 4009 02:03:10,380 --> 02:03:12,659 powerful new input system is okay so 4010 02:03:12,659 --> 02:03:14,280 with this our basic character movement 4011 02:03:14,280 --> 02:03:15,840 is working great we can walk around 4012 02:03:15,840 --> 02:03:18,179 everything looks great now in the next 4013 02:03:18,179 --> 02:03:19,920 lecture let's apply some collisions to 4014 02:03:19,920 --> 02:03:22,199 our player 4015 02:03:22,199 --> 02:03:23,820 hey again here's another quick 4016 02:03:23,820 --> 02:03:25,380 intermission I hope you've already 4017 02:03:25,380 --> 02:03:27,599 learned a ton from the course have you 4018 02:03:27,599 --> 02:03:29,040 seen the benefits of writing good clean 4019 02:03:29,040 --> 02:03:30,960 code has the course already helped you 4020 02:03:30,960 --> 02:03:33,060 understand some more advanced concepts I 4021 02:03:33,060 --> 02:03:34,440 really hope the answer is yes to both 4022 02:03:34,440 --> 02:03:36,420 those remember to follow the website 4023 02:03:36,420 --> 02:03:38,159 page as you follow along I won't be 4024 02:03:38,159 --> 02:03:39,719 adding frequently asked questions to 4025 02:03:39,719 --> 02:03:42,179 every lecture if you ever get stuck you 4026 02:03:42,179 --> 02:03:43,619 can just download the project files for 4027 02:03:43,619 --> 02:03:45,960 a lecture and compare with your own and 4028 02:03:45,960 --> 02:03:47,219 definitely check out the related videos 4029 02:03:47,219 --> 02:03:49,199 when I reference them this course is 4030 02:03:49,199 --> 02:03:50,699 focused on making this game but you 4031 02:03:50,699 --> 02:03:52,139 should definitely learn more about some 4032 02:03:52,139 --> 02:03:54,060 of these Concepts in more detail and you 4033 02:03:54,060 --> 02:03:55,320 can learn that in the videos that I 4034 02:03:55,320 --> 02:03:56,940 mentioned by the way if you're watching 4035 02:03:56,940 --> 02:03:59,099 this right now this is the secret con 4036 02:03:59,099 --> 02:04:00,960 loud so go ahead post the time step in 4037 02:04:00,960 --> 02:04:02,940 the comments with a nice monk Emoji I 4038 02:04:02,940 --> 02:04:04,440 want to see how many people make it this 4039 02:04:04,440 --> 02:04:06,900 far okay so that's it for now let's go 4040 02:04:06,900 --> 02:04:08,880 to the next lecture 4041 02:04:08,880 --> 02:04:10,860 hello and welcome I'm your code monkey 4042 02:04:10,860 --> 02:04:12,840 in this lecture we're going to apply 4043 02:04:12,840 --> 02:04:14,400 some collisions to our player movement 4044 02:04:14,400 --> 02:04:17,040 okay so here we have our game so far we 4045 02:04:17,040 --> 02:04:18,480 have our player walking around and 4046 02:04:18,480 --> 02:04:20,520 everything looks pretty good however now 4047 02:04:20,520 --> 02:04:22,199 let's create over here in the hurricane 4048 02:04:22,199 --> 02:04:24,060 let's right click create a brand new 4049 02:04:24,060 --> 02:04:26,639 Cube so there you go let's place it over 4050 02:04:26,639 --> 02:04:30,179 here and push it down okay there's the 4051 02:04:30,179 --> 02:04:33,179 cube make it just a little bit bigger so 4052 02:04:33,179 --> 02:04:34,920 there's the cube and by default it has a 4053 02:04:34,920 --> 02:04:36,480 boxcon leather component so it has 4054 02:04:36,480 --> 02:04:39,000 physics and the player if I move and 4055 02:04:39,000 --> 02:04:40,560 nope there's our issue the player is 4056 02:04:40,560 --> 02:04:42,540 going right through the object now the 4057 02:04:42,540 --> 02:04:44,099 player is not meant to be a ghost so 4058 02:04:44,099 --> 02:04:46,619 let's fix this over here in our player 4059 02:04:46,619 --> 02:04:49,080 script we are hearing the input Vector 4060 02:04:49,080 --> 02:04:50,760 calculating the move Direction and then 4061 02:04:50,760 --> 02:04:52,800 just moving the transform so right now 4062 02:04:52,800 --> 02:04:54,360 we're moving it no matter what now 4063 02:04:54,360 --> 02:04:56,219 before we do that let's first do a test 4064 02:04:56,219 --> 02:04:58,560 to see if any object is in the way and 4065 02:04:58,560 --> 02:05:00,179 how we're going to do that is by firing 4066 02:05:00,179 --> 02:05:02,460 a raycast this one is a physics 4067 02:05:02,460 --> 02:05:04,380 operation that basically fires on laser 4068 02:05:04,380 --> 02:05:06,000 from a certain point towards a certain 4069 02:05:06,000 --> 02:05:07,619 direction and then tells you if it hits 4070 02:05:07,619 --> 02:05:09,840 something how we do that is let's go 4071 02:05:09,840 --> 02:05:12,060 inside the physics class and let's call 4072 02:05:12,060 --> 02:05:14,159 the raycast function 4073 02:05:14,159 --> 02:05:16,260 this one as you can see has many many 4074 02:05:16,260 --> 02:05:18,000 versions of this function with all kinds 4075 02:05:18,000 --> 02:05:19,980 of parameters let's use this one option 4076 02:05:19,980 --> 02:05:22,139 number seven which takes a vector 3 for 4077 02:05:22,139 --> 02:05:23,820 the origin a direction and a max 4078 02:05:23,820 --> 02:05:26,400 distance so first for the origin that is 4079 02:05:26,400 --> 02:05:28,199 from where we want to fire our recast 4080 02:05:28,199 --> 02:05:30,540 let's put the player object in so that's 4081 02:05:30,540 --> 02:05:32,639 transform dot position 4082 02:05:32,639 --> 02:05:34,320 then for the direction this is going to 4083 02:05:34,320 --> 02:05:35,880 be our move Direction so let's use our 4084 02:05:35,880 --> 02:05:37,800 move there and finally for distance 4085 02:05:37,800 --> 02:05:40,260 let's use some kind of player size 4086 02:05:40,260 --> 02:05:42,540 player width something like that 4087 02:05:42,540 --> 02:05:44,340 some lights to find up here a float for 4088 02:05:44,340 --> 02:05:48,800 the player size and put that 0.7 units 4089 02:05:48,900 --> 02:05:50,639 let's try out with the size just like 4090 02:05:50,639 --> 02:05:52,860 this okay so basically this returns a 4091 02:05:52,860 --> 02:05:54,719 Boolean it's going to return true if it 4092 02:05:54,719 --> 02:05:56,400 hits something and funks if nothing is 4093 02:05:56,400 --> 02:05:58,980 in the way so let's just do a bone call 4094 02:05:58,980 --> 02:06:01,980 it can move and basically we can move if 4095 02:06:01,980 --> 02:06:03,719 this raycast doesn't hit anything so we 4096 02:06:03,719 --> 02:06:05,940 can move if this one is false so if the 4097 02:06:05,940 --> 02:06:07,679 raycast is false then can move is going 4098 02:06:07,679 --> 02:06:09,060 to be true 4099 02:06:09,060 --> 02:06:11,219 that's very simple so if we can move 4100 02:06:11,219 --> 02:06:12,900 then we move the transform position 4101 02:06:12,900 --> 02:06:15,480 otherwise we don't okay that's it super 4102 02:06:15,480 --> 02:06:16,920 simple Let's test 4103 02:06:16,920 --> 02:06:18,719 so here we are I can move around and if 4104 02:06:18,719 --> 02:06:20,580 I go towards the cube and nope no longer 4105 02:06:20,580 --> 02:06:22,739 works so I can no longer go inside that 4106 02:06:22,739 --> 02:06:25,980 Cube okay great now in your case if it's 4107 02:06:25,980 --> 02:06:27,239 not working 4108 02:06:27,239 --> 02:06:29,099 first of all make sure that the cube 4109 02:06:29,099 --> 02:06:31,199 make sure it is touching the floor we 4110 02:06:31,199 --> 02:06:33,179 use the transform position as the origin 4111 02:06:33,179 --> 02:06:35,340 which is right on the floor so if the 4112 02:06:35,340 --> 02:06:36,840 box is raised up then you won't be able 4113 02:06:36,840 --> 02:06:38,340 to go through so make sure the cube is 4114 02:06:38,340 --> 02:06:40,020 touching the form also make sure the 4115 02:06:40,020 --> 02:06:42,420 cube has a box on leather component it 4116 02:06:42,420 --> 02:06:43,980 can be any type of calendar but you if 4117 02:06:43,980 --> 02:06:45,420 you made a cube then it should have a 4118 02:06:45,420 --> 02:06:47,340 box layer by default and it should have 4119 02:06:47,340 --> 02:06:49,139 the same shape as the visual 4120 02:06:49,139 --> 02:06:51,480 and also remember that the 2D and the 3D 4121 02:06:51,480 --> 02:06:52,920 physics systems those are completely 4122 02:06:52,920 --> 02:06:54,480 separate they are completely different 4123 02:06:54,480 --> 02:06:56,820 worlds so make sure you're using 3D 4124 02:06:56,820 --> 02:06:58,860 components and not the 2D ones so for 4125 02:06:58,860 --> 02:07:01,260 example if I add boxing weather 2D if I 4126 02:07:01,260 --> 02:07:03,420 add this one then it will not work so 4127 02:07:03,420 --> 02:07:05,099 make sure you're using the 3D and not 4128 02:07:05,099 --> 02:07:07,139 the 2D components same thing over here 4129 02:07:07,139 --> 02:07:08,639 on the script make sure you're using 4130 02:07:08,639 --> 02:07:11,699 physics and not physics 2D also finally 4131 02:07:11,699 --> 02:07:13,199 if you're still having issues make sure 4132 02:07:13,199 --> 02:07:14,820 you check the player position 4133 02:07:14,820 --> 02:07:16,860 again the player should be on a y of 4134 02:07:16,860 --> 02:07:18,840 zero the only thing that might have an 4135 02:07:18,840 --> 02:07:20,400 offset is the player Vision although if 4136 02:07:20,400 --> 02:07:22,020 you're using the same acid me then this 4137 02:07:22,020 --> 02:07:23,820 one should also be on a y of zero so all 4138 02:07:23,820 --> 02:07:26,040 of these on y of zero and then you can 4139 02:07:26,040 --> 02:07:28,320 also check the four by default this one 4140 02:07:28,320 --> 02:07:30,360 has a mesh calendar but if it is exactly 4141 02:07:30,360 --> 02:07:32,219 on yf0 with no rotation then it 4142 02:07:32,219 --> 02:07:34,320 shouldn't cause any issues alternatively 4143 02:07:34,320 --> 02:07:36,000 you can also just disable or remove the 4144 02:07:36,000 --> 02:07:37,560 mesh con leather from before since we're 4145 02:07:37,560 --> 02:07:39,239 not going to need that so with all that 4146 02:07:39,239 --> 02:07:40,679 yep everything works I can move the 4147 02:07:40,679 --> 02:07:42,179 player but I cannot go through solid 4148 02:07:42,179 --> 02:07:45,300 objects alright awesome so it is working 4149 02:07:45,300 --> 02:07:47,760 but for this particular use case a 4150 02:07:47,760 --> 02:07:49,679 recast isn't necessarily the best method 4151 02:07:49,679 --> 02:07:52,320 we should use basically Rick asses like 4152 02:07:52,320 --> 02:07:54,480 I said kind of like a super thin laser 4153 02:07:54,480 --> 02:07:56,460 but as you can see the player visually 4154 02:07:56,460 --> 02:07:59,280 has an actual body shape so the visual 4155 02:07:59,280 --> 02:08:00,719 and logic are using can only in 4156 02:08:00,719 --> 02:08:02,699 different shapes if I go ahead and push 4157 02:08:02,699 --> 02:08:04,320 towards the box you can see it works 4158 02:08:04,320 --> 02:08:07,139 just fine however if the player is a bit 4159 02:08:07,139 --> 02:08:08,880 more off to the side and the center of 4160 02:08:08,880 --> 02:08:10,440 the player right in front of it is not 4161 02:08:10,440 --> 02:08:12,239 the box and I move and yep there you go 4162 02:08:12,239 --> 02:08:14,040 now I am going through the box the 4163 02:08:14,040 --> 02:08:15,420 reason is because the erase accounts 4164 02:08:15,420 --> 02:08:16,560 being fired from the center of the 4165 02:08:16,560 --> 02:08:18,719 player and like I said it's kind of like 4166 02:08:18,719 --> 02:08:20,880 an infinitely thin laser so it has no 4167 02:08:20,880 --> 02:08:22,800 shape so as long as the center of the 4168 02:08:22,800 --> 02:08:24,540 player is not hitting the box and it can 4169 02:08:24,540 --> 02:08:26,699 go through it whereas what we really 4170 02:08:26,699 --> 02:08:28,619 want is for the visual and logic to have 4171 02:08:28,619 --> 02:08:31,139 pretty much the same shape so let's not 4172 02:08:31,139 --> 02:08:33,239 use a raycast over here on the code 4173 02:08:33,239 --> 02:08:35,580 instead of a recast we can use a physics 4174 02:08:35,580 --> 02:08:37,380 query with an actual shape 4175 02:08:37,380 --> 02:08:39,480 there are all kinds of casts you can use 4176 02:08:39,480 --> 02:08:41,219 as you can see all of them with 4177 02:08:41,219 --> 02:08:42,599 different shapes you've got a box cast 4178 02:08:42,599 --> 02:08:44,340 if you want to have a box a capsule if 4179 02:08:44,340 --> 02:08:45,659 you want the capsule or a sphere cast 4180 02:08:45,659 --> 02:08:47,880 all of these were pretty much the exact 4181 02:08:47,880 --> 02:08:50,040 same way except instead of a raycast 4182 02:08:50,040 --> 02:08:51,960 which fires an infinitely thin laser 4183 02:08:51,960 --> 02:08:53,760 these are going to have an actual shape 4184 02:08:53,760 --> 02:08:55,679 and for player controllers for the most 4185 02:08:55,679 --> 02:08:57,179 part you really want to be using a 4186 02:08:57,179 --> 02:08:58,619 capsule cast that's usually the 4187 02:08:58,619 --> 02:09:00,780 generally accepted player shape although 4188 02:09:00,780 --> 02:09:02,400 alternatively a boxcast also can work 4189 02:09:02,400 --> 02:09:04,380 very well in our case let's just go with 4190 02:09:04,380 --> 02:09:06,719 a simple capsule cast this one to define 4191 02:09:06,719 --> 02:09:09,599 a capsule has a 0.1 and a 0.2 by the way 4192 02:09:09,599 --> 02:09:11,159 if you have no idea what is a capsule 4193 02:09:11,159 --> 02:09:12,179 then we can go over here in the 4194 02:09:12,179 --> 02:09:13,860 hurricane let's right click create a 3D 4195 02:09:13,860 --> 02:09:15,960 object let's make it a capsule and there 4196 02:09:15,960 --> 02:09:17,219 you go this is the capsule it's kind of 4197 02:09:17,219 --> 02:09:19,679 like a stretch sphere so it has around 4198 02:09:19,679 --> 02:09:21,239 the top round bottom and then over here 4199 02:09:21,239 --> 02:09:23,099 in the middle it's just a cylinder and 4200 02:09:23,099 --> 02:09:25,020 over here for the raycast takes a 0.1 4201 02:09:25,020 --> 02:09:27,239 and a 0.2 so that is going to be the 4202 02:09:27,239 --> 02:09:28,800 bottom of the capsule and the top of the 4203 02:09:28,800 --> 02:09:30,840 capsule basically with those two points 4204 02:09:30,840 --> 02:09:32,280 we can Define the height of the actual 4205 02:09:32,280 --> 02:09:34,199 capsule okay so let's just get rid of 4206 02:09:34,199 --> 02:09:36,599 this capsule let's just lean it and over 4207 02:09:36,599 --> 02:09:39,599 in the code let's put those now 4.1 it 4208 02:09:39,599 --> 02:09:41,219 is indeed going to be the transformed 4209 02:09:41,219 --> 02:09:42,719 opposition since that is the point at 4210 02:09:42,719 --> 02:09:45,780 the bottom and for the second point 4211 02:09:45,780 --> 02:09:47,340 for this one it's essentially going to 4212 02:09:47,340 --> 02:09:49,619 be the player head so we can take the 4213 02:09:49,619 --> 02:09:51,420 transform dot position so this is the 4214 02:09:51,420 --> 02:09:53,460 bottom and we can essentially just lift 4215 02:09:53,460 --> 02:09:56,639 it up so let's add a vector 3 dot up and 4216 02:09:56,639 --> 02:09:58,320 multiply by some kind of player height 4217 02:09:58,320 --> 02:10:00,780 let's define up here a float for the 4218 02:10:00,780 --> 02:10:02,159 player height 4219 02:10:02,159 --> 02:10:04,260 and I tested it in the editor and the 4220 02:10:04,260 --> 02:10:06,179 player is about T and Stone 4221 02:10:06,179 --> 02:10:07,679 so over here let's go ahead and move it 4222 02:10:07,679 --> 02:10:09,000 up by that much 4223 02:10:09,000 --> 02:10:12,119 okay so next we want the radius so this 4224 02:10:12,119 --> 02:10:13,560 is pretty much the player size that we 4225 02:10:13,560 --> 02:10:15,300 defined previously so let's use the same 4226 02:10:15,300 --> 02:10:16,199 thing 4227 02:10:16,199 --> 02:10:17,580 but as always let's make sure to write 4228 02:10:17,580 --> 02:10:19,679 good clean code since now we are 4229 02:10:19,679 --> 02:10:21,480 referring to a radius let's actually 4230 02:10:21,480 --> 02:10:23,880 rename this to be a bit more clear and 4231 02:10:23,880 --> 02:10:25,320 by the way here's a quick Visual Studio 4232 02:10:25,320 --> 02:10:28,320 tip you can right click on a symbol and 4233 02:10:28,320 --> 02:10:29,940 then you can click on the rename option 4234 02:10:29,940 --> 02:10:32,040 alternatively use a shortcut Ctrl R 4235 02:10:32,040 --> 02:10:34,139 control R if you do that then now you 4236 02:10:34,139 --> 02:10:35,639 can change the name so for example on 4237 02:10:35,639 --> 02:10:37,860 player radius and note how it changes 4238 02:10:37,860 --> 02:10:40,020 every single instance of that variable 4239 02:10:40,020 --> 02:10:42,060 so this renaming feature is extremely 4240 02:10:42,060 --> 02:10:44,099 useful always make sure to rename 4241 02:10:44,099 --> 02:10:45,360 something if you find the name that 4242 02:10:45,360 --> 02:10:47,699 works best Okay so let's rename this to 4243 02:10:47,699 --> 02:10:50,159 play radius then we have Direction so 4244 02:10:50,159 --> 02:10:51,719 that is as usual going to be our move 4245 02:10:51,719 --> 02:10:52,739 Direction 4246 02:10:52,739 --> 02:10:54,300 and then finally we have the move 4247 02:10:54,300 --> 02:10:56,460 distance for that we can use the actual 4248 02:10:56,460 --> 02:10:58,679 move distance so that is going to be the 4249 02:10:58,679 --> 02:11:00,599 movement speed multiplied by time dot 4250 02:11:00,599 --> 02:11:01,739 all the time 4251 02:11:01,739 --> 02:11:03,960 so I just find here a fluid for the move 4252 02:11:03,960 --> 02:11:05,880 distance 4253 02:11:05,880 --> 02:11:07,619 and you should see that just move speed 4254 02:11:07,619 --> 02:11:10,560 time dot Delta time we have the move 4255 02:11:10,560 --> 02:11:12,420 distance and we use it both in here as 4256 02:11:12,420 --> 02:11:13,860 well as down here 4257 02:11:13,860 --> 02:11:16,800 okay so here we have our cancel cast the 4258 02:11:16,800 --> 02:11:18,420 rest logic is exactly the same so if 4259 02:11:18,420 --> 02:11:19,920 this one is false that means it didn't 4260 02:11:19,920 --> 02:11:21,599 hit anything so if it didn't hit 4261 02:11:21,599 --> 02:11:23,340 anything then we can move and then we 4262 02:11:23,340 --> 02:11:26,159 move the transform okay let's test and 4263 02:11:26,159 --> 02:11:27,719 over here now if I go towards the box 4264 02:11:27,719 --> 02:11:29,280 and the Epson works is only the same as 4265 02:11:29,280 --> 02:11:30,900 previously that's great and now if I go 4266 02:11:30,900 --> 02:11:32,520 towards the end and make sure that the 4267 02:11:32,520 --> 02:11:34,320 center is not hitting the box and I try 4268 02:11:34,320 --> 02:11:36,239 to move forward and nope now we no 4269 02:11:36,239 --> 02:11:38,099 longer go inside the cube so even on the 4270 02:11:38,099 --> 02:11:39,780 edges everything still works perfectly 4271 02:11:39,780 --> 02:11:43,320 alright awesome so it works it looks 4272 02:11:43,320 --> 02:11:45,599 good but it also is a little bit janky 4273 02:11:45,599 --> 02:11:47,760 for example let's stretch this cube out 4274 02:11:47,760 --> 02:11:50,880 a little bit so let's put it just on One 4275 02:11:50,880 --> 02:11:53,159 Direction so stretches like this let's 4276 02:11:53,159 --> 02:11:55,800 see now if I move towards it then nope I 4277 02:11:55,800 --> 02:11:57,239 cannot go through it so that is correct 4278 02:11:57,239 --> 02:11:59,400 and if I move left and right yep that's 4279 02:11:59,400 --> 02:12:01,679 also correct that works however if I now 4280 02:12:01,679 --> 02:12:03,780 press W and D at the same time in order 4281 02:12:03,780 --> 02:12:05,940 to move diagonally and nope right now it 4282 02:12:05,940 --> 02:12:07,860 does not move the reason is because the 4283 02:12:07,860 --> 02:12:09,360 diagonal Vector that one is indeed 4284 02:12:09,360 --> 02:12:11,580 hitting the collider but usually in 4285 02:12:11,580 --> 02:12:13,380 games when you move diagonally and you 4286 02:12:13,380 --> 02:12:14,880 cannot move in when Direction then it 4287 02:12:14,880 --> 02:12:16,440 tries to essentially hug the wall and 4288 02:12:16,440 --> 02:12:19,199 move around it so if I press wnd it 4289 02:12:19,199 --> 02:12:20,520 should essentially be moving straight to 4290 02:12:20,520 --> 02:12:22,800 the right so let's solve that so here in 4291 02:12:22,800 --> 02:12:24,300 our code we're making our Capstone cast 4292 02:12:24,300 --> 02:12:26,520 okay that's great then we need to test 4293 02:12:26,520 --> 02:12:29,699 if we cannot move so let's see if we 4294 02:12:29,699 --> 02:12:33,960 cannot move so it can move is false 4295 02:12:33,960 --> 02:12:36,179 if so then that means we cannot move 4296 02:12:36,179 --> 02:12:38,960 towards this direction 4297 02:12:40,020 --> 02:12:41,639 and if we can then essentially we 4298 02:12:41,639 --> 02:12:43,260 basically want to split the movement 4299 02:12:43,260 --> 02:12:45,719 Direction and just move on the X or just 4300 02:12:45,719 --> 02:12:48,360 on the Z so first let's attempt just the 4301 02:12:48,360 --> 02:12:49,739 X movement 4302 02:12:49,739 --> 02:12:53,280 so attempt only X movement let's create 4303 02:12:53,280 --> 02:12:55,139 a new vector 3. 4304 02:12:55,139 --> 02:12:57,540 let's call it move the year X and we 4305 02:12:57,540 --> 02:12:59,639 make a new Vector three let's take in 4306 02:12:59,639 --> 02:13:02,280 the move there dot X then zero on all 4307 02:13:02,280 --> 02:13:03,599 the other so we only want the test 4308 02:13:03,599 --> 02:13:05,520 moving in the X Direction 4309 02:13:05,520 --> 02:13:07,380 and then let's do literally the same 4310 02:13:07,380 --> 02:13:10,260 thing so let's get our can move try to 4311 02:13:10,260 --> 02:13:12,179 move under this direction so let's go 4312 02:13:12,179 --> 02:13:14,460 inside a move there move there on the X 4313 02:13:14,460 --> 02:13:16,679 so we do that capsule cast 4314 02:13:16,679 --> 02:13:19,079 and if we can move then that means we 4315 02:13:19,079 --> 02:13:22,079 can move only on the x-axis 4316 02:13:22,079 --> 02:13:25,800 so can move only on the X 4317 02:13:25,800 --> 02:13:27,360 and if so let's set the move there 4318 02:13:27,360 --> 02:13:30,119 equals the move there X 4319 02:13:30,119 --> 02:13:31,920 so if we can move them down here when we 4320 02:13:31,920 --> 02:13:33,179 use the move there we're going to move 4321 02:13:33,179 --> 02:13:34,500 only on the X 4322 02:13:34,500 --> 02:13:36,300 and if we cannot move 4323 02:13:36,300 --> 02:13:38,460 then that means we cannot move only on 4324 02:13:38,460 --> 02:13:39,659 the X 4325 02:13:39,659 --> 02:13:42,300 and if so then let's attempt only Zed 4326 02:13:42,300 --> 02:13:44,699 movement so over here again let's do the 4327 02:13:44,699 --> 02:13:46,560 exact same thing so let's copy this 4328 02:13:46,560 --> 02:13:48,840 let's just change this one so instead of 4329 02:13:48,840 --> 02:13:50,520 move to your X we've got moved here on 4330 02:13:50,520 --> 02:13:53,340 the Zen so over here we use 0 on the X 0 4331 02:13:53,340 --> 02:13:55,800 and Y and axis we moved here and get the 4332 02:13:55,800 --> 02:13:58,079 Zen then let's use this movement 4333 02:13:58,079 --> 02:14:00,360 Direction over there and finally the 4334 02:14:00,360 --> 02:14:03,480 same thing so if we can move 4335 02:14:03,480 --> 02:14:05,880 then that means we can move only on the 4336 02:14:05,880 --> 02:14:08,340 Zen and let's set the move there equals 4337 02:14:08,340 --> 02:14:10,260 the move there Z 4338 02:14:10,260 --> 02:14:13,260 and if not then we cannot move in any 4339 02:14:13,260 --> 02:14:14,820 direction 4340 02:14:14,820 --> 02:14:17,040 okay so that's it now this might seem a 4341 02:14:17,040 --> 02:14:18,420 bit confusing but it becomes a lot more 4342 02:14:18,420 --> 02:14:20,340 clear When You See It In Action again 4343 02:14:20,340 --> 02:14:21,780 remember the scenario we're trying to 4344 02:14:21,780 --> 02:14:24,000 solve which is when moving diagonally so 4345 02:14:24,000 --> 02:14:25,560 for example when we're moving forwards 4346 02:14:25,560 --> 02:14:27,719 into the right if we do that then let's 4347 02:14:27,719 --> 02:14:28,860 say this one is going to hit something 4348 02:14:28,860 --> 02:14:31,199 so we cannot move so if we are trying to 4349 02:14:31,199 --> 02:14:33,179 move both forwards and to the right then 4350 02:14:33,179 --> 02:14:34,320 we're going to only attempt the X 4351 02:14:34,320 --> 02:14:35,639 movement so we're only going to try 4352 02:14:35,639 --> 02:14:37,440 moving to the right and then we're going 4353 02:14:37,440 --> 02:14:39,000 to see yep going to the right that does 4354 02:14:39,000 --> 02:14:40,679 work so we can move and we're going to 4355 02:14:40,679 --> 02:14:42,719 move just to the right all right so 4356 02:14:42,719 --> 02:14:44,159 let's test and see if all of this is 4357 02:14:44,159 --> 02:14:46,199 working all right so here we are and if 4358 02:14:46,199 --> 02:14:47,760 I move straight to the wall and nope 4359 02:14:47,760 --> 02:14:49,199 there is 11 so I cannot move anymore 4360 02:14:49,199 --> 02:14:51,780 okay great now if I move just left and 4361 02:14:51,780 --> 02:14:53,520 just right and it does work now if I 4362 02:14:53,520 --> 02:14:55,739 press W and then D and if there you go 4363 02:14:55,739 --> 02:14:57,960 now it does hug the wall and continues 4364 02:14:57,960 --> 02:15:00,420 to move same thing if I go on the left 4365 02:15:00,420 --> 02:15:02,400 over here if I press D no I cannot go 4366 02:15:02,400 --> 02:15:04,320 through it now if I press D and S at the 4367 02:15:04,320 --> 02:15:05,639 same time and there you go it hugs the 4368 02:15:05,639 --> 02:15:07,679 wall and moves around so now our 4369 02:15:07,679 --> 02:15:09,840 controller is much more easy much more 4370 02:15:09,840 --> 02:15:11,040 understandable 4371 02:15:11,040 --> 02:15:13,500 okay so this is great now this is one of 4372 02:15:13,500 --> 02:15:14,760 those tiny things that makes your 4373 02:15:14,760 --> 02:15:16,079 character controller feel much more 4374 02:15:16,079 --> 02:15:18,540 responsive so that's great however we 4375 02:15:18,540 --> 02:15:21,000 also do see one more issue right now you 4376 02:15:21,000 --> 02:15:22,619 can see that I'm right next to the wall 4377 02:15:22,619 --> 02:15:24,719 and if I press A and D then look at that 4378 02:15:24,719 --> 02:15:27,239 I'm moving with this spin however now if 4379 02:15:27,239 --> 02:15:29,639 I press wnd look at that now I'm moving 4380 02:15:29,639 --> 02:15:31,139 diagonally and it's actually moving 4381 02:15:31,139 --> 02:15:33,360 slower basically this is the same issue 4382 02:15:33,360 --> 02:15:34,920 that we saw previously where we had to 4383 02:15:34,920 --> 02:15:36,599 normalize the input so we didn't go 4384 02:15:36,599 --> 02:15:38,579 faster in diagonals basically now we 4385 02:15:38,579 --> 02:15:40,679 have the opposite problem since we are 4386 02:15:40,679 --> 02:15:42,300 normalizing the vector we are cutting 4387 02:15:42,300 --> 02:15:44,699 down on the left right vector and with 4388 02:15:44,699 --> 02:15:45,900 that basically if we are moving 4389 02:15:45,900 --> 02:15:47,699 diagonally then we are essentially going 4390 02:15:47,699 --> 02:15:49,860 slower whereas if I stop moving diagonal 4391 02:15:49,860 --> 02:15:51,300 and just move left right it moves at a 4392 02:15:51,300 --> 02:15:53,219 different speed that solution for this 4393 02:15:53,219 --> 02:15:55,679 is really super simple over here in our 4394 02:15:55,679 --> 02:15:57,300 code when we are constructing the move 4395 02:15:57,300 --> 02:15:59,159 to your X and move the ears in when we 4396 02:15:59,159 --> 02:16:01,020 do this very simple let's just normalize 4397 02:16:01,020 --> 02:16:03,239 it so if this one is less than one then 4398 02:16:03,239 --> 02:16:04,619 it won't be going into one so let's 4399 02:16:04,619 --> 02:16:07,020 normalize that one and down okay that's 4400 02:16:07,020 --> 02:16:09,119 it let's test and now from here move 4401 02:16:09,119 --> 02:16:10,739 forward and hug the wall on left right 4402 02:16:10,739 --> 02:16:12,540 yep does work and if I stop moving 4403 02:16:12,540 --> 02:16:14,520 diagonally just going left right yep all 4404 02:16:14,520 --> 02:16:16,500 still works with the exact same speed 4405 02:16:16,500 --> 02:16:19,500 all right awesome okay so that's really 4406 02:16:19,500 --> 02:16:21,480 it as you can see it's super simple to 4407 02:16:21,480 --> 02:16:23,159 add Collision detection to your movement 4408 02:16:23,159 --> 02:16:25,380 scripts you just do a physics query to 4409 02:16:25,380 --> 02:16:26,880 testify our character should move and 4410 02:16:26,880 --> 02:16:28,739 just move it by the way if you want to 4411 02:16:28,739 --> 02:16:30,420 learn more about collisions and physics 4412 02:16:30,420 --> 02:16:32,580 queries there's a bunch of interesting 4413 02:16:32,580 --> 02:16:34,379 videos that you can watch for example 4414 02:16:34,379 --> 02:16:36,299 one is on various methods of finding a 4415 02:16:36,299 --> 02:16:38,580 Target then another one is on various 4416 02:16:38,580 --> 02:16:40,920 methods of handling projectiles and 4417 02:16:40,920 --> 02:16:42,240 finally another one is a very quick 4418 02:16:42,240 --> 02:16:43,920 checklist on why collisions are not 4419 02:16:43,920 --> 02:16:45,959 working basically there's lots of really 4420 02:16:45,959 --> 02:16:47,040 interesting things you can do with 4421 02:16:47,040 --> 02:16:48,240 physics so make sure you understand 4422 02:16:48,240 --> 02:16:50,820 these functions okay so now that we have 4423 02:16:50,820 --> 02:16:52,620 all of this working let's first just 4424 02:16:52,620 --> 02:16:54,718 clean up our scene so over here our 4425 02:16:54,718 --> 02:16:56,340 default Cube we don't want this so let's 4426 02:16:56,340 --> 02:16:58,558 just get rid of this and with this we 4427 02:16:58,558 --> 02:17:00,000 are ready to build our first kitchen 4428 02:17:00,000 --> 02:17:01,859 counter and let's do that in the next 4429 02:17:01,859 --> 02:17:03,420 lecture 4430 02:17:03,420 --> 02:17:05,340 hello and welcome I'm your code monkey 4431 02:17:05,340 --> 02:17:07,138 in this lecture we're going to begin 4432 02:17:07,138 --> 02:17:09,058 building one of our main game mechanics 4433 02:17:09,058 --> 02:17:10,859 we're going to make a kitchen counter 4434 02:17:10,859 --> 02:17:12,660 and handle the logic for the player to 4435 02:17:12,660 --> 02:17:14,519 be able to interact with that counter 4436 02:17:14,519 --> 02:17:16,558 okay so let's begin by making our 4437 02:17:16,558 --> 02:17:18,540 kitchen counter and just like we did 4438 02:17:18,540 --> 02:17:20,340 when we made the player let's first make 4439 02:17:20,340 --> 02:17:21,780 an empty game object and place the 4440 02:17:21,780 --> 02:17:23,820 visual inside of it so let's right click 4441 02:17:23,820 --> 02:17:25,080 on the hierarchy and create an empty 4442 02:17:25,080 --> 02:17:27,299 game object call this the clear counter 4443 02:17:27,299 --> 02:17:28,978 so it's going to be clear on top so we 4444 02:17:28,978 --> 02:17:31,500 can place and pick up objects let's make 4445 02:17:31,500 --> 02:17:33,179 sure to reset our transform so let's put 4446 02:17:33,179 --> 02:17:35,099 it on zero zero zero let's move it just 4447 02:17:35,099 --> 02:17:36,840 a little bit just so it's not exactly on 4448 02:17:36,840 --> 02:17:39,299 top of the player okay now inside let's 4449 02:17:39,299 --> 02:17:40,799 add the visual so let's go inside the 4450 02:17:40,799 --> 02:17:42,959 assets folder and then over here we've 4451 02:17:42,959 --> 02:17:44,638 got the prefabs visuals and inside we've 4452 02:17:44,638 --> 02:17:46,558 got the counters visuals and over here 4453 02:17:46,558 --> 02:17:48,420 let's find the clear counter Vision so 4454 02:17:48,420 --> 02:17:50,040 let's go ahead and drag it inside the 4455 02:17:50,040 --> 02:17:52,019 game object again make sure the 4456 02:17:52,019 --> 02:17:53,820 challenge visual is on zero zero zero 4457 02:17:53,820 --> 02:17:56,160 the unlockable position okay great now 4458 02:17:56,160 --> 02:17:58,019 just like we did in the online lecture 4459 02:17:58,019 --> 02:18:00,120 where we added Collision detection that 4460 02:18:00,120 --> 02:18:01,439 shouldn't already be working by default 4461 02:18:01,439 --> 02:18:02,939 but in order for it to work it needs a 4462 02:18:02,939 --> 02:18:05,218 physics line either however note how the 4463 02:18:05,218 --> 02:18:07,138 vision over here there's no collider and 4464 02:18:07,138 --> 02:18:08,638 inside there's no collider there's only 4465 02:18:08,638 --> 02:18:10,620 visuals again this is the same thing 4466 02:18:10,620 --> 02:18:12,179 that relates to separating logic and 4467 02:18:12,179 --> 02:18:14,700 visuals basically the visual prefab this 4468 02:18:14,700 --> 02:18:16,620 one only has visual components so only 4469 02:18:16,620 --> 02:18:19,019 meshes animations and that sort of thing 4470 02:18:19,019 --> 02:18:20,939 and the main Parent Game object this is 4471 02:18:20,939 --> 02:18:22,200 the one that is going to have all of the 4472 02:18:22,200 --> 02:18:24,599 logic components set means any kind of 4473 02:18:24,599 --> 02:18:26,099 scripts Behavior as well as any 4474 02:18:26,099 --> 02:18:27,299 colliders 4475 02:18:27,299 --> 02:18:29,040 so over here on the parent game object 4476 02:18:29,040 --> 02:18:31,260 let's add new component let's find a box 4477 02:18:31,260 --> 02:18:33,840 Collider again make sure you add a box 4478 02:18:33,840 --> 02:18:36,299 of leather not a boxing leather 2D and I 4479 02:18:36,299 --> 02:18:37,679 chose a boxing Ledges because this is 4480 02:18:37,679 --> 02:18:39,179 the shape that makes most sense for our 4481 02:18:39,179 --> 02:18:41,340 counter and now let's scale the boxing 4482 02:18:41,340 --> 02:18:43,019 leather again that's the boxing ladder 4483 02:18:43,019 --> 02:18:44,459 not the transform so leave that one with 4484 02:18:44,459 --> 02:18:46,500 a scale of one one that's good and over 4485 02:18:46,500 --> 02:18:48,120 here on the box leather for the size 4486 02:18:48,120 --> 02:18:50,760 let's put it up with a size that fits 4487 02:18:50,760 --> 02:18:54,718 the visual so 1.5 1.5 1.5 and finally we 4488 02:18:54,718 --> 02:18:56,879 just need to lift it up a bit over here 4489 02:18:56,879 --> 02:18:58,080 on the scene view you can see those 4490 02:18:58,080 --> 02:19:00,599 little green tiny lines these refer to 4491 02:19:00,599 --> 02:19:02,939 the boxing leather shape so let's lift 4492 02:19:02,939 --> 02:19:04,439 it up by a little bit in order to make 4493 02:19:04,439 --> 02:19:06,540 it perfect let's put it up by 0.5 on the 4494 02:19:06,540 --> 02:19:08,519 Y alright so there you go that one does 4495 02:19:08,519 --> 02:19:10,138 have the perfect shape 4496 02:19:10,138 --> 02:19:11,879 if we test just like this it should 4497 02:19:11,879 --> 02:19:13,920 already be working it's okay so here's 4498 02:19:13,920 --> 02:19:15,478 my player and if I move towards it and 4499 02:19:15,478 --> 02:19:17,398 yep there you go it does work so it is a 4500 02:19:17,398 --> 02:19:19,439 solid object I cannot go through it okay 4501 02:19:19,439 --> 02:19:20,459 great 4502 02:19:20,459 --> 02:19:22,799 let's just visually rotate the calendar 4503 02:19:22,799 --> 02:19:24,780 so let's do that and again for rotation 4504 02:19:24,780 --> 02:19:26,398 let's make sure we rotate the apparent 4505 02:19:26,398 --> 02:19:28,500 game object and not the visual we want 4506 02:19:28,500 --> 02:19:30,120 the visual to be on rotation zero zero 4507 02:19:30,120 --> 02:19:31,620 zero okay great so on the parent game 4508 02:19:31,620 --> 02:19:33,840 object let's just rotate it around by 4509 02:19:33,840 --> 02:19:35,519 the way here's a quick empty tap if you 4510 02:19:35,519 --> 02:19:37,558 want to rotate hold down control and 4511 02:19:37,558 --> 02:19:39,660 then click to rotate and now instead of 4512 02:19:39,660 --> 02:19:41,879 rotating on every angle it goes on a 15 4513 02:19:41,879 --> 02:19:44,340 angle increment so just hold down this 4514 02:19:44,340 --> 02:19:46,138 way you can easily get it to 180 degrees 4515 02:19:46,138 --> 02:19:48,120 so it's just for fun just make it face 4516 02:19:48,120 --> 02:19:50,160 the player okay great so now let's 4517 02:19:50,160 --> 02:19:52,080 interact with this counter and doing 4518 02:19:52,080 --> 02:19:53,939 this is actually super simple 4519 02:19:53,939 --> 02:19:55,979 we already learned how to do a raycast 4520 02:19:55,979 --> 02:19:57,420 to handle collisions and for 4521 02:19:57,420 --> 02:19:59,040 interactions that's exactly the same 4522 02:19:59,040 --> 02:19:59,939 thing 4523 02:19:59,939 --> 02:20:02,399 so let's go into our player script and 4524 02:20:02,399 --> 02:20:03,960 we're going to do a recast to handle 4525 02:20:03,960 --> 02:20:04,740 that 4526 02:20:04,740 --> 02:20:07,260 but before we do let's organize our code 4527 02:20:07,260 --> 02:20:08,760 here let's make a proper function to 4528 02:20:08,760 --> 02:20:10,260 handle our movement 4529 02:20:10,260 --> 02:20:12,060 so let's make it private since this is 4530 02:20:12,060 --> 02:20:13,920 going to be in local function return 4531 02:20:13,920 --> 02:20:17,040 void and call it handle movement 4532 02:20:17,040 --> 02:20:19,200 and then inside let's put all of this 4533 02:20:19,200 --> 02:20:21,359 code so let's copy all this put it in 4534 02:20:21,359 --> 02:20:23,100 there and then on update we simply call 4535 02:20:23,100 --> 02:20:25,859 this function okay great and now let's 4536 02:20:25,859 --> 02:20:27,540 make another function so private void 4537 02:20:27,540 --> 02:20:31,340 let's call it handle interactions 4538 02:20:33,240 --> 02:20:35,340 and we just call this function on our 4539 02:20:35,340 --> 02:20:37,800 update okay great everything is much 4540 02:20:37,800 --> 02:20:40,380 more organized so now here let's do a 4541 02:20:40,380 --> 02:20:41,819 raycast 4542 02:20:41,819 --> 02:20:44,160 so once again go inside physics do a 4543 02:20:44,160 --> 02:20:45,180 raycast 4544 02:20:45,180 --> 02:20:46,680 for the origin let's start on 4545 02:20:46,680 --> 02:20:48,540 transform.position 4546 02:20:48,540 --> 02:20:50,160 for this obviously we want the move 4547 02:20:50,160 --> 02:20:52,200 Direction so an approach would be to 4548 02:20:52,200 --> 02:20:54,180 make this a film variable sorted up here 4549 02:20:54,180 --> 02:20:55,740 so that way we can access it in both 4550 02:20:55,740 --> 02:20:58,200 functions however if you remember how we 4551 02:20:58,200 --> 02:20:59,939 handled the whole issue with the 4552 02:20:59,939 --> 02:21:01,500 diagonals basically we're modifying the 4553 02:21:01,500 --> 02:21:03,899 move Direction so for moving diagonally 4554 02:21:03,899 --> 02:21:05,760 then this one modifies to only move left 4555 02:21:05,760 --> 02:21:07,680 or right we don't want that for the 4556 02:21:07,680 --> 02:21:09,060 interaction we want pretty much the 4557 02:21:09,060 --> 02:21:10,500 exact same one even if it's pointing 4558 02:21:10,500 --> 02:21:12,960 towards a solid object so let's not make 4559 02:21:12,960 --> 02:21:14,580 the same member variable only reuse it 4560 02:21:14,580 --> 02:21:16,500 instead let's just grab it again create 4561 02:21:16,500 --> 02:21:18,899 it again over here so we get it and we 4562 02:21:18,899 --> 02:21:20,160 want this one even if it's pointing 4563 02:21:20,160 --> 02:21:21,899 towards a solid object so let's use this 4564 02:21:21,899 --> 02:21:23,460 as our move Direction 4565 02:21:23,460 --> 02:21:25,800 and now for the distance let's define a 4566 02:21:25,800 --> 02:21:27,000 fixed distance 4567 02:21:27,000 --> 02:21:29,460 so something like two units would work 4568 02:21:29,460 --> 02:21:31,380 and also here's another very important 4569 02:21:31,380 --> 02:21:32,939 lesson with regards to writing good 4570 02:21:32,939 --> 02:21:34,680 clean code so you would think to write 4571 02:21:34,680 --> 02:21:36,300 code like this so let's put the two 4572 02:21:36,300 --> 02:21:38,100 right in here that would work everything 4573 02:21:38,100 --> 02:21:40,439 would work perfectly but then let's say 4574 02:21:40,439 --> 02:21:42,240 you get back to this code after one week 4575 02:21:42,240 --> 02:21:44,640 would you remember what this 2f means 4576 02:21:44,640 --> 02:21:46,560 the answer is probably not you would 4577 02:21:46,560 --> 02:21:48,420 probably very easily forget exactly what 4578 02:21:48,420 --> 02:21:50,460 this means so because of that you should 4579 02:21:50,460 --> 02:21:52,200 never use numbers directly in the code 4580 02:21:52,200 --> 02:21:54,479 like this instead you can either make a 4581 02:21:54,479 --> 02:21:56,040 field appear if you want to make it 4582 02:21:56,040 --> 02:21:57,240 customizable 4583 02:21:57,240 --> 02:21:59,040 or much simpler is actually what we 4584 02:21:59,040 --> 02:22:00,780 already did previously so let's define a 4585 02:22:00,780 --> 02:22:03,000 local variable with a proper name 4586 02:22:03,000 --> 02:22:05,640 so let's define a float and this one is 4587 02:22:05,640 --> 02:22:07,080 going to represent our interact distance 4588 02:22:07,080 --> 02:22:08,939 so let's call it exactly that interact 4589 02:22:08,939 --> 02:22:11,700 with the distance and let's put 2f and 4590 02:22:11,700 --> 02:22:13,200 over here instead of using a number 4591 02:22:13,200 --> 02:22:15,720 let's just use that variable now if we 4592 02:22:15,720 --> 02:22:17,340 were to get back to this code after a 4593 02:22:17,340 --> 02:22:18,899 long time it would be extremely clear 4594 02:22:18,899 --> 02:22:21,000 what this parameter represents 4595 02:22:21,000 --> 02:22:23,040 the technical term for what we did here 4596 02:22:23,040 --> 02:22:24,840 is called Magic numbers and I've also 4597 02:22:24,840 --> 02:22:26,100 covered them in detail in another quick 4598 02:22:26,100 --> 02:22:26,939 video 4599 02:22:26,939 --> 02:22:29,040 but as I always remember very simply 4600 02:22:29,040 --> 02:22:31,020 never use magic numbers 4601 02:22:31,020 --> 02:22:33,060 okay so with this we have our recast 4602 02:22:33,060 --> 02:22:35,000 it's pointing forwards for this distance 4603 02:22:35,000 --> 02:22:37,500 but this is actually not very useful 4604 02:22:37,500 --> 02:22:39,120 because the rickhouse this one only 4605 02:22:39,120 --> 02:22:41,520 returns a bullion so all this tells us 4606 02:22:41,520 --> 02:22:43,319 is if there's something in front or not 4607 02:22:43,319 --> 02:22:45,720 it does not actually get as the actual 4608 02:22:45,720 --> 02:22:48,300 object reference so for that let's use a 4609 02:22:48,300 --> 02:22:49,560 different version of the raycast 4610 02:22:49,560 --> 02:22:51,479 function so as you can see we've got all 4611 02:22:51,479 --> 02:22:53,399 kinds of versions in order to get the 4612 02:22:53,399 --> 02:22:55,319 object reference let's use this version 4613 02:22:55,319 --> 02:22:57,479 right here this one which has an out 4614 02:22:57,479 --> 02:23:00,180 parameter for a raycast hit note the out 4615 02:23:00,180 --> 02:23:02,520 keyword here this is important this 4616 02:23:02,520 --> 02:23:04,200 means that this is an output parameter 4617 02:23:04,200 --> 02:23:06,240 whereas the other parameters those are 4618 02:23:06,240 --> 02:23:07,740 all essentially inputs that you give to 4619 02:23:07,740 --> 02:23:10,080 the function whereas this output this is 4620 02:23:10,080 --> 02:23:11,220 basically a value that the function 4621 02:23:11,220 --> 02:23:13,140 outputs so let's use this so we've got 4622 02:23:13,140 --> 02:23:15,180 the origin we've got Direction then 4623 02:23:15,180 --> 02:23:17,220 we've got the rake asset in order to use 4624 02:23:17,220 --> 02:23:18,960 it we need to make sure to write the out 4625 02:23:18,960 --> 02:23:20,700 keyword here and then also very 4626 02:23:20,700 --> 02:23:22,620 important we need to write the type 4627 02:23:22,620 --> 02:23:25,319 so let's call it break asset and then 4628 02:23:25,319 --> 02:23:27,960 the name so let's call it break asset 4629 02:23:27,960 --> 02:23:29,520 basically what we're doing here is 4630 02:23:29,520 --> 02:23:31,200 essentially defining a variable of this 4631 02:23:31,200 --> 02:23:33,359 type with this name we're defining it 4632 02:23:33,359 --> 02:23:34,319 and giving it to the function 4633 02:23:34,319 --> 02:23:36,060 immediately so we can use it afterwards 4634 02:23:36,060 --> 02:23:37,920 if you don't include the type if you 4635 02:23:37,920 --> 02:23:39,300 just include the name then you get an 4636 02:23:39,300 --> 02:23:41,280 error because this name Rick has said 4637 02:23:41,280 --> 02:23:43,319 this was never defined alternatively you 4638 02:23:43,319 --> 02:23:44,700 can Define it before you pass it in so 4639 02:23:44,700 --> 02:23:47,520 over here you can do recast it recast it 4640 02:23:47,520 --> 02:23:49,260 and just like this it works because you 4641 02:23:49,260 --> 02:23:50,819 are defining it here and using it here 4642 02:23:50,819 --> 02:23:52,680 but in order to make the code a bit more 4643 02:23:52,680 --> 02:23:54,720 compact you can just Define it here in 4644 02:23:54,720 --> 02:23:56,640 the same place where you get it okay so 4645 02:23:56,640 --> 02:23:58,380 let's use this and with this the 4646 02:23:58,380 --> 02:24:00,060 function still returns just a Boolean so 4647 02:24:00,060 --> 02:24:02,580 just hit something or not but then we've 4648 02:24:02,580 --> 02:24:05,040 got the rake asset output this will be 4649 02:24:05,040 --> 02:24:06,600 filmed with data from the Collision if 4650 02:24:06,600 --> 02:24:07,979 we do hit something 4651 02:24:07,979 --> 02:24:09,899 we can inspect this to see what that it 4652 02:24:09,899 --> 02:24:11,580 contains so you can right click on top 4653 02:24:11,580 --> 02:24:13,500 of the type and then go to definition 4654 02:24:13,500 --> 02:24:16,080 and up here we do see the definition for 4655 02:24:16,080 --> 02:24:18,120 the rake acid struct you can see this is 4656 02:24:18,120 --> 02:24:19,859 a structure to get information back from 4657 02:24:19,859 --> 02:24:22,200 a raycast you can inspect this to see 4658 02:24:22,200 --> 02:24:23,700 all of the kinds of things that this one 4659 02:24:23,700 --> 02:24:26,040 returns for example you have a vector 3 4660 02:24:26,040 --> 02:24:27,899 point for the impact point in workspace 4661 02:24:27,899 --> 02:24:30,240 where the ray actually had a collider it 4662 02:24:30,240 --> 02:24:31,979 can get the normal of the surface and so 4663 02:24:31,979 --> 02:24:33,479 on so you can get all kinds of things 4664 02:24:33,479 --> 02:24:35,640 for a use case what we want is to 4665 02:24:35,640 --> 02:24:37,319 identify the object that we hit and for 4666 02:24:37,319 --> 02:24:39,180 that we can use the transform so it's 4667 02:24:39,180 --> 02:24:40,740 going to be the transform of the rigid 4668 02:24:40,740 --> 02:24:42,720 body or the collider that was hit so 4669 02:24:42,720 --> 02:24:44,340 let's just do a quick test if we hit 4670 02:24:44,340 --> 02:24:45,960 something lets you unlock on that object 4671 02:24:45,960 --> 02:24:48,540 so let's do an if so if this one is true 4672 02:24:48,540 --> 02:24:50,640 then that means we hit something so if 4673 02:24:50,640 --> 02:24:52,979 so let's do a debug unlock go inside the 4674 02:24:52,979 --> 02:24:55,560 rake asset and log the transform okay so 4675 02:24:55,560 --> 02:24:56,819 like this we should be able to see on 4676 02:24:56,819 --> 02:24:58,800 the console if we do hit something let's 4677 02:24:58,800 --> 02:25:00,780 also do an ounce just to be able to 4678 02:25:00,780 --> 02:25:03,240 easily see when we hit something so on 4679 02:25:03,240 --> 02:25:06,300 else let's just log an empty Dash and in 4680 02:25:06,300 --> 02:25:07,620 our game in order to make sure that our 4681 02:25:07,620 --> 02:25:09,000 Collision is working that we are 4682 02:25:09,000 --> 02:25:10,680 correctly detecting it let's just 4683 02:25:10,680 --> 02:25:12,479 duplicate this object but before we do 4684 02:25:12,479 --> 02:25:14,760 let's make this a proper prefab if you 4685 02:25:14,760 --> 02:25:16,200 have an object of a certain tab that you 4686 02:25:16,200 --> 02:25:17,819 want to create multiple instances of it 4687 02:25:17,819 --> 02:25:19,620 you should be using a prefab rather than 4688 02:25:19,620 --> 02:25:21,300 just duplicate an object that way with 4689 02:25:21,300 --> 02:25:22,920 the prefab if you make any changes to 4690 02:25:22,920 --> 02:25:24,720 that prefab it applies to all of the 4691 02:25:24,720 --> 02:25:26,520 copies of that prefab 4692 02:25:26,520 --> 02:25:28,380 so let's first make this one a prefab 4693 02:25:28,380 --> 02:25:30,359 and again since this is our first prefab 4694 02:25:30,359 --> 02:25:32,100 let's first make a nice folder to keep 4695 02:25:32,100 --> 02:25:34,140 things organized so folder for our 4696 02:25:34,140 --> 02:25:36,780 prefabs and to make game module prefab 4697 02:25:36,780 --> 02:25:38,399 is super simple you just click and drag 4698 02:25:38,399 --> 02:25:40,080 directly from the hierarchy and drop it 4699 02:25:40,080 --> 02:25:41,580 inside the folder there you go there's 4700 02:25:41,580 --> 02:25:43,439 our prefront and now let's just 4701 02:25:43,439 --> 02:25:45,000 duplicate this make sure it has a 4702 02:25:45,000 --> 02:25:46,319 different name so it has one so that's 4703 02:25:46,319 --> 02:25:48,300 enough with this we should be able to 4704 02:25:48,300 --> 02:25:49,859 see it just for testing let's put it 4705 02:25:49,859 --> 02:25:51,600 just off to the side okay so let's see 4706 02:25:51,600 --> 02:25:53,340 so here we are in the console we see a 4707 02:25:53,340 --> 02:25:54,960 dash so by default we are not hitting 4708 02:25:54,960 --> 02:25:57,240 anything okay so that makes sense now if 4709 02:25:57,240 --> 02:25:58,979 I move towards this object and if there 4710 02:25:58,979 --> 02:26:00,479 you go it does I didn't find that object 4711 02:26:00,479 --> 02:26:02,340 and if I stop moving it stops 4712 02:26:02,340 --> 02:26:03,899 identifying okay great now if I move 4713 02:26:03,899 --> 02:26:05,700 towards this one and if there we go this 4714 02:26:05,700 --> 02:26:07,200 is the one with the name of one and this 4715 02:26:07,200 --> 02:26:08,939 is the one with the name of none all 4716 02:26:08,939 --> 02:26:10,920 right awesome so just like this we are 4717 02:26:10,920 --> 02:26:12,780 correctly identifying what object is in 4718 02:26:12,780 --> 02:26:16,140 front except we also have an issue so if 4719 02:26:16,140 --> 02:26:17,640 I move towards the object then yep it 4720 02:26:17,640 --> 02:26:19,740 does work but if I stop moving once I'm 4721 02:26:19,740 --> 02:26:21,479 still facing that object right now it's 4722 02:26:21,479 --> 02:26:23,220 returning none now the reason for that 4723 02:26:23,220 --> 02:26:24,600 is because of the move data that we're 4724 02:26:24,600 --> 02:26:26,700 using here if we're not moving in any 4725 02:26:26,700 --> 02:26:28,140 direction then basically this Vector 4726 02:26:28,140 --> 02:26:30,180 won't be zero zero zero so we're going 4727 02:26:30,180 --> 02:26:31,740 to be firing a raycast towards no 4728 02:26:31,740 --> 02:26:33,300 direction at all so obviously it's not 4729 02:26:33,300 --> 02:26:35,399 going to hit anything the solution to 4730 02:26:35,399 --> 02:26:37,080 that is super simple we just need to 4731 02:26:37,080 --> 02:26:38,640 keep track of the last interact move 4732 02:26:38,640 --> 02:26:40,859 Direction so let's go up here to find a 4733 02:26:40,859 --> 02:26:42,660 film for that so let's make a private 4734 02:26:42,660 --> 02:26:45,060 let's make a vector 3 and call it the 4735 02:26:45,060 --> 02:26:47,280 last interact Direction 4736 02:26:47,280 --> 02:26:48,899 and then down here when we have our 4737 02:26:48,899 --> 02:26:50,100 handle interaction so we get the 4738 02:26:50,100 --> 02:26:52,080 movement here okay that's great so then 4739 02:26:52,080 --> 02:26:54,660 we just check if the move direction is 4740 02:26:54,660 --> 02:26:57,420 different from Vector 3.0 by the way 4741 02:26:57,420 --> 02:26:59,460 this is a constant a shorthand for zero 4742 02:26:59,460 --> 02:27:01,500 zero zero so if it is not zero then that 4743 02:27:01,500 --> 02:27:05,060 means we are moving in some Direction 4744 02:27:05,819 --> 02:27:07,500 so so let's set the unless in direct 4745 02:27:07,500 --> 02:27:09,540 direction to this move Direction and 4746 02:27:09,540 --> 02:27:11,220 basically if it is not if move there is 4747 02:27:11,220 --> 02:27:12,660 zero then we are not going to modify 4748 02:27:12,660 --> 02:27:14,100 this so this one is only going to 4749 02:27:14,100 --> 02:27:15,540 contain the unless interact Direction 4750 02:27:15,540 --> 02:27:17,340 and then down here instead of using the 4751 02:27:17,340 --> 02:27:18,960 move Direction Let's just use this one 4752 02:27:18,960 --> 02:27:21,180 so that way even when we stop moving we 4753 02:27:21,180 --> 02:27:22,500 are still going to be using the last 4754 02:27:22,500 --> 02:27:24,479 indirect Direction okay so with this 4755 02:27:24,479 --> 02:27:26,700 let's test so here we are and if I move 4756 02:27:26,700 --> 02:27:28,439 towards it yep it works and if I stop 4757 02:27:28,439 --> 02:27:30,899 moving and yep it still works alright 4758 02:27:30,899 --> 02:27:32,399 great so we can move towards it Point 4759 02:27:32,399 --> 02:27:34,740 towards a certain object and then yep it 4760 02:27:34,740 --> 02:27:37,140 still works okay great now let's 4761 02:27:37,140 --> 02:27:39,359 actually interact with this counter and 4762 02:27:39,359 --> 02:27:41,040 to do that let's make a class for the 4763 02:27:41,040 --> 02:27:43,140 counters itself so let's make a new 4764 02:27:43,140 --> 02:27:45,120 script in the UC sharp script let's come 4765 02:27:45,120 --> 02:27:48,859 with the same name so clear counter 4766 02:27:49,140 --> 02:27:50,939 okay there's our script 4767 02:27:50,939 --> 02:27:53,580 now very importantly for attaching the 4768 02:27:53,580 --> 02:27:55,680 script remember that we have two 4769 02:27:55,680 --> 02:27:58,200 instances of our prefab if you just 4770 02:27:58,200 --> 02:27:59,939 select it in the heart key and you just 4771 02:27:59,939 --> 02:28:01,979 drag it on there if you do that then 4772 02:28:01,979 --> 02:28:03,600 you're not actually adding this script 4773 02:28:03,600 --> 02:28:05,640 to the prefab itself you're only adding 4774 02:28:05,640 --> 02:28:07,319 it to this specific instance of that 4775 02:28:07,319 --> 02:28:09,420 prefab so if you look at this one yep it 4776 02:28:09,420 --> 02:28:11,160 has a script but this other one which is 4777 02:28:11,160 --> 02:28:12,780 a copy of the same prefab this one does 4778 02:28:12,780 --> 02:28:14,520 not have it also over here on the 4779 02:28:14,520 --> 02:28:16,260 inspector you can see the little script 4780 02:28:16,260 --> 02:28:18,780 icon has a nice little plus that means 4781 02:28:18,780 --> 02:28:20,220 it is something that you are adding on 4782 02:28:20,220 --> 02:28:22,020 top of the prefab so that means this 4783 02:28:22,020 --> 02:28:23,880 script is not present on the base prefab 4784 02:28:23,880 --> 02:28:26,220 basically this is not what we want we 4785 02:28:26,220 --> 02:28:28,380 don't want just this object to have this 4786 02:28:28,380 --> 02:28:30,600 script we want all instances of this 4787 02:28:30,600 --> 02:28:32,760 prefab to have this script so instead 4788 02:28:32,760 --> 02:28:35,040 let's get rid of this one from here we 4789 02:28:35,040 --> 02:28:37,500 want to modify the prefab itself so one 4790 02:28:37,500 --> 02:28:39,120 way to do that is to select the prefab 4791 02:28:39,120 --> 02:28:40,740 on the project window so here it is the 4792 02:28:40,740 --> 02:28:43,020 actual prefab and now we can drag the 4793 02:28:43,020 --> 02:28:45,300 script on there so that works or another 4794 02:28:45,300 --> 02:28:47,100 alternative is something like the prefab 4795 02:28:47,100 --> 02:28:49,800 in the hierarchy and on the inspector 4796 02:28:49,800 --> 02:28:51,240 over here we see a nice button to open 4797 02:28:51,240 --> 02:28:53,160 the prefab and if we actually go into 4798 02:28:53,160 --> 02:28:54,660 scene view then we can see what that 4799 02:28:54,660 --> 02:28:56,819 does so with the object selected so this 4800 02:28:56,819 --> 02:28:58,859 is an instance of that prefab but if we 4801 02:28:58,859 --> 02:29:00,359 click on open then essentially we are 4802 02:29:00,359 --> 02:29:01,859 opening and we are working inside the 4803 02:29:01,859 --> 02:29:04,260 prefab so now if we make sure to add our 4804 02:29:04,260 --> 02:29:06,359 script and let's go back outside this 4805 02:29:06,359 --> 02:29:08,340 prefab so on the top left corner over 4806 02:29:08,340 --> 02:29:10,200 here we can see where we are so we were 4807 02:29:10,200 --> 02:29:11,819 inside our scene and then we are inside 4808 02:29:11,819 --> 02:29:14,340 the clear counter prefab so if we click 4809 02:29:14,340 --> 02:29:16,080 on the scenes we can go back now it 4810 02:29:16,080 --> 02:29:17,399 tells us that we made some changes to 4811 02:29:17,399 --> 02:29:19,740 the prefab so let's save them and if we 4812 02:29:19,740 --> 02:29:21,120 add that script and we can see both 4813 02:29:21,120 --> 02:29:22,920 instances of the prefab they both have 4814 02:29:22,920 --> 02:29:24,660 the same script and we can see on there 4815 02:29:24,660 --> 02:29:26,640 on the icon that this is not an override 4816 02:29:26,640 --> 02:29:28,620 this is an actual script at on the base 4817 02:29:28,620 --> 02:29:30,899 prefab so whenever working with prefabs 4818 02:29:30,899 --> 02:29:32,280 always make very sure that you are 4819 02:29:32,280 --> 02:29:33,960 adding it on the right place 4820 02:29:33,960 --> 02:29:35,760 if you want something on the base prefab 4821 02:29:35,760 --> 02:29:37,140 make sure you either add it on the 4822 02:29:37,140 --> 02:29:39,540 prefab itself or go inside the prefab by 4823 02:29:39,540 --> 02:29:41,340 double clicking on it or select an 4824 02:29:41,340 --> 02:29:42,960 instance in there and open to go inside 4825 02:29:42,960 --> 02:29:44,399 the prefab so always keep in mind 4826 02:29:44,399 --> 02:29:46,380 different switches between a prefab and 4827 02:29:46,380 --> 02:29:48,600 an instance of a prefab okay so we have 4828 02:29:48,600 --> 02:29:50,700 our script let's open it and over here 4829 02:29:50,700 --> 02:29:52,319 let's just make one super simple 4830 02:29:52,319 --> 02:29:53,340 function 4831 02:29:53,340 --> 02:29:55,260 so let's make it public because we want 4832 02:29:55,260 --> 02:29:57,300 to call this from our player class let's 4833 02:29:57,300 --> 02:30:00,899 return void and just call it interact 4834 02:30:00,899 --> 02:30:02,880 okay that's it super simple for now 4835 02:30:02,880 --> 02:30:05,160 let's just do a debug.log and just say 4836 02:30:05,160 --> 02:30:06,180 interact 4837 02:30:06,180 --> 02:30:08,640 okay so that's it and now over here on 4838 02:30:08,640 --> 02:30:10,319 the player when we have our handle 4839 02:30:10,319 --> 02:30:12,540 interactions function so interact we do 4840 02:30:12,540 --> 02:30:14,220 our raycast and we find out if we hit 4841 02:30:14,220 --> 02:30:16,380 something so when we do the first thing 4842 02:30:16,380 --> 02:30:18,240 that we should do is identify what this 4843 02:30:18,240 --> 02:30:20,340 transform is so is this something just 4844 02:30:20,340 --> 02:30:22,740 like a dumb Cube or is it an actual 4845 02:30:22,740 --> 02:30:24,899 counter now when it comes to identifying 4846 02:30:24,899 --> 02:30:26,819 things this is another place where a lot 4847 02:30:26,819 --> 02:30:28,380 of beginner tutorials will teach you to 4848 02:30:28,380 --> 02:30:30,660 use the unity attack system so that's 4849 02:30:30,660 --> 02:30:32,220 over here in the editor when you select 4850 02:30:32,220 --> 02:30:34,260 any object over here in the inspector 4851 02:30:34,260 --> 02:30:35,340 you can see a tag so you can see 4852 02:30:35,340 --> 02:30:36,960 untagged and you can add all kinds of 4853 02:30:36,960 --> 02:30:38,880 tags this is something that a lot of 4854 02:30:38,880 --> 02:30:41,460 beginner tutorials teach but Unity tags 4855 02:30:41,460 --> 02:30:43,380 are horrible you should never never use 4856 02:30:43,380 --> 02:30:45,600 them I covered in more detail why that 4857 02:30:45,600 --> 02:30:48,060 is in the advanced concepts video the 4858 02:30:48,060 --> 02:30:49,740 main reason is because of well pretty 4859 02:30:49,740 --> 02:30:51,000 much the same thing that I mentioned a 4860 02:30:51,000 --> 02:30:52,740 while ago when we were handling animator 4861 02:30:52,740 --> 02:30:54,840 parameters so you were doing this and I 4862 02:30:54,840 --> 02:30:56,520 talked about how this one takes a string 4863 02:30:56,520 --> 02:30:58,260 and how strings are horrible way for 4864 02:30:58,260 --> 02:31:00,359 identifying objects they are very 4865 02:31:00,359 --> 02:31:02,220 brittle very error prone it's very easy 4866 02:31:02,220 --> 02:31:04,319 to make mistakes and tags have the exact 4867 02:31:04,319 --> 02:31:06,359 same problems because tags are strings 4868 02:31:06,359 --> 02:31:08,520 so we do not want to use tags to 4869 02:31:08,520 --> 02:31:10,740 identify objects instead over here on 4870 02:31:10,740 --> 02:31:12,000 the player script let's use a different 4871 02:31:12,000 --> 02:31:14,160 method for identifying objects and the 4872 02:31:14,160 --> 02:31:15,899 best way to do that is to Simply get our 4873 02:31:15,899 --> 02:31:17,399 counter component 4874 02:31:17,399 --> 02:31:19,800 so we have our transform and then from 4875 02:31:19,800 --> 02:31:21,420 inside that transform we can call the 4876 02:31:21,420 --> 02:31:24,060 function try get component this one then 4877 02:31:24,060 --> 02:31:26,160 takes the type of component and again 4878 02:31:26,160 --> 02:31:28,439 note how this is an out parameter so 4879 02:31:28,439 --> 02:31:30,240 let's put out and we want to test if 4880 02:31:30,240 --> 02:31:32,040 this is a type clear counter so clear 4881 02:31:32,040 --> 02:31:34,740 counter and call it clear counter 4882 02:31:34,740 --> 02:31:36,359 and this one basically does the same 4883 02:31:36,359 --> 02:31:38,100 thing as a recast so it returns a 4884 02:31:38,100 --> 02:31:40,020 Boolean so either true or false 4885 02:31:40,020 --> 02:31:42,240 so if this one is true then that means 4886 02:31:42,240 --> 02:31:44,399 that object has that component so over 4887 02:31:44,399 --> 02:31:47,580 here we know has clear counter 4888 02:31:47,580 --> 02:31:49,080 by the way if you're not familiar with 4889 02:31:49,080 --> 02:31:50,880 tryget component this is pretty much the 4890 02:31:50,880 --> 02:31:52,800 same thing as the regular get component 4891 02:31:52,800 --> 02:31:54,780 except it automatically handles the null 4892 02:31:54,780 --> 02:31:55,859 check for you 4893 02:31:55,859 --> 02:31:57,840 so if we just did this it's exactly the 4894 02:31:57,840 --> 02:32:00,300 same thing as this so you do an if 4895 02:32:00,300 --> 02:32:02,819 recast it what's X is a transform get 4896 02:32:02,819 --> 02:32:05,359 component 4897 02:32:06,600 --> 02:32:10,760 component of type clear counter 4898 02:32:10,920 --> 02:32:12,960 naturally this one is not inside now but 4899 02:32:12,960 --> 02:32:14,640 let's store this 4900 02:32:14,640 --> 02:32:16,680 well your counter equals this then you 4901 02:32:16,680 --> 02:32:19,020 do if this one is not known 4902 02:32:19,020 --> 02:32:22,439 then we know has a clear counter 4903 02:32:22,439 --> 02:32:24,300 so basically what we have up here is the 4904 02:32:24,300 --> 02:32:25,560 exact same thing that we have down here 4905 02:32:25,560 --> 02:32:27,359 so just using trigate component it's 4906 02:32:27,359 --> 02:32:29,160 just a bit more Compact and I find much 4907 02:32:29,160 --> 02:32:30,960 easier to read than to always get 4908 02:32:30,960 --> 02:32:32,580 component and test if it is not null 4909 02:32:32,580 --> 02:32:34,500 over here we just have one function with 4910 02:32:34,500 --> 02:32:35,640 a nice out parameter and everything 4911 02:32:35,640 --> 02:32:37,680 works perfectly so that's the try get 4912 02:32:37,680 --> 02:32:39,180 component I much prefer that method so 4913 02:32:39,180 --> 02:32:41,399 let's use that by the way on the trackit 4914 02:32:41,399 --> 02:32:43,080 component over here you can see it has a 4915 02:32:43,080 --> 02:32:44,819 type inside some angle brackets 4916 02:32:44,819 --> 02:32:46,859 basically these are called c-sharp 4917 02:32:46,859 --> 02:32:49,200 generics these are an extremely powerful 4918 02:32:49,200 --> 02:32:51,899 c-sharp tool I have a dedicated video on 4919 02:32:51,899 --> 02:32:53,340 them and I've used them in tons of 4920 02:32:53,340 --> 02:32:54,899 videos definitely go ahead and learn 4921 02:32:54,899 --> 02:32:57,060 about them basically this lets you write 4922 02:32:57,060 --> 02:32:58,859 code that works with many classes not 4923 02:32:58,859 --> 02:33:00,899 just one specific type in this case the 4924 02:33:00,899 --> 02:33:02,760 target component can work with any type 4925 02:33:02,760 --> 02:33:03,960 of component 4926 02:33:03,960 --> 02:33:05,939 so it can be Unity built-in components 4927 02:33:05,939 --> 02:33:07,200 or it can be components that you made 4928 02:33:07,200 --> 02:33:09,120 yourself then if it finds a type it 4929 02:33:09,120 --> 02:33:11,520 returns true so for right now it's not 4930 02:33:11,520 --> 02:33:13,859 strictly necessary to know the specifics 4931 02:33:13,859 --> 02:33:16,020 about how c-sharp generics work but 4932 02:33:16,020 --> 02:33:17,340 definitely make sure you add that video 4933 02:33:17,340 --> 02:33:18,899 to your queue and watch it afterwards 4934 02:33:18,899 --> 02:33:20,880 c-sharp generics are an extremely useful 4935 02:33:20,880 --> 02:33:23,100 c-sharp feature okay so we do this and 4936 02:33:23,100 --> 02:33:24,600 basically if we are inside of here then 4937 02:33:24,600 --> 02:33:26,580 we know this object has a clear counter 4938 02:33:26,580 --> 02:33:28,140 and we have our clear counter reference 4939 02:33:28,140 --> 02:33:29,819 so over here it's super simple let's 4940 02:33:29,819 --> 02:33:32,040 just call the interact function 4941 02:33:32,040 --> 02:33:34,080 alright so that's really it let's just 4942 02:33:34,080 --> 02:33:35,520 get ready else we no longer want that 4943 02:33:35,520 --> 02:33:36,960 log so we should be able to see unlock 4944 02:33:36,960 --> 02:33:38,939 whenever we call our interact in a 4945 02:33:38,939 --> 02:33:41,220 counter alright so here we are and if I 4946 02:33:41,220 --> 02:33:42,840 move around okay that's good over here 4947 02:33:42,840 --> 02:33:44,760 the console is empty all right now if I 4948 02:33:44,760 --> 02:33:46,080 move towards the counter if there you go 4949 02:33:46,080 --> 02:33:47,580 I'm interacting with it and if I move 4950 02:33:47,580 --> 02:33:48,780 towards this one if there you go 4951 02:33:48,780 --> 02:33:50,760 interacting all right great so with this 4952 02:33:50,760 --> 02:33:52,680 we are correctly identifying the object 4953 02:33:52,680 --> 02:33:54,899 and interacting with it now let's just 4954 02:33:54,899 --> 02:33:57,180 do one final thing over here we are 4955 02:33:57,180 --> 02:33:59,640 doing a recast to find the counter 4956 02:33:59,640 --> 02:34:01,560 and right now we are doing a raycast 4957 02:34:01,560 --> 02:34:03,840 towards any object that has any kind of 4958 02:34:03,840 --> 02:34:05,040 physics calendar 4959 02:34:05,040 --> 02:34:06,600 so maybe that's our counter or maybe 4960 02:34:06,600 --> 02:34:09,359 just a random wall for example if we had 4961 02:34:09,359 --> 02:34:11,040 an invisible wall in front of our 4962 02:34:11,040 --> 02:34:13,080 counter then this code would not work 4963 02:34:13,080 --> 02:34:14,819 that's because this raycast and this 4964 02:34:14,819 --> 02:34:17,220 raycast set it only Returns the very 4965 02:34:17,220 --> 02:34:19,260 first object that it does hit so if the 4966 02:34:19,260 --> 02:34:20,819 counter was behind the wall then the 4967 02:34:20,819 --> 02:34:22,439 brake acid object here would be a 4968 02:34:22,439 --> 02:34:24,479 reference to that long object perhaps 4969 02:34:24,479 --> 02:34:26,580 that's what you want or perhaps not in 4970 02:34:26,580 --> 02:34:28,080 that scenario one thing you can do is 4971 02:34:28,080 --> 02:34:30,060 instead of using recast you can use the 4972 02:34:30,060 --> 02:34:32,220 function raycast all 4973 02:34:32,220 --> 02:34:33,840 and difference for this one is instead 4974 02:34:33,840 --> 02:34:35,580 of returning just a Boeing just true or 4975 02:34:35,580 --> 02:34:37,620 false instead it returns an array of all 4976 02:34:37,620 --> 02:34:39,240 of the objects that it hit with that 4977 02:34:39,240 --> 02:34:40,979 raycast then you could cycle through 4978 02:34:40,979 --> 02:34:43,319 them and identify the object so that's 4979 02:34:43,319 --> 02:34:45,720 one approach or another option is over 4980 02:34:45,720 --> 02:34:47,399 here on the recast 4981 02:34:47,399 --> 02:34:50,220 if we look at these function versions We 4982 02:34:50,220 --> 02:34:51,899 can see that some of them has what it's 4983 02:34:51,899 --> 02:34:54,240 called a layer mask basically you can 4984 02:34:54,240 --> 02:34:56,399 set a certain game object to a specific 4985 02:34:56,399 --> 02:34:58,500 layer and then if you're using layer 4986 02:34:58,500 --> 02:35:00,060 mask then you can make sure this recast 4987 02:35:00,060 --> 02:35:01,979 will only hit objects within that layer 4988 02:35:01,979 --> 02:35:04,140 anything not on that layer will be 4989 02:35:04,140 --> 02:35:06,300 ignored for that recast this is super 4990 02:35:06,300 --> 02:35:08,520 useful so let's learn how it works for 4991 02:35:08,520 --> 02:35:10,620 layer mask we can go up here and Define 4992 02:35:10,620 --> 02:35:12,780 a type of layer mask so let's make 4993 02:35:12,780 --> 02:35:15,120 another serialized field private let's 4994 02:35:15,120 --> 02:35:17,520 make it of type layer mask let's call it 4995 02:35:17,520 --> 02:35:20,580 the counters layer mask 4996 02:35:20,580 --> 02:35:22,560 okay so we have this and then down here 4997 02:35:22,560 --> 02:35:25,439 when we have our recast let's use it so 4998 02:35:25,439 --> 02:35:27,180 let's find the function that matches up 4999 02:35:27,180 --> 02:35:29,640 these parameters with the layer mask so 5000 02:35:29,640 --> 02:35:31,920 here it is we have the origin then we 5001 02:35:31,920 --> 02:35:33,540 have Direction Drake acid the max 5002 02:35:33,540 --> 02:35:35,700 distance and then finally we have our 5003 02:35:35,700 --> 02:35:37,080 layer mask and let's use our counters 5004 02:35:37,080 --> 02:35:39,540 layer mask okay great now back in the 5005 02:35:39,540 --> 02:35:41,880 editor let's select our player game 5006 02:35:41,880 --> 02:35:43,920 object and yep there we see our field of 5007 02:35:43,920 --> 02:35:45,960 type layer mask and you can see how we 5008 02:35:45,960 --> 02:35:48,060 can select all kinds of layers and how 5009 02:35:48,060 --> 02:35:49,560 we set these layers to an object is 5010 02:35:49,560 --> 02:35:51,780 let's just select our clear counter 5011 02:35:51,780 --> 02:35:53,819 although again we want to make sure that 5012 02:35:53,819 --> 02:35:55,859 this change applies to all encounters 5013 02:35:55,859 --> 02:35:57,720 not just this one specific instance so 5014 02:35:57,720 --> 02:35:59,880 let's go inside the prefab and over here 5015 02:35:59,880 --> 02:36:02,040 we've got a Film Forum layer and you can 5016 02:36:02,040 --> 02:36:03,420 see we've got a bunch of default layers 5017 02:36:03,420 --> 02:36:05,100 and then we can add some more so let's 5018 02:36:05,100 --> 02:36:07,080 add some layers and over here let's go 5019 02:36:07,080 --> 02:36:09,120 to the first empty one and let's call it 5020 02:36:09,120 --> 02:36:11,280 counters okay we've added the layers so 5021 02:36:11,280 --> 02:36:13,560 let's go back select our object and now 5022 02:36:13,560 --> 02:36:14,819 on the layer let's put it on the 5023 02:36:14,819 --> 02:36:16,979 counters now it asks you if you want to 5024 02:36:16,979 --> 02:36:18,720 modify the layer for all Channel objects 5025 02:36:18,720 --> 02:36:21,060 now since we made sure to keep the Dean 5026 02:36:21,060 --> 02:36:22,680 logic and physics components only on the 5027 02:36:22,680 --> 02:36:24,720 parent object let's just modify this one 5028 02:36:24,720 --> 02:36:26,340 and leave the other ones on the default 5029 02:36:26,340 --> 02:36:28,439 so let's just modify this object only 5030 02:36:28,439 --> 02:36:30,600 okay so with that our counter is now on 5031 02:36:30,600 --> 02:36:32,220 the counters layer let's leave the 5032 02:36:32,220 --> 02:36:33,960 prefab make sure to save it okay great 5033 02:36:33,960 --> 02:36:35,760 and now if we go back into the player 5034 02:36:35,760 --> 02:36:37,200 and over here on the counters layer mask 5035 02:36:37,200 --> 02:36:39,300 yep we do see the counters layer so 5036 02:36:39,300 --> 02:36:41,340 let's just click the selected by the way 5037 02:36:41,340 --> 02:36:43,080 this drop down menu can actually select 5038 02:36:43,080 --> 02:36:45,240 multiple so you can select all kinds of 5039 02:36:45,240 --> 02:36:47,280 layers so this is multi-select but we 5040 02:36:47,280 --> 02:36:49,080 only want to counter so only like this 5041 02:36:49,080 --> 02:36:52,020 and just like this if we do test and if 5042 02:36:52,020 --> 02:36:53,340 I move towards it and if there you go 5043 02:36:53,340 --> 02:36:55,439 get the nice interact on both them so 5044 02:36:55,439 --> 02:36:56,760 everything still works is only the same 5045 02:36:56,760 --> 02:36:58,680 but now if we had another physics on 5046 02:36:58,680 --> 02:37:00,120 leather in front of it it would still 5047 02:37:00,120 --> 02:37:01,859 work because we're using a layer mask to 5048 02:37:01,859 --> 02:37:03,660 only recast against counter objects 5049 02:37:03,660 --> 02:37:06,180 alright great now I should point out 5050 02:37:06,180 --> 02:37:08,040 another way to work with layers is with 5051 02:37:08,040 --> 02:37:10,319 something called a bit mask that's a bit 5052 02:37:10,319 --> 02:37:12,120 more advanced usually the layer mask is 5053 02:37:12,120 --> 02:37:14,040 much easier to follow but if you want to 5054 02:37:14,040 --> 02:37:15,420 learn about bitmask go ahead and watch 5055 02:37:15,420 --> 02:37:17,460 that video and also another quick note 5056 02:37:17,460 --> 02:37:19,080 in this game we're only going to 5057 02:37:19,080 --> 02:37:20,819 interact with one single object type 5058 02:37:20,819 --> 02:37:22,740 it's only going to be a counter even 5059 02:37:22,740 --> 02:37:23,880 though we're going to have multiple 5060 02:37:23,880 --> 02:37:26,280 types of counters but for games where 5061 02:37:26,280 --> 02:37:27,540 you want to interact with multiple 5062 02:37:27,540 --> 02:37:29,520 objects like for example having an 5063 02:37:29,520 --> 02:37:31,319 interact action to talk with an NPC 5064 02:37:31,319 --> 02:37:33,240 another one to open a door or push a 5065 02:37:33,240 --> 02:37:35,160 button for those kinds of multiple 5066 02:37:35,160 --> 02:37:36,600 interactions to build the system like 5067 02:37:36,600 --> 02:37:38,399 that make sure you look into my how to 5068 02:37:38,399 --> 02:37:40,560 interact with objects video it covers 5069 02:37:40,560 --> 02:37:42,120 how to do all of that how to interact 5070 02:37:42,120 --> 02:37:44,280 with all kinds of objects it's all based 5071 02:37:44,280 --> 02:37:45,780 on c-sharp interfaces which we're 5072 02:37:45,780 --> 02:37:47,280 actually going to use in a few lectures 5073 02:37:47,280 --> 02:37:49,200 and also have a dedicated video on that 5074 02:37:49,200 --> 02:37:51,120 topic so keep following this course but 5075 02:37:51,120 --> 02:37:53,220 then make sure to watch those videos add 5076 02:37:53,220 --> 02:37:54,600 them to your watch list and make sure 5077 02:37:54,600 --> 02:37:56,520 you do watch them watch out how to 5078 02:37:56,520 --> 02:37:58,439 interact video it is something that is 5079 02:37:58,439 --> 02:37:59,939 necessary in so many games and most 5080 02:37:59,939 --> 02:38:01,500 tutorials don't actually teach you the 5081 02:38:01,500 --> 02:38:03,300 correct way of doing it anyway so back 5082 02:38:03,300 --> 02:38:05,220 in our game we are correctly identifying 5083 02:38:05,220 --> 02:38:07,620 and interacting with each counter but 5084 02:38:07,620 --> 02:38:09,180 obviously we don't want to interact 5085 02:38:09,180 --> 02:38:11,100 automatically just like this instead we 5086 02:38:11,100 --> 02:38:12,960 want to press a nice button to interact 5087 02:38:12,960 --> 02:38:14,340 so that means we're going to need to 5088 02:38:14,340 --> 02:38:16,560 create an interact input action so let's 5089 02:38:16,560 --> 02:38:19,380 do all of that in the next lecture 5090 02:38:19,380 --> 02:38:21,300 hello and welcome I'm your code monkey 5091 02:38:21,300 --> 02:38:23,520 in this lecture we're going to create a 5092 02:38:23,520 --> 02:38:25,620 proper interact input action and in 5093 02:38:25,620 --> 02:38:27,180 doing so we're also going to learn about 5094 02:38:27,180 --> 02:38:28,920 a very powerful and c-sharp feature 5095 02:38:28,920 --> 02:38:30,180 called events 5096 02:38:30,180 --> 02:38:32,580 okay so here we have our game so we have 5097 02:38:32,580 --> 02:38:34,200 the player and if we move towards the 5098 02:38:34,200 --> 02:38:36,240 counter yep we are correctly identifying 5099 02:38:36,240 --> 02:38:38,340 it and interacting with it except of 5100 02:38:38,340 --> 02:38:39,960 course we don't want the interaction to 5101 02:38:39,960 --> 02:38:41,700 happen automatically it should be on a 5102 02:38:41,700 --> 02:38:43,859 player input so let's make our interact 5103 02:38:43,859 --> 02:38:46,380 action let's go inside our player input 5104 02:38:46,380 --> 02:38:48,359 action so let's double click on it and 5105 02:38:48,359 --> 02:38:49,800 let's make a brand new action so we've 5106 02:38:49,800 --> 02:38:50,880 got to move and now we're going to have 5107 02:38:50,880 --> 02:38:52,140 another one so let's click on the plus 5108 02:38:52,140 --> 02:38:54,840 icon for this one let's call it interact 5109 02:38:54,840 --> 02:38:56,939 and for this one action type we do want 5110 02:38:56,939 --> 02:38:59,460 it to be a button okay great then on the 5111 02:38:59,460 --> 02:39:01,140 default binding let's go into path let's 5112 02:39:01,140 --> 02:39:03,479 listen and by default let's bind it to 5113 02:39:03,479 --> 02:39:05,460 the E key just like so many games so 5114 02:39:05,460 --> 02:39:07,560 let's go ahead select this one and once 5115 02:39:07,560 --> 02:39:09,300 again let's make sure to save the asset 5116 02:39:09,300 --> 02:39:12,600 and let the C sharp OS be generated okay 5117 02:39:12,600 --> 02:39:14,760 and over here in our game input script 5118 02:39:14,760 --> 02:39:16,500 in order to listen that is very simple 5119 02:39:16,500 --> 02:39:18,899 so we go inside the player input actions 5120 02:39:18,899 --> 02:39:21,240 then inside the player action map and 5121 02:39:21,240 --> 02:39:23,760 then we can find the interact action 5122 02:39:23,760 --> 02:39:25,800 and then over here we can see a whole 5123 02:39:25,800 --> 02:39:27,240 bunch of events that we can interact 5124 02:39:27,240 --> 02:39:29,280 with we've got these three cancel 5125 02:39:29,280 --> 02:39:31,800 performed and started these are the 5126 02:39:31,800 --> 02:39:34,680 three phases of every input again I 5127 02:39:34,680 --> 02:39:36,300 cover these stages in detail in the 5128 02:39:36,300 --> 02:39:38,160 input system video the important thing 5129 02:39:38,160 --> 02:39:40,680 is that these are c-sharp events which I 5130 02:39:40,680 --> 02:39:42,420 also covered in another dedicated video 5131 02:39:42,420 --> 02:39:44,340 essentially they are a way for how you 5132 02:39:44,340 --> 02:39:46,500 can write code to then get notified when 5133 02:39:46,500 --> 02:39:48,720 something happens rather than running 5134 02:39:48,720 --> 02:39:50,580 code on every single update constantly 5135 02:39:50,580 --> 02:39:52,740 testing something for example over here 5136 02:39:52,740 --> 02:39:54,720 on the movement movement is a 5137 02:39:54,720 --> 02:39:56,280 pre-constant action so it does make 5138 02:39:56,280 --> 02:39:58,560 sense to ask the input on every single 5139 02:39:58,560 --> 02:40:00,899 update if any movement is pressed but 5140 02:40:00,899 --> 02:40:03,060 for an action like the interact the 5141 02:40:03,060 --> 02:40:04,500 player is only going to press that say 5142 02:40:04,500 --> 02:40:06,720 once every five seconds so it makes no 5143 02:40:06,720 --> 02:40:08,040 sense to constantly check for that 5144 02:40:08,040 --> 02:40:11,040 action on every single update instead we 5145 02:40:11,040 --> 02:40:12,660 just want to be notified when that 5146 02:40:12,660 --> 02:40:14,520 action is triggered and that is exactly 5147 02:40:14,520 --> 02:40:16,680 what an event does again watch the 5148 02:40:16,680 --> 02:40:18,000 dedicated video to learn all about 5149 02:40:18,000 --> 02:40:19,920 c-sharp events in detail they are 5150 02:40:19,920 --> 02:40:21,720 insanely powerful and we won't be using 5151 02:40:21,720 --> 02:40:23,220 them more and more as we go through this 5152 02:40:23,220 --> 02:40:23,939 course 5153 02:40:23,939 --> 02:40:25,680 for now here are the absolute Basics 5154 02:40:25,680 --> 02:40:28,140 events have Publishers and subscribers 5155 02:40:28,140 --> 02:40:30,540 the publisher creates and fires the 5156 02:40:30,540 --> 02:40:32,640 event when something happens and the 5157 02:40:32,640 --> 02:40:34,439 subscriber listens that event and gets 5158 02:40:34,439 --> 02:40:35,880 the enlisting function called when the 5159 02:40:35,880 --> 02:40:37,740 event is fired now on the generated 5160 02:40:37,740 --> 02:40:39,899 c-sharp class we've got these three 5161 02:40:39,899 --> 02:40:42,120 events the one that we want for this 5162 02:40:42,120 --> 02:40:44,760 case is the performed event so let's go 5163 02:40:44,760 --> 02:40:46,200 into this one and basically we want to 5164 02:40:46,200 --> 02:40:48,000 add a listener to that event 5165 02:40:48,000 --> 02:40:50,220 and we can subscribe to that by doing 5166 02:40:50,220 --> 02:40:52,380 plus equals so this assigns a listener 5167 02:40:52,380 --> 02:40:54,479 to that event and now Visual Studio has 5168 02:40:54,479 --> 02:40:56,880 a nice shortcut so if we press on Tab if 5169 02:40:56,880 --> 02:40:58,260 there go it automatically creates a 5170 02:40:58,260 --> 02:41:00,300 function now if you're not using visual 5171 02:41:00,300 --> 02:41:01,859 studio you can just manually write this 5172 02:41:01,859 --> 02:41:03,479 function the only thing you need to make 5173 02:41:03,479 --> 02:41:04,979 sure is that the function signature 5174 02:41:04,979 --> 02:41:06,540 personally matches the event signature 5175 02:41:06,540 --> 02:41:08,580 as usual we can inspect the event so we 5176 02:41:08,580 --> 02:41:10,020 can right click on it and go to the 5177 02:41:10,020 --> 02:41:12,020 definition and up here is the definition 5178 02:41:12,020 --> 02:41:15,060 and you can see that this is an event of 5179 02:41:15,060 --> 02:41:17,760 type action with a combat context action 5180 02:41:17,760 --> 02:41:20,100 is what is called a dungit I also have a 5181 02:41:20,100 --> 02:41:21,479 video on delegates if you want to learn 5182 02:41:21,479 --> 02:41:23,340 more about them in detail for now we 5183 02:41:23,340 --> 02:41:24,720 don't really need to worry about what is 5184 02:41:24,720 --> 02:41:26,880 delegate we just need to use it so in 5185 02:41:26,880 --> 02:41:28,439 order to subscribe to the event we need 5186 02:41:28,439 --> 02:41:30,180 to make sure that this one returns voyne 5187 02:41:30,180 --> 02:41:32,520 because an action returns void and needs 5188 02:41:32,520 --> 02:41:34,380 to have a parameter of this type combat 5189 02:41:34,380 --> 02:41:37,680 context if I erase this parameter if 5190 02:41:37,680 --> 02:41:39,000 there go now we have an error because 5191 02:41:39,000 --> 02:41:41,340 the function signature does not match so 5192 02:41:41,340 --> 02:41:42,899 it always needs to match the exact same 5193 02:41:42,899 --> 02:41:45,060 signature okay and also one more note 5194 02:41:45,060 --> 02:41:46,740 over here when subscribing to the event 5195 02:41:46,740 --> 02:41:48,720 make sure you only add the function name 5196 02:41:48,720 --> 02:41:51,180 meaning you do not add parentheses we do 5197 02:41:51,180 --> 02:41:52,740 not want to count function we just want 5198 02:41:52,740 --> 02:41:54,479 to pass in the function itself as a 5199 02:41:54,479 --> 02:41:56,399 reference okay so now when the player 5200 02:41:56,399 --> 02:41:57,899 presses the interact action it's going 5201 02:41:57,899 --> 02:41:59,880 to fire off this event which in turn 5202 02:41:59,880 --> 02:42:01,740 will call this function so over here 5203 02:42:01,740 --> 02:42:03,720 let's do a debug download just see what 5204 02:42:03,720 --> 02:42:05,700 this contains for example let's print 5205 02:42:05,700 --> 02:42:07,740 out the compact context okay so let's 5206 02:42:07,740 --> 02:42:10,200 see so here we are and if I press on E 5207 02:42:10,200 --> 02:42:11,819 if there you go I've got a nice event 5208 02:42:11,819 --> 02:42:13,979 okay great so with this we know when the 5209 02:42:13,979 --> 02:42:15,960 player presses the key now the next step 5210 02:42:15,960 --> 02:42:18,300 is how do we get the player class how do 5211 02:42:18,300 --> 02:42:19,979 we get this one to know when this is 5212 02:42:19,979 --> 02:42:21,720 performed and the answer is we're going 5213 02:42:21,720 --> 02:42:23,399 to do the exact same thing we're going 5214 02:42:23,399 --> 02:42:24,899 to make an event over here on the game 5215 02:42:24,899 --> 02:42:26,760 input class and the player won't listen 5216 02:42:26,760 --> 02:42:28,500 to that which in turn the game input 5217 02:42:28,500 --> 02:42:30,780 grabs from the input system again the 5218 02:42:30,780 --> 02:42:33,180 home point is separating our concerns so 5219 02:42:33,180 --> 02:42:34,800 the player does not care about the input 5220 02:42:34,800 --> 02:42:36,420 system does not care about the interact 5221 02:42:36,420 --> 02:42:37,920 action it only wants to know when 5222 02:42:37,920 --> 02:42:40,200 something related to interact happens so 5223 02:42:40,200 --> 02:42:41,700 over here let's make that nice event 5224 02:42:41,700 --> 02:42:43,560 first of all let's make it public 5225 02:42:43,560 --> 02:42:45,420 because we want the player to access it 5226 02:42:45,420 --> 02:42:47,700 then we need to add the event keyword 5227 02:42:47,700 --> 02:42:50,640 next we add the donkey type like I said 5228 02:42:50,640 --> 02:42:52,200 you can learn more about delegates in my 5229 02:42:52,200 --> 02:42:54,420 dedicated video you can create your own 5230 02:42:54,420 --> 02:42:56,640 custom Delegate for your event or you 5231 02:42:56,640 --> 02:42:58,620 can just follow the c-sharp standard and 5232 02:42:58,620 --> 02:43:01,319 just use the standard event handler and 5233 02:43:01,319 --> 02:43:03,720 this one exists inside system 5234 02:43:03,720 --> 02:43:05,939 so let's make sure to go up here and add 5235 02:43:05,939 --> 02:43:08,340 using system and this one has the event 5236 02:43:08,340 --> 02:43:10,439 handler class this one is pretty much 5237 02:43:10,439 --> 02:43:12,720 easy sharp standard for events as you 5238 02:43:12,720 --> 02:43:14,760 can see it returns void it has an object 5239 02:43:14,760 --> 02:43:17,220 for the sender and an event RX parameter 5240 02:43:17,220 --> 02:43:19,380 like I mentioned in the events video you 5241 02:43:19,380 --> 02:43:21,000 are not forced to use this target you 5242 02:43:21,000 --> 02:43:22,859 can use whatever delegate you want like 5243 02:43:22,859 --> 02:43:24,840 for example you saw that the performed 5244 02:43:24,840 --> 02:43:26,760 uses an action delegate so you can use 5245 02:43:26,760 --> 02:43:28,140 anything you want to choose that the 5246 02:43:28,140 --> 02:43:30,180 event handler is the c-sharp standard so 5247 02:43:30,180 --> 02:43:32,520 it's easier to follow unless you have a 5248 02:43:32,520 --> 02:43:34,080 specific reason to deviate from the 5249 02:43:34,080 --> 02:43:35,399 standard you should probably use this 5250 02:43:35,399 --> 02:43:37,500 one so let's use this and then finally 5251 02:43:37,500 --> 02:43:39,720 for the name usually you start the name 5252 02:43:39,720 --> 02:43:41,819 with on and then whatever happened so in 5253 02:43:41,819 --> 02:43:43,560 our case let's go with on interact 5254 02:43:43,560 --> 02:43:45,840 action 5255 02:43:45,840 --> 02:43:48,240 okay so we have defined our event and 5256 02:43:48,240 --> 02:43:50,460 now for firing it let's go down here 5257 02:43:50,460 --> 02:43:52,500 into when we have the interact performed 5258 02:43:52,500 --> 02:43:54,479 and let's go into the event and for 5259 02:43:54,479 --> 02:43:55,979 finding it it's pretty much exactly the 5260 02:43:55,979 --> 02:43:57,479 same thing as calling a regular function 5261 02:43:57,479 --> 02:43:59,939 so we just call it with parentheses then 5262 02:43:59,939 --> 02:44:01,800 usually for the object sender this is a 5263 02:44:01,800 --> 02:44:03,120 reference to whoever is sending this 5264 02:44:03,120 --> 02:44:05,580 event so usually the this keyword and 5265 02:44:05,580 --> 02:44:07,439 then for the event RX this is in case 5266 02:44:07,439 --> 02:44:08,880 you want to send some arguments with the 5267 02:44:08,880 --> 02:44:10,800 event in our case we don't really need 5268 02:44:10,800 --> 02:44:12,600 to send any extra data for this one just 5269 02:44:12,600 --> 02:44:13,920 firing the event is going to be enough 5270 02:44:13,920 --> 02:44:15,960 so for that we can use the constant 5271 02:44:15,960 --> 02:44:19,020 event RX dot empty okay so that's it 5272 02:44:19,020 --> 02:44:21,420 with this we are firing an event except 5273 02:44:21,420 --> 02:44:22,680 just like this we're actually going to 5274 02:44:22,680 --> 02:44:25,620 have one potential error if we have no 5275 02:44:25,620 --> 02:44:27,479 subscribers no listeners to this event 5276 02:44:27,479 --> 02:44:29,460 then essentially this field won't be 5277 02:44:29,460 --> 02:44:31,020 known so this one over here is going to 5278 02:44:31,020 --> 02:44:33,180 trigger a non-reference exception let's 5279 02:44:33,180 --> 02:44:34,500 do a quick test just to see this 5280 02:44:34,500 --> 02:44:37,020 happening so here if I press on E if 5281 02:44:37,020 --> 02:44:38,340 there go we have a null reference 5282 02:44:38,340 --> 02:44:39,240 exception 5283 02:44:39,240 --> 02:44:40,859 so when working with events you need to 5284 02:44:40,859 --> 02:44:42,540 first test if there are any listeners 5285 02:44:42,540 --> 02:44:44,220 and only then do you actually trigger 5286 02:44:44,220 --> 02:44:45,479 the event 5287 02:44:45,479 --> 02:44:48,300 so you do if this one is not null if it 5288 02:44:48,300 --> 02:44:49,680 is not known that means there are some 5289 02:44:49,680 --> 02:44:52,080 subscribers so we can fire the event so 5290 02:44:52,080 --> 02:44:53,880 like this it won't work but there's an 5291 02:44:53,880 --> 02:44:55,439 even more compact way to do this which 5292 02:44:55,439 --> 02:44:59,220 is perfect for events so instead of this 5293 02:44:59,220 --> 02:45:01,500 we've got our on interact action then we 5294 02:45:01,500 --> 02:45:03,720 can add a question mark this is called 5295 02:45:03,720 --> 02:45:06,180 the non-conditional operator basically 5296 02:45:06,180 --> 02:45:07,920 the code is going to execute from left 5297 02:45:07,920 --> 02:45:09,000 to right 5298 02:45:09,000 --> 02:45:10,620 and then when it gets to this question 5299 02:45:10,620 --> 02:45:12,840 mark it's going to evaluate the left 5300 02:45:12,840 --> 02:45:15,060 side and if it is null then the 5301 02:45:15,060 --> 02:45:16,740 execution won't stop right here on the 5302 02:45:16,740 --> 02:45:18,120 question mark and will not throw any 5303 02:45:18,120 --> 02:45:20,520 errors whereas if this one is not null 5304 02:45:20,520 --> 02:45:22,140 then it continues executing to the right 5305 02:45:22,140 --> 02:45:24,540 except with this syntax we have an error 5306 02:45:24,540 --> 02:45:26,760 We cannot put parentheses directly after 5307 02:45:26,760 --> 02:45:29,280 the question mark but what we can do is 5308 02:45:29,280 --> 02:45:31,380 simply just call invoke and that does 5309 02:45:31,380 --> 02:45:32,640 the exact same thing that console 5310 02:45:32,640 --> 02:45:35,100 function so what we have here is exactly 5311 02:45:35,100 --> 02:45:38,479 the same thing that we had previously 5312 02:45:45,180 --> 02:45:47,460 so what we have over here and over here 5313 02:45:47,460 --> 02:45:49,680 these are the exact same thing it's just 5314 02:45:49,680 --> 02:45:51,899 this one is much nice much more Compact 5315 02:45:51,899 --> 02:45:54,060 and especially for events this one is 5316 02:45:54,060 --> 02:45:56,160 super useful okay so with this we are 5317 02:45:56,160 --> 02:45:58,140 correctly firing for our event now let's 5318 02:45:58,140 --> 02:46:00,240 actually listen to it so let's go over 5319 02:46:00,240 --> 02:46:01,979 here into the player class 5320 02:46:01,979 --> 02:46:04,020 and let's listen to our event 5321 02:46:04,020 --> 02:46:06,720 let's do it on a private void start make 5322 02:46:06,720 --> 02:46:09,060 it on start not an awake this is a very 5323 02:46:09,060 --> 02:46:10,319 important rule which I'm actually going 5324 02:46:10,319 --> 02:46:11,880 to cover in detail in the next lecture 5325 02:46:11,880 --> 02:46:13,740 but for now just make sure to listen on 5326 02:46:13,740 --> 02:46:16,020 start and not on awake so over here we 5327 02:46:16,020 --> 02:46:18,600 access the game input then let's access 5328 02:46:18,600 --> 02:46:20,460 the on interact action event and as 5329 02:46:20,460 --> 02:46:22,080 usual let's listen to it so let's use 5330 02:46:22,080 --> 02:46:24,300 press tab to listen to it so it is 5331 02:46:24,300 --> 02:46:25,920 exactly over here that we want to run 5332 02:46:25,920 --> 02:46:28,439 our interact code so let's go down into 5333 02:46:28,439 --> 02:46:30,060 the handle interaction code that we had 5334 02:46:30,060 --> 02:46:31,680 previously so this one 5335 02:46:31,680 --> 02:46:34,800 so let's copy paste all this code put it 5336 02:46:34,800 --> 02:46:35,640 up here 5337 02:46:35,640 --> 02:46:37,380 so we get the interaction going to the 5338 02:46:37,380 --> 02:46:39,240 object and Trigger the interact now 5339 02:46:39,240 --> 02:46:40,979 obviously code duplication is a big 5340 02:46:40,979 --> 02:46:43,620 No-No so we're only duplicating our code 5341 02:46:43,620 --> 02:46:45,120 just for a quick test just make sure it 5342 02:46:45,120 --> 02:46:46,020 works 5343 02:46:46,020 --> 02:46:47,880 once again refactoring is super useful 5344 02:46:47,880 --> 02:46:49,560 so we're going to refactor this code to 5345 02:46:49,560 --> 02:46:51,300 get rid of code duplication in the next 5346 02:46:51,300 --> 02:46:53,340 lecture but for now we just want to test 5347 02:46:53,340 --> 02:46:55,020 to make sure that this does work 5348 02:46:55,020 --> 02:46:56,700 so let's just remove the interact over 5349 02:46:56,700 --> 02:46:58,859 here from the handle interactions so the 5350 02:46:58,859 --> 02:47:00,540 only interact function being called is 5351 02:47:00,540 --> 02:47:02,399 over here when we have our actual input 5352 02:47:02,399 --> 02:47:04,500 so let's test and see if we can press to 5353 02:47:04,500 --> 02:47:06,540 interact with the counter alright so 5354 02:47:06,540 --> 02:47:08,280 here we are and as I move around if I 5355 02:47:08,280 --> 02:47:09,899 approach a counter yep there you go we 5356 02:47:09,899 --> 02:47:12,300 no longer have the automated interaction 5357 02:47:12,300 --> 02:47:14,220 and now if I'm facing the counter and I 5358 02:47:14,220 --> 02:47:16,200 press the enter I key if there go here 5359 02:47:16,200 --> 02:47:18,240 we have our nice interaction all right 5360 02:47:18,240 --> 02:47:20,160 awesome so I can approach I can interact 5361 02:47:20,160 --> 02:47:21,899 and do whatever I want 5362 02:47:21,899 --> 02:47:24,420 alright so here we learned about c-sharp 5363 02:47:24,420 --> 02:47:26,700 events these are super powerful so if 5364 02:47:26,700 --> 02:47:27,960 this is the first time you're hearing 5365 02:47:27,960 --> 02:47:29,700 about them then you've just had an 5366 02:47:29,700 --> 02:47:31,020 awesome new tool to your tone box 5367 02:47:31,020 --> 02:47:32,580 definitely make sure you watch my 5368 02:47:32,580 --> 02:47:34,020 dedicated video to learn about them in 5369 02:47:34,020 --> 02:47:36,960 more detail events are super useful the 5370 02:47:36,960 --> 02:47:38,399 next thing we're going to need is just a 5371 02:47:38,399 --> 02:47:40,080 visual to highlight the current selected 5372 02:47:40,080 --> 02:47:41,700 counter so let's do that in the next 5373 02:47:41,700 --> 02:47:43,020 lecture 5374 02:47:43,020 --> 02:47:45,060 hello and welcome I'm your code monkey 5375 02:47:45,060 --> 02:47:47,160 in this lecture we're going to add a 5376 02:47:47,160 --> 02:47:48,899 visual to our selected counter and in 5377 02:47:48,899 --> 02:47:50,580 doing so we're also going to learn about 5378 02:47:50,580 --> 02:47:52,859 the very useful Singleton pattern okay 5379 02:47:52,859 --> 02:47:54,780 so over here we already have the logic 5380 02:47:54,780 --> 02:47:56,220 to identify the counter in front of the 5381 02:47:56,220 --> 02:47:57,899 player and we can interact with it 5382 02:47:57,899 --> 02:48:00,540 however once the logic works there is no 5383 02:48:00,540 --> 02:48:02,340 visual indicator at all so let's add 5384 02:48:02,340 --> 02:48:05,100 that now as usual the super quick and 5385 02:48:05,100 --> 02:48:06,600 dirty way of doing it would be pretty 5386 02:48:06,600 --> 02:48:08,700 simple over here on the player script we 5387 02:48:08,700 --> 02:48:10,740 could just directly enable a visual mesh 5388 02:48:10,740 --> 02:48:12,960 on the target counter so down here on 5389 02:48:12,960 --> 02:48:14,520 the handle interaction when we have this 5390 02:48:14,520 --> 02:48:16,260 over here we can tell the clear counter 5391 02:48:16,260 --> 02:48:17,580 to enable some kind of visual 5392 02:48:17,580 --> 02:48:19,920 technically that would work but that 5393 02:48:19,920 --> 02:48:22,319 would be some pretty dirty code we would 5394 02:48:22,319 --> 02:48:23,700 basically be making the player 5395 02:48:23,700 --> 02:48:25,319 responsible for enabling some kind of 5396 02:48:25,319 --> 02:48:27,359 visual which would mean that we were 5397 02:48:27,359 --> 02:48:30,060 mixing logic with visuals again we 5398 02:48:30,060 --> 02:48:31,800 always want to try separating the logic 5399 02:48:31,800 --> 02:48:33,479 from the visuals as much as possible to 5400 02:48:33,479 --> 02:48:35,399 keep our code nice and organized so 5401 02:48:35,399 --> 02:48:36,840 instead of doing the quick and dirty 5402 02:48:36,840 --> 02:48:39,240 route let's do it properly back in the 5403 02:48:39,240 --> 02:48:41,160 editor let's create a brand new c-sharp 5404 02:48:41,160 --> 02:48:43,920 script call this the selected counter 5405 02:48:43,920 --> 02:48:45,060 visual 5406 02:48:45,060 --> 02:48:48,000 and now let's go into the prefab again 5407 02:48:48,000 --> 02:48:49,560 let's go inside it so let's select the 5408 02:48:49,560 --> 02:48:51,120 clear counter on the hierarchy then on 5409 02:48:51,120 --> 02:48:52,740 the inspector let's open up go inside 5410 02:48:52,740 --> 02:48:55,020 the prefab and now let's select the 5411 02:48:55,020 --> 02:48:56,760 visual inside it and let's duplicate 5412 02:48:56,760 --> 02:48:58,140 this so you can press Ctrl D to 5413 02:48:58,140 --> 02:49:00,359 duplicate it let's name this when it's 5414 02:49:00,359 --> 02:49:02,819 selected and then inside there's a 5415 02:49:02,819 --> 02:49:04,680 visual with a mesh filter and a mesh 5416 02:49:04,680 --> 02:49:06,720 render so over here let's swap out the 5417 02:49:06,720 --> 02:49:07,800 material 5418 02:49:07,800 --> 02:49:10,319 so let's click on the circle icon and 5419 02:49:10,319 --> 02:49:12,660 now included in the assets is this 5420 02:49:12,660 --> 02:49:15,120 material counter selected so it's all 5421 02:49:15,120 --> 02:49:16,979 the way yep up here the counter selected 5422 02:49:16,979 --> 02:49:19,319 basically it's just a solid white color 5423 02:49:19,319 --> 02:49:21,300 within low Alpha so on the kitchen 5424 02:49:21,300 --> 02:49:23,160 counter inside the sunlight game object 5425 02:49:23,160 --> 02:49:25,200 let's make sure to use this one with 5426 02:49:25,200 --> 02:49:27,180 this we have kind of like a ghost visual 5427 02:49:27,180 --> 02:49:29,160 so if we enable and disable this game 5428 02:49:29,160 --> 02:49:31,020 object we can see the difference Also 5429 02:49:31,020 --> 02:49:33,359 let's do one tiny thing which is right 5430 02:49:33,359 --> 02:49:35,340 now we duplicated the actual visual 5431 02:49:35,340 --> 02:49:37,260 meaning that these objects are exactly 5432 02:49:37,260 --> 02:49:39,060 the same they have the exact same size 5433 02:49:39,060 --> 02:49:41,220 and when that happens you might end up 5434 02:49:41,220 --> 02:49:43,500 with some rendering bugs if two meshes 5435 02:49:43,500 --> 02:49:45,000 are on the exact same position you might 5436 02:49:45,000 --> 02:49:46,979 sometimes see the colors constantly flip 5437 02:49:46,979 --> 02:49:48,120 back and forth 5438 02:49:48,120 --> 02:49:49,620 so in order to make sure that doesn't 5439 02:49:49,620 --> 02:49:52,140 happen let's make this one deselected a 5440 02:49:52,140 --> 02:49:54,240 tiny tiny bit bigger so over here with 5441 02:49:54,240 --> 02:49:56,760 the selected game object selected on the 5442 02:49:56,760 --> 02:49:58,020 inspector over here we've got the scale 5443 02:49:58,020 --> 02:49:59,520 and also we've got this nice little 5444 02:49:59,520 --> 02:50:01,800 button here if it's like this then we 5445 02:50:01,800 --> 02:50:03,540 can modify each proportion differently 5446 02:50:03,540 --> 02:50:06,240 from one another whereas if we click now 5447 02:50:06,240 --> 02:50:08,580 these are all linked so now I'm 5448 02:50:08,580 --> 02:50:10,140 modifying one will modify all of them so 5449 02:50:10,140 --> 02:50:13,439 let's put this on 1.01 meaning this one 5450 02:50:13,439 --> 02:50:15,000 is going to be literally just one 5451 02:50:15,000 --> 02:50:16,859 percent bigger so that's enough of a 5452 02:50:16,859 --> 02:50:18,000 difference to make sure we don't have 5453 02:50:18,000 --> 02:50:20,280 any rendering bugs and by default let's 5454 02:50:20,280 --> 02:50:22,319 also start with the visual hidden so 5455 02:50:22,319 --> 02:50:24,060 let's do that not on the parent select 5456 02:50:24,060 --> 02:50:25,500 game object but rather on the kitchen 5457 02:50:25,500 --> 02:50:27,479 counter inside of it let's make sure to 5458 02:50:27,479 --> 02:50:29,939 disable this game object by the way the 5459 02:50:29,939 --> 02:50:32,280 quick shortcut is shift alt and a you 5460 02:50:32,280 --> 02:50:34,020 can enable or disable the object very 5461 02:50:34,020 --> 02:50:35,700 useful so let's start with this one 5462 02:50:35,700 --> 02:50:37,500 disabled so that it's hidden and 5463 02:50:37,500 --> 02:50:39,840 basically the goal is that when this 5464 02:50:39,840 --> 02:50:41,100 counter is selected we're going to 5465 02:50:41,100 --> 02:50:42,960 enable it and show this Visual and when 5466 02:50:42,960 --> 02:50:44,399 it's not selected we're going to disable 5467 02:50:44,399 --> 02:50:46,560 it okay so over here on the selected 5468 02:50:46,560 --> 02:50:47,760 let's add the script that we made so 5469 02:50:47,760 --> 02:50:49,380 these selected comes revision all right 5470 02:50:49,380 --> 02:50:51,899 so let's open it now here first thing we 5471 02:50:51,899 --> 02:50:53,700 need to know is know which counter is 5472 02:50:53,700 --> 02:50:56,220 selected meaning we need to know which 5473 02:50:56,220 --> 02:50:57,720 counter the player is currently looking 5474 02:50:57,720 --> 02:51:00,000 at so let's go over here onto the player 5475 02:51:00,000 --> 02:51:01,979 script and let's basically just do some 5476 02:51:01,979 --> 02:51:03,359 simple logic to keep track of the 5477 02:51:03,359 --> 02:51:05,460 selected counter so over here let's make 5478 02:51:05,460 --> 02:51:07,859 a field so a private 5479 02:51:07,859 --> 02:51:10,620 let's make it a type clear counter and 5480 02:51:10,620 --> 02:51:13,680 just come with the selected counter 5481 02:51:13,680 --> 02:51:15,780 then down here we have our handle 5482 02:51:15,780 --> 02:51:17,760 interactions logic okay so we do all of 5483 02:51:17,760 --> 02:51:19,859 this we try to find the counter in front 5484 02:51:19,859 --> 02:51:21,420 and if we do find it then we have it 5485 02:51:21,420 --> 02:51:23,580 here so here on let's just check if it's 5486 02:51:23,580 --> 02:51:25,680 different so if this clear counter if 5487 02:51:25,680 --> 02:51:27,300 the one in front is different from the 5488 02:51:27,300 --> 02:51:29,280 current selected then let's set the 5489 02:51:29,280 --> 02:51:32,280 selected to this one 5490 02:51:32,280 --> 02:51:34,260 and let's also make sure to essentially 5491 02:51:34,260 --> 02:51:36,240 unselect so we want to make sure to set 5492 02:51:36,240 --> 02:51:37,800 this one to know when there's nothing in 5493 02:51:37,800 --> 02:51:39,899 front of the player so if the raycast 5494 02:51:39,899 --> 02:51:41,340 does not hit anything then there is 5495 02:51:41,340 --> 02:51:42,479 nothing in front of the player so let's 5496 02:51:42,479 --> 02:51:44,280 set this like the counter back into null 5497 02:51:44,280 --> 02:51:46,200 and also if there is something but that 5498 02:51:46,200 --> 02:51:47,399 something does not have the clear 5499 02:51:47,399 --> 02:51:48,899 counter script then it's also not a 5500 02:51:48,899 --> 02:51:50,760 counter so over here let's also do an 5501 02:51:50,760 --> 02:51:53,160 else selected counter equals no so 5502 02:51:53,160 --> 02:51:54,359 basically if there's a counter in from 5503 02:51:54,359 --> 02:51:55,800 the player then it's going to set it if 5504 02:51:55,800 --> 02:51:57,540 not then it's going to be no 5505 02:51:57,540 --> 02:52:00,180 let's just do a simple debug download to 5506 02:52:00,180 --> 02:52:02,640 check on the selected counter okay and 5507 02:52:02,640 --> 02:52:04,560 also just briefly now that we've made 5508 02:52:04,560 --> 02:52:06,720 this selected counter logic actually up 5509 02:52:06,720 --> 02:52:08,460 here when we have our interact action 5510 02:52:08,460 --> 02:52:11,460 like we saw we were previously copying 5511 02:52:11,460 --> 02:52:12,960 some duplicated code 5512 02:52:12,960 --> 02:52:14,819 but now we no longer need this since we 5513 02:52:14,819 --> 02:52:16,560 already know the selected counter so 5514 02:52:16,560 --> 02:52:17,939 over here when we've got the interact 5515 02:52:17,939 --> 02:52:18,899 action 5516 02:52:18,899 --> 02:52:20,580 let's just check if we do have a 5517 02:52:20,580 --> 02:52:23,220 selected counter so if it is not null if 5518 02:52:23,220 --> 02:52:24,779 so then we go there and we call the 5519 02:52:24,779 --> 02:52:26,340 interact function so that's it we no 5520 02:52:26,340 --> 02:52:28,140 longer need all of this logic okay 5521 02:52:28,140 --> 02:52:30,540 that's great so let's test back in the 5522 02:52:30,540 --> 02:52:31,859 editor and let's go back into scenes 5523 02:52:31,859 --> 02:52:33,960 let's make sure to save the prefab 5524 02:52:33,960 --> 02:52:35,819 make sure the script was attached save 5525 02:52:35,819 --> 02:52:37,920 it and let's hit on play and right now 5526 02:52:37,920 --> 02:52:39,479 if I'm down here yep there you go we've 5527 02:52:39,479 --> 02:52:41,460 got null and as I approach if there go 5528 02:52:41,460 --> 02:52:42,960 that one is a clear counter and if I 5529 02:52:42,960 --> 02:52:44,520 move towards this one yep it's that one 5530 02:52:44,520 --> 02:52:46,560 okay so basically we are keeping track 5531 02:52:46,560 --> 02:52:48,779 of the kernel selected counter now 5532 02:52:48,779 --> 02:52:50,460 basically we just need to notify the 5533 02:52:50,460 --> 02:52:52,260 visual whenever this one changes so when 5534 02:52:52,260 --> 02:52:53,580 this one is pointing at that one or 5535 02:52:53,580 --> 02:52:54,899 pointing at no or pointing at that one 5536 02:52:54,899 --> 02:52:56,939 we need to know when that happens 5537 02:52:56,939 --> 02:52:58,920 and for that we basically have two 5538 02:52:58,920 --> 02:53:01,020 options now one option is pretty much 5539 02:53:01,020 --> 02:53:03,000 what I mentioned a while ago which is 5540 02:53:03,000 --> 02:53:04,500 over here we have the selected counter 5541 02:53:04,500 --> 02:53:06,420 so we can run some kind of logic on the 5542 02:53:06,420 --> 02:53:08,460 sunlight counter we can do that over 5543 02:53:08,460 --> 02:53:10,680 here on the player then perhaps over 5544 02:53:10,680 --> 02:53:12,600 here the counter would fire off some 5545 02:53:12,600 --> 02:53:13,859 kind of event saying it has been 5546 02:53:13,859 --> 02:53:16,260 selected and then the counter visual 5547 02:53:16,260 --> 02:53:17,880 would listen to that event and update 5548 02:53:17,880 --> 02:53:20,160 itself now that approach would be useful 5549 02:53:20,160 --> 02:53:22,140 if we wanted to add some kind of logic 5550 02:53:22,140 --> 02:53:24,540 on the clear counter while selected and 5551 02:53:24,540 --> 02:53:25,680 that approach would also have the 5552 02:53:25,680 --> 02:53:27,540 benefit where the visual encounter would 5553 02:53:27,540 --> 02:53:29,279 only listen to events on its own counter 5554 02:53:29,279 --> 02:53:31,140 so that's one approach pretty much a 5555 02:53:31,140 --> 02:53:33,960 very direct approach but another one is 5556 02:53:33,960 --> 02:53:36,180 very simple the player would simply fire 5557 02:53:36,180 --> 02:53:37,800 off an event whenever the selected 5558 02:53:37,800 --> 02:53:39,779 counter changes and then all of the 5559 02:53:39,779 --> 02:53:41,160 counter visuals would listen to that 5560 02:53:41,160 --> 02:53:43,439 event then they would identify if the 5561 02:53:43,439 --> 02:53:45,300 event relates to that counter and if so 5562 02:53:45,300 --> 02:53:46,680 update their state 5563 02:53:46,680 --> 02:53:48,540 now the benefit of this approach is that 5564 02:53:48,540 --> 02:53:50,220 the logic doesn't get bothered with any 5565 02:53:50,220 --> 02:53:52,380 selection logic so over here the clear 5566 02:53:52,380 --> 02:53:54,060 counter script never really knows if 5567 02:53:54,060 --> 02:53:55,500 it's light or not and that's a good 5568 02:53:55,500 --> 02:53:56,760 thing because it doesn't need to know 5569 02:53:56,760 --> 02:53:58,800 although the potential con with that 5570 02:53:58,800 --> 02:54:00,779 approach is that all of these selected 5571 02:54:00,779 --> 02:54:02,340 countervisions are only going to listen 5572 02:54:02,340 --> 02:54:04,680 to the same event so both approaches 5573 02:54:04,680 --> 02:54:06,840 have pros and cons here on let's go with 5574 02:54:06,840 --> 02:54:08,100 the second approach where all the 5575 02:54:08,100 --> 02:54:09,840 counters listen to a player event 5576 02:54:09,840 --> 02:54:11,819 the potential performance con doesn't 5577 02:54:11,819 --> 02:54:13,979 really matter on a game of this scale 5578 02:54:13,979 --> 02:54:15,960 we're only going to have about a dozen 5579 02:54:15,960 --> 02:54:18,600 counters so even if 11 of them are just 5580 02:54:18,600 --> 02:54:20,460 wasting on listening to the event it's 5581 02:54:20,460 --> 02:54:22,680 really not going to matter and going in 5582 02:54:22,680 --> 02:54:24,000 with this approach will actually help us 5583 02:54:24,000 --> 02:54:25,800 learn about the Singleton pattern which 5584 02:54:25,800 --> 02:54:28,020 is extremely useful so first let's go 5585 02:54:28,020 --> 02:54:29,640 over here onto the player class and 5586 02:54:29,640 --> 02:54:30,899 let's make the event that we're going to 5587 02:54:30,899 --> 02:54:31,680 fire 5588 02:54:31,680 --> 02:54:33,479 so as usual let's make it public so we 5589 02:54:33,479 --> 02:54:36,000 can access it let's make it an event and 5590 02:54:36,000 --> 02:54:37,920 as usual let's also use the standard 5591 02:54:37,920 --> 02:54:40,080 event handler let's make sure to add 5592 02:54:40,080 --> 02:54:42,479 using system so here Visual Studio adds 5593 02:54:42,479 --> 02:54:44,040 it automatically okay 5594 02:54:44,040 --> 02:54:46,979 then let's call this on selected counter 5595 02:54:46,979 --> 02:54:49,460 changed 5596 02:54:52,920 --> 02:54:54,960 also this is a great moment to learn 5597 02:54:54,960 --> 02:54:57,479 about the event arcs this is how you can 5598 02:54:57,479 --> 02:54:59,939 extend a c-sharp event in order to pass 5599 02:54:59,939 --> 02:55:02,340 in some more data so how you do it by 5600 02:55:02,340 --> 02:55:03,960 following the c-sharp standard is very 5601 02:55:03,960 --> 02:55:06,060 simple we just create a class 5602 02:55:06,060 --> 02:55:08,819 so over here let's make a public class 5603 02:55:08,819 --> 02:55:11,100 then for name usually you include the 5604 02:55:11,100 --> 02:55:12,840 name of the event with eventars at the 5605 02:55:12,840 --> 02:55:15,840 end so in this case on selected counter 5606 02:55:15,840 --> 02:55:18,840 changed and then event arcs then on this 5607 02:55:18,840 --> 02:55:22,319 class we make it extend event arcs 5608 02:55:22,319 --> 02:55:24,180 and finally inside the class we add 5609 02:55:24,180 --> 02:55:26,220 whatever that we want like for example 5610 02:55:26,220 --> 02:55:28,439 we want the current selected counter so 5611 02:55:28,439 --> 02:55:31,620 let's make a public clear counter and 5612 02:55:31,620 --> 02:55:34,740 put the selected counter 5613 02:55:34,740 --> 02:55:37,020 okay so we have this nice event arcs 5614 02:55:37,020 --> 02:55:38,460 with a bunch of extra data and then over 5615 02:55:38,460 --> 02:55:40,140 here on the event handler we use the 5616 02:55:40,140 --> 02:55:41,939 version that takes a generic and we pass 5617 02:55:41,939 --> 02:55:44,760 in our event arcs again I covered the 5618 02:55:44,760 --> 02:55:46,439 generics in more detail in a separate 5619 02:55:46,439 --> 02:55:48,420 video definitely go watch that one if 5620 02:55:48,420 --> 02:55:50,340 you haven't seen it yet c-sharp generics 5621 02:55:50,340 --> 02:55:51,899 are one of c-sharp's most powerful 5622 02:55:51,899 --> 02:55:54,600 features okay great so we now have our 5623 02:55:54,600 --> 02:55:57,000 nice event now let's fire it off so 5624 02:55:57,000 --> 02:55:58,560 let's go down here to when we're 5625 02:55:58,560 --> 02:56:00,600 modifying the selected counter so here 5626 02:56:00,600 --> 02:56:02,460 it is we've got all of these ones so 5627 02:56:02,460 --> 02:56:04,020 when we modify let's fire off the event 5628 02:56:04,020 --> 02:56:05,760 so we go into this event and as usual 5629 02:56:05,760 --> 02:56:07,200 let's use the question mark and then 5630 02:56:07,200 --> 02:56:09,540 call invoke then for the object sender 5631 02:56:09,540 --> 02:56:10,859 it's going to be this so pretty much is 5632 02:56:10,859 --> 02:56:12,479 centered and then for our custom 5633 02:56:12,479 --> 02:56:14,520 eventarics let's construct an object of 5634 02:56:14,520 --> 02:56:17,340 that type so construct a new object and 5635 02:56:17,340 --> 02:56:18,840 then inside we pass in the selected 5636 02:56:18,840 --> 02:56:20,460 counter and we set it to this selected 5637 02:56:20,460 --> 02:56:22,500 counter now don't be confused by the 5638 02:56:22,500 --> 02:56:23,640 fact that we're using the exact same 5639 02:56:23,640 --> 02:56:25,620 name if you actually Mouse over the 5640 02:56:25,620 --> 02:56:27,240 cursor Visual Studio actually helps you 5641 02:56:27,240 --> 02:56:29,279 by telling you which object refers to 5642 02:56:29,279 --> 02:56:31,740 this so with the cursor here note how 5643 02:56:31,740 --> 02:56:33,300 all of these are highlighted but this 5644 02:56:33,300 --> 02:56:35,160 one is not highlighted that's because 5645 02:56:35,160 --> 02:56:37,319 this field this is the film inside the 5646 02:56:37,319 --> 02:56:39,120 unselected counter change event RX 5647 02:56:39,120 --> 02:56:40,920 whereas this one out here is the object 5648 02:56:40,920 --> 02:56:42,899 that we're referencing in here so even 5649 02:56:42,899 --> 02:56:44,160 though these two have the exact same 5650 02:56:44,160 --> 02:56:45,840 name here we're accessing the film 5651 02:56:45,840 --> 02:56:47,700 inside of that and we're assigning it to 5652 02:56:47,700 --> 02:56:48,899 the reference that we have down here 5653 02:56:48,899 --> 02:56:50,760 okay so that's really it we're firing 5654 02:56:50,760 --> 02:56:52,380 off the event when the selected changes 5655 02:56:52,380 --> 02:56:54,540 and we're passing it in and let's also 5656 02:56:54,540 --> 02:56:56,220 make sure to do it over here so let's 5657 02:56:56,220 --> 02:56:58,380 copy and paste some code and there you 5658 02:56:58,380 --> 02:57:00,540 go just like this except of course we 5659 02:57:00,540 --> 02:57:01,800 can already see a bunch of code 5660 02:57:01,800 --> 02:57:03,899 duplication usually that means it's time 5661 02:57:03,899 --> 02:57:05,520 to refactor so let's do that pretty 5662 02:57:05,520 --> 02:57:08,100 quickly let's go down and make a brand 5663 02:57:08,100 --> 02:57:10,020 new function so let's make a private 5664 02:57:10,020 --> 02:57:13,620 Droid let's call it set selected counter 5665 02:57:13,620 --> 02:57:15,840 and we're going to receive a clear 5666 02:57:15,840 --> 02:57:19,760 counter for the selected counter 5667 02:57:20,220 --> 02:57:22,140 then over here we just set this dot 5668 02:57:22,140 --> 02:57:23,520 selected counter so we're modifying the 5669 02:57:23,520 --> 02:57:25,080 member variable with the one that we 5670 02:57:25,080 --> 02:57:27,120 receive on the parameter and then let's 5671 02:57:27,120 --> 02:57:28,979 also fire off the event so let's copy 5672 02:57:28,979 --> 02:57:30,120 paste the event 5673 02:57:30,120 --> 02:57:32,520 just like this the exact same thing okay 5674 02:57:32,520 --> 02:57:34,380 so that's it and now up there instead of 5675 02:57:34,380 --> 02:57:36,960 code duplication we just do this 5676 02:57:36,960 --> 02:57:38,760 so over here we set the clear counter 5677 02:57:38,760 --> 02:57:40,800 just call the function pass in that one 5678 02:57:40,800 --> 02:57:43,680 and get rid of this and on that one just 5679 02:57:43,680 --> 02:57:46,439 pass a null just like this get rid of 5680 02:57:46,439 --> 02:57:48,600 all this and here the same thing just 5681 02:57:48,600 --> 02:57:51,060 pass in no alright so with this our code 5682 02:57:51,060 --> 02:57:52,500 is much cleaner and everything still 5683 02:57:52,500 --> 02:57:54,840 works is all the same so here we have 5684 02:57:54,840 --> 02:57:56,520 everything done on the player side let's 5685 02:57:56,520 --> 02:57:58,200 just get rid of unlock we know we need 5686 02:57:58,200 --> 02:58:00,479 this so we're still handling the 5687 02:58:00,479 --> 02:58:02,279 selected counter logic and then down 5688 02:58:02,279 --> 02:58:04,380 here we're firing off the event now we 5689 02:58:04,380 --> 02:58:06,120 need to do is go over here into the 5690 02:58:06,120 --> 02:58:08,399 selected counter visual script and here 5691 02:58:08,399 --> 02:58:09,840 what we want to do is to listen to that 5692 02:58:09,840 --> 02:58:11,760 event in order to do that we need a 5693 02:58:11,760 --> 02:58:14,100 reference to the player object now so 5694 02:58:14,100 --> 02:58:15,779 far when we've been listening to events 5695 02:58:15,779 --> 02:58:18,120 like for example any player class up 5696 02:58:18,120 --> 02:58:19,979 here we were listening to some events on 5697 02:58:19,979 --> 02:58:21,359 the game input so there you go the 5698 02:58:21,359 --> 02:58:23,880 uninteract action so for the game input 5699 02:58:23,880 --> 02:58:25,979 reference we just added as a serialized 5700 02:58:25,979 --> 02:58:26,760 field 5701 02:58:26,760 --> 02:58:28,439 we did this and then we drag the 5702 02:58:28,439 --> 02:58:30,060 reference directly and technically we 5703 02:58:30,060 --> 02:58:31,859 could do the same thing over here on the 5704 02:58:31,859 --> 02:58:33,840 sound like the counter visual but we're 5705 02:58:33,840 --> 02:58:35,520 going to have like a dozen counters in 5706 02:58:35,520 --> 02:58:37,560 our map so it would be pretty tedious to 5707 02:58:37,560 --> 02:58:39,060 drag and drop the play reference to 5708 02:58:39,060 --> 02:58:41,580 every single one of them so instead of 5709 02:58:41,580 --> 02:58:43,020 using a serialized field another 5710 02:58:43,020 --> 02:58:44,760 approach is to use the Singleton pattern 5711 02:58:44,760 --> 02:58:46,439 this one is an extremely useful 5712 02:58:46,439 --> 02:58:48,899 programming pattern it's very useful for 5713 02:58:48,899 --> 02:58:50,580 things where you only have one instance 5714 02:58:50,580 --> 02:58:51,960 of something 5715 02:58:51,960 --> 02:58:53,399 in this case we're making this game 5716 02:58:53,399 --> 02:58:55,140 single players so we're only ever going 5717 02:58:55,140 --> 02:58:57,420 to have a single player by the way 5718 02:58:57,420 --> 02:58:59,939 here's one obvious quick note like I 5719 02:58:59,939 --> 02:59:01,140 mentioned in the beginning of this 5720 02:59:01,140 --> 02:59:01,979 course 5721 02:59:01,979 --> 02:59:03,899 after this video there's going to be 5722 02:59:03,899 --> 02:59:05,460 another one converting this game into 5723 02:59:05,460 --> 02:59:07,319 multiplayer and in that case we will 5724 02:59:07,319 --> 02:59:09,779 have multiple player instances but this 5725 02:59:09,779 --> 02:59:11,340 is also an excellent reminder of how 5726 02:59:11,340 --> 02:59:13,859 refactoring code is perfectly fine for 5727 02:59:13,859 --> 02:59:15,720 right now for this game it is intended 5728 02:59:15,720 --> 02:59:17,220 as single player so for now we're going 5729 02:59:17,220 --> 02:59:19,740 to use the Singleton pattern then in the 5730 02:59:19,740 --> 02:59:21,060 future when we convert this to 5731 02:59:21,060 --> 02:59:22,800 multiplayer we won't simply refactor 5732 02:59:22,800 --> 02:59:25,140 that logic again don't be afraid of 5733 02:59:25,140 --> 02:59:27,060 refactoring code it's a Perfectly 5734 02:59:27,060 --> 02:59:28,740 Natural part of programming and game 5735 02:59:28,740 --> 02:59:30,779 development okay so let's implement the 5736 02:59:30,779 --> 02:59:32,399 single note pattern this is actually 5737 02:59:32,399 --> 02:59:33,840 super simple the name sounds 5738 02:59:33,840 --> 02:59:35,520 intimidating but it really is very 5739 02:59:35,520 --> 02:59:36,359 simple 5740 02:59:36,359 --> 02:59:38,460 over here on the player script 5741 02:59:38,460 --> 02:59:41,580 let's make a public field this one let's 5742 02:59:41,580 --> 02:59:43,260 make it static 5743 02:59:43,260 --> 02:59:45,300 if you don't know static basically it 5744 02:59:45,300 --> 02:59:47,040 means that this film belongs to the 5745 02:59:47,040 --> 02:59:48,779 player class itself and not to any 5746 02:59:48,779 --> 02:59:50,939 instance of a player so for example if 5747 02:59:50,939 --> 02:59:53,340 you had a hundred players you would have 5748 02:59:53,340 --> 02:59:55,380 a hundred instances of moose mean you 5749 02:59:55,380 --> 02:59:57,720 would have one for each player but there 5750 02:59:57,720 --> 02:59:59,399 would only be a single static film 5751 02:59:59,399 --> 03:00:01,140 because this static film belongs to the 5752 03:00:01,140 --> 03:00:03,720 class itself and not to any instance so 5753 03:00:03,720 --> 03:00:05,880 let's make a field of Thai player and 5754 03:00:05,880 --> 03:00:07,560 then for the name the convention is to 5755 03:00:07,560 --> 03:00:09,779 call it instance and the reason why I'm 5756 03:00:09,779 --> 03:00:12,120 using Pascal case here so capitalized in 5757 03:00:12,120 --> 03:00:13,859 the beginning the reason for that is 5758 03:00:13,859 --> 03:00:15,479 because this is actually not going to be 5759 03:00:15,479 --> 03:00:17,340 a film but instead it's going to be a 5760 03:00:17,340 --> 03:00:18,359 property 5761 03:00:18,359 --> 03:00:20,220 remember the naming rooms that we 5762 03:00:20,220 --> 03:00:21,680 covered in the beginning of this course 5763 03:00:21,680 --> 03:00:23,819 it's very important you follow your 5764 03:00:23,819 --> 03:00:25,859 naming rules always be consistent so 5765 03:00:25,859 --> 03:00:27,600 your code is easier to understand 5766 03:00:27,600 --> 03:00:29,100 so with that said since this is the 5767 03:00:29,100 --> 03:00:30,779 first time we're using a property let me 5768 03:00:30,779 --> 03:00:32,399 quickly explain what it is 5769 03:00:32,399 --> 03:00:34,260 basically it's the exact same thing as a 5770 03:00:34,260 --> 03:00:36,540 regular variable except you can add some 5771 03:00:36,540 --> 03:00:37,979 logic when getting and setting that 5772 03:00:37,979 --> 03:00:40,260 field so here let me write some quick 5773 03:00:40,260 --> 03:00:41,880 code just to show difference between a 5774 03:00:41,880 --> 03:00:44,520 property and a regular field so for a 5775 03:00:44,520 --> 03:00:45,899 regular field you would call this maybe 5776 03:00:45,899 --> 03:00:47,819 instance field something like this so 5777 03:00:47,819 --> 03:00:49,500 this is a regular field 5778 03:00:49,500 --> 03:00:51,660 then you would have some kind of public 5779 03:00:51,660 --> 03:00:54,439 static 5780 03:00:54,899 --> 03:00:56,700 return the player and call it get 5781 03:00:56,700 --> 03:00:59,100 instance field 5782 03:00:59,100 --> 03:01:00,960 then over here you would return the 5783 03:01:00,960 --> 03:01:02,340 instance field 5784 03:01:02,340 --> 03:01:04,439 and then maybe another public static 5785 03:01:04,439 --> 03:01:07,439 void set instance field where you 5786 03:01:07,439 --> 03:01:11,220 receive a player for the instance field 5787 03:01:11,220 --> 03:01:12,660 and you would set the player that 5788 03:01:12,660 --> 03:01:14,340 instance film into this instance field 5789 03:01:14,340 --> 03:01:16,800 so this is how you do this logic with 5790 03:01:16,800 --> 03:01:19,740 fields and now with properties 5791 03:01:19,740 --> 03:01:22,319 you would do public static Flair then 5792 03:01:22,319 --> 03:01:23,939 call it instance 5793 03:01:23,939 --> 03:01:26,040 then on the property itself you open up 5794 03:01:26,040 --> 03:01:27,960 the currently brackets 5795 03:01:27,960 --> 03:01:30,840 inside the property you put a get then 5796 03:01:30,840 --> 03:01:32,340 you return something 5797 03:01:32,340 --> 03:01:34,380 so for that something usually a property 5798 03:01:34,380 --> 03:01:36,359 has a field underneath it 5799 03:01:36,359 --> 03:01:39,840 so you'd have a private static player 5800 03:01:39,840 --> 03:01:41,700 for the instance that's a different name 5801 03:01:41,700 --> 03:01:43,200 from this one 5802 03:01:43,200 --> 03:01:45,600 on the get you would return that 5803 03:01:45,600 --> 03:01:47,580 and on the set 5804 03:01:47,580 --> 03:01:49,380 you would set the instance equals z 5805 03:01:49,380 --> 03:01:50,760 value 5806 03:01:50,760 --> 03:01:52,319 if you're confused here don't worry 5807 03:01:52,319 --> 03:01:54,479 basically I'm just repeating just so you 5808 03:01:54,479 --> 03:01:56,279 can see difference here we have a field 5809 03:01:56,279 --> 03:01:58,560 with a get and a set function so regular 5810 03:01:58,560 --> 03:02:00,840 functions and up here we have a property 5811 03:02:00,840 --> 03:02:02,520 and inside the property the property 5812 03:02:02,520 --> 03:02:05,220 itself has a get and set functions which 5813 03:02:05,220 --> 03:02:06,899 can also do some logic so you can do 5814 03:02:06,899 --> 03:02:09,240 some logic in between or you can just 5815 03:02:09,240 --> 03:02:11,700 return the underlying value so basically 5816 03:02:11,700 --> 03:02:13,680 using your property is pretty much the 5817 03:02:13,680 --> 03:02:15,540 exact same thing as using a separate get 5818 03:02:15,540 --> 03:02:18,300 and set function also one more bonus 5819 03:02:18,300 --> 03:02:20,760 thing which is that c-sharp is smart 5820 03:02:20,760 --> 03:02:22,260 enough to automatically create the 5821 03:02:22,260 --> 03:02:24,359 underlying film for a certain property 5822 03:02:24,359 --> 03:02:26,520 so if you just want to do a get and a 5823 03:02:26,520 --> 03:02:27,779 set then you don't need to Define all 5824 03:02:27,779 --> 03:02:30,479 this you can just Define a property and 5825 03:02:30,479 --> 03:02:33,840 then inside you can just do get and set 5826 03:02:33,840 --> 03:02:35,819 and there you go this code here works 5827 03:02:35,819 --> 03:02:37,140 the exact same thing as we had 5828 03:02:37,140 --> 03:02:39,060 previously which in turn is the exact 5829 03:02:39,060 --> 03:02:40,560 same thing as all the code we have here 5830 03:02:40,560 --> 03:02:42,660 with the getter and a Setter function so 5831 03:02:42,660 --> 03:02:44,939 here it is a valid functional c-sharp 5832 03:02:44,939 --> 03:02:46,620 property now I have to say that 5833 03:02:46,620 --> 03:02:48,720 personally I very very rarely use 5834 03:02:48,720 --> 03:02:51,000 properties in fact the only place where 5835 03:02:51,000 --> 03:02:52,740 I use them is over here on the Singleton 5836 03:02:52,740 --> 03:02:55,140 pattern for everything else I normally 5837 03:02:55,140 --> 03:02:56,880 use regular films with get and set 5838 03:02:56,880 --> 03:02:58,800 functions personally that's just the way 5839 03:02:58,800 --> 03:03:00,660 that I like to code but that's really 5840 03:03:00,660 --> 03:03:02,939 just personal preference so if you don't 5841 03:03:02,939 --> 03:03:04,560 like to use properties then go ahead and 5842 03:03:04,560 --> 03:03:07,319 use them anyway so the reason why I like 5843 03:03:07,319 --> 03:03:09,120 using a property specifically for the 5844 03:03:09,120 --> 03:03:11,700 single pattern is because the implicit 5845 03:03:11,700 --> 03:03:13,080 implementation allows you to do 5846 03:03:13,080 --> 03:03:15,300 something really nice again remember to 5847 03:03:15,300 --> 03:03:17,760 go on with clean code we want to 5848 03:03:17,760 --> 03:03:19,500 minimize complexity and the best way to 5849 03:03:19,500 --> 03:03:21,960 do that is minimize access here if we 5850 03:03:21,960 --> 03:03:23,460 set this property and we set it as 5851 03:03:23,460 --> 03:03:25,380 public then that means that any other 5852 03:03:25,380 --> 03:03:27,899 class can both get and set so anyone 5853 03:03:27,899 --> 03:03:29,779 else can have both read and write access 5854 03:03:29,779 --> 03:03:32,279 so we have the exact same problems that 5855 03:03:32,279 --> 03:03:33,600 I warned you about when I spoke about 5856 03:03:33,600 --> 03:03:34,920 why you should not make everything 5857 03:03:34,920 --> 03:03:37,200 public and of course if we make this 5858 03:03:37,200 --> 03:03:38,340 private 5859 03:03:38,340 --> 03:03:40,140 then at that point we kind of lose the 5860 03:03:40,140 --> 03:03:41,700 purpose of our Singleton since no one 5861 03:03:41,700 --> 03:03:43,020 else will be able to access this 5862 03:03:43,020 --> 03:03:45,060 basically we want to be able to access 5863 03:03:45,060 --> 03:03:46,859 this reference from classes outside of 5864 03:03:46,859 --> 03:03:48,420 this one we just don't want those 5865 03:03:48,420 --> 03:03:50,700 classes to also have right access 5866 03:03:50,700 --> 03:03:52,560 now thankfully properties have an 5867 03:03:52,560 --> 03:03:53,760 excellent thing which is you can Define 5868 03:03:53,760 --> 03:03:55,800 accessors for here both the get and the 5869 03:03:55,800 --> 03:03:57,840 set so we can make the property itself 5870 03:03:57,840 --> 03:04:00,420 public which means by default both of 5871 03:04:00,420 --> 03:04:02,399 these won't be public but then we can 5872 03:04:02,399 --> 03:04:04,680 also add the accessor over here private 5873 03:04:04,680 --> 03:04:06,359 which in turn means that the get won't 5874 03:04:06,359 --> 03:04:08,220 be public so any other class can get 5875 03:04:08,220 --> 03:04:10,319 this but private means that only this 5876 03:04:10,319 --> 03:04:12,840 class can set it this way we have the 5877 03:04:12,840 --> 03:04:14,640 exact level of accessibility that we 5878 03:04:14,640 --> 03:04:16,500 want this is the reason why for this 5879 03:04:16,500 --> 03:04:18,180 specific use case properties are very 5880 03:04:18,180 --> 03:04:20,520 useful with just this one line of code 5881 03:04:20,520 --> 03:04:22,200 we already have our instance with the 5882 03:04:22,200 --> 03:04:24,060 perfect level of accessibility 5883 03:04:24,060 --> 03:04:27,000 so now that we have this field to set it 5884 03:04:27,000 --> 03:04:28,800 let's make a simple awake so let's go 5885 03:04:28,800 --> 03:04:30,779 over here private void awake and on 5886 03:04:30,779 --> 03:04:33,479 awake we just set instance equals this 5887 03:04:33,479 --> 03:04:35,700 however remember that a key point of the 5888 03:04:35,700 --> 03:04:37,740 Singleton pattern is you only have a 5889 03:04:37,740 --> 03:04:39,600 single instance of something 5890 03:04:39,600 --> 03:04:41,399 so in this case we should never have 5891 03:04:41,399 --> 03:04:43,200 more than one player if we do then 5892 03:04:43,200 --> 03:04:44,640 something went wrong 5893 03:04:44,640 --> 03:04:46,859 so we can add a nice safety feature here 5894 03:04:46,859 --> 03:04:50,100 let's just check if instance if it is 5895 03:04:50,100 --> 03:04:51,779 not known meaning it has already been 5896 03:04:51,779 --> 03:04:53,160 set to something 5897 03:04:53,160 --> 03:04:55,260 if so then that's an error something bad 5898 03:04:55,260 --> 03:04:58,380 happened similar to a debug.log error 5899 03:04:58,380 --> 03:05:00,359 because this should never happen so 5900 03:05:00,359 --> 03:05:03,120 let's say there is more than one player 5901 03:05:03,120 --> 03:05:05,640 instance this way we have a nice safety 5902 03:05:05,640 --> 03:05:07,340 check just in case something goes wrong 5903 03:05:07,340 --> 03:05:09,540 alright so that's really it for the 5904 03:05:09,540 --> 03:05:11,220 Singleton pattern we just defined a 5905 03:05:11,220 --> 03:05:13,080 property with a public yet in a private 5906 03:05:13,080 --> 03:05:14,939 set and on the Wake we just set the 5907 03:05:14,939 --> 03:05:17,040 instance that's it as you can see it's 5908 03:05:17,040 --> 03:05:19,140 super simple and now for the really 5909 03:05:19,140 --> 03:05:21,540 useful part over here on the selected 5910 03:05:21,540 --> 03:05:23,760 counter visual now we can access the 5911 03:05:23,760 --> 03:05:25,560 Singleton instance in a super easy way 5912 03:05:25,560 --> 03:05:28,439 let's make a private void start and on 5913 03:05:28,439 --> 03:05:30,180 start we just access the player class 5914 03:05:30,180 --> 03:05:32,460 and from the class we can access the 5915 03:05:32,460 --> 03:05:33,899 static instance so we can access the 5916 03:05:33,899 --> 03:05:36,060 Singleton and now we can listen to The 5917 03:05:36,060 --> 03:05:38,279 unselected Counter event and over here 5918 03:05:38,279 --> 03:05:40,380 by default Visual Studio gives this 5919 03:05:40,380 --> 03:05:42,180 function the name of the event and also 5920 03:05:42,180 --> 03:05:43,200 the property 5921 03:05:43,200 --> 03:05:45,060 this is in the very descriptive name so 5922 03:05:45,060 --> 03:05:47,819 I like to rename this so control RR and 5923 03:05:47,819 --> 03:05:49,680 just rename the instance here instead of 5924 03:05:49,680 --> 03:05:51,840 instance let's rename it to player okay 5925 03:05:51,840 --> 03:05:54,000 great so over here we can listen to this 5926 03:05:54,000 --> 03:05:54,720 event 5927 03:05:54,720 --> 03:05:56,580 however here is yet another extremely 5928 03:05:56,580 --> 03:05:58,859 important thing note how I made this on 5929 03:05:58,859 --> 03:06:01,319 start that is very important if you do 5930 03:06:01,319 --> 03:06:03,060 this over here on a week instead of 5931 03:06:03,060 --> 03:06:05,100 start and over here on the player you're 5932 03:06:05,100 --> 03:06:07,260 also setting the instance on awake if 5933 03:06:07,260 --> 03:06:08,819 you do that basically there is a chance 5934 03:06:08,819 --> 03:06:10,680 that this code won't run before this 5935 03:06:10,680 --> 03:06:12,840 code and if that happens well then this 5936 03:06:12,840 --> 03:06:14,399 one the player instance has not been set 5937 03:06:14,399 --> 03:06:16,319 yet so this will be null and don't throw 5938 03:06:16,319 --> 03:06:18,420 a known reference exception now whether 5939 03:06:18,420 --> 03:06:19,680 this happens or not it's actually 5940 03:06:19,680 --> 03:06:22,260 somewhat random it depends on the order 5941 03:06:22,260 --> 03:06:24,240 in which Unity decides to run both these 5942 03:06:24,240 --> 03:06:26,580 scripts if Unity decides to run the 5943 03:06:26,580 --> 03:06:29,340 player first and this one second 5944 03:06:29,340 --> 03:06:30,899 if that happens then there's no problem 5945 03:06:30,899 --> 03:06:32,880 but if Unity decides to run this first 5946 03:06:32,880 --> 03:06:34,500 and then this one then we have a problem 5947 03:06:34,500 --> 03:06:36,359 let me do a quick test and see if in my 5948 03:06:36,359 --> 03:06:38,520 case it triggers that error any up in my 5949 03:06:38,520 --> 03:06:40,439 case it did trigger that error so here 5950 03:06:40,439 --> 03:06:42,660 we have a no reference exception 5951 03:06:42,660 --> 03:06:44,460 any app it is being fired on this line 5952 03:06:44,460 --> 03:06:46,800 now one solution to this problem is you 5953 03:06:46,800 --> 03:06:48,479 can tell Unity specifically which order 5954 03:06:48,479 --> 03:06:50,700 the script should run in so you can go 5955 03:06:50,700 --> 03:06:52,620 up here into edit then go into the 5956 03:06:52,620 --> 03:06:53,760 project settings 5957 03:06:53,760 --> 03:06:55,380 then on the left side you've got 5958 03:06:55,380 --> 03:06:56,819 something called The Script execution 5959 03:06:56,819 --> 03:06:58,979 order and basically over here you can 5960 03:06:58,979 --> 03:07:00,420 set the order in which all of these 5961 03:07:00,420 --> 03:07:02,760 scripts run so if you were to make the 5962 03:07:02,760 --> 03:07:04,319 player script run before the default 5963 03:07:04,319 --> 03:07:06,120 time that would make sure that even 5964 03:07:06,120 --> 03:07:07,560 though both these scripts aren't awake 5965 03:07:07,560 --> 03:07:09,359 this one would run before this one so 5966 03:07:09,359 --> 03:07:11,640 that would fix that problem however you 5967 03:07:11,640 --> 03:07:12,960 should really only use this approach in 5968 03:07:12,960 --> 03:07:14,520 the last case possible where there 5969 03:07:14,520 --> 03:07:16,920 really is no other way in this case we 5970 03:07:16,920 --> 03:07:19,500 do have another better Wing personally I 5971 03:07:19,500 --> 03:07:21,000 have a very simple room that I like to 5972 03:07:21,000 --> 03:07:23,040 follow that helps solve this issue as 5973 03:07:23,040 --> 03:07:25,260 you know Unity has both an awake and a 5974 03:07:25,260 --> 03:07:26,100 start 5975 03:07:26,100 --> 03:07:28,319 and all of the awakes on all the objects 5976 03:07:28,319 --> 03:07:31,020 will all run before all these starts so 5977 03:07:31,020 --> 03:07:32,700 the simple rule that I follow is that I 5978 03:07:32,700 --> 03:07:34,439 use a wake for the initialization of 5979 03:07:34,439 --> 03:07:36,779 that script and for any external 5980 03:07:36,779 --> 03:07:39,420 reference for that I use it on start so 5981 03:07:39,420 --> 03:07:41,220 in this case for initializing the player 5982 03:07:41,220 --> 03:07:43,260 and setting the instance that will lead 5983 03:07:43,260 --> 03:07:44,760 to the initialization of the player so 5984 03:07:44,760 --> 03:07:46,439 let's do it on the Wake whereas over 5985 03:07:46,439 --> 03:07:47,939 here on the visual 5986 03:07:47,939 --> 03:07:49,680 since here we're going to access the 5987 03:07:49,680 --> 03:07:51,359 player which is an external reference 5988 03:07:51,359 --> 03:07:53,760 for this one instead of doing it on Wake 5989 03:07:53,760 --> 03:07:56,580 let's do it on start this way we are 5990 03:07:56,580 --> 03:07:58,020 guaranteed to make sure that this 5991 03:07:58,020 --> 03:08:00,420 instance has been set okay so with all 5992 03:08:00,420 --> 03:08:01,800 of that here we have our instance so 5993 03:08:01,800 --> 03:08:03,300 that works great and we have our events 5994 03:08:03,300 --> 03:08:05,340 so that's great then here we have our 5995 03:08:05,340 --> 03:08:07,020 event and inside we've got our event 5996 03:08:07,020 --> 03:08:09,720 arcs so we can go inside the event arcs 5997 03:08:09,720 --> 03:08:11,580 object and inside we have our selected 5998 03:08:11,580 --> 03:08:14,160 counter so we need to do is just compare 5999 03:08:14,160 --> 03:08:16,859 which counter this Vision belongs to 6000 03:08:16,859 --> 03:08:19,020 so let's actually make a film up here so 6001 03:08:19,020 --> 03:08:21,660 as usual let's make a serialized film of 6002 03:08:21,660 --> 03:08:24,800 type clear counter 6003 03:08:25,080 --> 03:08:27,060 so we have this one and before we go 6004 03:08:27,060 --> 03:08:28,200 into the editor just make sure it 6005 03:08:28,200 --> 03:08:30,120 compiles and let's comment this out so 6006 03:08:30,120 --> 03:08:32,340 now let's go back into the editor and 6007 03:08:32,340 --> 03:08:34,020 over here let's drag the reference but 6008 03:08:34,020 --> 03:08:35,640 again remember we're working with a 6009 03:08:35,640 --> 03:08:37,620 prefab so let's click on open to go 6010 03:08:37,620 --> 03:08:40,500 inside the prefab and now once inside it 6011 03:08:40,500 --> 03:08:42,420 let's select the selected game object 6012 03:08:42,420 --> 03:08:44,100 and just drag the clear counter 6013 03:08:44,100 --> 03:08:46,200 reference okay great let's go back 6014 03:08:46,200 --> 03:08:48,120 outside and save the changes all right 6015 03:08:48,120 --> 03:08:49,740 so now here in the code it's actually 6016 03:08:49,740 --> 03:08:52,080 very simple so we just do an if 6017 03:08:52,080 --> 03:08:54,180 if the selected counter matches this 6018 03:08:54,180 --> 03:08:55,680 clear counter 6019 03:08:55,680 --> 03:08:57,540 if so then we want to show this visual 6020 03:08:57,540 --> 03:08:59,760 if not we want to hide it so let's also 6021 03:08:59,760 --> 03:09:02,100 add a reference for that visual so let's 6022 03:09:02,100 --> 03:09:03,600 add another serialized field of type 6023 03:09:03,600 --> 03:09:08,479 game object for the visual game object 6024 03:09:08,520 --> 03:09:10,319 then back in the editor again let's go 6025 03:09:10,319 --> 03:09:11,819 inside the prefab and on the select 6026 03:09:11,819 --> 03:09:13,560 let's drag the channel kitchen counter 6027 03:09:13,560 --> 03:09:15,300 so drag down that is the visual game 6028 03:09:15,300 --> 03:09:18,000 object okay let's go back save and back 6029 03:09:18,000 --> 03:09:19,859 in the code here let's make some simple 6030 03:09:19,859 --> 03:09:21,960 show and hide functions so private void 6031 03:09:21,960 --> 03:09:22,859 show 6032 03:09:22,859 --> 03:09:25,439 and a private void hides 6033 03:09:25,439 --> 03:09:27,540 and now on the show just going to visual 6034 03:09:27,540 --> 03:09:30,060 game object and call set active so this 6035 03:09:30,060 --> 03:09:32,279 enables or disables the game object so 6036 03:09:32,279 --> 03:09:34,380 for sure let's set it to true and for 6037 03:09:34,380 --> 03:09:36,300 hiding let's set it back into fonts okay 6038 03:09:36,300 --> 03:09:38,160 so now it's super simple if the selected 6039 03:09:38,160 --> 03:09:39,840 counter is this counter then let's show 6040 03:09:39,840 --> 03:09:42,540 the visual if it is not then let's hide 6041 03:09:42,540 --> 03:09:44,580 the visual alright that's it super 6042 03:09:44,580 --> 03:09:47,160 simple let's test so here we are and if 6043 03:09:47,160 --> 03:09:49,080 I approach that counter yep there you go 6044 03:09:49,080 --> 03:09:50,939 look at that nice selected Visual and if 6045 03:09:50,939 --> 03:09:52,319 I get into this one yep there you go I 6046 03:09:52,319 --> 03:09:55,920 can see it all right great so here we 6047 03:09:55,920 --> 03:09:58,080 had a really nice visual to our selected 6048 03:09:58,080 --> 03:10:00,120 counter and more importantly we'll learn 6049 03:10:00,120 --> 03:10:02,160 about the super useful Singleton pattern 6050 03:10:02,160 --> 03:10:04,020 as well as learning about c-sharp 6051 03:10:04,020 --> 03:10:06,420 properties and a very helpful room for 6052 03:10:06,420 --> 03:10:08,939 how to avoid code timing issues so this 6053 03:10:08,939 --> 03:10:10,500 was a really detailed really important 6054 03:10:10,500 --> 03:10:12,540 lecture if you're feeling confused about 6055 03:10:12,540 --> 03:10:14,700 anything go ahead watch it again or just 6056 03:10:14,700 --> 03:10:16,020 post a question in the comments and I'll 6057 03:10:16,020 --> 03:10:18,120 do my best to help so with all of this 6058 03:10:18,120 --> 03:10:19,800 this is all great we have these unlike 6059 03:10:19,800 --> 03:10:21,300 the counter and we can see which one is 6060 03:10:21,300 --> 03:10:23,460 actually being selected then by pressing 6061 03:10:23,460 --> 03:10:25,200 a button we can actually interact with 6062 03:10:25,200 --> 03:10:27,000 it so I can move and interact with any 6063 03:10:27,000 --> 03:10:29,399 of these counters but right now just 6064 03:10:29,399 --> 03:10:30,840 interacting with them doesn't really do 6065 03:10:30,840 --> 03:10:33,120 anything so the next thing we need is to 6066 03:10:33,120 --> 03:10:34,680 create some proper objects for all of 6067 03:10:34,680 --> 03:10:36,479 our ingredients so we can later pick 6068 03:10:36,479 --> 03:10:38,580 them up and drop them on counters so 6069 03:10:38,580 --> 03:10:40,080 let's begin doing that in the next 6070 03:10:40,080 --> 03:10:41,819 lecture 6071 03:10:41,819 --> 03:10:43,979 hey again quick intermission your pass 6072 03:10:43,979 --> 03:10:45,859 C15 lecture marks so congratulations 6073 03:10:45,859 --> 03:10:48,420 looking at my regular core stats it 6074 03:10:48,420 --> 03:10:50,580 seems about 80 of people give up by this 6075 03:10:50,580 --> 03:10:52,439 point so great job with sticking with it 6076 03:10:52,439 --> 03:10:54,720 the difficulty in complexity is 6077 03:10:54,720 --> 03:10:56,340 increasing over the lectures so I just 6078 03:10:56,340 --> 03:10:57,540 want to check in to make sure you're 6079 03:10:57,540 --> 03:10:59,760 understanding everything remember to 6080 03:10:59,760 --> 03:11:01,080 post in the comments if you need extra 6081 03:11:01,080 --> 03:11:03,240 clarification on anything and I'll do my 6082 03:11:03,240 --> 03:11:04,439 best to answer 6083 03:11:04,439 --> 03:11:06,120 also check the website to see what 6084 03:11:06,120 --> 03:11:07,859 questions others have asked and of 6085 03:11:07,859 --> 03:11:09,300 course remember this is your Learning 6086 03:11:09,300 --> 03:11:10,920 Journey you're not competing with anyone 6087 03:11:10,920 --> 03:11:13,620 but yourself so take your time re-watch 6088 03:11:13,620 --> 03:11:15,300 some lectures if you need to just focus 6089 03:11:15,300 --> 03:11:17,640 on learning okay let's go to the next 6090 03:11:17,640 --> 03:11:19,080 lecture 6091 03:11:19,080 --> 03:11:21,060 hello and welcome I'm your code monkey 6092 03:11:21,060 --> 03:11:23,160 in this lecture we're going to learn how 6093 03:11:23,160 --> 03:11:25,080 to create the kitchen objects like the 6094 03:11:25,080 --> 03:11:27,479 various ingredients okay so far we have 6095 03:11:27,479 --> 03:11:29,460 our player we can walk around I can 6096 03:11:29,460 --> 03:11:31,140 approach each of these counters and I 6097 03:11:31,140 --> 03:11:33,000 can interact with now the next one is to 6098 03:11:33,000 --> 03:11:34,620 create objects the player can pick up 6099 03:11:34,620 --> 03:11:36,300 and drop when interacting with a clear 6100 03:11:36,300 --> 03:11:38,520 counter so let's begin by making the 6101 03:11:38,520 --> 03:11:40,319 actual objects so let's create a new 6102 03:11:40,319 --> 03:11:42,300 empty game object call this one the 6103 03:11:42,300 --> 03:11:44,220 Tomato then again as usual let's 6104 03:11:44,220 --> 03:11:46,560 separate the visual so in the included 6105 03:11:46,560 --> 03:11:48,420 assets let's go inside of it then we've 6106 03:11:48,420 --> 03:11:50,160 got the prefab visuals and we've got the 6107 03:11:50,160 --> 03:11:52,439 kitchen objects visuals and inside we've 6108 03:11:52,439 --> 03:11:54,479 got all of the ingredients so let's just 6109 03:11:54,479 --> 03:11:56,220 find the Tomato Visual and drag it as a 6110 03:11:56,220 --> 03:11:58,319 child of the tomato and again as usual 6111 03:11:58,319 --> 03:11:59,880 make sure to put on position low 6112 03:11:59,880 --> 03:12:02,640 composition zero zero zero and for the 6113 03:12:02,640 --> 03:12:04,740 main one let's put it on a y of zero and 6114 03:12:04,740 --> 03:12:06,000 just push it a little bit off to the 6115 03:12:06,000 --> 03:12:07,979 side just so we can see okay great 6116 03:12:07,979 --> 03:12:10,140 now this one is obviously not going to 6117 03:12:10,140 --> 03:12:11,700 exist over here in our world instead 6118 03:12:11,700 --> 03:12:13,920 we're going to spawn it so let's make it 6119 03:12:13,920 --> 03:12:15,479 a prefab let's just drag it over here 6120 03:12:15,479 --> 03:12:18,120 into our prefabs okay there it is let's 6121 03:12:18,120 --> 03:12:20,700 delete it from our scene and actually on 6122 03:12:20,700 --> 03:12:22,680 our prefabs let's make a nice folder to 6123 03:12:22,680 --> 03:12:24,479 keep things nicely separated 6124 03:12:24,479 --> 03:12:26,399 so inside the prefabs let's make a 6125 03:12:26,399 --> 03:12:27,899 subfolder 6126 03:12:27,899 --> 03:12:30,300 currently the kitchen objects 6127 03:12:30,300 --> 03:12:32,399 let's put the tomato inside of it and 6128 03:12:32,399 --> 03:12:34,380 let's also make another folder 6129 03:12:34,380 --> 03:12:36,660 for the counters and let's put the clear 6130 03:12:36,660 --> 03:12:38,279 counter inside of it okay so everything 6131 03:12:38,279 --> 03:12:40,560 is nicely organized all right now that 6132 03:12:40,560 --> 03:12:42,720 we have this let's go inside our clear 6133 03:12:42,720 --> 03:12:45,300 counter script and over here let's add a 6134 03:12:45,300 --> 03:12:47,460 simple reference to our prefab 6135 03:12:47,460 --> 03:12:49,920 so let's make a type transform called 6136 03:12:49,920 --> 03:12:52,740 the Tomato prefab 6137 03:12:52,740 --> 03:12:54,479 by the way here you could make this 6138 03:12:54,479 --> 03:12:56,340 prefab reference of type game object 6139 03:12:56,340 --> 03:12:58,260 which type you use in this scenario is 6140 03:12:58,260 --> 03:13:00,240 pretty interchangeable I talked about 6141 03:13:00,240 --> 03:13:02,279 those differences in another video so 6142 03:13:02,279 --> 03:13:04,319 when using prefabs using them as 6143 03:13:04,319 --> 03:13:06,000 transforms or game objects that's pretty 6144 03:13:06,000 --> 03:13:07,800 much personal preference and personally 6145 03:13:07,800 --> 03:13:10,020 I just prefer to use them as transforms 6146 03:13:10,020 --> 03:13:11,819 okay so we have this let's just make 6147 03:13:11,819 --> 03:13:13,620 this a serialized field so we can set it 6148 03:13:13,620 --> 03:13:15,540 in the editor and over here in the 6149 03:13:15,540 --> 03:13:17,580 editor let's open up go inside the 6150 03:13:17,580 --> 03:13:19,439 counter prefab and just drag the Tomato 6151 03:13:19,439 --> 03:13:21,240 reference okay great let's go back 6152 03:13:21,240 --> 03:13:24,000 outside save now back in the code here 6153 03:13:24,000 --> 03:13:25,859 when the player interacts with it let's 6154 03:13:25,859 --> 03:13:27,899 just spawn it so let's call instantiate 6155 03:13:27,899 --> 03:13:30,840 pass in the Tomato prefab and now here 6156 03:13:30,840 --> 03:13:32,340 is a good question which is where 6157 03:13:32,340 --> 03:13:34,800 exactly do we spawn this we don't want 6158 03:13:34,800 --> 03:13:36,479 to spawn on this counter's origin 6159 03:13:36,479 --> 03:13:38,700 remember that the counter the way we set 6160 03:13:38,700 --> 03:13:40,560 it up the origin on the actual object is 6161 03:13:40,560 --> 03:13:42,600 over there on the bottom we don't want 6162 03:13:42,600 --> 03:13:44,580 to spawn the tomato inside the mesh that 6163 03:13:44,580 --> 03:13:46,500 would not make sense instead what we 6164 03:13:46,500 --> 03:13:48,779 want is to spawn up here so the next 6165 03:13:48,779 --> 03:13:50,460 question is okay so how do we get this 6166 03:13:50,460 --> 03:13:52,500 point on top of the counter one approach 6167 03:13:52,500 --> 03:13:54,359 would be to use a vector 3 directly in 6168 03:13:54,359 --> 03:13:56,279 the code that would work but not very 6169 03:13:56,279 --> 03:13:58,620 usable so a more designer friendly 6170 03:13:58,620 --> 03:14:00,240 method is to Simply use an empty game 6171 03:14:00,240 --> 03:14:02,460 object as a Target so on the counter 6172 03:14:02,460 --> 03:14:04,859 let's first go inside our prefab 6173 03:14:04,859 --> 03:14:06,720 and over here let's create an empty game 6174 03:14:06,720 --> 03:14:09,120 object inside of it let's call this the 6175 03:14:09,120 --> 03:14:10,979 counter top point 6176 03:14:10,979 --> 03:14:12,479 let's make sure to leave this one as 6177 03:14:12,479 --> 03:14:14,520 empty so no components just a transform 6178 03:14:14,520 --> 03:14:16,439 and now let's just position it so let's 6179 03:14:16,439 --> 03:14:18,540 lift it up by just about enough so let's 6180 03:14:18,540 --> 03:14:21,000 make sure we see so there you go just 6181 03:14:21,000 --> 03:14:23,640 about that so let's put it on position a 6182 03:14:23,640 --> 03:14:26,340 y of 1.3 all right so this point is 6183 03:14:26,340 --> 03:14:28,260 going to be our spawn point let's make 6184 03:14:28,260 --> 03:14:29,819 sure to save the prefab 6185 03:14:29,819 --> 03:14:31,680 then back in the code here let's add a 6186 03:14:31,680 --> 03:14:33,180 reference to our point 6187 03:14:33,180 --> 03:14:35,100 and for reference let's also use a 6188 03:14:35,100 --> 03:14:37,260 transform reference currently the 6189 03:14:37,260 --> 03:14:39,479 countertop point 6190 03:14:39,479 --> 03:14:41,580 okay now let's just come this line just 6191 03:14:41,580 --> 03:14:43,020 so the code compiles so we can drag the 6192 03:14:43,020 --> 03:14:45,000 reference back in the editor inside the 6193 03:14:45,000 --> 03:14:46,680 prefab let's just write the countertop 6194 03:14:46,680 --> 03:14:49,140 Point reference okay great so now here 6195 03:14:49,140 --> 03:14:51,060 when we call instantiate let's 6196 03:14:51,060 --> 03:14:53,220 instantiate it inside the countertop 6197 03:14:53,220 --> 03:14:55,319 point so this one's found the object so 6198 03:14:55,319 --> 03:14:57,420 let's say the transform for the Tomato 6199 03:14:57,420 --> 03:14:59,100 transform 6200 03:14:59,100 --> 03:15:01,140 and then we go inside this one and let's 6201 03:15:01,140 --> 03:15:02,939 just make sure we position it correctly 6202 03:15:02,939 --> 03:15:04,740 so let's put it on in local position of 6203 03:15:04,740 --> 03:15:07,020 vector 3.0 so this one put the object 6204 03:15:07,020 --> 03:15:09,180 exactly on top of our countertop point 6205 03:15:09,180 --> 03:15:11,640 also here very important don't make a 6206 03:15:11,640 --> 03:15:13,439 mistake make sure you're modifying the 6207 03:15:13,439 --> 03:15:15,300 low composition and not the global 6208 03:15:15,300 --> 03:15:17,880 position okay so with this let's test 6209 03:15:17,880 --> 03:15:19,920 over here in the editor let's go back 6210 03:15:19,920 --> 03:15:22,080 save our prefab and hit on play so here 6211 03:15:22,080 --> 03:15:23,580 we are let's approach a counter and 6212 03:15:23,580 --> 03:15:25,319 interact with it and if there you go it 6213 03:15:25,319 --> 03:15:27,240 does work the Tomato was indeed spawned 6214 03:15:27,240 --> 03:15:29,700 all right awesome okay so with this we 6215 03:15:29,700 --> 03:15:31,680 have pretty much our Basics working 6216 03:15:31,680 --> 03:15:33,960 we can move up to a counter we can 6217 03:15:33,960 --> 03:15:36,000 interact with it and spawn an object but 6218 03:15:36,000 --> 03:15:37,740 now let's say that we want to spawn a 6219 03:15:37,740 --> 03:15:39,300 different object so let's say now we 6220 03:15:39,300 --> 03:15:41,220 want to spawn some genes first of all 6221 03:15:41,220 --> 03:15:43,080 let's make the actual object so on the 6222 03:15:43,080 --> 03:15:45,060 Tomato let's press Ctrl D to duplicate 6223 03:15:45,060 --> 03:15:47,220 this one let's rename this to the cheese 6224 03:15:47,220 --> 03:15:50,279 block and let's go inside of it 6225 03:15:50,279 --> 03:15:52,620 now in here instead of the Tomato visual 6226 03:15:52,620 --> 03:15:54,600 let's drag here it is the cheeseboard 6227 03:15:54,600 --> 03:15:56,460 visual so let's use this one instead 6228 03:15:56,460 --> 03:15:58,620 okay there's our nice visual 6229 03:15:58,620 --> 03:16:00,420 let's make sure to save the prefab and 6230 03:16:00,420 --> 03:16:02,520 go back out and now let's say that we 6231 03:16:02,520 --> 03:16:04,200 want this one to spawn a tomato and this 6232 03:16:04,200 --> 03:16:06,420 one on the left to spawn some cheese so 6233 03:16:06,420 --> 03:16:07,920 let's override the prefab and over here 6234 03:16:07,920 --> 03:16:10,200 drag the cheese block and now if we hit 6235 03:16:10,200 --> 03:16:11,100 on play 6236 03:16:11,100 --> 03:16:12,960 can go up to this one yep there's a 6237 03:16:12,960 --> 03:16:14,460 tomato go this one any up there's some 6238 03:16:14,460 --> 03:16:17,340 cheese okay so it all looks great but 6239 03:16:17,340 --> 03:16:18,779 now let's say we want to know what 6240 03:16:18,779 --> 03:16:20,880 object we just spawned like what object 6241 03:16:20,880 --> 03:16:22,979 is on top of this spawn transform just 6242 03:16:22,979 --> 03:16:24,840 like this in the code all we have is a 6243 03:16:24,840 --> 03:16:27,180 transform reference so with this the 6244 03:16:27,180 --> 03:16:28,859 only way to know what type we spawned 6245 03:16:28,859 --> 03:16:30,960 would be if we had different prefabs for 6246 03:16:30,960 --> 03:16:32,700 every single object then we could 6247 03:16:32,700 --> 03:16:34,319 compare them one by one and see which 6248 03:16:34,319 --> 03:16:36,600 one this matches but then let's say what 6249 03:16:36,600 --> 03:16:38,520 if we wanted an actual string for the 6250 03:16:38,520 --> 03:16:40,800 object well then we would need to add 6251 03:16:40,800 --> 03:16:42,720 tons of fields for all these strings for 6252 03:16:42,720 --> 03:16:45,000 all of the objects then what about an 6253 03:16:45,000 --> 03:16:46,859 icon for each type once again we would 6254 03:16:46,859 --> 03:16:49,020 need tons of fields each one for each 6255 03:16:49,020 --> 03:16:51,060 icon but if we did it just like that 6256 03:16:51,060 --> 03:16:52,680 with a bunch of lists then they would be 6257 03:16:52,680 --> 03:16:54,960 separate that's not very good we should 6258 03:16:54,960 --> 03:16:56,819 have a proper way of defining our object 6259 03:16:56,819 --> 03:16:59,279 types and all the data related to them 6260 03:16:59,279 --> 03:17:01,200 so this is exactly where scriptable 6261 03:17:01,200 --> 03:17:03,420 objects come in these are objects you 6262 03:17:03,420 --> 03:17:05,100 can create in your project funnels which 6263 03:17:05,100 --> 03:17:06,720 are perfect for anything where you have 6264 03:17:06,720 --> 03:17:08,939 multiple instances of a type like for 6265 03:17:08,939 --> 03:17:11,040 example multiple weapons multiple armors 6266 03:17:11,040 --> 03:17:13,140 multiple recipes or maybe multiple 6267 03:17:13,140 --> 03:17:15,600 ingredients as usual I have a dedicated 6268 03:17:15,600 --> 03:17:17,760 video on script along objects they are 6269 03:17:17,760 --> 03:17:19,260 super useful definitely watch out for 6270 03:17:19,260 --> 03:17:21,000 more detail over here on let's just use 6271 03:17:21,000 --> 03:17:22,859 them so the first thing we're going to 6272 03:17:22,859 --> 03:17:24,660 need is to actually Define the type and 6273 03:17:24,660 --> 03:17:27,000 we do that in a c-sharp script so in our 6274 03:17:27,000 --> 03:17:28,620 scripts folder let's create new c-sharp 6275 03:17:28,620 --> 03:17:32,279 script call this the kitchen object so 6276 03:17:32,279 --> 03:17:34,680 now personally so is just what I like to 6277 03:17:34,680 --> 03:17:36,600 open to my scriptable object definitions 6278 03:17:36,600 --> 03:17:38,640 just to make it very clear that it's a 6279 03:17:38,640 --> 03:17:40,859 script mode object however this is not a 6280 03:17:40,859 --> 03:17:42,540 requirement it's just a naming room that 6281 03:17:42,540 --> 03:17:44,340 I like to follow and we're calling this 6282 03:17:44,340 --> 03:17:45,720 kitchen object because we're going to 6283 03:17:45,720 --> 03:17:47,700 use this to Define any kitchen object we 6284 03:17:47,700 --> 03:17:49,020 want to interact with 6285 03:17:49,020 --> 03:17:50,760 so that's going to be our ingredients 6286 03:17:50,760 --> 03:17:52,140 like for example the tomato and cheese 6287 03:17:52,140 --> 03:17:54,540 but also things like a plate and then 6288 03:17:54,540 --> 03:17:55,920 potentially you could Implement things 6289 03:17:55,920 --> 03:17:57,840 like a frying pan or framing signature 6290 03:17:57,840 --> 03:17:59,640 or anything like that so it's going to 6291 03:17:59,640 --> 03:18:01,500 represent any kind of kitchen object the 6292 03:18:01,500 --> 03:18:03,479 player can interact with Okay so let's 6293 03:18:03,479 --> 03:18:05,880 make the script and now let's open it 6294 03:18:05,880 --> 03:18:08,640 and over here okay first things first is 6295 03:18:08,640 --> 03:18:11,580 this is not a monobehavior instead let's 6296 03:18:11,580 --> 03:18:14,220 extend scriptable object and then 6297 03:18:14,220 --> 03:18:15,720 technically you can have functions 6298 03:18:15,720 --> 03:18:17,640 inside a straight ball object but for 6299 03:18:17,640 --> 03:18:19,140 now let's just get rid of this so just 6300 03:18:19,140 --> 03:18:21,180 an empty class and over here on let's 6301 03:18:21,180 --> 03:18:22,800 just Place whatever fields we need to 6302 03:18:22,800 --> 03:18:24,899 store whatever that we want so like I 6303 03:18:24,899 --> 03:18:26,760 said first we want a prefab so let's 6304 03:18:26,760 --> 03:18:29,279 make a public transform for our prefab 6305 03:18:29,279 --> 03:18:31,380 by the way here note how I am indeed 6306 03:18:31,380 --> 03:18:33,660 using public this is pretty much the one 6307 03:18:33,660 --> 03:18:35,700 exception to the room I only use 6308 03:18:35,700 --> 03:18:37,500 scripting objects as read-only data 6309 03:18:37,500 --> 03:18:39,960 containers I never write to them so 6310 03:18:39,960 --> 03:18:41,640 since I found that rule I usually make 6311 03:18:41,640 --> 03:18:42,899 the fields in the description object 6312 03:18:42,899 --> 03:18:44,939 public that way I can access them 6313 03:18:44,939 --> 03:18:46,560 directly without having to make a public 6314 03:18:46,560 --> 03:18:48,899 getter but if you want to feel free to 6315 03:18:48,899 --> 03:18:50,340 keep following the general rule of not 6316 03:18:50,340 --> 03:18:52,080 making anything public you could 6317 03:18:52,080 --> 03:18:53,520 definitely make this just a regular 6318 03:18:53,520 --> 03:18:55,200 serialized film then exposed with a get 6319 03:18:55,200 --> 03:18:57,420 function that would work personally I 6320 03:18:57,420 --> 03:18:58,920 just find it simpler to make it public 6321 03:18:58,920 --> 03:19:01,080 since I know that as a personal rule I 6322 03:19:01,080 --> 03:19:02,760 will never write to a script mode object 6323 03:19:02,760 --> 03:19:04,859 field okay so we have a transform for 6324 03:19:04,859 --> 03:19:07,859 our prefab let's also add a Sprite for 6325 03:19:07,859 --> 03:19:10,319 the icon Sprite and finally let's just 6326 03:19:10,319 --> 03:19:13,680 add a simple string for the object name 6327 03:19:13,680 --> 03:19:15,840 all right so we have our scribble object 6328 03:19:15,840 --> 03:19:17,939 definition we have all of the fields for 6329 03:19:17,939 --> 03:19:20,220 all of the data we want to store now how 6330 03:19:20,220 --> 03:19:22,260 do we actually create a scribble object 6331 03:19:22,260 --> 03:19:24,060 for that let's go up here before the 6332 03:19:24,060 --> 03:19:25,740 class name and we're going to add the 6333 03:19:25,740 --> 03:19:27,120 attribute so let's add the square 6334 03:19:27,120 --> 03:19:29,640 brackets and the attribute is the create 6335 03:19:29,640 --> 03:19:31,800 asset menu this takes some optional 6336 03:19:31,800 --> 03:19:33,899 parameters again I cover them in detail 6337 03:19:33,899 --> 03:19:35,520 in the dedicated script and objects 6338 03:19:35,520 --> 03:19:37,500 video for now let's just leave all the 6339 03:19:37,500 --> 03:19:39,600 parameters as empty just use defaults 6340 03:19:39,600 --> 03:19:41,580 and close the attribute okay so that's 6341 03:19:41,580 --> 03:19:43,200 it let's save this and go back into the 6342 03:19:43,200 --> 03:19:45,660 editor and over here if we go into the 6343 03:19:45,660 --> 03:19:47,220 project window click on the plus icon 6344 03:19:47,220 --> 03:19:49,260 and right up top yep we do see a kitchen 6345 03:19:49,260 --> 03:19:50,520 object so 6346 03:19:50,520 --> 03:19:52,680 so if we selected if there you go it 6347 03:19:52,680 --> 03:19:54,420 creates a brand new object inside of our 6348 03:19:54,420 --> 03:19:57,359 project files let's name this one tomato 6349 03:19:57,359 --> 03:19:58,979 and obviously let's keep our project 6350 03:19:58,979 --> 03:20:00,720 nice and organized so we don't want this 6351 03:20:00,720 --> 03:20:03,060 inside the scripts folder instead let's 6352 03:20:03,060 --> 03:20:04,859 make a proper folder so create a new 6353 03:20:04,859 --> 03:20:07,380 folder come with our scriptable objects 6354 03:20:07,380 --> 03:20:09,540 and then inside let's put a different 6355 03:20:09,540 --> 03:20:11,520 folder for each type so let's make 6356 03:20:11,520 --> 03:20:13,680 another subfolder call it the kitchen 6357 03:20:13,680 --> 03:20:16,380 object so and let's place the tomato 6358 03:20:16,380 --> 03:20:18,720 inside of it okay now with the Tomato 6359 03:20:18,720 --> 03:20:20,520 selected we can look in the inspector 6360 03:20:20,520 --> 03:20:22,920 and you can see yup it does have all of 6361 03:20:22,920 --> 03:20:25,200 the fields that we Define okay great so 6362 03:20:25,200 --> 03:20:27,120 now we can just assign them so this is 6363 03:20:27,120 --> 03:20:28,740 the tomatoes let's drag the Tomato 6364 03:20:28,740 --> 03:20:31,740 prefab for the icon Sprite let's find it 6365 03:20:31,740 --> 03:20:33,600 so there are Sprites included in the 6366 03:20:33,600 --> 03:20:35,040 regular assets so here is the Tomato 6367 03:20:35,040 --> 03:20:37,620 Sprite so it's inside the acids then 6368 03:20:37,620 --> 03:20:39,720 inside textures icons and we have all 6369 03:20:39,720 --> 03:20:42,060 the icons and finally for the readable 6370 03:20:42,060 --> 03:20:44,100 name let's just call it tomato alright 6371 03:20:44,100 --> 03:20:46,380 so that's it here we have a really nice 6372 03:20:46,380 --> 03:20:48,240 scribble object containing all the data 6373 03:20:48,240 --> 03:20:50,100 required for our tomato okay awesome 6374 03:20:50,100 --> 03:20:52,200 with that then we can now go back into 6375 03:20:52,200 --> 03:20:54,300 our clear counter script and here 6376 03:20:54,300 --> 03:20:56,160 instead of having a field for our tomato 6377 03:20:56,160 --> 03:20:58,500 prefab instead of this let's sort of 6378 03:20:58,500 --> 03:21:01,260 reference of type kitchen object so and 6379 03:21:01,260 --> 03:21:03,600 let's go on with kitchen object so and 6380 03:21:03,600 --> 03:21:05,340 then when spawning let's go inside our 6381 03:21:05,340 --> 03:21:07,020 scriptball object and just spawn the 6382 03:21:07,020 --> 03:21:09,300 prefab reference so this is going to be 6383 03:21:09,300 --> 03:21:13,080 the kitchen object transform then over 6384 03:21:13,080 --> 03:21:14,700 here in the editor let's go inside the 6385 03:21:14,700 --> 03:21:16,800 clear counter and let's assign the 6386 03:21:16,800 --> 03:21:18,960 Tomato Kitchen object okay so let's save 6387 03:21:18,960 --> 03:21:20,220 it and test 6388 03:21:20,220 --> 03:21:22,319 so here we are on let's approach hit any 6389 03:21:22,319 --> 03:21:23,760 up there you go it still spawns eat 6390 03:21:23,760 --> 03:21:26,160 tomato okay great now let's make another 6391 03:21:26,160 --> 03:21:28,439 type for our cheese block so let's 6392 03:21:28,439 --> 03:21:30,120 create a brand new kitchen object so 6393 03:21:30,120 --> 03:21:32,939 called the cheese block and again let's 6394 03:21:32,939 --> 03:21:34,920 assign first of all the prefab there it 6395 03:21:34,920 --> 03:21:36,540 is then for the Sprite of the cheese 6396 03:21:36,540 --> 03:21:39,300 walk and finally this is the cheese well 6397 03:21:39,300 --> 03:21:41,220 okay so now for example let's go into 6398 03:21:41,220 --> 03:21:43,560 the second one and on the second counter 6399 03:21:43,560 --> 03:21:45,660 let's override and say this one spawn a 6400 03:21:45,660 --> 03:21:48,120 cheese block so let's test so here we 6401 03:21:48,120 --> 03:21:49,560 are approach this one yep there's tomato 6402 03:21:49,560 --> 03:21:51,240 this one any of there's some cheese okay 6403 03:21:51,240 --> 03:21:53,760 great so everything is working so far 6404 03:21:53,760 --> 03:21:55,859 however the original problem that we're 6405 03:21:55,859 --> 03:21:57,840 trying to solve identifying the spawn 6406 03:21:57,840 --> 03:21:59,640 prefab we still don't have a solution 6407 03:21:59,640 --> 03:22:01,979 for that basically when we spawn a 6408 03:22:01,979 --> 03:22:03,960 prefab we need to know from which script 6409 03:22:03,960 --> 03:22:06,000 No Object this prefab came from so 6410 03:22:06,000 --> 03:22:07,380 essentially what I like to do is just 6411 03:22:07,380 --> 03:22:08,760 attach some reference to the scripting 6412 03:22:08,760 --> 03:22:10,859 object in our prefab however again 6413 03:22:10,859 --> 03:22:12,840 remember that scripting objects are not 6414 03:22:12,840 --> 03:22:15,479 mono behaviors so if I select the prefab 6415 03:22:15,479 --> 03:22:16,680 and I try dragging the description 6416 03:22:16,680 --> 03:22:18,960 object nope it does not work so what we 6417 03:22:18,960 --> 03:22:21,600 can do is just create a new script so 6418 03:22:21,600 --> 03:22:23,399 let's make a brand new c-sharp script 6419 03:22:23,399 --> 03:22:26,160 let's call it kitchen object 6420 03:22:26,160 --> 03:22:28,680 let's attach this to both prefab so both 6421 03:22:28,680 --> 03:22:30,359 the cheese and the block attach the same 6422 03:22:30,359 --> 03:22:32,880 one to both of them and let's open 6423 03:22:32,880 --> 03:22:34,740 and over here very simple let's just add 6424 03:22:34,740 --> 03:22:36,479 a serialized film for our kitchen object 6425 03:22:36,479 --> 03:22:39,840 so a serialized film of type 6426 03:22:39,840 --> 03:22:42,240 kitchen object so for the kitchen object 6427 03:22:42,240 --> 03:22:43,380 the cell 6428 03:22:43,380 --> 03:22:45,120 then let's also make a quick function to 6429 03:22:45,120 --> 03:22:46,200 expose it so we're going to return 6430 03:22:46,200 --> 03:22:48,840 kitchen object as so get kitchen object 6431 03:22:48,840 --> 03:22:51,180 so and we just return the kitchen object 6432 03:22:51,180 --> 03:22:53,640 as well yep just like this so now here 6433 03:22:53,640 --> 03:22:55,380 in the editor for the Tomato yep we've 6434 03:22:55,380 --> 03:22:57,000 got the film so let's say this one is a 6435 03:22:57,000 --> 03:22:58,920 tomato and the cheese block this one is 6436 03:22:58,920 --> 03:23:01,439 a cheese block now here obviously we 6437 03:23:01,439 --> 03:23:03,660 need to make very very sure to drag the 6438 03:23:03,660 --> 03:23:05,220 correct reference to the right scriven 6439 03:23:05,220 --> 03:23:07,080 object if you drag the wrong one like 6440 03:23:07,080 --> 03:23:08,580 for example over here on cheese you 6441 03:23:08,580 --> 03:23:10,380 would say this one is a tomato if you 6442 03:23:10,380 --> 03:23:11,700 did that then obviously you would get 6443 03:23:11,700 --> 03:23:14,279 some very weird results so make sure to 6444 03:23:14,279 --> 03:23:16,140 check and double check that you drag the 6445 03:23:16,140 --> 03:23:18,300 right preferences both over here on the 6446 03:23:18,300 --> 03:23:19,739 prefabs make sure they are referencing 6447 03:23:19,739 --> 03:23:21,840 the correct Circle object and on the 6448 03:23:21,840 --> 03:23:23,399 script module itself make sure they are 6449 03:23:23,399 --> 03:23:25,500 referencing the correct prefont okay so 6450 03:23:25,500 --> 03:23:27,479 now if you go here on the clear counter 6451 03:23:27,479 --> 03:23:30,540 we spawn our object okay great then on 6452 03:23:30,540 --> 03:23:32,700 this object we can do get component of 6453 03:23:32,700 --> 03:23:35,340 type kitchen object and then we can just 6454 03:23:35,340 --> 03:23:37,319 ask it to give us the kitchen object as 6455 03:23:37,319 --> 03:23:39,540 well so for example let's do a debug 6456 03:23:39,540 --> 03:23:41,399 download on this one 6457 03:23:41,399 --> 03:23:43,319 so inside you get the kitchen object to 6458 03:23:43,319 --> 03:23:44,939 sew and then let's print out the object 6459 03:23:44,939 --> 03:23:46,920 name all right so here we are let's 6460 03:23:46,920 --> 03:23:48,359 interact with this one and if there you 6461 03:23:48,359 --> 03:23:50,160 go interacted and spawn the tomato and 6462 03:23:50,160 --> 03:23:52,200 on this one yep interacted and spawned a 6463 03:23:52,200 --> 03:23:54,720 cheese block okay awesome we spawned a 6464 03:23:54,720 --> 03:23:56,760 transform prefab and we identify the 6465 03:23:56,760 --> 03:23:58,620 spawn object is indeed this type of 6466 03:23:58,620 --> 03:24:00,720 object all right so here we'll learn 6467 03:24:00,720 --> 03:24:02,399 about one of the most powerful ENT 6468 03:24:02,399 --> 03:24:04,800 features scribble objects these are 6469 03:24:04,800 --> 03:24:06,660 extremely useful for defining a type and 6470 03:24:06,660 --> 03:24:08,460 then creating multiple instances of that 6471 03:24:08,460 --> 03:24:10,800 type with whatever that we want so there 6472 03:24:10,800 --> 03:24:12,239 can be some ingredients like we have 6473 03:24:12,239 --> 03:24:14,640 here or it could be some weapons could 6474 03:24:14,640 --> 03:24:16,739 even be some NPC data maybe some Quest 6475 03:24:16,739 --> 03:24:19,260 data and so on it really is an insanely 6476 03:24:19,260 --> 03:24:21,420 very useful feature definitely go ahead 6477 03:24:21,420 --> 03:24:23,340 and watch a dedicated video on script on 6478 03:24:23,340 --> 03:24:25,260 objects then if you want you can also 6479 03:24:25,260 --> 03:24:26,700 watch some more videos where I've used 6480 03:24:26,700 --> 03:24:28,739 scriven objects for example in the 6481 03:24:28,739 --> 03:24:30,120 Minecraft crafting system using 6482 03:24:30,120 --> 03:24:32,520 scripting objects or the hydrogenated 6483 03:24:32,520 --> 03:24:34,080 crafting system which again also uses 6484 03:24:34,080 --> 03:24:36,359 scribdon objects okay so this is done 6485 03:24:36,359 --> 03:24:38,760 it's working great now let's continue to 6486 03:24:38,760 --> 03:24:40,260 the next lecture where we're going to 6487 03:24:40,260 --> 03:24:42,120 help the kitchen object know where it 6488 03:24:42,120 --> 03:24:44,220 belongs and help each counter know what 6489 03:24:44,220 --> 03:24:46,859 kitchen object is on top of it 6490 03:24:46,859 --> 03:24:49,020 hello and welcome I'm your code monkey 6491 03:24:49,020 --> 03:24:51,420 in this lecture we're going to create a 6492 03:24:51,420 --> 03:24:53,520 kitchen object parent meaning that the 6493 03:24:53,520 --> 03:24:55,500 kitchen object will know where it is and 6494 03:24:55,500 --> 03:24:57,359 the counter will know if something is on 6495 03:24:57,359 --> 03:24:59,460 it this is important so that later on we 6496 03:24:59,460 --> 03:25:01,380 can pick up a kitchen object from one 6497 03:25:01,380 --> 03:25:03,720 place and drop it in another okay so 6498 03:25:03,720 --> 03:25:05,520 here we have our player I can move 6499 03:25:05,520 --> 03:25:07,080 towards this counter interact with it 6500 03:25:07,080 --> 03:25:08,819 and yep spawn a tomato then on this 6501 03:25:08,819 --> 03:25:11,580 one's want some cheese okay great but I 6502 03:25:11,580 --> 03:25:13,739 cannot do anything else in fact if I 6503 03:25:13,739 --> 03:25:16,319 interact a bunch more times really all I 6504 03:25:16,319 --> 03:25:17,760 did was just spawn a whole bunch more 6505 03:25:17,760 --> 03:25:20,040 cheese so instead I want to be able to 6506 03:25:20,040 --> 03:25:22,319 spawn some cheese and then pick it up so 6507 03:25:22,319 --> 03:25:23,700 let's think about exactly what that 6508 03:25:23,700 --> 03:25:25,979 means we want a kitchen object to 6509 03:25:25,979 --> 03:25:27,479 essentially be placed on a specific 6510 03:25:27,479 --> 03:25:29,580 Place based on the design that we're 6511 03:25:29,580 --> 03:25:31,020 trying to implement we're never going to 6512 03:25:31,020 --> 03:25:32,760 have a kitchen object just randomly 6513 03:25:32,760 --> 03:25:34,739 thrown around the world we're not going 6514 03:25:34,739 --> 03:25:36,380 to have tomatoes all over the floor 6515 03:25:36,380 --> 03:25:38,700 instead the objects will always need to 6516 03:25:38,700 --> 03:25:40,560 be placed somewhere and that somewhere 6517 03:25:40,560 --> 03:25:42,359 can be either a counter or it can be 6518 03:25:42,359 --> 03:25:44,460 being held by the player so essentially 6519 03:25:44,460 --> 03:25:46,260 that means that each kitchen object is 6520 03:25:46,260 --> 03:25:47,700 going to have some kind of parent that 6521 03:25:47,700 --> 03:25:49,380 it's attached to we're going to make 6522 03:25:49,380 --> 03:25:50,939 sure the counter knows if there is a 6523 03:25:50,939 --> 03:25:52,920 kitchen object placed on top of it and 6524 03:25:52,920 --> 03:25:53,939 we're also going to make sure the 6525 03:25:53,939 --> 03:25:55,739 kitchen object itself knows where it is 6526 03:25:55,739 --> 03:25:57,840 so first let's do that logic over here 6527 03:25:57,840 --> 03:25:58,920 on the counter 6528 03:25:58,920 --> 03:26:01,140 so on the clear counter script let's 6529 03:26:01,140 --> 03:26:03,960 keep a field for a kitchen object 6530 03:26:03,960 --> 03:26:06,359 so just a simple private of type kitchen 6531 03:26:06,359 --> 03:26:10,080 object kitchen object 6532 03:26:10,080 --> 03:26:12,060 then when the player interacts with it 6533 03:26:12,060 --> 03:26:14,640 by the way we can get rid of these debug 6534 03:26:14,640 --> 03:26:16,439 transforms debug logs in all you need 6535 03:26:16,439 --> 03:26:18,840 them okay so when the plane interacts so 6536 03:26:18,840 --> 03:26:20,760 if the kitchen object is known 6537 03:26:20,760 --> 03:26:23,460 if so then we're going to spawn it then 6538 03:26:23,460 --> 03:26:25,319 when we spawn it let's assign it so this 6539 03:26:25,319 --> 03:26:27,239 one equals the kitchen object get 6540 03:26:27,239 --> 03:26:30,359 component of type kitchen object okay 6541 03:26:30,359 --> 03:26:32,220 so if that one is no we spawn it and we 6542 03:26:32,220 --> 03:26:34,439 assign it and just with this we should 6543 03:26:34,439 --> 03:26:36,060 have fixed the issue where we can spawn 6544 03:26:36,060 --> 03:26:37,680 infinite objects 6545 03:26:37,680 --> 03:26:40,020 so over here I can interact and now I've 6546 03:26:40,020 --> 03:26:41,700 interact a bunch more times 6547 03:26:41,700 --> 03:26:43,739 and now look in the hierarchy inside the 6548 03:26:43,739 --> 03:26:44,939 clear counter 6549 03:26:44,939 --> 03:26:47,100 and I go inside the counter top Point 6550 03:26:47,100 --> 03:26:49,080 nope there's only one tomato okay great 6551 03:26:49,080 --> 03:26:51,180 so with this basically we made the clear 6552 03:26:51,180 --> 03:26:52,739 counter know if there's something on top 6553 03:26:52,739 --> 03:26:53,580 of it 6554 03:26:53,580 --> 03:26:56,220 now let's do the other side so let's go 6555 03:26:56,220 --> 03:26:57,540 into the kitchen object and make sure 6556 03:26:57,540 --> 03:26:59,880 that it knows where it is so over here 6557 03:26:59,880 --> 03:27:01,620 on the kitchen object script 6558 03:27:01,620 --> 03:27:03,899 let's add a simple field for a counter 6559 03:27:03,899 --> 03:27:06,359 so private of type clear counter for the 6560 03:27:06,359 --> 03:27:08,100 clear counter 6561 03:27:08,100 --> 03:27:09,720 and now let's just basically make two 6562 03:27:09,720 --> 03:27:11,580 functions one to set it and one to get 6563 03:27:11,580 --> 03:27:15,859 it so a public void set clear counter 6564 03:27:18,420 --> 03:27:20,399 and we're going to receive a parameter 6565 03:27:20,399 --> 03:27:22,920 of type clear counter okay great and 6566 03:27:22,920 --> 03:27:24,479 then we're going to have a public return 6567 03:27:24,479 --> 03:27:26,340 a clear counter for the get clear 6568 03:27:26,340 --> 03:27:27,660 counter 6569 03:27:27,660 --> 03:27:29,819 and we're just going to return our clear 6570 03:27:29,819 --> 03:27:32,160 counter and on this one just set this 6571 03:27:32,160 --> 03:27:33,899 dark layer counter equals this layer 6572 03:27:33,899 --> 03:27:34,859 counter 6573 03:27:34,859 --> 03:27:36,180 all right so on this function we're 6574 03:27:36,180 --> 03:27:37,380 assigning this field and on this 6575 03:27:37,380 --> 03:27:39,300 function we're returning this field 6576 03:27:39,300 --> 03:27:41,640 so now back on the counter script we get 6577 03:27:41,640 --> 03:27:43,620 the kitchen object reference so on this 6578 03:27:43,620 --> 03:27:45,779 one let's call set clear counter and 6579 03:27:45,779 --> 03:27:47,220 pass it in this one 6580 03:27:47,220 --> 03:27:48,660 and if it is not known so if there's 6581 03:27:48,660 --> 03:27:51,000 something on top of this let's just do a 6582 03:27:51,000 --> 03:27:53,220 debug.log let's go on to the kitchen 6583 03:27:53,220 --> 03:27:56,580 object and get the clear counter 6584 03:27:56,580 --> 03:27:58,319 so we should be able to click once and 6585 03:27:58,319 --> 03:28:00,420 spawn an object and click twice and the 6586 03:28:00,420 --> 03:28:01,979 second time we should be able to see the 6587 03:28:01,979 --> 03:28:03,660 name of this layer counter 6588 03:28:03,660 --> 03:28:05,460 all right so over here let's approach 6589 03:28:05,460 --> 03:28:07,319 and click and yep it's spawn now click 6590 03:28:07,319 --> 03:28:08,100 again 6591 03:28:08,100 --> 03:28:10,200 and if we've got the message this one is 6592 03:28:10,200 --> 03:28:13,020 on the planet counter okay great so far 6593 03:28:13,020 --> 03:28:13,920 so good 6594 03:28:13,920 --> 03:28:15,720 so the counter knows if there's a 6595 03:28:15,720 --> 03:28:17,580 kitchen object on top of it and the 6596 03:28:17,580 --> 03:28:19,260 kitchen object itself knows where it is 6597 03:28:19,260 --> 03:28:21,359 now let's add some logic to be able to 6598 03:28:21,359 --> 03:28:23,939 change a parent counter it's over here 6599 03:28:23,939 --> 03:28:26,340 on the clear counter script we basically 6600 03:28:26,340 --> 03:28:28,200 just need to call the set layer counter 6601 03:28:28,200 --> 03:28:30,120 function with a different counter 6602 03:28:30,120 --> 03:28:32,580 reference so just for testing let's add 6603 03:28:32,580 --> 03:28:34,500 a serialized film for the second counter 6604 03:28:34,500 --> 03:28:37,080 so clear counter for the second clear 6605 03:28:37,080 --> 03:28:38,939 counter 6606 03:28:38,939 --> 03:28:40,739 now we're doing this just for testing 6607 03:28:40,739 --> 03:28:42,359 just make sure the logic Works before we 6608 03:28:42,359 --> 03:28:44,580 come up with a more General system 6609 03:28:44,580 --> 03:28:46,319 so just for testing let's come up with 6610 03:28:46,319 --> 03:28:48,660 some input and again for testing using 6611 03:28:48,660 --> 03:28:50,340 the lazy input manager to get something 6612 03:28:50,340 --> 03:28:52,560 quickly up and running is a great thing 6613 03:28:52,560 --> 03:28:54,660 so let's quickly get a button input on 6614 03:28:54,660 --> 03:28:56,460 the counter so let's make a private void 6615 03:28:56,460 --> 03:28:57,420 update 6616 03:28:57,420 --> 03:28:59,580 and for testing we only want the testing 6617 03:28:59,580 --> 03:29:01,800 to work on one counter so let's also add 6618 03:29:01,800 --> 03:29:04,859 up here just a ball testing 6619 03:29:04,859 --> 03:29:08,279 and then on update if we are testing and 6620 03:29:08,279 --> 03:29:11,220 we have the input.getkeydown on let's 6621 03:29:11,220 --> 03:29:12,840 say the T key 6622 03:29:12,840 --> 03:29:14,640 so if you have that then we can run some 6623 03:29:14,640 --> 03:29:16,500 kind of testing code so let's say for 6624 03:29:16,500 --> 03:29:18,180 example if the kitchen object does not 6625 03:29:18,180 --> 03:29:20,760 know so if we have something on top of 6626 03:29:20,760 --> 03:29:22,920 this kitchen counter let's go into the 6627 03:29:22,920 --> 03:29:25,739 kitchen object and call set counter and 6628 03:29:25,739 --> 03:29:28,620 let's pass in the second clear counter 6629 03:29:28,620 --> 03:29:30,420 so basically with this we should be able 6630 03:29:30,420 --> 03:29:32,700 to interact to spawn an object and then 6631 03:29:32,700 --> 03:29:34,739 press the T key and we should be able to 6632 03:29:34,739 --> 03:29:36,540 see that object be set to a different 6633 03:29:36,540 --> 03:29:37,560 parent 6634 03:29:37,560 --> 03:29:39,180 so here in the after I'll let you set 6635 03:29:39,180 --> 03:29:40,680 down let's say this one is our main 6636 03:29:40,680 --> 03:29:43,140 counter so let's drag a reference to the 6637 03:29:43,140 --> 03:29:44,640 second one the second higher counter 6638 03:29:44,640 --> 03:29:46,200 drag it and make this one the testing 6639 03:29:46,200 --> 03:29:48,300 script and also just to verify that it 6640 03:29:48,300 --> 03:29:49,920 worked over here and lets you a get on 6641 03:29:49,920 --> 03:29:52,140 the clear counter all right so let's 6642 03:29:52,140 --> 03:29:53,279 test and see 6643 03:29:53,279 --> 03:29:55,380 okay so here we are let's approach this 6644 03:29:55,380 --> 03:29:57,060 one interact and there you go spawn 6645 03:29:57,060 --> 03:29:59,279 tomato and now if I interact again yep 6646 03:29:59,279 --> 03:30:00,600 it says the tomato is on the similar 6647 03:30:00,600 --> 03:30:02,700 counter now if I press the testing key 6648 03:30:02,700 --> 03:30:04,979 if there go the Tomato was moved onto 6649 03:30:04,979 --> 03:30:06,300 the other counter 6650 03:30:06,300 --> 03:30:08,279 okay so the parent change the logic 6651 03:30:08,279 --> 03:30:10,800 worked however obviously we have two big 6652 03:30:10,800 --> 03:30:12,960 issues the first one is just a visual 6653 03:30:12,960 --> 03:30:14,700 you can see the object is still placed 6654 03:30:14,700 --> 03:30:15,960 on top of this counter even though 6655 03:30:15,960 --> 03:30:18,000 technically now it belongs to this one 6656 03:30:18,000 --> 03:30:19,560 and the second issue is that this 6657 03:30:19,560 --> 03:30:21,239 counter still thinks that it owns this 6658 03:30:21,239 --> 03:30:23,399 kitchen object and this other counter 6659 03:30:23,399 --> 03:30:25,080 does not know that it now owns this 6660 03:30:25,080 --> 03:30:27,600 object so we need to sort all of that 6661 03:30:27,600 --> 03:30:29,520 first for the visual it's actually very 6662 03:30:29,520 --> 03:30:30,479 simple 6663 03:30:30,479 --> 03:30:32,340 here when spawning we are spawning it 6664 03:30:32,340 --> 03:30:33,840 inside the counter top point and then 6665 03:30:33,840 --> 03:30:36,180 setting the alarm position to zero so 6666 03:30:36,180 --> 03:30:38,279 whenever we move to a different second 6667 03:30:38,279 --> 03:30:40,620 parent when we do that we can just ask 6668 03:30:40,620 --> 03:30:42,000 that second parent to return the 6669 03:30:42,000 --> 03:30:43,979 countertop point and move it there so 6670 03:30:43,979 --> 03:30:45,660 for that let's make a function to return 6671 03:30:45,660 --> 03:30:46,620 that 6672 03:30:46,620 --> 03:30:48,479 so public we're going to return 6673 03:30:48,479 --> 03:30:50,760 transform so get the kitchen object 6674 03:30:50,760 --> 03:30:53,520 follow transform so it's going to be our 6675 03:30:53,520 --> 03:30:55,020 countertop point 6676 03:30:55,020 --> 03:30:58,380 so let's return the counter top point 6677 03:30:58,380 --> 03:31:00,420 then let's go into the function on the 6678 03:31:00,420 --> 03:31:01,739 kitchen object when we set the clear 6679 03:31:01,739 --> 03:31:03,840 counter so over here on the kitchen 6680 03:31:03,840 --> 03:31:05,399 object on this function so we set the 6681 03:31:05,399 --> 03:31:06,540 color counter 6682 03:31:06,540 --> 03:31:08,760 then let's modify this transform.parent 6683 03:31:08,760 --> 03:31:11,700 go into the nuclear counter in order to 6684 03:31:11,700 --> 03:31:13,200 get the kitchen object funnel transform 6685 03:31:13,200 --> 03:31:15,660 and again let's make sure to set the low 6686 03:31:15,660 --> 03:31:18,840 composition back into Vector 3.0 6687 03:31:18,840 --> 03:31:21,000 okay so with this when we set the clear 6688 03:31:21,000 --> 03:31:22,620 counter to a different one it should 6689 03:31:22,620 --> 03:31:24,420 automatically teleport to the other 6690 03:31:24,420 --> 03:31:27,180 counter so let's test so here we are in 6691 03:31:27,180 --> 03:31:28,439 first let's interact with this one there 6692 03:31:28,439 --> 03:31:29,880 you go it's Pawn now if I press C 6693 03:31:29,880 --> 03:31:31,500 testing key and if there go it does move 6694 03:31:31,500 --> 03:31:33,660 visually okay great so far so good 6695 03:31:33,660 --> 03:31:35,520 however the counters still have the 6696 03:31:35,520 --> 03:31:37,739 wrong data by the way here's a quick 6697 03:31:37,739 --> 03:31:40,620 empty tub on the inspector you already 6698 03:31:40,620 --> 03:31:42,300 know that you can only see the public 6699 03:31:42,300 --> 03:31:44,640 and the serialized Fields however there 6700 03:31:44,640 --> 03:31:46,260 is actually a way to look at private 6701 03:31:46,260 --> 03:31:48,479 fields on the inspector on the top right 6702 03:31:48,479 --> 03:31:50,220 there's these three dots and if you 6703 03:31:50,220 --> 03:31:52,080 click on it over here you can modify it 6704 03:31:52,080 --> 03:31:54,180 into a debug inspector 6705 03:31:54,180 --> 03:31:55,859 and when you go into this one Yep this 6706 03:31:55,859 --> 03:31:58,140 one does show all the private fields 6707 03:31:58,140 --> 03:31:59,700 so you can see for example on the clear 6708 03:31:59,700 --> 03:32:01,319 counter so that's the right one this one 6709 03:32:01,319 --> 03:32:02,819 over here the kitchen object is indeed 6710 03:32:02,819 --> 03:32:04,920 assigned and we can go into the other 6711 03:32:04,920 --> 03:32:06,540 one and we can see this one has it as 6712 03:32:06,540 --> 03:32:08,819 null so debug inspector is really useful 6713 03:32:08,819 --> 03:32:10,500 in these kinds of cases if you want to 6714 03:32:10,500 --> 03:32:12,060 inspect any kind of private Fields you 6715 03:32:12,060 --> 03:32:14,640 can go to this and see it now let's swap 6716 03:32:14,640 --> 03:32:17,100 back into the regular inspector and 6717 03:32:17,100 --> 03:32:18,600 let's fix that issue by notifying the 6718 03:32:18,600 --> 03:32:20,939 counters that the object has changed 6719 03:32:20,939 --> 03:32:22,680 so over here basically we have two 6720 03:32:22,680 --> 03:32:24,420 options over here on the calendar 6721 03:32:24,420 --> 03:32:26,760 counter when we modify the parent when 6722 03:32:26,760 --> 03:32:28,319 we tell the kitchen object to go to a 6723 03:32:28,319 --> 03:32:30,359 new parent when we do that we can make 6724 03:32:30,359 --> 03:32:32,040 the new parent responsible to updating 6725 03:32:32,040 --> 03:32:34,380 itself or we can just make the kitchen 6726 03:32:34,380 --> 03:32:36,540 object itself be the one responsible for 6727 03:32:36,540 --> 03:32:39,060 notifying the new parent both approaches 6728 03:32:39,060 --> 03:32:41,220 can work personally I think it makes 6729 03:32:41,220 --> 03:32:42,720 more sense for the kitchen object to 6730 03:32:42,720 --> 03:32:44,040 handle itself 6731 03:32:44,040 --> 03:32:46,260 so we just call this function to set the 6732 03:32:46,260 --> 03:32:48,000 new parent and when this happens 6733 03:32:48,000 --> 03:32:49,680 basically this kitchen object needs to 6734 03:32:49,680 --> 03:32:52,260 tell the old parent that it is no longer 6735 03:32:52,260 --> 03:32:53,700 there and needs to tell the new parent 6736 03:32:53,700 --> 03:32:55,859 that it is on there so on the counter 6737 03:32:55,859 --> 03:32:57,720 let's make some function to set and get 6738 03:32:57,720 --> 03:32:59,160 a kitchen object 6739 03:32:59,160 --> 03:33:00,720 so over here on the calendar counter 6740 03:33:00,720 --> 03:33:02,460 script let's go down 6741 03:33:02,460 --> 03:33:04,680 let's make first one to set so public 6742 03:33:04,680 --> 03:33:07,800 void set kitchen object and receive a 6743 03:33:07,800 --> 03:33:10,520 kitchen object 6744 03:33:10,859 --> 03:33:12,779 and just do this dot kitchen object 6745 03:33:12,779 --> 03:33:14,520 equals this kitchen object okay great 6746 03:33:14,520 --> 03:33:16,739 then let's make a getter so public 6747 03:33:16,739 --> 03:33:19,380 return a kitchen object get the kitchen 6748 03:33:19,380 --> 03:33:20,520 object 6749 03:33:20,520 --> 03:33:23,460 and just return this kitchen object okay 6750 03:33:23,460 --> 03:33:25,380 then let's also make one just to clear 6751 03:33:25,380 --> 03:33:27,899 it so probably avoid clear kitchen 6752 03:33:27,899 --> 03:33:30,479 object 6753 03:33:30,479 --> 03:33:32,040 and this one just sets the kitchen 6754 03:33:32,040 --> 03:33:34,020 object into null 6755 03:33:34,020 --> 03:33:35,819 and finally just a nice sample function 6756 03:33:35,819 --> 03:33:37,680 to test if this counter has anything on 6757 03:33:37,680 --> 03:33:40,439 top so just a public Bowl has kitchen 6758 03:33:40,439 --> 03:33:42,359 object 6759 03:33:42,359 --> 03:33:44,279 and over here we just return if the 6760 03:33:44,279 --> 03:33:46,140 kitchen object is not known 6761 03:33:46,140 --> 03:33:49,200 okay so some four very simple functions 6762 03:33:49,200 --> 03:33:51,060 now if we go into our kitchen of the 6763 03:33:51,060 --> 03:33:51,899 script 6764 03:33:51,899 --> 03:33:53,880 over here when we tell it to change the 6765 03:33:53,880 --> 03:33:55,979 parent let's first go into the current 6766 03:33:55,979 --> 03:33:58,560 parent and clear it 6767 03:33:58,560 --> 03:34:00,840 so let's first of all do a quick test 6768 03:34:00,840 --> 03:34:02,939 for null so if this documentary counter 6769 03:34:02,939 --> 03:34:04,920 which is the current parent so if this 6770 03:34:04,920 --> 03:34:07,020 one is not null then we go into the 6771 03:34:07,020 --> 03:34:09,359 current parent so the clear counter and 6772 03:34:09,359 --> 03:34:12,000 we tell it to clear the kitchen object 6773 03:34:12,000 --> 03:34:14,460 and then we go into the new parent 6774 03:34:14,460 --> 03:34:16,140 and we tell new parent to set the 6775 03:34:16,140 --> 03:34:18,420 kitchen object and the kitchen object is 6776 03:34:18,420 --> 03:34:19,439 this one 6777 03:34:19,439 --> 03:34:21,300 now here will be very very important 6778 03:34:21,300 --> 03:34:23,160 don't make the mistake of clearing the 6779 03:34:23,160 --> 03:34:25,380 wrong counter keep in mind that over 6780 03:34:25,380 --> 03:34:27,000 here this documentary counter this 6781 03:34:27,000 --> 03:34:29,279 refers to the previous player counter 6782 03:34:29,279 --> 03:34:31,439 whereas the one in the parameter this is 6783 03:34:31,439 --> 03:34:33,779 the one this is the new one so make sure 6784 03:34:33,779 --> 03:34:35,460 you clear the kitchen object from the 6785 03:34:35,460 --> 03:34:37,200 previous clear counter before you assign 6786 03:34:37,200 --> 03:34:39,180 it and then you set it on the new clear 6787 03:34:39,180 --> 03:34:41,760 counter so be very very careful here 6788 03:34:41,760 --> 03:34:43,560 make sure you don't make mistakes 6789 03:34:43,560 --> 03:34:45,359 between the quote unquote old color 6790 03:34:45,359 --> 03:34:47,520 counter and the nuclear counter 6791 03:34:47,520 --> 03:34:49,560 okay so that's it basically we have this 6792 03:34:49,560 --> 03:34:51,239 function to set the nuclear counter so 6793 03:34:51,239 --> 03:34:53,520 set the new parent we clear the kitchen 6794 03:34:53,520 --> 03:34:55,500 object from the old player counter we 6795 03:34:55,500 --> 03:34:57,840 added a new one and we update the visual 6796 03:34:57,840 --> 03:34:59,939 now we can also add some nice safety 6797 03:34:59,939 --> 03:35:01,319 checks here just to make sure we never 6798 03:35:01,319 --> 03:35:03,779 make a mistake the kitchen object should 6799 03:35:03,779 --> 03:35:05,520 never be set to a parent that is already 6800 03:35:05,520 --> 03:35:08,160 holding something so before we set the 6801 03:35:08,160 --> 03:35:10,140 kitchen object before we do that let's 6802 03:35:10,140 --> 03:35:11,939 make sure that one is empty 6803 03:35:11,939 --> 03:35:14,040 so over here just do an if if the clear 6804 03:35:14,040 --> 03:35:16,260 counter so that's a new one if this one 6805 03:35:16,260 --> 03:35:18,840 has a kitchen object then it already has 6806 03:35:18,840 --> 03:35:20,819 something on there this should never 6807 03:35:20,819 --> 03:35:23,040 ever happen so let's see what debug.log 6808 03:35:23,040 --> 03:35:26,340 error and say counter already has a 6809 03:35:26,340 --> 03:35:28,439 kitchen object 6810 03:35:28,439 --> 03:35:30,239 we're going to eventually add tests to 6811 03:35:30,239 --> 03:35:31,739 make sure that this never ever happens 6812 03:35:31,739 --> 03:35:33,960 but having the air here won't be helpful 6813 03:35:33,960 --> 03:35:35,939 just in case we missed something 6814 03:35:35,939 --> 03:35:37,620 so far as the kitchen object we're going 6815 03:35:37,620 --> 03:35:39,479 to fire an error but this should never 6816 03:35:39,479 --> 03:35:40,979 happen so we just set the error update 6817 03:35:40,979 --> 03:35:42,479 to visual and so on 6818 03:35:42,479 --> 03:35:44,640 okay so finally let's just go over here 6819 03:35:44,640 --> 03:35:47,100 into the clear counter script and down 6820 03:35:47,100 --> 03:35:49,680 here we have the interact action so we 6821 03:35:49,680 --> 03:35:51,960 instantiate the kitchen object we're 6822 03:35:51,960 --> 03:35:53,819 currently repositioning it and then 6823 03:35:53,819 --> 03:35:55,979 we're setting this field assigning it to 6824 03:35:55,979 --> 03:35:58,020 this one now we made the kitchen object 6825 03:35:58,020 --> 03:35:59,640 responsible for doing all that for 6826 03:35:59,640 --> 03:36:01,260 modifying the position and for setting 6827 03:36:01,260 --> 03:36:02,640 the field so we don't need to do this 6828 03:36:02,640 --> 03:36:05,580 instead we really just need to go and 6829 03:36:05,580 --> 03:36:07,260 get the component of that 6830 03:36:07,260 --> 03:36:09,420 and just pass in set for your counter 6831 03:36:09,420 --> 03:36:12,359 and pass in as this one 6832 03:36:12,359 --> 03:36:14,399 so we no longer need all this now our 6833 03:36:14,399 --> 03:36:16,319 code is much more simple also 6834 03:36:16,319 --> 03:36:18,060 importantly up here we were previously 6835 03:36:18,060 --> 03:36:19,620 setting the color counter and then doing 6836 03:36:19,620 --> 03:36:22,260 a debug.log but when we set it a new one 6837 03:36:22,260 --> 03:36:23,520 that is actually going to clear this 6838 03:36:23,520 --> 03:36:25,140 field so if we leave this then this is 6839 03:36:25,140 --> 03:36:26,279 going to throw a null reference 6840 03:36:26,279 --> 03:36:28,260 exception so let's just get rid of the 6841 03:36:28,260 --> 03:36:30,779 slog here we normally need it okay so 6842 03:36:30,779 --> 03:36:32,399 let's test and see if all of our logic 6843 03:36:32,399 --> 03:36:33,540 is working 6844 03:36:33,540 --> 03:36:35,340 all right so here we are let's go to 6845 03:36:35,340 --> 03:36:38,100 this one interactive spawn it okay great 6846 03:36:38,100 --> 03:36:40,200 and once again we can look in the debug 6847 03:36:40,200 --> 03:36:42,300 inspector so let's put it on debug look 6848 03:36:42,300 --> 03:36:43,620 at this layer counter so that's the 6849 03:36:43,620 --> 03:36:45,239 right one and yep there you go it does 6850 03:36:45,239 --> 03:36:46,500 have the kitchen object and if I'm 6851 03:36:46,500 --> 03:36:47,939 looking the other one Yep this one has 6852 03:36:47,939 --> 03:36:49,439 no okay great 6853 03:36:49,439 --> 03:36:51,479 now if I press the testing key yep 6854 03:36:51,479 --> 03:36:53,700 visually it did change and if you look 6855 03:36:53,700 --> 03:36:55,080 at the counter so if you look at the old 6856 03:36:55,080 --> 03:36:56,760 ones that's the right one this one is at 6857 03:36:56,760 --> 03:36:58,859 no okay that's great correct and if you 6858 03:36:58,859 --> 03:37:00,300 look at the new one Yep this one does 6859 03:37:00,300 --> 03:37:03,000 have the reference all right awesome 6860 03:37:03,000 --> 03:37:04,920 so now that we are correctly changing 6861 03:37:04,920 --> 03:37:07,140 the kitchen object parent for example we 6862 03:37:07,140 --> 03:37:08,580 can now interact again with this one and 6863 03:37:08,580 --> 03:37:11,160 yep it does spawn a brand new one and of 6864 03:37:11,160 --> 03:37:12,720 course if we try moving it to the other 6865 03:37:12,720 --> 03:37:14,640 one then we should have our error as 6866 03:37:14,640 --> 03:37:16,800 intended this one is currently already 6867 03:37:16,800 --> 03:37:18,600 occupied the kitchen object so we should 6868 03:37:18,600 --> 03:37:20,100 not be able to drop something on there 6869 03:37:20,100 --> 03:37:22,020 but if I press the testing key if there 6870 03:37:22,020 --> 03:37:24,180 go nicer okay so that's great 6871 03:37:24,180 --> 03:37:25,859 we're basically going to fix this error 6872 03:37:25,859 --> 03:37:27,660 later on when we check to make sure the 6873 03:37:27,660 --> 03:37:29,399 object can only be spawned when it can 6874 03:37:29,399 --> 03:37:31,620 be spawned but for now all of our basic 6875 03:37:31,620 --> 03:37:33,420 logic is working we can spawn an object 6876 03:37:33,420 --> 03:37:35,819 and change a parent alright so with that 6877 03:37:35,819 --> 03:37:37,380 here we have added a really important 6878 03:37:37,380 --> 03:37:39,479 feature to our game that is the ability 6879 03:37:39,479 --> 03:37:42,000 to know where a kitchen object is now 6880 03:37:42,000 --> 03:37:43,859 the next step is to enable the player to 6881 03:37:43,859 --> 03:37:45,300 be able to pick it up and drop it 6882 03:37:45,300 --> 03:37:46,920 somewhere so let's do that in the next 6883 03:37:46,920 --> 03:37:48,899 lecture 6884 03:37:48,899 --> 03:37:50,880 hello and welcome I'm your code monkey 6885 03:37:50,880 --> 03:37:52,859 in this lecture we're going to enable 6886 03:37:52,859 --> 03:37:54,840 the player to pick up a kitchen object 6887 03:37:54,840 --> 03:37:56,399 and in doing so we're going to learn 6888 03:37:56,399 --> 03:37:58,319 about another awesome c-sharp feature 6889 03:37:58,319 --> 03:37:59,880 called interfaces 6890 03:37:59,880 --> 03:38:01,859 okay so right now with our game I can 6891 03:38:01,859 --> 03:38:03,420 already move the player I can approach a 6892 03:38:03,420 --> 03:38:05,819 counter and try to spawn an object and 6893 03:38:05,819 --> 03:38:07,439 with the testing key I can move it to a 6894 03:38:07,439 --> 03:38:08,520 different parent 6895 03:38:08,520 --> 03:38:10,380 so all of that logic is working now 6896 03:38:10,380 --> 03:38:11,939 let's make it work actually with the 6897 03:38:11,939 --> 03:38:14,399 player let's say when we interact once 6898 03:38:14,399 --> 03:38:16,680 we want to spawn it and if there's an 6899 03:38:16,680 --> 03:38:18,120 object already on top of it and I 6900 03:38:18,120 --> 03:38:19,620 interact again then I want to give it to 6901 03:38:19,620 --> 03:38:20,700 the player 6902 03:38:20,700 --> 03:38:22,979 okay so here on the clear counter script 6903 03:38:22,979 --> 03:38:24,899 we've got our interact function in order 6904 03:38:24,899 --> 03:38:26,580 to make that work we need to have a 6905 03:38:26,580 --> 03:38:28,620 reference to the player so I just passed 6906 03:38:28,620 --> 03:38:30,540 it in over here as an argument for our 6907 03:38:30,540 --> 03:38:32,880 interaction so just pass in the player 6908 03:38:32,880 --> 03:38:33,779 reference 6909 03:38:33,779 --> 03:38:35,520 now over here let's do the logic that I 6910 03:38:35,520 --> 03:38:37,500 send so if the kitchen object is known 6911 03:38:37,500 --> 03:38:38,760 so if there's nothing here then let's 6912 03:38:38,760 --> 03:38:40,979 spawn it okay great but if there is 6913 03:38:40,979 --> 03:38:42,180 something 6914 03:38:42,180 --> 03:38:45,840 then let's give the object to the player 6915 03:38:45,840 --> 03:38:48,120 so how we change the object parent is 6916 03:38:48,120 --> 03:38:50,340 just like what we did up here so let's 6917 03:38:50,340 --> 03:38:51,899 go into that one set the clear counter 6918 03:38:51,899 --> 03:38:54,180 and pass in deploy a reference except of 6919 03:38:54,180 --> 03:38:56,640 course this obviously does not work the 6920 03:38:56,640 --> 03:38:58,500 parameter on this function is supposed 6921 03:38:58,500 --> 03:39:00,359 to be of clear counter it does not work 6922 03:39:00,359 --> 03:39:02,880 with the type of player recently on the 6923 03:39:02,880 --> 03:39:04,380 logic that we built for setting the 6924 03:39:04,380 --> 03:39:06,540 parent and change the parent this whole 6925 03:39:06,540 --> 03:39:08,279 thing only works with the counter so it 6926 03:39:08,279 --> 03:39:10,200 does not work with any other type so we 6927 03:39:10,200 --> 03:39:12,720 cannot set the player as a parent now to 6928 03:39:12,720 --> 03:39:14,100 solve this problem is exactly where 6929 03:39:14,100 --> 03:39:16,680 c-sharp interfaces come in again I have 6930 03:39:16,680 --> 03:39:18,120 a video going through them in detail 6931 03:39:18,120 --> 03:39:19,739 definitely watch it and learn everything 6932 03:39:19,739 --> 03:39:22,500 about interfaces basically what it is is 6933 03:39:22,500 --> 03:39:24,840 a contract you define some functions in 6934 03:39:24,840 --> 03:39:27,180 the interface and then any type can 6935 03:39:27,180 --> 03:39:29,040 Implement that interface and you can 6936 03:39:29,040 --> 03:39:30,479 write some code that works with the 6937 03:39:30,479 --> 03:39:32,040 interface which in turn means that the 6938 03:39:32,040 --> 03:39:33,899 code won't work with any type as long as 6939 03:39:33,899 --> 03:39:35,760 it implements that interface 6940 03:39:35,760 --> 03:39:38,040 so in this specific example we're going 6941 03:39:38,040 --> 03:39:39,840 to make an interface to represent a 6942 03:39:39,840 --> 03:39:41,880 kitchen object parent then we're going 6943 03:39:41,880 --> 03:39:43,620 to implement that interface on both the 6944 03:39:43,620 --> 03:39:45,600 counter and the player and that way both 6945 03:39:45,600 --> 03:39:47,399 of them won't be able to be parents of a 6946 03:39:47,399 --> 03:39:49,439 kitchen object so let's do exactly that 6947 03:39:49,439 --> 03:39:51,359 now the first thing we do to Define an 6948 03:39:51,359 --> 03:39:53,220 interface is Let's Make a c-sharp script 6949 03:39:53,220 --> 03:39:55,439 so let's right click create new c-sharp 6950 03:39:55,439 --> 03:39:57,660 script and now the standard is to start 6951 03:39:57,660 --> 03:40:00,000 interface names with the capital I and 6952 03:40:00,000 --> 03:40:01,979 then the name so in this case let's name 6953 03:40:01,979 --> 03:40:03,120 it I 6954 03:40:03,120 --> 03:40:05,760 kitchen object parents 6955 03:40:05,760 --> 03:40:09,120 and let's open it okay so now to make an 6956 03:40:09,120 --> 03:40:11,100 interface first of all this does not 6957 03:40:11,100 --> 03:40:13,800 extend mono Behavior nope and secondly 6958 03:40:13,800 --> 03:40:16,380 this is not a class instead this is an 6959 03:40:16,380 --> 03:40:18,720 interface now like I said an interface 6960 03:40:18,720 --> 03:40:20,520 is essentially a contract where each 6961 03:40:20,520 --> 03:40:22,080 class that implements that interface 6962 03:40:22,080 --> 03:40:23,880 must follow that contract 6963 03:40:23,880 --> 03:40:25,680 what that really means is you can define 6964 03:40:25,680 --> 03:40:27,899 a bunch of functions here by the way 6965 03:40:27,899 --> 03:40:29,040 quick note you can also define 6966 03:40:29,040 --> 03:40:31,500 properties but not Fields I cover all of 6967 03:40:31,500 --> 03:40:33,060 that in the dedicated interface video 6968 03:40:33,060 --> 03:40:35,100 but for now here we just want some 6969 03:40:35,100 --> 03:40:37,319 functions like for example let's just 6970 03:40:37,319 --> 03:40:38,939 put all of the parent functions that we 6971 03:40:38,939 --> 03:40:40,859 made previously on the counter 6972 03:40:40,859 --> 03:40:42,479 so over here on the corner counter a 6973 03:40:42,479 --> 03:40:44,040 while ago we made all these functions 6974 03:40:44,040 --> 03:40:45,779 that we needed to make it work as a 6975 03:40:45,779 --> 03:40:47,340 kitchen object parent 6976 03:40:47,340 --> 03:40:49,140 so we got the transform set kitchen 6977 03:40:49,140 --> 03:40:51,000 object get it clear it then has it so 6978 03:40:51,000 --> 03:40:52,739 let's just copy all this and paste it 6979 03:40:52,739 --> 03:40:54,420 over here on the interface 6980 03:40:54,420 --> 03:40:56,399 however one important note is on the 6981 03:40:56,399 --> 03:40:58,080 interfaces you don't actually include 6982 03:40:58,080 --> 03:41:00,120 any function implementation 6983 03:41:00,120 --> 03:41:01,979 the implementation is up to the class 6984 03:41:01,979 --> 03:41:03,960 that implements this interface although 6985 03:41:03,960 --> 03:41:05,160 again I should also point out another 6986 03:41:05,160 --> 03:41:07,439 quick note as of c-sharp 7 you can 6987 03:41:07,439 --> 03:41:09,239 include a default implementation but 6988 03:41:09,239 --> 03:41:11,340 that's for more advanced use cases so 6989 03:41:11,340 --> 03:41:13,020 for here let's just use the basic and 6990 03:41:13,020 --> 03:41:15,060 not apply any default implementation 6991 03:41:15,060 --> 03:41:17,100 right here so we just defined the 6992 03:41:17,100 --> 03:41:17,880 function 6993 03:41:17,880 --> 03:41:20,460 and put a semicolon so just like this 6994 03:41:20,460 --> 03:41:22,560 just the function definition with the 6995 03:41:22,560 --> 03:41:25,380 exact signature so just like this okay 6996 03:41:25,380 --> 03:41:27,300 so now that we have defined our 6997 03:41:27,300 --> 03:41:28,979 interface and all the functions that we 6998 03:41:28,979 --> 03:41:31,560 want to have with this now let's go on 6999 03:41:31,560 --> 03:41:33,300 to the counter script so over here on 7000 03:41:33,300 --> 03:41:35,520 the clear counter script over here let's 7001 03:41:35,520 --> 03:41:37,260 implement the interface and the way we 7002 03:41:37,260 --> 03:41:39,000 do that is pretty much exactly the same 7003 03:41:39,000 --> 03:41:41,700 as by extending a class so over here we 7004 03:41:41,700 --> 03:41:43,200 are already extending Model Behavior 7005 03:41:43,200 --> 03:41:44,939 then let's set a comment and let's say 7006 03:41:44,939 --> 03:41:47,040 we are also implementing the ikitchen 7007 03:41:47,040 --> 03:41:48,840 object parent interface 7008 03:41:48,840 --> 03:41:51,060 so right now you might be wondering so 7009 03:41:51,060 --> 03:41:52,680 this is pretty much the same thing as 7010 03:41:52,680 --> 03:41:55,020 extending a base class and kind of 7011 03:41:55,020 --> 03:41:57,420 except for one huge difference 7012 03:41:57,420 --> 03:41:59,580 when extending a base class you can only 7013 03:41:59,580 --> 03:42:02,160 have a single Base Class like for 7014 03:42:02,160 --> 03:42:04,200 example over here we have monobehavior 7015 03:42:04,200 --> 03:42:06,600 you cannot extend multiple base classes 7016 03:42:06,600 --> 03:42:09,060 there can only be one however when it 7017 03:42:09,060 --> 03:42:11,040 comes to interfaces you can Implement as 7018 03:42:11,040 --> 03:42:13,319 many interfaces as you want so over here 7019 03:42:13,319 --> 03:42:15,720 we have defined our interface and right 7020 03:42:15,720 --> 03:42:17,520 now we don't even have any errors that's 7021 03:42:17,520 --> 03:42:19,439 because we already implemented pretty 7022 03:42:19,439 --> 03:42:21,960 much all the exact functions also Visual 7023 03:42:21,960 --> 03:42:23,700 Studio has a really nice software icon 7024 03:42:23,700 --> 03:42:25,739 over here on the left side it is 7025 03:42:25,739 --> 03:42:27,000 basically saying that this function this 7026 03:42:27,000 --> 03:42:28,739 implementation is based on the interface 7027 03:42:28,739 --> 03:42:30,899 but let's see what happens if I decide 7028 03:42:30,899 --> 03:42:33,479 to comment out these functions so if I 7029 03:42:33,479 --> 03:42:35,040 comment out all of this 7030 03:42:35,040 --> 03:42:37,140 and if there we go over here we have an 7031 03:42:37,140 --> 03:42:39,239 error it is telling us that this class 7032 03:42:39,239 --> 03:42:41,100 does not implement the members for the 7033 03:42:41,100 --> 03:42:43,560 interface like I said an interface is 7034 03:42:43,560 --> 03:42:46,080 like a contract so you must write all of 7035 03:42:46,080 --> 03:42:48,300 the functions included in the interface 7036 03:42:48,300 --> 03:42:50,460 so we must Implement these so let's get 7037 03:42:50,460 --> 03:42:52,560 rid of the comments okay 7038 03:42:52,560 --> 03:42:54,300 with this our interface is perfectly 7039 03:42:54,300 --> 03:42:55,319 working over here on the calendar 7040 03:42:55,319 --> 03:42:56,700 counter 7041 03:42:56,700 --> 03:42:58,439 now let's just go into the kitchen 7042 03:42:58,439 --> 03:43:00,779 object over here on this script 7043 03:43:00,779 --> 03:43:02,580 for now we're still working with the 7044 03:43:02,580 --> 03:43:04,620 type clear counter so let's just 7045 03:43:04,620 --> 03:43:06,239 refactor this to instead of working with 7046 03:43:06,239 --> 03:43:07,979 a clear counter let's make it work with 7047 03:43:07,979 --> 03:43:09,660 a kitchen object parent 7048 03:43:09,660 --> 03:43:12,060 so let's just change this from type that 7049 03:43:12,060 --> 03:43:14,460 to Kitchen object parent let's also 7050 03:43:14,460 --> 03:43:16,859 rename this so let's use Ctrl RR for the 7051 03:43:16,859 --> 03:43:19,319 kitchen object parent 7052 03:43:19,319 --> 03:43:20,700 then we've got a function to return the 7053 03:43:20,700 --> 03:43:22,260 kitchen object okay that's good for this 7054 03:43:22,260 --> 03:43:23,700 one instead of setting your counter and 7055 03:43:23,700 --> 03:43:25,859 let's once again rename this to set 7056 03:43:25,859 --> 03:43:28,500 kitchen object parent 7057 03:43:28,500 --> 03:43:31,739 and inside again we receive of type I 7058 03:43:31,739 --> 03:43:34,319 kitchen object parent 7059 03:43:34,319 --> 03:43:36,420 then let's also rename the parameter to 7060 03:43:36,420 --> 03:43:38,640 Kitchen object parents 7061 03:43:38,640 --> 03:43:40,560 okay so all the names here I have 7062 03:43:40,560 --> 03:43:42,359 changed okay they're all correct we set 7063 03:43:42,359 --> 03:43:44,460 it we assign it over here instead of 7064 03:43:44,460 --> 03:43:46,319 counter let's say kitchen object parent 7065 03:43:46,319 --> 03:43:49,560 already has that so just like this 7066 03:43:49,560 --> 03:43:51,960 and finally down here let's return I 7067 03:43:51,960 --> 03:43:54,720 kitchen object parent and rename this to 7068 03:43:54,720 --> 03:43:57,180 get kitchen object parent 7069 03:43:57,180 --> 03:43:59,100 and we return that 7070 03:43:59,100 --> 03:44:00,660 all right so we have changed everything 7071 03:44:00,660 --> 03:44:02,580 I can even do control F to search for 7072 03:44:02,580 --> 03:44:04,380 counter and nope there's no instance of 7073 03:44:04,380 --> 03:44:06,660 any counter so all this code has now 7074 03:44:06,660 --> 03:44:08,220 been Rewritten to work with a kitchen 7075 03:44:08,220 --> 03:44:09,540 object parent 7076 03:44:09,540 --> 03:44:11,040 something like this everything should be 7077 03:44:11,040 --> 03:44:12,540 working it's only the same as previously 7078 03:44:12,540 --> 03:44:14,520 we have no errors here 7079 03:44:14,520 --> 03:44:16,319 and over here on the clear counter we 7080 03:44:16,319 --> 03:44:17,460 just have this error on the player and 7081 03:44:17,460 --> 03:44:19,080 let's fix this in a little bit for now 7082 03:44:19,080 --> 03:44:21,180 let's just comment it let's just test it 7083 03:44:21,180 --> 03:44:22,620 out to see if everything still works 7084 03:44:22,620 --> 03:44:24,899 exactly the same as previously also one 7085 03:44:24,899 --> 03:44:26,340 final thing since we modified the 7086 03:44:26,340 --> 03:44:27,840 interact function over here on the 7087 03:44:27,840 --> 03:44:29,399 player class when we have the interact 7088 03:44:29,399 --> 03:44:31,439 we just need to pass in this reference 7089 03:44:31,439 --> 03:44:33,420 okay so let's test 7090 03:44:33,420 --> 03:44:35,340 all right so here we are let's approach 7091 03:44:35,340 --> 03:44:37,800 this one interact yep there it is now 7092 03:44:37,800 --> 03:44:39,300 let me press the testing key and if 7093 03:44:39,300 --> 03:44:41,279 there go it does move okay so everything 7094 03:44:41,279 --> 03:44:42,960 is still working exactly the same as 7095 03:44:42,960 --> 03:44:44,880 previously once again another successful 7096 03:44:44,880 --> 03:44:47,460 refactoring now here comes the magical 7097 03:44:47,460 --> 03:44:49,560 moment so right now again everything is 7098 03:44:49,560 --> 03:44:50,700 still working exactly the same as 7099 03:44:50,700 --> 03:44:52,500 previously so we can only have counters 7100 03:44:52,500 --> 03:44:54,660 as parents but now let's go over here 7101 03:44:54,660 --> 03:44:56,760 onto the player script and over here 7102 03:44:56,760 --> 03:44:58,560 let's also implement the same interface 7103 03:44:58,560 --> 03:45:00,060 so let's implement the eye kitchen 7104 03:45:00,060 --> 03:45:01,260 object parent 7105 03:45:01,260 --> 03:45:03,300 and again as usual we have our error so 7106 03:45:03,300 --> 03:45:04,800 we need to implement this 7107 03:45:04,800 --> 03:45:06,720 also again Visual Studio is very helpful 7108 03:45:06,720 --> 03:45:09,180 so we can click on the light bulb icon 7109 03:45:09,180 --> 03:45:11,640 and let's say implement the interface 7110 03:45:11,640 --> 03:45:13,800 and if we scroll down here it will 7111 03:45:13,800 --> 03:45:15,479 automatically create all these functions 7112 03:45:15,479 --> 03:45:18,239 so let's just actually Implement them 7113 03:45:18,239 --> 03:45:20,100 so for implementing this interface the 7114 03:45:20,100 --> 03:45:21,540 code is really going to be exactly the 7115 03:45:21,540 --> 03:45:22,739 same 7116 03:45:22,739 --> 03:45:24,180 so let's go up here into the clear 7117 03:45:24,180 --> 03:45:26,279 counter let's go down find all of these 7118 03:45:26,279 --> 03:45:28,319 functions let's copy them and on the 7119 03:45:28,319 --> 03:45:30,300 player let's paste them down here at the 7120 03:45:30,300 --> 03:45:31,200 bottom 7121 03:45:31,200 --> 03:45:33,239 so we just need to also pick up the 7122 03:45:33,239 --> 03:45:35,100 kitchen object as well as a reference to 7123 03:45:35,100 --> 03:45:37,500 the top point so over here on the clear 7124 03:45:37,500 --> 03:45:40,140 counter and let's just grab both those 7125 03:45:40,140 --> 03:45:42,000 so let's just grab the kitchen object so 7126 03:45:42,000 --> 03:45:43,800 go into the player and over here let's 7127 03:45:43,800 --> 03:45:46,319 add a film for the kitchen object and 7128 03:45:46,319 --> 03:45:47,640 finally let's add another one for the 7129 03:45:47,640 --> 03:45:49,620 counter top point so over here a 7130 03:45:49,620 --> 03:45:50,939 serialized film for the counter top 7131 03:45:50,939 --> 03:45:51,899 point 7132 03:45:51,899 --> 03:45:53,700 except obviously the player is not a 7133 03:45:53,700 --> 03:45:55,319 counter so this name makes no sense on 7134 03:45:55,319 --> 03:45:57,180 the player so let's just quickly rename 7135 03:45:57,180 --> 03:46:00,180 this and set call it kitchen object home 7136 03:46:00,180 --> 03:46:01,500 point 7137 03:46:01,500 --> 03:46:03,779 okay here we have our new name we've got 7138 03:46:03,779 --> 03:46:05,939 the kitchen object and down here all of 7139 03:46:05,939 --> 03:46:07,200 our functions they're all working no 7140 03:46:07,200 --> 03:46:09,540 errors all right now let's just assign 7141 03:46:09,540 --> 03:46:11,580 this in the editor 7142 03:46:11,580 --> 03:46:13,260 so over here let's just go into our 7143 03:46:13,260 --> 03:46:14,700 player there's a player script and 7144 03:46:14,700 --> 03:46:16,200 requires a reference to the kitchen 7145 03:46:16,200 --> 03:46:17,700 object home point 7146 03:46:17,700 --> 03:46:19,920 so for that let's do it just like we did 7147 03:46:19,920 --> 03:46:21,120 for the Counterpoint so inside the 7148 03:46:21,120 --> 03:46:23,340 player let's create an empty game object 7149 03:46:23,340 --> 03:46:26,939 currently the kitchen object hold points 7150 03:46:26,939 --> 03:46:29,040 and I always just position it just 7151 03:46:29,040 --> 03:46:31,140 slightly in front of the player 7152 03:46:31,140 --> 03:46:34,140 so let's put it on a x of 0 on a y of 7153 03:46:34,140 --> 03:46:36,899 1.3 and on a set of one so there you go 7154 03:46:36,899 --> 03:46:38,880 just ahead that's where the player is 7155 03:46:38,880 --> 03:46:40,979 going to be holding the objects finally 7156 03:46:40,979 --> 03:46:42,359 over here on the player let's just drag 7157 03:46:42,359 --> 03:46:43,800 that reference 7158 03:46:43,800 --> 03:46:46,739 okay so far so good also one note here 7159 03:46:46,739 --> 03:46:48,420 like I mentioned previously in order to 7160 03:46:48,420 --> 03:46:50,160 implement the interface it requires you 7161 03:46:50,160 --> 03:46:51,899 to write the function code 7162 03:46:51,899 --> 03:46:53,460 basically what this means is that 7163 03:46:53,460 --> 03:46:55,020 different objects can implement the 7164 03:46:55,020 --> 03:46:56,580 exact same interface whilst having 7165 03:46:56,580 --> 03:46:58,319 different implementations 7166 03:46:58,319 --> 03:47:00,300 so for example over here on the player 7167 03:47:00,300 --> 03:47:02,340 when setting the kitchen object 7168 03:47:02,340 --> 03:47:04,439 perhaps over here you could play some 7169 03:47:04,439 --> 03:47:06,540 kind of item grab animation or maybe 7170 03:47:06,540 --> 03:47:08,279 when clearing a kitchen object you could 7171 03:47:08,279 --> 03:47:09,960 do some kind of logging 7172 03:47:09,960 --> 03:47:11,580 the only thing that needs to match 7173 03:47:11,580 --> 03:47:13,739 perfectly is just the function signature 7174 03:47:13,739 --> 03:47:15,600 and the function signature that means 7175 03:47:15,600 --> 03:47:17,460 the return type as well as the name and 7176 03:47:17,460 --> 03:47:19,680 any parameters the implementation itself 7177 03:47:19,680 --> 03:47:21,420 that is up to the class that wants to 7178 03:47:21,420 --> 03:47:23,279 implement that interface but in this 7179 03:47:23,279 --> 03:47:25,020 case we wanted to behave pretty much 7180 03:47:25,020 --> 03:47:26,939 exam the same way so like this it should 7181 03:47:26,939 --> 03:47:28,080 be working 7182 03:47:28,080 --> 03:47:29,939 so we can now go back here onto the 7183 03:47:29,939 --> 03:47:32,100 clear counter script and okay we have 7184 03:47:32,100 --> 03:47:33,840 our interaction all right great 7185 03:47:33,840 --> 03:47:35,160 so if there's nothing we're going to 7186 03:47:35,160 --> 03:47:36,779 spawn it and if there is something on 7187 03:47:36,779 --> 03:47:38,100 top of it we want to give it to the 7188 03:47:38,100 --> 03:47:39,899 player so now let's go into the kitchen 7189 03:47:39,899 --> 03:47:42,000 object and call the function set kitchen 7190 03:47:42,000 --> 03:47:43,680 object parent and pass in the play 7191 03:47:43,680 --> 03:47:44,760 reference 7192 03:47:44,760 --> 03:47:46,800 and that's it no errors because again 7193 03:47:46,800 --> 03:47:48,660 this takes a parameter of type kitchen 7194 03:47:48,660 --> 03:47:50,160 object parent and the player does 7195 03:47:50,160 --> 03:47:51,840 implement that interface so that's all 7196 03:47:51,840 --> 03:47:52,979 valid 7197 03:47:52,979 --> 03:47:54,720 now with this let's says and see if our 7198 03:47:54,720 --> 03:47:55,800 code is working 7199 03:47:55,800 --> 03:47:57,300 alright so here we are and let's 7200 03:47:57,300 --> 03:47:58,979 interact with this counter and there you 7201 03:47:58,979 --> 03:48:01,260 go the object has been spawned and now 7202 03:48:01,260 --> 03:48:03,060 if I interact again if they're going to 7203 03:48:03,060 --> 03:48:04,319 look that the player picked up the 7204 03:48:04,319 --> 03:48:06,779 object and since our logic is using a 7205 03:48:06,779 --> 03:48:09,239 transform home Point as the parent the 7206 03:48:09,239 --> 03:48:10,800 player is automatically carrying this 7207 03:48:10,800 --> 03:48:13,920 tomato alright awesome so this is really 7208 03:48:13,920 --> 03:48:15,060 great 7209 03:48:15,060 --> 03:48:16,680 now over here on the counter we no 7210 03:48:16,680 --> 03:48:18,960 longer need all of this testing code we 7211 03:48:18,960 --> 03:48:20,700 now have the ability to actually pick up 7212 03:48:20,700 --> 03:48:23,160 objects from the player so let's get rid 7213 03:48:23,160 --> 03:48:24,479 of all this so we don't need this 7214 03:48:24,479 --> 03:48:26,399 testing code don't need a reference to 7215 03:48:26,399 --> 03:48:28,140 the second color counter or the testing 7216 03:48:28,140 --> 03:48:31,200 okay great so here you can see the power 7217 03:48:31,200 --> 03:48:33,660 of interfaces by just implementing the 7218 03:48:33,660 --> 03:48:35,460 interface we can now place an item 7219 03:48:35,460 --> 03:48:38,160 anywhere we want and importantly on any 7220 03:48:38,160 --> 03:48:39,600 type we want 7221 03:48:39,600 --> 03:48:41,880 so the counter can hold a kitchen object 7222 03:48:41,880 --> 03:48:44,100 the player can also hold it we could 7223 03:48:44,100 --> 03:48:46,080 make a dog character and make it hold a 7224 03:48:46,080 --> 03:48:47,819 kitchen object we could make a vehicle 7225 03:48:47,819 --> 03:48:50,520 hold it or anything again interfaces are 7226 03:48:50,520 --> 03:48:52,500 really really awesome one of the best C 7227 03:48:52,500 --> 03:48:54,779 sharp features definitely go ahead pause 7228 03:48:54,779 --> 03:48:56,220 this course for now and watch a 7229 03:48:56,220 --> 03:48:58,319 dedicated video on them you should be 7230 03:48:58,319 --> 03:49:00,479 very very familiar with interfaces they 7231 03:49:00,479 --> 03:49:01,979 will help you in making all kinds of 7232 03:49:01,979 --> 03:49:03,180 systems and games 7233 03:49:03,180 --> 03:49:04,979 if you want to see a clear example of 7234 03:49:04,979 --> 03:49:06,600 the power of interface you can go watch 7235 03:49:06,600 --> 03:49:09,420 my how to interact with NPC's video that 7236 03:49:09,420 --> 03:49:10,920 video takes advantage of interface to 7237 03:49:10,920 --> 03:49:12,300 make sure that the player can interact 7238 03:49:12,300 --> 03:49:14,460 with any kind of object alright so 7239 03:49:14,460 --> 03:49:16,319 thanks to interface we can now change 7240 03:49:16,319 --> 03:49:18,239 the parent of the kitchen object and put 7241 03:49:18,239 --> 03:49:20,520 it on either a counter or the player now 7242 03:49:20,520 --> 03:49:22,439 in the next lecture let's make a proper 7243 03:49:22,439 --> 03:49:24,300 different counter type 7244 03:49:24,300 --> 03:49:26,220 hello and welcome I'm your code monkey 7245 03:49:26,220 --> 03:49:28,739 in this lecture we're going to create a 7246 03:49:28,739 --> 03:49:30,420 different counter type from where we can 7247 03:49:30,420 --> 03:49:32,279 grab some ingredients 7248 03:49:32,279 --> 03:49:34,319 okay so far here we have our character 7249 03:49:34,319 --> 03:49:36,300 working and we have an empty counter and 7250 03:49:36,300 --> 03:49:37,979 by interacting with it we can spawn an 7251 03:49:37,979 --> 03:49:40,020 object but obviously that's not the 7252 03:49:40,020 --> 03:49:42,000 behavior we want in the final game we 7253 03:49:42,000 --> 03:49:43,500 want different counter types that do 7254 03:49:43,500 --> 03:49:45,420 different things the cleaner counter 7255 03:49:45,420 --> 03:49:46,680 should only be used as a place for 7256 03:49:46,680 --> 03:49:48,479 putting down and grabbing objects it 7257 03:49:48,479 --> 03:49:50,040 should not spawn anything 7258 03:49:50,040 --> 03:49:52,560 so let's build a new counter type 7259 03:49:52,560 --> 03:49:54,960 and for that one option is to make a 7260 03:49:54,960 --> 03:49:56,640 brand new prefab and build it on from 7261 03:49:56,640 --> 03:49:58,739 scratch another option is we can 7262 03:49:58,739 --> 03:50:00,479 duplicate this counter and change a 7263 03:50:00,479 --> 03:50:02,220 bunch of things or there's a third 7264 03:50:02,220 --> 03:50:03,899 option that was added in recent TNT 7265 03:50:03,899 --> 03:50:04,920 versions 7266 03:50:04,920 --> 03:50:07,020 you can now have what is called prefab 7267 03:50:07,020 --> 03:50:09,660 variants meaning that we can have a base 7268 03:50:09,660 --> 03:50:11,700 counter and then we can make variants 7269 03:50:11,700 --> 03:50:14,279 for all the types so let's do exactly 7270 03:50:14,279 --> 03:50:16,739 that to learn about prefab variants now 7271 03:50:16,739 --> 03:50:18,180 first let's duplicate this one just so 7272 03:50:18,180 --> 03:50:19,920 we don't lose any changes 7273 03:50:19,920 --> 03:50:22,439 let's rename this prefab to underscore 7274 03:50:22,439 --> 03:50:23,939 base counter 7275 03:50:23,939 --> 03:50:26,040 no I'd like to add an underscore just so 7276 03:50:26,040 --> 03:50:27,720 that the bass prefab is on top since 7277 03:50:27,720 --> 03:50:30,000 this window is sorted alphabetically 7278 03:50:30,000 --> 03:50:31,979 now let's go inside the base counter 7279 03:50:31,979 --> 03:50:33,840 let's go into the scene view so here it 7280 03:50:33,840 --> 03:50:34,920 is 7281 03:50:34,920 --> 03:50:37,080 and recently over here we only want to 7282 03:50:37,080 --> 03:50:38,580 have all of the things that all of the 7283 03:50:38,580 --> 03:50:40,979 counters will have so all the counters 7284 03:50:40,979 --> 03:50:43,020 will have a boxing ladder only the same 7285 03:50:43,020 --> 03:50:45,420 shape so that's good they will also all 7286 03:50:45,420 --> 03:50:47,760 have a counter top point 7287 03:50:47,760 --> 03:50:49,260 however for the visual different 7288 03:50:49,260 --> 03:50:50,939 counters will have different Visions so 7289 03:50:50,939 --> 03:50:52,739 let's get rid of this same thing for the 7290 03:50:52,739 --> 03:50:54,840 selected let's get rid of this 7291 03:50:54,840 --> 03:50:56,340 and on the actual object different 7292 03:50:56,340 --> 03:50:58,680 encounters will have different Scripts 7293 03:50:58,680 --> 03:51:00,779 so let's also get rid of this 7294 03:51:00,779 --> 03:51:02,640 okay so that's it this is the base 7295 03:51:02,640 --> 03:51:05,279 counter it only has all the things that 7296 03:51:05,279 --> 03:51:07,439 every single encounter will have so 7297 03:51:07,439 --> 03:51:09,420 let's go ahead save this prefab go back 7298 03:51:09,420 --> 03:51:11,760 outside and now let's right click on the 7299 03:51:11,760 --> 03:51:13,080 base counter 7300 03:51:13,080 --> 03:51:16,080 and go into create and over here let's 7301 03:51:16,080 --> 03:51:18,180 scroll down and find the prefab variant 7302 03:51:18,180 --> 03:51:20,460 now let's name this the clear counter 7303 03:51:20,460 --> 03:51:22,200 except obviously we can't have two 7304 03:51:22,200 --> 03:51:24,000 different names so let's put this one 7305 03:51:24,000 --> 03:51:26,399 into backup we're going to get rid of 7306 03:51:26,399 --> 03:51:27,779 this one in a little bit 7307 03:51:27,779 --> 03:51:29,640 so on the very end let's name it clear 7308 03:51:29,640 --> 03:51:31,020 counter 7309 03:51:31,020 --> 03:51:33,060 let's open up this variant 7310 03:51:33,060 --> 03:51:34,800 and now here let's add everything just 7311 03:51:34,800 --> 03:51:37,560 like we had on the own player counter so 7312 03:51:37,560 --> 03:51:38,819 since it's going to be exactly let's 7313 03:51:38,819 --> 03:51:41,460 actually go inside the backup one so 7314 03:51:41,460 --> 03:51:43,080 here let's just copy the visual in the 7315 03:51:43,080 --> 03:51:45,239 selected so let's copy this 7316 03:51:45,239 --> 03:51:47,460 go back inside the clear counter variant 7317 03:51:47,460 --> 03:51:48,960 and over here only let's paste it so 7318 03:51:48,960 --> 03:51:50,399 Ctrl V 7319 03:51:50,399 --> 03:51:52,140 see if there it is he selected any 7320 03:51:52,140 --> 03:51:53,220 visual 7321 03:51:53,220 --> 03:51:55,560 finally just scripts over here let's add 7322 03:51:55,560 --> 03:51:57,779 the clear counter script 7323 03:51:57,779 --> 03:51:59,760 and now let's just write the references 7324 03:51:59,760 --> 03:52:01,020 so the kitchen object we're actually 7325 03:52:01,020 --> 03:52:02,399 going to remove this in a little bit but 7326 03:52:02,399 --> 03:52:04,500 for now let's assign it the counter top 7327 03:52:04,500 --> 03:52:06,600 Point Let's drag it and on the selected 7328 03:52:06,600 --> 03:52:08,580 we also need to drag the kitchen counter 7329 03:52:08,580 --> 03:52:09,660 reference 7330 03:52:09,660 --> 03:52:12,779 okay so here is our clear counter as a 7331 03:52:12,779 --> 03:52:15,000 variant of the base counter so let's go 7332 03:52:15,000 --> 03:52:17,760 ahead save this and go back outside 7333 03:52:17,760 --> 03:52:20,100 and now we can finally delete the owned 7334 03:52:20,100 --> 03:52:21,899 prefab of the clear counter so let's go 7335 03:52:21,899 --> 03:52:23,460 ahead and delete this 7336 03:52:23,460 --> 03:52:24,840 and of course over here on the scene 7337 03:52:24,840 --> 03:52:26,460 we've got some broken prefabs so let's 7338 03:52:26,460 --> 03:52:28,920 get rid of both these and let's drop the 7339 03:52:28,920 --> 03:52:30,720 clear counter variant so let's drop it 7340 03:52:30,720 --> 03:52:33,239 place it over here so let's put it on X 7341 03:52:33,239 --> 03:52:37,859 of 0 y of zero and Z of 3.5 7342 03:52:37,859 --> 03:52:39,540 okay so that's the clear counter and 7343 03:52:39,540 --> 03:52:40,920 let's just put another one to the side 7344 03:52:40,920 --> 03:52:42,960 and perfectly on the side so on an X of 7345 03:52:42,960 --> 03:52:45,840 minus 1.5 okay now we can begin making 7346 03:52:45,840 --> 03:52:47,819 our container counter 7347 03:52:47,819 --> 03:52:49,620 so for that once again let's make a 7348 03:52:49,620 --> 03:52:51,120 variant so right click on the base 7349 03:52:51,120 --> 03:52:52,800 counter and go into create and let's 7350 03:52:52,800 --> 03:52:54,600 create a prefab variant 7351 03:52:54,600 --> 03:52:57,359 call this the container counter 7352 03:52:57,359 --> 03:52:59,819 and let's go inside of it now here first 7353 03:52:59,819 --> 03:53:01,620 thing we need is the visual so let's go 7354 03:53:01,620 --> 03:53:03,960 inside our assets we've got the prefab 7355 03:53:03,960 --> 03:53:05,939 visuals inside we have the counters 7356 03:53:05,939 --> 03:53:08,279 visuals and let's find the container 7357 03:53:08,279 --> 03:53:10,439 counter so let's drag it inside again 7358 03:53:10,439 --> 03:53:12,000 for the low composition make sure it's 7359 03:53:12,000 --> 03:53:14,220 on zero zero zero okay great 7360 03:53:14,220 --> 03:53:16,380 then we need to make the selected so 7361 03:53:16,380 --> 03:53:18,359 let's duplicate this visual let's rename 7362 03:53:18,359 --> 03:53:20,100 this to selecton 7363 03:53:20,100 --> 03:53:23,220 let's go inside on all of these 7364 03:53:23,220 --> 03:53:25,260 then let's modify the material for the 7365 03:53:25,260 --> 03:53:27,000 selected material so let's click on the 7366 03:53:27,000 --> 03:53:28,500 circle icon and select the counter 7367 03:53:28,500 --> 03:53:30,540 select material okay we've got our nice 7368 03:53:30,540 --> 03:53:32,340 little ghost icon 7369 03:53:32,340 --> 03:53:34,020 and just like we did previously let's 7370 03:53:34,020 --> 03:53:35,700 start with these disabled so all these 7371 03:53:35,700 --> 03:53:37,380 game options disabled so they are hidden 7372 03:53:37,380 --> 03:53:39,479 and on the selected let's make sure the 7373 03:53:39,479 --> 03:53:42,779 scale is one percent bigger so 1.01 7374 03:53:42,779 --> 03:53:44,340 also in the selected this one does not 7375 03:53:44,340 --> 03:53:45,840 need an animator so let's get rid of 7376 03:53:45,840 --> 03:53:46,739 this 7377 03:53:46,739 --> 03:53:49,439 now let's add the selected counter 7378 03:53:49,439 --> 03:53:51,779 visual and obviously for this one we're 7379 03:53:51,779 --> 03:53:53,460 eventually going to need to refactor it 7380 03:53:53,460 --> 03:53:55,560 to support multiple visual objects as 7381 03:53:55,560 --> 03:53:57,600 you can see this selected has multiple 7382 03:53:57,600 --> 03:53:59,520 but for now just make sure that it works 7383 03:53:59,520 --> 03:54:01,380 let's just drag just the first one okay 7384 03:54:01,380 --> 03:54:02,340 great 7385 03:54:02,340 --> 03:54:04,560 so our container counter has been built 7386 03:54:04,560 --> 03:54:06,120 the only thing that we need is the main 7387 03:54:06,120 --> 03:54:08,399 logic script so let's do that 7388 03:54:08,399 --> 03:54:10,620 let's go into our scripts folder let's 7389 03:54:10,620 --> 03:54:12,960 create a brand new c-sharp script 7390 03:54:12,960 --> 03:54:15,720 name it the container counter 7391 03:54:15,720 --> 03:54:17,760 and let's select the main game object 7392 03:54:17,760 --> 03:54:20,279 attach a script and let's open it 7393 03:54:20,279 --> 03:54:22,319 alright so now here let's first think 7394 03:54:22,319 --> 03:54:24,600 what we want for this counter we want 7395 03:54:24,600 --> 03:54:26,460 the player to interact with it and when 7396 03:54:26,460 --> 03:54:28,020 it does we want to spawn an ingredient 7397 03:54:28,020 --> 03:54:30,420 and give it to the player so that means 7398 03:54:30,420 --> 03:54:31,680 that we're going to want pretty much the 7399 03:54:31,680 --> 03:54:33,180 exact same behavior that we made over 7400 03:54:33,180 --> 03:54:35,520 here on the clear counter so when the 7401 03:54:35,520 --> 03:54:37,319 player interacts we spawn and we give it 7402 03:54:37,319 --> 03:54:39,300 to the player so let's actually copy all 7403 03:54:39,300 --> 03:54:41,760 of this code let's go into the Container 7404 03:54:41,760 --> 03:54:44,399 counter and over here let's face this 7405 03:54:44,399 --> 03:54:46,560 we just need to grab the references to 7406 03:54:46,560 --> 03:54:47,699 the kitchen object and the kitchen 7407 03:54:47,699 --> 03:54:49,620 object as so so again just like we did 7408 03:54:49,620 --> 03:54:51,779 on the container counter let's copy all 7409 03:54:51,779 --> 03:54:53,100 these references 7410 03:54:53,100 --> 03:54:55,680 and over here let's paste all of them 7411 03:54:55,680 --> 03:54:57,600 and of course here we have an error in 7412 03:54:57,600 --> 03:54:58,979 order for this work this needs to 7413 03:54:58,979 --> 03:55:00,540 implement our interface and let's do 7414 03:55:00,540 --> 03:55:02,279 exactly that so let's implement the eye 7415 03:55:02,279 --> 03:55:04,140 kitchen object parent 7416 03:55:04,140 --> 03:55:06,180 and back in the clear counter let's just 7417 03:55:06,180 --> 03:55:07,979 copy the exact same code so all of these 7418 03:55:07,979 --> 03:55:09,840 functions let's just copy them and on 7419 03:55:09,840 --> 03:55:11,220 the container counter just paste them 7420 03:55:11,220 --> 03:55:12,720 okay great 7421 03:55:12,720 --> 03:55:15,000 so we don't have any more errors here so 7422 03:55:15,000 --> 03:55:17,220 everything should work we should be able 7423 03:55:17,220 --> 03:55:18,779 to interact with the container counter 7424 03:55:18,779 --> 03:55:20,340 and we should be able to see an object 7425 03:55:20,340 --> 03:55:22,140 being spawned on top of it 7426 03:55:22,140 --> 03:55:23,880 over here in the editor let's just make 7427 03:55:23,880 --> 03:55:25,859 sure to assign it so let's assign a 7428 03:55:25,859 --> 03:55:27,300 default kitchen object so let's say 7429 03:55:27,300 --> 03:55:29,580 tomato and the counter top Point Let's 7430 03:55:29,580 --> 03:55:31,560 drag the reference and okay everything 7431 03:55:31,560 --> 03:55:33,840 else should be working so over here on 7432 03:55:33,840 --> 03:55:35,460 the selected we've got the visual game 7433 03:55:35,460 --> 03:55:36,840 object on the container counter we've 7434 03:55:36,840 --> 03:55:38,460 got this okay great so let's go outside 7435 03:55:38,460 --> 03:55:39,899 into scene View 7436 03:55:39,899 --> 03:55:41,939 and over here let's just Place some 7437 03:55:41,939 --> 03:55:43,920 container counters so let's drag one up 7438 03:55:43,920 --> 03:55:44,880 there 7439 03:55:44,880 --> 03:55:47,819 let's place it on an X of 1.5 on a y of 7440 03:55:47,819 --> 03:55:50,939 0 and Z of 3.5 and let's also Place 7441 03:55:50,939 --> 03:55:53,399 another one down here so let's rotate it 7442 03:55:53,399 --> 03:55:55,439 to face it upwards 7443 03:55:55,439 --> 03:55:57,899 okay so on position zero zero minus five 7444 03:55:57,899 --> 03:55:59,220 okay great 7445 03:55:59,220 --> 03:56:00,660 and let's make them spawn different 7446 03:56:00,660 --> 03:56:01,920 things 7447 03:56:01,920 --> 03:56:03,600 so on this one up here let's actually 7448 03:56:03,600 --> 03:56:05,699 spawn a cheese block and on this one 7449 03:56:05,699 --> 03:56:07,920 down here let's one tomato so let's also 7450 03:56:07,920 --> 03:56:09,540 modify the icon here 7451 03:56:09,540 --> 03:56:12,000 so from cheese block and let's put a 7452 03:56:12,000 --> 03:56:14,520 tomato icon so here it is 7453 03:56:14,520 --> 03:56:16,439 okay we've got two counters and two 7454 03:56:16,439 --> 03:56:18,300 clear counters so let's test 7455 03:56:18,300 --> 03:56:20,279 so here we are and if I approach a 7456 03:56:20,279 --> 03:56:21,720 container counter and I press the 7457 03:56:21,720 --> 03:56:23,580 interact button and nope nothing 7458 03:56:23,580 --> 03:56:25,920 happened we cannot interact with that at 7459 03:56:25,920 --> 03:56:28,199 all even the selection visual even that 7460 03:56:28,199 --> 03:56:30,420 one is broken so as I approach note the 7461 03:56:30,420 --> 03:56:32,100 visual is not showing up 7462 03:56:32,100 --> 03:56:33,300 now the reason for this is actually 7463 03:56:33,300 --> 03:56:34,859 pretty obvious 7464 03:56:34,859 --> 03:56:36,960 if we go over here on the player script 7465 03:56:36,960 --> 03:56:39,180 down here when we're handling our 7466 03:56:39,180 --> 03:56:41,220 interactions so let's go into the handle 7467 03:56:41,220 --> 03:56:42,720 interactions function 7468 03:56:42,720 --> 03:56:45,180 over here we are doing a recast and we 7469 03:56:45,180 --> 03:56:46,560 are trying to get component of type 7470 03:56:46,560 --> 03:56:48,060 clear counter 7471 03:56:48,060 --> 03:56:50,100 so basically we're not doing anything if 7472 03:56:50,100 --> 03:56:51,779 that object has a container counter 7473 03:56:51,779 --> 03:56:54,180 instead of a clear counter so again we 7474 03:56:54,180 --> 03:56:55,920 have a similar issue to the one that we 7475 03:56:55,920 --> 03:56:58,199 had in the object parent logic basically 7476 03:56:58,199 --> 03:57:00,660 we have two types a clear counter and a 7477 03:57:00,660 --> 03:57:02,580 container counter and we want the player 7478 03:57:02,580 --> 03:57:04,680 to be able to interact with both them 7479 03:57:04,680 --> 03:57:07,020 so as a solution for this exact same 7480 03:57:07,020 --> 03:57:08,399 problem we could also Implement an 7481 03:57:08,399 --> 03:57:10,800 interface just like we did that would 7482 03:57:10,800 --> 03:57:12,479 work that would enable the player to 7483 03:57:12,479 --> 03:57:14,520 interact with multiple counters but in 7484 03:57:14,520 --> 03:57:16,020 this case since the counters are all 7485 03:57:16,020 --> 03:57:18,000 very similar very related objects 7486 03:57:18,000 --> 03:57:19,920 they're all going to be kitchen counters 7487 03:57:19,920 --> 03:57:21,779 as opposed to object parents where the 7488 03:57:21,779 --> 03:57:23,040 player and encounter are completely 7489 03:57:23,040 --> 03:57:23,939 different 7490 03:57:23,939 --> 03:57:25,620 in this case since they are all very 7491 03:57:25,620 --> 03:57:27,479 similar a better approach is actually to 7492 03:57:27,479 --> 03:57:29,819 use inheritance now here I should point 7493 03:57:29,819 --> 03:57:31,500 out that inheritance is one of those 7494 03:57:31,500 --> 03:57:33,000 things that is simultaneously very 7495 03:57:33,000 --> 03:57:35,520 powerful but also very dangerous usually 7496 03:57:35,520 --> 03:57:37,140 beginners get really excited when they 7497 03:57:37,140 --> 03:57:38,760 first hear about inheritance but after 7498 03:57:38,760 --> 03:57:40,319 gaining some experience they start to 7499 03:57:40,319 --> 03:57:42,060 see the massive downsides 7500 03:57:42,060 --> 03:57:44,580 one funny joke about it is let's say you 7501 03:57:44,580 --> 03:57:45,899 want to write some code that all it 7502 03:57:45,899 --> 03:57:48,180 needs is a Banana class but because of 7503 03:57:48,180 --> 03:57:49,680 messy inheritance you end up with a 7504 03:57:49,680 --> 03:57:51,779 monkey and the entire jungle behind it 7505 03:57:51,779 --> 03:57:53,399 basically the banana extends a monkey 7506 03:57:53,399 --> 03:57:55,140 which extends a tree which extends the 7507 03:57:55,140 --> 03:57:57,239 jungle and so on so you just want a 7508 03:57:57,239 --> 03:57:59,040 small thing but because of a complex 7509 03:57:59,040 --> 03:58:00,840 inheritance you end up picking up a huge 7510 03:58:00,840 --> 03:58:02,880 object some of that to say inheritance 7511 03:58:02,880 --> 03:58:04,560 is something you must use very very 7512 03:58:04,560 --> 03:58:06,779 carefully it's a powerful tool 7513 03:58:06,779 --> 03:58:08,220 definitely but you need to make sure 7514 03:58:08,220 --> 03:58:10,020 that you absolutely use it in the right 7515 03:58:10,020 --> 03:58:11,399 approach for the problem you're trying 7516 03:58:11,399 --> 03:58:13,620 to solve now in this case like I said 7517 03:58:13,620 --> 03:58:15,120 since all of the counters are going to 7518 03:58:15,120 --> 03:58:17,580 be very closely related in this case it 7519 03:58:17,580 --> 03:58:18,840 does make sense 7520 03:58:18,840 --> 03:58:20,640 and of course in the future if that does 7521 03:58:20,640 --> 03:58:22,680 change we can always refactor 7522 03:58:22,680 --> 03:58:24,420 if you're a beginner definitely go ahead 7523 03:58:24,420 --> 03:58:26,340 and research a bit more on c-sharp 7524 03:58:26,340 --> 03:58:28,439 inheritance the pros and cons 7525 03:58:28,439 --> 03:58:30,420 I don't have any dedicated video on that 7526 03:58:30,420 --> 03:58:32,100 topic myself but if you search I'm sure 7527 03:58:32,100 --> 03:58:34,620 you'll find tons of content again it's a 7528 03:58:34,620 --> 03:58:36,359 very powerful but also very dangerous 7529 03:58:36,359 --> 03:58:38,580 tool so definitely use it wisely 7530 03:58:38,580 --> 03:58:40,680 over here let's make sure we rise so 7531 03:58:40,680 --> 03:58:42,060 let's use it 7532 03:58:42,060 --> 03:58:43,859 first thing we need to do is to find the 7533 03:58:43,859 --> 03:58:45,899 base counter class so let's create a new 7534 03:58:45,899 --> 03:58:48,120 c-sharp script let's call it the base 7535 03:58:48,120 --> 03:58:49,859 counter 7536 03:58:49,859 --> 03:58:51,840 so over here on the script let's get rid 7537 03:58:51,840 --> 03:58:53,279 of the functions we don't want any 7538 03:58:53,279 --> 03:58:55,199 default functions and let's also make 7539 03:58:55,199 --> 03:58:57,899 sure that we do extend mono Behavior we 7540 03:58:57,899 --> 03:58:59,460 do want that we still want to use this 7541 03:58:59,460 --> 03:59:00,779 as a component 7542 03:59:00,779 --> 03:59:02,340 so let's leave the script just like this 7543 03:59:02,340 --> 03:59:03,720 let's save it 7544 03:59:03,720 --> 03:59:06,120 then let's go over here into the clear 7545 03:59:06,120 --> 03:59:07,500 counter script 7546 03:59:07,500 --> 03:59:09,060 and on this one instead of extending 7547 03:59:09,060 --> 03:59:10,800 Model Behavior let's extend the base 7548 03:59:10,800 --> 03:59:12,000 counter 7549 03:59:12,000 --> 03:59:13,620 okay that's it that's the only change 7550 03:59:13,620 --> 03:59:15,239 and now let's go into the Container 7551 03:59:15,239 --> 03:59:16,739 counter and over here same thing let's 7552 03:59:16,739 --> 03:59:18,420 extend the base counter inside of Model 7553 03:59:18,420 --> 03:59:20,640 Behavior so now both these counters 7554 03:59:20,640 --> 03:59:22,439 extend the exact same base counter 7555 03:59:22,439 --> 03:59:24,600 script so now if we go into the player 7556 03:59:24,600 --> 03:59:26,100 score so here we are on the player 7557 03:59:26,100 --> 03:59:28,620 script and on the handle interactions 7558 03:59:28,620 --> 03:59:30,540 function over here instead of trying to 7559 03:59:30,540 --> 03:59:32,279 get a component of type player counter 7560 03:59:32,279 --> 03:59:34,500 let's try to get component of type base 7561 03:59:34,500 --> 03:59:36,840 counter so let's also rename the so 7562 03:59:36,840 --> 03:59:39,479 control RR to rename rename this to base 7563 03:59:39,479 --> 03:59:42,060 counter and of course we need to rename 7564 03:59:42,060 --> 03:59:44,100 all these references that expect a clear 7565 03:59:44,100 --> 03:59:46,080 counter instead of the base counter so 7566 03:59:46,080 --> 03:59:47,699 over here for the selected counter let's 7567 03:59:47,699 --> 03:59:50,939 modify the type to base counter then 7568 03:59:50,939 --> 03:59:53,520 also up here when we've got the event RX 7569 03:59:53,520 --> 03:59:55,680 let's modify the type okay 7570 03:59:55,680 --> 03:59:57,479 so over here we have the interactor 7571 03:59:57,479 --> 03:59:59,160 let's leave this for a bit let's go down 7572 03:59:59,160 --> 04:00:01,140 and let's fix this issue so let's go 7573 04:00:01,140 --> 04:00:02,580 down into that function to set the 7574 04:00:02,580 --> 04:00:04,380 selected counter instead of this time 7575 04:00:04,380 --> 04:00:06,479 let's receive a base counter 7576 04:00:06,479 --> 04:00:08,699 okay so all of these errors have been 7577 04:00:08,699 --> 04:00:10,199 solved there's only one left and it's 7578 04:00:10,199 --> 04:00:11,819 this one the interact 7579 04:00:11,819 --> 04:00:13,620 we see this error because obviously the 7580 04:00:13,620 --> 04:00:15,120 base less does not have any kind of 7581 04:00:15,120 --> 04:00:18,000 interact method so let's add that 7582 04:00:18,000 --> 04:00:20,100 now for adding methods to a base layer 7583 04:00:20,100 --> 04:00:21,420 it's sectionally very simple it's really 7584 04:00:21,420 --> 04:00:23,819 just like any other method so first the 7585 04:00:23,819 --> 04:00:25,920 accessor for the interact we want the 7586 04:00:25,920 --> 04:00:27,359 player to be able to access it so let's 7587 04:00:27,359 --> 04:00:28,620 make it public 7588 04:00:28,620 --> 04:00:29,939 and also since we're talking about 7589 04:00:29,939 --> 04:00:31,319 inheritance I should probably mention 7590 04:00:31,319 --> 04:00:33,899 the other accessor now you already know 7591 04:00:33,899 --> 04:00:35,520 about public and you also already know 7592 04:00:35,520 --> 04:00:37,560 about private but there's another one 7593 04:00:37,560 --> 04:00:38,939 you might not know which is called 7594 04:00:38,939 --> 04:00:40,319 protected 7595 04:00:40,319 --> 04:00:42,239 basically this one means that whatever 7596 04:00:42,239 --> 04:00:43,979 function we defined with this successor 7597 04:00:43,979 --> 04:00:45,960 it is going to be accessible to this 7598 04:00:45,960 --> 04:00:48,540 class and any class that extends it so 7599 04:00:48,540 --> 04:00:50,520 for example if we had a function that 7600 04:00:50,520 --> 04:00:52,920 was protected the clear counter could 7601 04:00:52,920 --> 04:00:54,300 count this function because it does 7602 04:00:54,300 --> 04:00:56,460 extend this Base Class however the 7603 04:00:56,460 --> 04:00:57,899 player would not be able to call this 7604 04:00:57,899 --> 04:01:00,180 because it is protected now in our case 7605 04:01:00,180 --> 04:01:01,800 for the interact action we do want to 7606 04:01:01,800 --> 04:01:03,420 play the comet so let's make it public 7607 04:01:03,420 --> 04:01:05,760 just like we had previously then another 7608 04:01:05,760 --> 04:01:08,399 keyword for every function that we want 7609 04:01:08,399 --> 04:01:10,020 the chunk lesses to be able to implement 7610 04:01:10,020 --> 04:01:11,819 in their own way we can Define it as 7611 04:01:11,819 --> 04:01:12,840 virtual 7612 04:01:12,840 --> 04:01:14,819 and finally the function signature as 7613 04:01:14,819 --> 04:01:16,979 normal so for the interact we made a 7614 04:01:16,979 --> 04:01:19,500 return void call it interact and we 7615 04:01:19,500 --> 04:01:23,720 received a player argument 7616 04:01:24,120 --> 04:01:25,979 okay so that's it that's our basic 7617 04:01:25,979 --> 04:01:27,060 signature 7618 04:01:27,060 --> 04:01:28,680 for the implementation let's leave it 7619 04:01:28,680 --> 04:01:30,540 empty over here on the base counter so 7620 04:01:30,540 --> 04:01:32,939 by default it's not going to do anything 7621 04:01:32,939 --> 04:01:34,260 in the game design that we're building 7622 04:01:34,260 --> 04:01:35,699 we're never actually going to end up 7623 04:01:35,699 --> 04:01:37,140 with anything like this 7624 04:01:37,140 --> 04:01:38,880 so if you want for safety we can just 7625 04:01:38,880 --> 04:01:41,880 add a debug.log error 7626 04:01:41,880 --> 04:01:44,160 to say just base counter.interact 7627 04:01:44,160 --> 04:01:46,319 because this should never be triggered 7628 04:01:46,319 --> 04:01:48,239 also I shouldn't point out for a more 7629 04:01:48,239 --> 04:01:49,500 advanced method 7630 04:01:49,500 --> 04:01:51,239 instead of making it virtual you could 7631 04:01:51,239 --> 04:01:53,699 make it abstract and basically what that 7632 04:01:53,699 --> 04:01:55,859 does is that forces all the classes to 7633 04:01:55,859 --> 04:01:58,260 implement their own implementation 7634 04:01:58,260 --> 04:02:00,779 so you would make this extract and just 7635 04:02:00,779 --> 04:02:02,699 put it just like this as if this were an 7636 04:02:02,699 --> 04:02:05,100 interface but in doing so you would also 7637 04:02:05,100 --> 04:02:06,600 need to define a base counter as 7638 04:02:06,600 --> 04:02:08,580 abstract and so on so basically this is 7639 04:02:08,580 --> 04:02:10,080 a more advanced method so don't worry 7640 04:02:10,080 --> 04:02:11,880 about it for now let's keep it a bit 7641 04:02:11,880 --> 04:02:14,040 more simple so let's make it just 7642 04:02:14,040 --> 04:02:17,100 virtual void interact okay great 7643 04:02:17,100 --> 04:02:19,380 so we have this let's save this and now 7644 04:02:19,380 --> 04:02:21,779 if we go on the calendar counter 7645 04:02:21,779 --> 04:02:24,180 over here on the interact notice how we 7646 04:02:24,180 --> 04:02:26,340 have a green screen line 7647 04:02:26,340 --> 04:02:28,140 basically this is a warning it's telling 7648 04:02:28,140 --> 04:02:30,540 us that we are hiding the base function 7649 04:02:30,540 --> 04:02:32,580 now in reality we don't want to hide it 7650 04:02:32,580 --> 04:02:35,340 instead we want to override it so before 7651 04:02:35,340 --> 04:02:37,140 the void before the return type we just 7652 04:02:37,140 --> 04:02:39,779 have the keyword override 7653 04:02:39,779 --> 04:02:41,939 and Yep this will now override the base 7654 04:02:41,939 --> 04:02:44,340 function so when the player interacts 7655 04:02:44,340 --> 04:02:46,080 with an object of type based counter and 7656 04:02:46,080 --> 04:02:47,760 that object is actually a clear counter 7657 04:02:47,760 --> 04:02:49,380 when the player calls the interact 7658 04:02:49,380 --> 04:02:51,120 function instead of running this code 7659 04:02:51,120 --> 04:02:53,580 it's actually going to run this code 7660 04:02:53,580 --> 04:02:55,199 now let's do the same thing on the 7661 04:02:55,199 --> 04:02:56,880 container counter so over here let's 7662 04:02:56,880 --> 04:02:58,380 also add the 7663 04:02:58,380 --> 04:03:01,080 keyword override to override the base 7664 04:03:01,080 --> 04:03:03,660 function okay great so we have no errors 7665 04:03:03,660 --> 04:03:05,399 here and on the player we also don't 7666 04:03:05,399 --> 04:03:07,020 have any more errors since that one does 7667 04:03:07,020 --> 04:03:09,180 now implement the interact function 7668 04:03:09,180 --> 04:03:10,620 so with this one it says and everything 7669 04:03:10,620 --> 04:03:12,779 should still be working so over here 7670 04:03:12,779 --> 04:03:14,819 let's approach the entire counter and 7671 04:03:14,819 --> 04:03:16,380 let's interact with it any up it does 7672 04:03:16,380 --> 04:03:18,120 work it spawn some cheese and down here 7673 04:03:18,120 --> 04:03:20,699 yep it's on the tomato and then if we go 7674 04:03:20,699 --> 04:03:22,620 on to the empty counter and interact and 7675 04:03:22,620 --> 04:03:25,680 yep it still works okay so here we added 7676 04:03:25,680 --> 04:03:27,120 the ability to interact with two 7677 04:03:27,120 --> 04:03:28,920 different counter types alright great 7678 04:03:28,920 --> 04:03:31,380 now knows how the selected logic isn't 7679 04:03:31,380 --> 04:03:33,779 really working well you can see the 7680 04:03:33,779 --> 04:03:35,040 container counters they are both 7681 04:03:35,040 --> 04:03:37,199 selected even though the player is not 7682 04:03:37,199 --> 04:03:39,180 looking at them and actually if I 7683 04:03:39,180 --> 04:03:40,500 approach it then it actually becomes 7684 04:03:40,500 --> 04:03:42,840 deselected basically the reason for that 7685 04:03:42,840 --> 04:03:44,939 is because these selected square of that 7686 04:03:44,939 --> 04:03:46,080 one is still referencing the clear 7687 04:03:46,080 --> 04:03:48,180 counter inside of the base counter 7688 04:03:48,180 --> 04:03:49,739 so right now it's only being selected 7689 04:03:49,739 --> 04:03:51,120 when the sunlight the counter is known 7690 04:03:51,120 --> 04:03:52,859 so that is why as I approach it actually 7691 04:03:52,859 --> 04:03:56,100 hides itself so let's fix this let's go 7692 04:03:56,100 --> 04:03:58,140 inside the container counter prefab and 7693 04:03:58,140 --> 04:04:00,239 inside we've got the selected any up 7694 04:04:00,239 --> 04:04:01,620 over there we have a reference to that 7695 04:04:01,620 --> 04:04:03,779 so let's open up this script and over 7696 04:04:03,779 --> 04:04:05,279 here all we need to do is just modify 7697 04:04:05,279 --> 04:04:07,080 this time so let's make it a type base 7698 04:04:07,080 --> 04:04:09,540 counter and let's rename this to base 7699 04:04:09,540 --> 04:04:12,120 counter 7700 04:04:12,120 --> 04:04:14,279 okay that's the only change we need 7701 04:04:14,279 --> 04:04:15,899 and by the way since we're here let's 7702 04:04:15,899 --> 04:04:18,300 also fix the other issue the issue we 7703 04:04:18,300 --> 04:04:20,460 had where we need to support more than 7704 04:04:20,460 --> 04:04:22,380 one visual game object 7705 04:04:22,380 --> 04:04:24,000 so instead of having a field of type 7706 04:04:24,000 --> 04:04:25,620 just game object let's receive a game 7707 04:04:25,620 --> 04:04:27,000 object ring 7708 04:04:27,000 --> 04:04:28,859 so let's modify this to game object 7709 04:04:28,859 --> 04:04:30,000 array 7710 04:04:30,000 --> 04:04:32,040 and then down here on the show hide is 7711 04:04:32,040 --> 04:04:33,960 actually very simple so let's just do a 7712 04:04:33,960 --> 04:04:36,600 four inch game object for the visual 7713 04:04:36,600 --> 04:04:39,319 game object 7714 04:04:40,680 --> 04:04:43,560 in the visual game object ring we go 7715 04:04:43,560 --> 04:04:46,319 inside set it to true and on this one we 7716 04:04:46,319 --> 04:04:48,840 set it to false 7717 04:04:48,840 --> 04:04:51,060 okay that's it super simple 7718 04:04:51,060 --> 04:04:53,760 now let's just update the prefabs so 7719 04:04:53,760 --> 04:04:55,439 first over here on the container counter 7720 04:04:55,439 --> 04:04:56,760 let's write the container counter 7721 04:04:56,760 --> 04:04:59,460 reference as the base counter okay great 7722 04:04:59,460 --> 04:05:01,739 and for divisions let's just drag all of 7723 04:05:01,739 --> 04:05:02,580 them 7724 04:05:02,580 --> 04:05:04,620 so let's write the counters only drag it 7725 04:05:04,620 --> 04:05:06,660 on top then the counter hole drag it on 7726 04:05:06,660 --> 04:05:09,120 top then the single door drag it and the 7727 04:05:09,120 --> 04:05:11,640 black drag it and also by the way over 7728 04:05:11,640 --> 04:05:13,380 here on this counter this one actually 7729 04:05:13,380 --> 04:05:15,120 has an objects right 7730 04:05:15,120 --> 04:05:17,460 this is the actual Sprite in there but 7731 04:05:17,460 --> 04:05:18,960 for the selected we really don't want 7732 04:05:18,960 --> 04:05:21,120 that so if I enable this game object 7733 04:05:21,120 --> 04:05:22,500 here we've got the object Sprite let's 7734 04:05:22,500 --> 04:05:24,239 actually delete this 7735 04:05:24,239 --> 04:05:26,460 we don't need the actual icon Sprite to 7736 04:05:26,460 --> 04:05:27,720 be highlighted so let's leave it just 7737 04:05:27,720 --> 04:05:29,220 like this so we only have these four 7738 04:05:29,220 --> 04:05:31,140 objects and all four of them are on the 7739 04:05:31,140 --> 04:05:31,859 list 7740 04:05:31,859 --> 04:05:33,960 okay that's right so all the references 7741 04:05:33,960 --> 04:05:36,239 in here they're all working perfectly 7742 04:05:36,239 --> 04:05:38,220 so let's go back outside let's save the 7743 04:05:38,220 --> 04:05:40,439 prefab let's go inside the empty clear 7744 04:05:40,439 --> 04:05:41,760 counter 7745 04:05:41,760 --> 04:05:43,380 and on this one same thing on the 7746 04:05:43,380 --> 04:05:45,239 selected let's Drag The Insider 7747 04:05:45,239 --> 04:05:47,399 reference and for the base counter let's 7748 04:05:47,399 --> 04:05:49,319 also drag that reference 7749 04:05:49,319 --> 04:05:51,779 okay so let's go outside save it and 7750 04:05:51,779 --> 04:05:53,040 let's test 7751 04:05:53,040 --> 04:05:54,779 and now let's see if the selected Works 7752 04:05:54,779 --> 04:05:56,340 once I approach this one yep it works 7753 04:05:56,340 --> 04:05:58,080 yep it works and on this one yep it 7754 04:05:58,080 --> 04:06:00,300 works and down here yep it works all 7755 04:06:00,300 --> 04:06:02,819 right awesome so we can interact and we 7756 04:06:02,819 --> 04:06:04,680 can highlight our selection okay 7757 04:06:04,680 --> 04:06:07,020 everything is working great so now that 7758 04:06:07,020 --> 04:06:08,819 all the code is working we can inspect 7759 04:06:08,819 --> 04:06:10,500 the code to see if we can refactor 7760 04:06:10,500 --> 04:06:11,939 anything 7761 04:06:11,939 --> 04:06:13,920 we can see for example if there's any 7762 04:06:13,920 --> 04:06:15,479 kind of common logic that all of the 7763 04:06:15,479 --> 04:06:16,979 counters share that we should probably 7764 04:06:16,979 --> 04:06:19,140 write in the base counter 7765 04:06:19,140 --> 04:06:20,939 and you can see right away that both the 7766 04:06:20,939 --> 04:06:22,560 clear counter and the container counter 7767 04:06:22,560 --> 04:06:24,359 both of them implement the kitchen 7768 04:06:24,359 --> 04:06:26,939 object parent interface that behavior is 7769 04:06:26,939 --> 04:06:28,140 something that all of the encounters 7770 04:06:28,140 --> 04:06:29,160 will share 7771 04:06:29,160 --> 04:06:30,960 so instead of defining it on each 7772 04:06:30,960 --> 04:06:32,699 counter itself let's actually do it on 7773 04:06:32,699 --> 04:06:34,560 the base class instead 7774 04:06:34,560 --> 04:06:36,239 so let's get rid of the interface 7775 04:06:36,239 --> 04:06:38,460 implementation here and also on the 7776 04:06:38,460 --> 04:06:40,439 container counter let's get rid of that 7777 04:06:40,439 --> 04:06:42,060 and set on base counter and let's 7778 04:06:42,060 --> 04:06:44,220 Implement that one so I catch an object 7779 04:06:44,220 --> 04:06:46,859 parent and for the functions let's do 7780 04:06:46,859 --> 04:06:49,080 the same thing so let's cut this one 7781 04:06:49,080 --> 04:06:51,000 from here and let's paste it on the base 7782 04:06:51,000 --> 04:06:52,260 counter 7783 04:06:52,260 --> 04:06:54,000 it's okay now we need these two points 7784 04:06:54,000 --> 04:06:56,880 so let's go ahead copy all of this let's 7785 04:06:56,880 --> 04:06:58,920 go into the base counter and paste in 7786 04:06:58,920 --> 04:07:00,779 except for the base one doesn't need a 7787 04:07:00,779 --> 04:07:02,460 kitchen object so so just the counter 7788 04:07:02,460 --> 04:07:04,439 top point and the kitchen object 7789 04:07:04,439 --> 04:07:06,479 okay so there are no errors on this one 7790 04:07:06,479 --> 04:07:08,399 let's go into the container 7791 04:07:08,399 --> 04:07:10,080 let's get rid of the kitchen object and 7792 04:07:10,080 --> 04:07:12,239 the counter top Point okay great 7793 04:07:12,239 --> 04:07:14,040 now we see an error but before we worry 7794 04:07:14,040 --> 04:07:15,359 about that let's actually go into the 7795 04:07:15,359 --> 04:07:16,979 clear counter and let's do the same 7796 04:07:16,979 --> 04:07:18,660 thing so let's get rid of this get rid 7797 04:07:18,660 --> 04:07:20,819 of this and down here get rid of all 7798 04:07:20,819 --> 04:07:22,260 these functions 7799 04:07:22,260 --> 04:07:24,479 okay so now the counter scripts are much 7800 04:07:24,479 --> 04:07:25,800 much more simple 7801 04:07:25,800 --> 04:07:27,600 all of the common code is now written 7802 04:07:27,600 --> 04:07:29,699 directly on the base counter 7803 04:07:29,699 --> 04:07:31,979 now for solving this the container 7804 04:07:31,979 --> 04:07:33,300 counter needs to know if there's a 7805 04:07:33,300 --> 04:07:35,819 kitchen object on top of it so now here 7806 04:07:35,819 --> 04:07:37,739 we have an interesting question with two 7807 04:07:37,739 --> 04:07:39,479 possible approaches 7808 04:07:39,479 --> 04:07:42,180 basically we need access to this object 7809 04:07:42,180 --> 04:07:44,340 so one approach would be to make this 7810 04:07:44,340 --> 04:07:46,739 protected like I said protected means 7811 04:07:46,739 --> 04:07:48,840 that any classes that extend this base 7812 04:07:48,840 --> 04:07:51,239 counter class any of those classes can 7813 04:07:51,239 --> 04:07:52,739 then modify that field something like 7814 04:07:52,739 --> 04:07:54,779 this yep there is no more errors that's 7815 04:07:54,779 --> 04:07:55,979 one approach 7816 04:07:55,979 --> 04:07:57,720 and the other approach is to instead 7817 04:07:57,720 --> 04:08:00,540 keep this one as private and whenever we 7818 04:08:00,540 --> 04:08:02,160 want to interact with it we simply 7819 04:08:02,160 --> 04:08:04,319 interact through these functions both 7820 04:08:04,319 --> 04:08:06,660 approaches can work and when in doubt as 7821 04:08:06,660 --> 04:08:08,160 usual you should probably go with the 7822 04:08:08,160 --> 04:08:10,500 more limited option so let's leave it as 7823 04:08:10,500 --> 04:08:12,060 private and work with these functions 7824 04:08:12,060 --> 04:08:13,020 and send 7825 04:08:13,020 --> 04:08:14,699 over here on the container counter 7826 04:08:14,699 --> 04:08:16,380 instead of testing if the kitchen object 7827 04:08:16,380 --> 04:08:19,080 is no let's just test has kitchen object 7828 04:08:19,080 --> 04:08:21,180 so if it does not have a kitchen object 7829 04:08:21,180 --> 04:08:23,100 then we're going to spawn it and for 7830 04:08:23,100 --> 04:08:25,199 spawning over here we could grab the 7831 04:08:25,199 --> 04:08:27,479 actual transform funnel 7832 04:08:27,479 --> 04:08:29,220 so this one up here we could call this 7833 04:08:29,220 --> 04:08:31,140 function to get it or since that is 7834 04:08:31,140 --> 04:08:32,040 actually going to be handled 7835 04:08:32,040 --> 04:08:33,420 automatically when we call this function 7836 04:08:33,420 --> 04:08:35,100 to set the parent then let's actually 7837 04:08:35,100 --> 04:08:37,500 not use this at all 7838 04:08:37,500 --> 04:08:39,300 so we just spawn it and set the kitchen 7839 04:08:39,300 --> 04:08:41,340 object parent okay great 7840 04:08:41,340 --> 04:08:43,080 so now let's just look at the clear 7841 04:08:43,080 --> 04:08:45,420 counter for this one like I said it's 7842 04:08:45,420 --> 04:08:47,460 not really meant to spawn anything solid 7843 04:08:47,460 --> 04:08:49,859 sectionally remove all of this code 7844 04:08:49,859 --> 04:08:51,960 this one is only going to serve to pick 7845 04:08:51,960 --> 04:08:53,880 up and drop items we're going to handle 7846 04:08:53,880 --> 04:08:55,920 that in the next lecture but for now 7847 04:08:55,920 --> 04:08:57,479 let's just go back into the Container 7848 04:08:57,479 --> 04:08:59,819 counter and let's do the proper logic 7849 04:08:59,819 --> 04:09:00,620 that I mentioned in the beginning 7850 04:09:00,620 --> 04:09:02,880 basically on this one we want to spawn 7851 04:09:02,880 --> 04:09:04,560 the object and we want to immediately 7852 04:09:04,560 --> 04:09:06,600 give it to the player so when we call 7853 04:09:06,600 --> 04:09:08,279 set kitchen object parent instead of 7854 04:09:08,279 --> 04:09:10,020 passing in this let's pass in the player 7855 04:09:10,020 --> 04:09:10,920 reference 7856 04:09:10,920 --> 04:09:12,540 and that's really it for the container 7857 04:09:12,540 --> 04:09:14,279 counter this is all we're going to do so 7858 04:09:14,279 --> 04:09:16,380 the player interacts and it spawns an 7859 04:09:16,380 --> 04:09:18,600 object and gives it to the player okay 7860 04:09:18,600 --> 04:09:20,520 so that's it with this as you can see 7861 04:09:20,520 --> 04:09:23,040 the code for all of our counters is much 7862 04:09:23,040 --> 04:09:25,020 much more simplified so basically it 7863 04:09:25,020 --> 04:09:26,819 only handles the logic related to that 7864 04:09:26,819 --> 04:09:28,680 specific counter everything else is on 7865 04:09:28,680 --> 04:09:31,800 the base counter so let's test this 7866 04:09:31,800 --> 04:09:33,779 so here we are and if I approach the 7867 04:09:33,779 --> 04:09:35,580 counter interact any of their go spawn 7868 04:09:35,580 --> 04:09:37,080 some cheese and gave it to the player 7869 04:09:37,080 --> 04:09:40,199 okay great now just for fun when I made 7870 04:09:40,199 --> 04:09:41,819 these assets I shall include a nice 7871 04:09:41,819 --> 04:09:42,779 animation 7872 04:09:42,779 --> 04:09:44,580 so if you go inside the container 7873 04:09:44,580 --> 04:09:46,739 counter over here on the visual note how 7874 04:09:46,739 --> 04:09:48,600 this already has an animator with an 7875 04:09:48,600 --> 04:09:50,520 animator control and attached to it 7876 04:09:50,520 --> 04:09:52,859 you can double click to open it up and 7877 04:09:52,859 --> 04:09:54,380 over here you can see it's very simple 7878 04:09:54,380 --> 04:09:56,819 basically just has two animations one is 7879 04:09:56,819 --> 04:09:58,620 the container close and one is container 7880 04:09:58,620 --> 04:10:00,779 opening and closing these transitions 7881 04:10:00,779 --> 04:10:01,979 are basically triggered by this 7882 04:10:01,979 --> 04:10:04,500 parameter this is a trigger parameter so 7883 04:10:04,500 --> 04:10:06,239 when triggers goes into the open close 7884 04:10:06,239 --> 04:10:07,739 and when this one ends goes back into 7885 04:10:07,739 --> 04:10:10,020 closed so let's just quickly add these 7886 04:10:10,020 --> 04:10:12,420 nice animations however again as usual 7887 04:10:12,420 --> 04:10:13,920 let's make sure to write some good clean 7888 04:10:13,920 --> 04:10:16,439 code so let's not add the visual over 7889 04:10:16,439 --> 04:10:18,359 here on the logic script instead let's 7890 04:10:18,359 --> 04:10:20,939 make a proper new script over here let's 7891 04:10:20,939 --> 04:10:23,699 create a new c-sharp script 7892 04:10:23,699 --> 04:10:27,600 call this the container counter visual 7893 04:10:27,600 --> 04:10:29,819 okay now we want to attach this only to 7894 04:10:29,819 --> 04:10:31,620 the visual game object so only this one 7895 04:10:31,620 --> 04:10:33,359 let's attach okay 7896 04:10:33,359 --> 04:10:35,220 and over here the first thing we need is 7897 04:10:35,220 --> 04:10:37,020 to get the animator 7898 04:10:37,020 --> 04:10:39,000 so let's sort of film for the animator 7899 04:10:39,000 --> 04:10:41,340 and since it's on the exact same object 7900 04:10:41,340 --> 04:10:43,560 we can just make an awake and get 7901 04:10:43,560 --> 04:10:46,560 component of type animator 7902 04:10:46,560 --> 04:10:50,600 and we just assigned this field okay 7903 04:10:51,239 --> 04:10:53,580 so with this we have the animator now we 7904 04:10:53,580 --> 04:10:55,140 just need to know when we should play 7905 04:10:55,140 --> 04:10:57,120 the animation so let's go over here on 7906 04:10:57,120 --> 04:10:58,380 the container counter script and 7907 04:10:58,380 --> 04:10:59,699 basically let's make an event that we're 7908 04:10:59,699 --> 04:11:01,140 going to fire when the player grabs an 7909 04:11:01,140 --> 04:11:02,580 object 7910 04:11:02,580 --> 04:11:05,220 so let's make a public event of time 7911 04:11:05,220 --> 04:11:06,840 let's stick with the standard so let's 7912 04:11:06,840 --> 04:11:08,640 use event handler inside using system 7913 04:11:08,640 --> 04:11:09,840 okay 7914 04:11:09,840 --> 04:11:14,640 let's name this on player grabbed object 7915 04:11:14,640 --> 04:11:16,319 then down here when the player interacts 7916 04:11:16,319 --> 04:11:17,699 and gets an object let's fire off this 7917 04:11:17,699 --> 04:11:19,439 event so invoke 7918 04:11:19,439 --> 04:11:21,899 let's invoke with this and event RX dot 7919 04:11:21,899 --> 04:11:24,120 empty 7920 04:11:24,120 --> 04:11:27,060 okay so we are firing off this event 7921 04:11:27,060 --> 04:11:28,620 and over here on the visual first we 7922 04:11:28,620 --> 04:11:30,120 need the film for the container counter 7923 04:11:30,120 --> 04:11:31,739 so let's set it up here let's add a 7924 04:11:31,739 --> 04:11:34,080 serialized field of tribe container 7925 04:11:34,080 --> 04:11:36,560 counter 7926 04:11:37,380 --> 04:11:39,479 okay we have this build now let's listen 7927 04:11:39,479 --> 04:11:41,819 to the event but again we're accessing 7928 04:11:41,819 --> 04:11:43,680 an external reference so let's make sure 7929 04:11:43,680 --> 04:11:46,080 to do it on start and not on awake 7930 04:11:46,080 --> 04:11:48,060 so let's go into this one and listen to 7931 04:11:48,060 --> 04:11:49,920 the on player grabbed object event okay 7932 04:11:49,920 --> 04:11:52,020 so here we have the event and it's over 7933 04:11:52,020 --> 04:11:53,640 here that we want to access the animator 7934 04:11:53,640 --> 04:11:55,859 and call set trigger in order to play 7935 04:11:55,859 --> 04:11:57,960 the animation again when working with 7936 04:11:57,960 --> 04:11:59,699 animator parameters suddenly we do need 7937 04:11:59,699 --> 04:12:01,380 to use strings there's no way around 7938 04:12:01,380 --> 04:12:03,180 that but at least we can make it a bit 7939 04:12:03,180 --> 04:12:05,460 more clean by defining a constant 7940 04:12:05,460 --> 04:12:08,040 so here a private con string call it 7941 04:12:08,040 --> 04:12:10,739 open close and let's make sure to use 7942 04:12:10,739 --> 04:12:12,720 the exact same parameter name so open 7943 04:12:12,720 --> 04:12:15,080 close 7944 04:12:15,300 --> 04:12:17,580 and then down here on the set trigger 7945 04:12:17,580 --> 04:12:19,380 let's call this trigger 7946 04:12:19,380 --> 04:12:21,060 okay so that said some very simple 7947 04:12:21,060 --> 04:12:22,620 visual logic 7948 04:12:22,620 --> 04:12:24,840 and now over here inside the prefab all 7949 04:12:24,840 --> 04:12:26,460 we need is to drag the container counter 7950 04:12:26,460 --> 04:12:28,500 reference so let's drag it also make 7951 04:12:28,500 --> 04:12:30,120 sure that it has the animator and the 7952 04:12:30,120 --> 04:12:31,920 animated controller so with that 7953 04:12:31,920 --> 04:12:33,479 everything should already be set up so 7954 04:12:33,479 --> 04:12:35,220 let's go back into the scenes save the 7955 04:12:35,220 --> 04:12:37,439 changes and let's hit on play 7956 04:12:37,439 --> 04:12:39,300 so here we are and if I go towards the 7957 04:12:39,300 --> 04:12:41,100 tomato and interact any of that I go it 7958 04:12:41,100 --> 04:12:43,380 plays a nice little animation alright 7959 04:12:43,380 --> 04:12:46,260 awesome okay so here we created a brand 7960 04:12:46,260 --> 04:12:48,540 new counter type and we refactored our 7961 04:12:48,540 --> 04:12:50,160 interact code to be able to interact 7962 04:12:50,160 --> 04:12:52,439 with any counter type the player can 7963 04:12:52,439 --> 04:12:54,000 interact with the container counter to 7964 04:12:54,000 --> 04:12:56,460 pick up an object now the next obvious 7965 04:12:56,460 --> 04:12:57,840 thing that we need is to enable the 7966 04:12:57,840 --> 04:12:59,460 player to drop an object on the clear 7967 04:12:59,460 --> 04:13:01,560 counter so let's do that in the next 7968 04:13:01,560 --> 04:13:02,819 lecture 7969 04:13:02,819 --> 04:13:04,859 hello and welcome I'm your code monkey 7970 04:13:04,859 --> 04:13:06,899 in this lecture we're going to enable 7971 04:13:06,899 --> 04:13:09,600 the player to pick up and drop objects 7972 04:13:09,600 --> 04:13:11,580 okay so we already have the player 7973 04:13:11,580 --> 04:13:13,260 working I can approach this container 7974 04:13:13,260 --> 04:13:14,819 counter interact with it and yep the 7975 04:13:14,819 --> 04:13:16,680 player picks up something now that's 7976 04:13:16,680 --> 04:13:18,300 left is being able to put our shade 7977 04:13:18,300 --> 04:13:19,739 clear counter and being able to drop 7978 04:13:19,739 --> 04:13:21,660 this object so let's do that 7979 04:13:21,660 --> 04:13:23,580 let's go over here on the clear counter 7980 04:13:23,580 --> 04:13:25,800 script and when we interact with it 7981 04:13:25,800 --> 04:13:27,960 we're going to do a bit of logic first 7982 04:13:27,960 --> 04:13:29,760 let's just check if this counter is 7983 04:13:29,760 --> 04:13:31,680 empty meaning if there is no kitchen 7984 04:13:31,680 --> 04:13:34,380 object on it so let's test if has 7985 04:13:34,380 --> 04:13:37,920 kitchen object or if not so let's say if 7986 04:13:37,920 --> 04:13:40,199 we don't have a kitchen object then 7987 04:13:40,199 --> 04:13:43,500 there is no kitchen object here 7988 04:13:43,500 --> 04:13:46,439 and if not then there is a kitchen 7989 04:13:46,439 --> 04:13:49,040 object here 7990 04:13:50,279 --> 04:13:52,920 okay these are the two valid options 7991 04:13:52,920 --> 04:13:55,680 so if there is nothing here then let's 7992 04:13:55,680 --> 04:13:57,720 check the player itself so we go into 7993 04:13:57,720 --> 04:13:59,220 the player and we can ask the same 7994 04:13:59,220 --> 04:14:01,380 question so it has kitchen object 7995 04:14:01,380 --> 04:14:05,100 so if the player is carrying something 7996 04:14:05,100 --> 04:14:07,739 so over here the player is carrying 7997 04:14:07,739 --> 04:14:09,660 something 7998 04:14:09,660 --> 04:14:11,460 if so then basically we just want to 7999 04:14:11,460 --> 04:14:13,319 drop that object from the player and 8000 04:14:13,319 --> 04:14:15,960 drop it in here so that's very simple we 8001 04:14:15,960 --> 04:14:17,819 just go into the player we get the 8002 04:14:17,819 --> 04:14:19,080 kitchen object that the player is 8003 04:14:19,080 --> 04:14:21,180 holding and we just modify the kitchen 8004 04:14:21,180 --> 04:14:24,420 object parent onto this object 8005 04:14:24,420 --> 04:14:26,340 all right so that's it just with this it 8006 04:14:26,340 --> 04:14:28,020 should already be working let's do a 8007 04:14:28,020 --> 04:14:29,580 quick test before we handle the rest of 8008 04:14:29,580 --> 04:14:30,899 the interactions 8009 04:14:30,899 --> 04:14:33,060 okay so here moving the player and if I 8010 04:14:33,060 --> 04:14:34,500 just interact with a clear counter and 8011 04:14:34,500 --> 04:14:36,120 nope nothing happens okay great since 8012 04:14:36,120 --> 04:14:37,680 the player is not carrying anything nope 8013 04:14:37,680 --> 04:14:39,420 nothing happens all right great 8014 04:14:39,420 --> 04:14:41,160 now let's pick up something from the 8015 04:14:41,160 --> 04:14:42,779 container counter okay so now the player 8016 04:14:42,779 --> 04:14:44,399 is carrying a tomato approaching clear 8017 04:14:44,399 --> 04:14:46,260 counter press a button and yep there you 8018 04:14:46,260 --> 04:14:48,359 go there it is alright Awesome 8019 04:14:48,359 --> 04:14:49,859 everything worked 8020 04:14:49,859 --> 04:14:51,720 now this is an excellent point to know 8021 04:14:51,720 --> 04:14:54,180 just how easy this was to implement and 8022 04:14:54,180 --> 04:14:55,800 the reason why it was so easy was 8023 04:14:55,800 --> 04:14:57,479 because we focus hard on running some 8024 04:14:57,479 --> 04:14:59,340 good clean code for how the object and 8025 04:14:59,340 --> 04:15:01,319 the appearance system works because we 8026 04:15:01,319 --> 04:15:03,359 took some time to think about that it 8027 04:15:03,359 --> 04:15:04,920 was now very easy to implement this 8028 04:15:04,920 --> 04:15:07,560 brand new action so this is a very very 8029 04:15:07,560 --> 04:15:09,239 clear example of the power of writing 8030 04:15:09,239 --> 04:15:11,819 good clean code okay so with that now 8031 04:15:11,819 --> 04:15:14,040 let's implement the rest so over here 8032 04:15:14,040 --> 04:15:15,660 there's no kitchen object here and the 8033 04:15:15,660 --> 04:15:17,460 player is carrying something but if not 8034 04:15:17,460 --> 04:15:21,779 we've got the L so player has nothing 8035 04:15:21,779 --> 04:15:23,279 so if the player doesn't have anything 8036 04:15:23,279 --> 04:15:25,920 so let's not do anything so player not 8037 04:15:25,920 --> 04:15:28,560 carrying anything 8038 04:15:28,560 --> 04:15:30,239 so those are all the possible States up 8039 04:15:30,239 --> 04:15:31,800 there and then down here if there is a 8040 04:15:31,800 --> 04:15:34,020 kitchen object on this layer counter if 8041 04:15:34,020 --> 04:15:36,600 so then let's check if the player has a 8042 04:15:36,600 --> 04:15:38,399 kitchen object 8043 04:15:38,399 --> 04:15:41,399 so in this deep layer is carrying 8044 04:15:41,399 --> 04:15:42,660 something 8045 04:15:42,660 --> 04:15:44,880 and if not 8046 04:15:44,880 --> 04:15:49,080 then the player is not carrying anything 8047 04:15:49,080 --> 04:15:50,580 so basically if there is a kitchen 8048 04:15:50,580 --> 04:15:52,080 object here and the player is carrying 8049 04:15:52,080 --> 04:15:53,640 something if so then we don't want to do 8050 04:15:53,640 --> 04:15:55,380 anything since we can't give the player 8051 04:15:55,380 --> 04:15:57,899 two items however if there is a kitchen 8052 04:15:57,899 --> 04:15:59,279 object here and the player is not 8053 04:15:59,279 --> 04:16:01,020 carrying anything then we want to give 8054 04:16:01,020 --> 04:16:03,180 it to the player so let's just get the 8055 04:16:03,180 --> 04:16:04,979 kitchen object the one that is on this 8056 04:16:04,979 --> 04:16:06,239 clear counter 8057 04:16:06,239 --> 04:16:08,220 and let's do the exact same thing so set 8058 04:16:08,220 --> 04:16:10,140 the parent and set the parent onto the 8059 04:16:10,140 --> 04:16:12,300 player okay so that's it as you can see 8060 04:16:12,300 --> 04:16:14,760 some very simple logic so let's test 8061 04:16:14,760 --> 04:16:17,100 okay here we are and if we interact nope 8062 04:16:17,100 --> 04:16:18,960 nothing happens okay great now pick up a 8063 04:16:18,960 --> 04:16:20,880 tomato go there drop it yep there it is 8064 04:16:20,880 --> 04:16:22,620 now if I interact again yeah there you 8065 04:16:22,620 --> 04:16:24,660 go I picked it up again so I can go 8066 04:16:24,660 --> 04:16:26,279 somewhere pick it up drop it and 8067 04:16:26,279 --> 04:16:28,260 everything works perfectly all right 8068 04:16:28,260 --> 04:16:29,520 awesome 8069 04:16:29,520 --> 04:16:30,899 now the last thing that we need to fix 8070 04:16:30,899 --> 04:16:32,819 is the container counter 8071 04:16:32,819 --> 04:16:34,319 right now it's giving out an object 8072 04:16:34,319 --> 04:16:35,939 every time even if the player has 8073 04:16:35,939 --> 04:16:37,979 something so if I pick up the other 8074 04:16:37,979 --> 04:16:39,779 works now if I pick up again there you 8075 04:16:39,779 --> 04:16:41,760 go we've got our nice helpful error this 8076 04:16:41,760 --> 04:16:43,020 should never happen 8077 04:16:43,020 --> 04:16:45,300 so let's add some nice checks 8078 04:16:45,300 --> 04:16:46,979 so over here on the container counter 8079 04:16:46,979 --> 04:16:48,779 okay we have our interaction 8080 04:16:48,779 --> 04:16:50,819 and before we spawn anything let's just 8081 04:16:50,819 --> 04:16:52,199 see if the player can pick up something 8082 04:16:52,199 --> 04:16:54,660 so once again very simple let's just go 8083 04:16:54,660 --> 04:16:56,220 into the player and we check does the 8084 04:16:56,220 --> 04:16:58,199 player have a kitchen object if so we're 8085 04:16:58,199 --> 04:17:00,060 not going to give it anything but if the 8086 04:17:00,060 --> 04:17:01,680 pointer does not have a kitchen object 8087 04:17:01,680 --> 04:17:03,540 then yep the player picks it up and we 8088 04:17:03,540 --> 04:17:06,260 give it the object 8089 04:17:10,800 --> 04:17:13,080 okay so that's it it's this simple Let's 8090 04:17:13,080 --> 04:17:14,040 test 8091 04:17:14,040 --> 04:17:15,720 so here we are let's pick up some cheese 8092 04:17:15,720 --> 04:17:17,399 okay great now pick up another one and 8093 04:17:17,399 --> 04:17:19,140 nope nothing happens okay great we're 8094 04:17:19,140 --> 04:17:20,640 already carrying something so we cannot 8095 04:17:20,640 --> 04:17:22,739 drop anything now drop it in there now 8096 04:17:22,739 --> 04:17:24,660 pick up a tomato any of it works I can 8097 04:17:24,660 --> 04:17:26,100 pick it up drop it and yep everything 8098 04:17:26,100 --> 04:17:29,399 works okay great let you see one more 8099 04:17:29,399 --> 04:17:30,180 thing 8100 04:17:30,180 --> 04:17:32,220 over here the container counter is 8101 04:17:32,220 --> 04:17:34,199 spawning the object and the object is 8102 04:17:34,199 --> 04:17:35,699 the one that we assigned 8103 04:17:35,699 --> 04:17:37,739 so over here in scene view we've got the 8104 04:17:37,739 --> 04:17:40,140 container counter this one is placed on 8105 04:17:40,140 --> 04:17:41,819 the scene and we made an override to 8106 04:17:41,819 --> 04:17:43,260 spawn a cheese block 8107 04:17:43,260 --> 04:17:45,600 technically we could keep doing this 8108 04:17:45,600 --> 04:17:47,399 pretty much just duplicate objects 8109 04:17:47,399 --> 04:17:49,140 modify the Sprite modify over here the 8110 04:17:49,140 --> 04:17:51,720 kitchen object that would work but 8111 04:17:51,720 --> 04:17:53,100 another better approach would be to 8112 04:17:53,100 --> 04:17:55,319 Simply make some prefab variants and yep 8113 04:17:55,319 --> 04:17:57,239 that does work you can make a variant of 8114 04:17:57,239 --> 04:17:59,939 a variant so let's do examine that over 8115 04:17:59,939 --> 04:18:02,100 here on the container counter let's 8116 04:18:02,100 --> 04:18:03,779 right click going to create and let's 8117 04:18:03,779 --> 04:18:06,300 create another prefab variant and let's 8118 04:18:06,300 --> 04:18:08,040 say container counter this one will be 8119 04:18:08,040 --> 04:18:10,380 the Tomato now let's go inside the 8120 04:18:10,380 --> 04:18:12,660 prefab and over here make sure it has 8121 04:18:12,660 --> 04:18:14,040 the kitchen object for the Tomato okay 8122 04:18:14,040 --> 04:18:16,560 great and over there on the Sprite so 8123 04:18:16,560 --> 04:18:19,199 let's find the object Sprite and choose 8124 04:18:19,199 --> 04:18:21,359 the Tomato Sprite so there you go this 8125 04:18:21,359 --> 04:18:24,479 one okay let's exit and Save 8126 04:18:24,479 --> 04:18:26,040 all right now once again let's right 8127 04:18:26,040 --> 04:18:27,779 click on the container and let's make it 8128 04:18:27,779 --> 04:18:29,939 another one this is going to be the one 8129 04:18:29,939 --> 04:18:31,920 for the cheese block 8130 04:18:31,920 --> 04:18:34,140 so let's go inside of it and over here 8131 04:18:34,140 --> 04:18:36,479 modify it for the cheese block and 8132 04:18:36,479 --> 04:18:38,880 inside the actual visual let's modify 8133 04:18:38,880 --> 04:18:40,560 the Sprite and sectionally down so the 8134 04:18:40,560 --> 04:18:42,359 cheese block okay great let's go back 8135 04:18:42,359 --> 04:18:43,260 outside 8136 04:18:43,260 --> 04:18:45,180 and since we're here doing this let's 8137 04:18:45,180 --> 04:18:47,040 make all of the other grab my objects 8138 04:18:47,040 --> 04:18:48,300 from the containers 8139 04:18:48,300 --> 04:18:50,340 so let's first make the kitchen object a 8140 04:18:50,340 --> 04:18:52,500 so so let's go over here we can right 8141 04:18:52,500 --> 04:18:54,359 click go into create create new kitchen 8142 04:18:54,359 --> 04:18:58,620 object so let's make one for the brand 8143 04:18:58,620 --> 04:19:00,239 then let's see if we get this one we're 8144 04:19:00,239 --> 04:19:02,160 going to have a cabbage and finally 8145 04:19:02,160 --> 04:19:04,020 we're going to have the meat Patty 8146 04:19:04,020 --> 04:19:05,460 uncooked 8147 04:19:05,460 --> 04:19:06,899 all right so now let's make sure to 8148 04:19:06,899 --> 04:19:08,580 assign all the data for all these script 8149 04:19:08,580 --> 04:19:09,720 along objects 8150 04:19:09,720 --> 04:19:11,520 first we need to make the actual kitchen 8151 04:19:11,520 --> 04:19:13,920 object so let's duplicate tomato name 8152 04:19:13,920 --> 04:19:16,439 this one bread let's go inside of it 8153 04:19:16,439 --> 04:19:18,180 and first for the kitchen object the 8154 04:19:18,180 --> 04:19:19,680 song Let's make sure to drag the correct 8155 04:19:19,680 --> 04:19:21,660 one okay there's the bread and for the 8156 04:19:21,660 --> 04:19:23,939 visual this one is not a tomato so let's 8157 04:19:23,939 --> 04:19:26,279 go inside our visual acids inside the 8158 04:19:26,279 --> 04:19:27,899 prefab visuals let's pick up the bread 8159 04:19:27,899 --> 04:19:30,479 visual okay there it is 8160 04:19:30,479 --> 04:19:31,800 that's all we need so let's go outside 8161 04:19:31,800 --> 04:19:34,319 save the changes and then select the 8162 04:19:34,319 --> 04:19:36,300 bread scripting object drag the prefab 8163 04:19:36,300 --> 04:19:38,640 reference okay for the Sprite this is 8164 04:19:38,640 --> 04:19:40,560 the bread and finally just call it bread 8165 04:19:40,560 --> 04:19:42,359 okay let's do the same thing for the 8166 04:19:42,359 --> 04:19:44,279 other one so next up for the Cabbage 8167 04:19:44,279 --> 04:19:47,040 let's do the Cabbage drag the Cabbage 8168 04:19:47,040 --> 04:19:49,620 script object let's go inside and modify 8169 04:19:49,620 --> 04:19:52,500 the visual so the Cabbage visual 8170 04:19:52,500 --> 04:19:54,600 okay that's it 8171 04:19:54,600 --> 04:19:56,699 then on the Cabbage scorpion object drag 8172 04:19:56,699 --> 04:19:58,620 the reference for the prefab let's 8173 04:19:58,620 --> 04:20:00,840 assign the Sprite and finally give it a 8174 04:20:00,840 --> 04:20:02,520 name cabbage 8175 04:20:02,520 --> 04:20:04,560 and finally the meat Patty and cooked so 8176 04:20:04,560 --> 04:20:06,120 let's do that one so let's duplicate it 8177 04:20:06,120 --> 04:20:10,100 name it meet Patty uncooked 8178 04:20:11,340 --> 04:20:14,040 let's go inside modify the kitchen 8179 04:20:14,040 --> 04:20:16,859 object so for this one and for the 8180 04:20:16,859 --> 04:20:19,080 visual let's select here it is the meat 8181 04:20:19,080 --> 04:20:20,640 Patty uncooked 8182 04:20:20,640 --> 04:20:23,880 okay let's go back outside and on the 8183 04:20:23,880 --> 04:20:25,380 escort mode object 8184 04:20:25,380 --> 04:20:27,600 let's just drag the prefab 8185 04:20:27,600 --> 04:20:29,760 assign the Sprites so this one is the 8186 04:20:29,760 --> 04:20:31,319 uncooked so it's this one 8187 04:20:31,319 --> 04:20:34,500 and finally meet Patty uncooked okay 8188 04:20:34,500 --> 04:20:36,300 great so we added all of these squared 8189 04:20:36,300 --> 04:20:37,560 more objects 8190 04:20:37,560 --> 04:20:39,359 we also have the pre-files with the 8191 04:20:39,359 --> 04:20:41,160 visuals and the electric scripts now 8192 04:20:41,160 --> 04:20:42,779 let's just make the container counter so 8193 04:20:42,779 --> 04:20:44,460 once again let's create another variant 8194 04:20:44,460 --> 04:20:47,819 so prefab variant this one is for let's 8195 04:20:47,819 --> 04:20:49,260 say for the brand 8196 04:20:49,260 --> 04:20:51,060 then let's make all the other ones 8197 04:20:51,060 --> 04:20:53,399 already so let's go make another prefab 8198 04:20:53,399 --> 04:20:54,300 variant 8199 04:20:54,300 --> 04:20:56,220 this one is going to be for the meat 8200 04:20:56,220 --> 04:20:58,620 Patty uncooked 8201 04:20:58,620 --> 04:21:00,899 and finally another variant also here 8202 04:21:00,899 --> 04:21:02,399 make sure you're creating a variant of 8203 04:21:02,399 --> 04:21:04,439 the container counter don't make an 8204 04:21:04,439 --> 04:21:05,760 accident of creating a variant of 8205 04:21:05,760 --> 04:21:07,020 something else let's make another 8206 04:21:07,020 --> 04:21:09,060 variant one final one 8207 04:21:09,060 --> 04:21:11,279 and this one is going to be for the 8208 04:21:11,279 --> 04:21:13,020 cabbage 8209 04:21:13,020 --> 04:21:14,760 okay we have all the variants now let's 8210 04:21:14,760 --> 04:21:16,319 just sign them so let's go inside the 8211 04:21:16,319 --> 04:21:18,300 bread and over there modify the 8212 04:21:18,300 --> 04:21:20,460 description object for the brand and for 8213 04:21:20,460 --> 04:21:23,279 the icon modify for the bread icon okay 8214 04:21:23,279 --> 04:21:25,979 let's go to the Cabbage save the changes 8215 04:21:25,979 --> 04:21:28,680 modify that one for the cabbage 8216 04:21:28,680 --> 04:21:32,279 go into the icon and modify the icon and 8217 04:21:32,279 --> 04:21:34,439 finally the meat Patty uncooked let's go 8218 04:21:34,439 --> 04:21:37,020 ahead modify this one for that one and 8219 04:21:37,020 --> 04:21:39,720 the icon put it on that one all right 8220 04:21:39,720 --> 04:21:41,399 everything is working 8221 04:21:41,399 --> 04:21:43,680 now let's just place them over here in 8222 04:21:43,680 --> 04:21:45,180 our scene so let's get rid of the ones 8223 04:21:45,180 --> 04:21:46,920 that we made some overrides 8224 04:21:46,920 --> 04:21:48,840 so let's get rid of that container 8225 04:21:48,840 --> 04:21:51,359 counter and set for that one let's drag 8226 04:21:51,359 --> 04:21:52,920 the cheese block put it right in there 8227 04:21:52,920 --> 04:21:57,660 let's put it on X 1.5 y of 0 Z of 3.5 8228 04:21:57,660 --> 04:21:58,859 okay 8229 04:21:58,859 --> 04:22:01,199 then down here for this one let's put 8230 04:22:01,199 --> 04:22:03,779 the Cabbage next to it let's rotate it 8231 04:22:03,779 --> 04:22:05,340 to face upwards 8232 04:22:05,340 --> 04:22:08,220 so like that let's put it on next of 8233 04:22:08,220 --> 04:22:12,180 minus 1.5 y of 0 and -5 on the Zen then 8234 04:22:12,180 --> 04:22:13,920 for tomato let's get rid of this one and 8235 04:22:13,920 --> 04:22:16,020 use the proper tomato one 8236 04:22:16,020 --> 04:22:18,779 so let's rotate it put it on an X of 0 y 8237 04:22:18,779 --> 04:22:20,640 0 and -5 8238 04:22:20,640 --> 04:22:23,520 okay next we want some bread so let's 8239 04:22:23,520 --> 04:22:24,960 put the bread up here on the left side 8240 04:22:24,960 --> 04:22:28,560 let's put it on X of minus three zero on 8241 04:22:28,560 --> 04:22:31,620 the Y and 3.5 on the Zen 8242 04:22:31,620 --> 04:22:33,300 and finally the meat Patty and Coke 8243 04:22:33,300 --> 04:22:34,739 let's put it over here a bit more on the 8244 04:22:34,739 --> 04:22:35,580 side 8245 04:22:35,580 --> 04:22:38,880 let's put it over here on X of 7.50 and 8246 04:22:38,880 --> 04:22:41,699 3.5 alright so we have positioned all of 8247 04:22:41,699 --> 04:22:43,080 them let's just make some more clear 8248 04:22:43,080 --> 04:22:45,000 counters so we can actually place the 8249 04:22:45,000 --> 04:22:47,160 objects so let's put this one over here 8250 04:22:47,160 --> 04:22:49,800 on minus 4.5 this one over there let's 8251 04:22:49,800 --> 04:22:52,140 also put some counters let's say one on 8252 04:22:52,140 --> 04:22:54,239 the right side and a bunch more down 8253 04:22:54,239 --> 04:22:58,100 here let's rotate them upwards 8254 04:22:58,380 --> 04:23:02,699 let's put this one on 1.5 minus 5. 8255 04:23:02,699 --> 04:23:06,239 and one more over here on the side 8256 04:23:06,239 --> 04:23:08,160 okay great so we have all of our 8257 04:23:08,160 --> 04:23:09,720 container counters as well as a bunch of 8258 04:23:09,720 --> 04:23:11,279 clear counters so let's test and make 8259 04:23:11,279 --> 04:23:13,319 sure that everything works okay so here 8260 04:23:13,319 --> 04:23:14,699 we are let's go down pick up a tomato 8261 04:23:14,699 --> 04:23:17,040 yep there's tomato now a cabbage yep 8262 04:23:17,040 --> 04:23:18,720 there's a cabbage now some bread there's 8263 04:23:18,720 --> 04:23:20,699 some bread and some cheese there's some 8264 04:23:20,699 --> 04:23:22,260 cheese and some meat and yep there's 8265 04:23:22,260 --> 04:23:24,420 some meat all right Awesome everything 8266 04:23:24,420 --> 04:23:25,620 works 8267 04:23:25,620 --> 04:23:27,300 so with this over here we added the 8268 04:23:27,300 --> 04:23:29,460 ability to pick up and drop objects on 8269 04:23:29,460 --> 04:23:31,199 an empty container and spawn them from 8270 04:23:31,199 --> 04:23:33,660 all kinds of container counters now in 8271 04:23:33,660 --> 04:23:35,279 the next lecture let's build the counter 8272 04:23:35,279 --> 04:23:36,720 we can interact with in a very 8273 04:23:36,720 --> 04:23:37,979 interesting way 8274 04:23:37,979 --> 04:23:39,899 hello and welcome I'm your code monkey 8275 04:23:39,899 --> 04:23:42,300 in this lecture we're going to create a 8276 04:23:42,300 --> 04:23:44,160 cutting counter so this is going to be a 8277 04:23:44,160 --> 04:23:45,600 counter where we can place an object 8278 04:23:45,600 --> 04:23:47,760 like for example tomato and after doing 8279 04:23:47,760 --> 04:23:50,040 a secondary interaction we can slice it 8280 04:23:50,040 --> 04:23:52,260 however before we do that let's just fix 8281 04:23:52,260 --> 04:23:54,359 one slightly annoying issue 8282 04:23:54,359 --> 04:23:55,680 so right now the player is walking 8283 04:23:55,680 --> 04:23:57,180 around okay that's great I can approach 8284 04:23:57,180 --> 04:23:58,680 a counter and interact with it that's 8285 04:23:58,680 --> 04:24:00,960 great however if I approach account from 8286 04:24:00,960 --> 04:24:02,819 the sign look how the player is pointing 8287 04:24:02,819 --> 04:24:05,100 towards the right and if I press the 8288 04:24:05,100 --> 04:24:07,260 double key I can indeed select it but 8289 04:24:07,260 --> 04:24:08,760 the player does not rotate to face the 8290 04:24:08,760 --> 04:24:10,680 counter so that's just a minor visual 8291 04:24:10,680 --> 04:24:12,060 issue but still I'd like to fix it so 8292 04:24:12,060 --> 04:24:14,100 let's do that very quickly basically the 8293 04:24:14,100 --> 04:24:15,840 issue is over here on our player script 8294 04:24:15,840 --> 04:24:18,060 so we scroll down and find our handle 8295 04:24:18,060 --> 04:24:19,680 movement function okay 8296 04:24:19,680 --> 04:24:21,479 so here we were doing a bunch of 8297 04:24:21,479 --> 04:24:23,520 Capstone cans in order to fix the 8298 04:24:23,520 --> 04:24:25,739 problem with the diagonal movement so 8299 04:24:25,739 --> 04:24:27,420 you try to move in One Direction if not 8300 04:24:27,420 --> 04:24:29,939 try to move in just one of those and if 8301 04:24:29,939 --> 04:24:31,380 we can move then we assign a move 8302 04:24:31,380 --> 04:24:33,660 Direction and then move it basically the 8303 04:24:33,660 --> 04:24:36,000 problem that we have here is that if I 8304 04:24:36,000 --> 04:24:38,699 press W to face towards the counter then 8305 04:24:38,699 --> 04:24:40,439 over here when we do this logic so it's 8306 04:24:40,439 --> 04:24:42,120 going to first attempt the X movement 8307 04:24:42,120 --> 04:24:44,220 only and the x is going to be zero so 8308 04:24:44,220 --> 04:24:45,899 the move there X is going to be zero 8309 04:24:45,899 --> 04:24:47,760 zero zero so it won't actually move 8310 04:24:47,760 --> 04:24:49,439 anywhere which means it won't be able to 8311 04:24:49,439 --> 04:24:52,260 move so this one becomes true which then 8312 04:24:52,260 --> 04:24:54,060 sets the move direction to zero zero 8313 04:24:54,060 --> 04:24:55,859 zero which then down here when we have 8314 04:24:55,859 --> 04:24:57,420 our rotation it's not actually going to 8315 04:24:57,420 --> 04:24:59,580 rotate to anything so we want the player 8316 04:24:59,580 --> 04:25:02,279 to still not go through any objects but 8317 04:25:02,279 --> 04:25:04,020 we only want to modify the move there 8318 04:25:04,020 --> 04:25:05,939 over here if we actually move in any of 8319 04:25:05,939 --> 04:25:07,680 these directions so the solution is 8320 04:25:07,680 --> 04:25:09,660 actually super simple it's over here for 8321 04:25:09,660 --> 04:25:11,220 the can move we can move if there's 8322 04:25:11,220 --> 04:25:13,560 nothing on there and if the move 8323 04:25:13,560 --> 04:25:16,979 direction.x is not zero 8324 04:25:16,979 --> 04:25:20,160 so that's really it if we are attempting 8325 04:25:20,160 --> 04:25:22,140 to move in the X at all and if there is 8326 04:25:22,140 --> 04:25:23,880 nothing on there then we can move which 8327 04:25:23,880 --> 04:25:25,260 means we then assign the move direction 8328 04:25:25,260 --> 04:25:28,080 if not then we don't touch this and same 8329 04:25:28,080 --> 04:25:30,540 thing down here so we can move if 8330 04:25:30,540 --> 04:25:32,399 there's nothing on it and if the move 8331 04:25:32,399 --> 04:25:35,819 there dot Zed is not zero 8332 04:25:35,819 --> 04:25:38,040 so that's it just this one simple change 8333 04:25:38,040 --> 04:25:39,779 and now the player should be able to 8334 04:25:39,779 --> 04:25:40,920 rotate 8335 04:25:40,920 --> 04:25:42,899 so here we are and if I look over there 8336 04:25:42,899 --> 04:25:44,399 and the player is currently unlocking to 8337 04:25:44,399 --> 04:25:46,680 the left and if I press W to point 8338 04:25:46,680 --> 04:25:48,120 towards the container counter and if 8339 04:25:48,120 --> 04:25:49,859 there you go the player does rotate a 8340 04:25:49,859 --> 04:25:51,479 little bit so that feels a bit more 8341 04:25:51,479 --> 04:25:52,260 natural 8342 04:25:52,260 --> 04:25:54,239 all right so that's just a tiny visual 8343 04:25:54,239 --> 04:25:56,040 thing that I wanted to fix okay so let's 8344 04:25:56,040 --> 04:25:57,300 keep going 8345 04:25:57,300 --> 04:25:59,279 now let's handle the actual cutting 8346 04:25:59,279 --> 04:26:00,239 counter 8347 04:26:00,239 --> 04:26:02,220 so first of all as usual let's make a 8348 04:26:02,220 --> 04:26:04,439 counter variant so let's right click on 8349 04:26:04,439 --> 04:26:06,120 the base counter create a new prefab 8350 04:26:06,120 --> 04:26:09,000 variant call it the cutting counter 8351 04:26:09,000 --> 04:26:11,340 let's go inside of it 8352 04:26:11,340 --> 04:26:13,080 and over here first thing we need is the 8353 04:26:13,080 --> 04:26:15,060 visual so let's pick up from the assets 8354 04:26:15,060 --> 04:26:18,420 The Cutting countervision so here it is 8355 04:26:18,420 --> 04:26:20,159 then we need the selected so let's 8356 04:26:20,159 --> 04:26:22,140 duplicate this one let's rename this one 8357 04:26:22,140 --> 04:26:24,899 to seal lectin and on the animator let's 8358 04:26:24,899 --> 04:26:26,760 get rid of it and instead at the 8359 04:26:26,760 --> 04:26:28,680 component the selected counter visual 8360 04:26:28,680 --> 04:26:31,380 okay great now let's write divisions for 8361 04:26:31,380 --> 04:26:33,960 the visual game object array and by the 8362 04:26:33,960 --> 04:26:36,120 way here's a quick tip on the right side 8363 04:26:36,120 --> 04:26:37,800 on the inspector you can see this nice 8364 04:26:37,800 --> 04:26:39,420 little lock icon 8365 04:26:39,420 --> 04:26:41,399 so if you click on it then that means 8366 04:26:41,399 --> 04:26:43,439 this inspector will not change as you 8367 04:26:43,439 --> 04:26:45,180 select other objects 8368 04:26:45,180 --> 04:26:46,979 so I can click on and select something 8369 04:26:46,979 --> 04:26:48,300 different and this one does not change 8370 04:26:48,300 --> 04:26:50,100 it is still showing the selected object 8371 04:26:50,100 --> 04:26:51,960 now this is this one when you want for 8372 04:26:51,960 --> 04:26:53,699 example to drag multiple things so you 8373 04:26:53,699 --> 04:26:55,560 can unlock the inspector then the 8374 04:26:55,560 --> 04:26:57,239 hierarchy you can use shift click to 8375 04:26:57,239 --> 04:26:58,859 select multiple objects and then just 8376 04:26:58,859 --> 04:27:01,080 drag them all directly inside the array 8377 04:27:01,080 --> 04:27:03,300 that's it just a nice quick tip so 8378 04:27:03,300 --> 04:27:05,220 everything is done let's unlock it there 8379 04:27:05,220 --> 04:27:07,500 it is okay so that said let's just 8380 04:27:07,500 --> 04:27:10,620 assign the selected material so the 8381 04:27:10,620 --> 04:27:12,479 counter select material let's make it 8382 04:27:12,479 --> 04:27:15,000 just one percent bigger so let's select 8383 04:27:15,000 --> 04:27:18,300 them all 1.01 okay and let's start with 8384 04:27:18,300 --> 04:27:20,460 all of them disabled okay 8385 04:27:20,460 --> 04:27:22,439 so the basic setup is done 8386 04:27:22,439 --> 04:27:24,359 now let's make our script to run this so 8387 04:27:24,359 --> 04:27:26,040 let's go down let's create a brand new 8388 04:27:26,040 --> 04:27:29,520 c-sharp script for The Cutting counter 8389 04:27:29,520 --> 04:27:31,260 let's select the apparent game object 8390 04:27:31,260 --> 04:27:33,180 and attach a cutting counter and let's 8391 04:27:33,180 --> 04:27:34,920 open 8392 04:27:34,920 --> 04:27:36,840 now here as usual instead of all this 8393 04:27:36,840 --> 04:27:39,180 let's start off by extending the base 8394 04:27:39,180 --> 04:27:41,340 counter okay 8395 04:27:41,340 --> 04:27:42,960 once again thanks to how we set things 8396 04:27:42,960 --> 04:27:44,880 up using such clean code this is pretty 8397 04:27:44,880 --> 04:27:46,739 much all we need to make a counter 8398 04:27:46,739 --> 04:27:48,779 with this the counter already works as a 8399 04:27:48,779 --> 04:27:50,580 counter then next thing we need is to 8400 04:27:50,580 --> 04:27:52,319 customize any logic specific to this 8401 04:27:52,319 --> 04:27:54,720 counter by just overriding the interact 8402 04:27:54,720 --> 04:27:57,239 function so that's it now over here we 8403 04:27:57,239 --> 04:27:58,920 can put whatever logic we want just for 8404 04:27:58,920 --> 04:28:01,080 the cutting counter and for this one for 8405 04:28:01,080 --> 04:28:02,580 star is actually going to be just like 8406 04:28:02,580 --> 04:28:04,140 the empty counter meaning we're going to 8407 04:28:04,140 --> 04:28:06,180 be able to drop objects on this 8408 04:28:06,180 --> 04:28:08,399 so let's just go directly into the clear 8409 04:28:08,399 --> 04:28:10,260 counter so here it is and let's just 8410 04:28:10,260 --> 04:28:11,760 copy all of this code go into the 8411 04:28:11,760 --> 04:28:13,859 cutting counter in Payson okay so the 8412 04:28:13,859 --> 04:28:15,600 exact same logic so checks if there is a 8413 04:28:15,600 --> 04:28:17,159 kitchen object or not checks if the 8414 04:28:17,159 --> 04:28:18,359 employer's carrying something or not and 8415 04:28:18,359 --> 04:28:20,580 picks up or drops in with this let's do 8416 04:28:20,580 --> 04:28:21,899 a quick test just to make sure this one 8417 04:28:21,899 --> 04:28:23,279 is working exactly like the clear 8418 04:28:23,279 --> 04:28:25,020 counter 8419 04:28:25,020 --> 04:28:26,399 so over here let's just make sure to 8420 04:28:26,399 --> 04:28:28,140 drag in less references so on The 8421 04:28:28,140 --> 04:28:29,460 Cutting counter let's make sure to drag 8422 04:28:29,460 --> 04:28:31,140 the countertop point so drag that 8423 04:28:31,140 --> 04:28:33,420 reference and then on the selected Drag 8424 04:28:33,420 --> 04:28:35,340 The Cutting counter reference okay 8425 04:28:35,340 --> 04:28:37,080 everything is good let's exit this 8426 04:28:37,080 --> 04:28:39,479 prefab make sure to save all the changes 8427 04:28:39,479 --> 04:28:41,220 and over here in the scene view let's 8428 04:28:41,220 --> 04:28:42,840 Place one of our cutting counter so 8429 04:28:42,840 --> 04:28:45,000 let's Basin right in there let's put it 8430 04:28:45,000 --> 04:28:48,420 on X of 4.5 0 and 3.5 8431 04:28:48,420 --> 04:28:50,340 okay so let's test 8432 04:28:50,340 --> 04:28:51,899 all right so here we are now if I 8433 04:28:51,899 --> 04:28:53,159 approach and I interact nope nothing 8434 04:28:53,159 --> 04:28:54,659 happens okay great pick up some cheese 8435 04:28:54,659 --> 04:28:56,699 and drop it on there any of there it is 8436 04:28:56,699 --> 04:28:58,620 I can pick it up I can pick up some 8437 04:28:58,620 --> 04:29:01,199 bread drop it and yep everything works 8438 04:29:01,199 --> 04:29:03,300 okay so far so good 8439 04:29:03,300 --> 04:29:05,460 now the next goal is to use the knife 8440 04:29:05,460 --> 04:29:07,140 and actually slice the object that is on 8441 04:29:07,140 --> 04:29:09,180 there and for that the first thing that 8442 04:29:09,180 --> 04:29:10,680 we need is we're going to need a 8443 04:29:10,680 --> 04:29:12,720 different input right now we only have 8444 04:29:12,720 --> 04:29:14,279 the movement and the interaction so 8445 04:29:14,279 --> 04:29:16,560 let's add another alt interaction 8446 04:29:16,560 --> 04:29:19,140 for that let's go into our input action 8447 04:29:19,140 --> 04:29:21,540 so let's open it up 8448 04:29:21,540 --> 04:29:24,060 let's make another action so create a 8449 04:29:24,060 --> 04:29:28,199 new action call it interact alternate 8450 04:29:28,199 --> 04:29:30,000 and for The Binding let's put it on 8451 04:29:30,000 --> 04:29:31,800 another key so let's listen and I think 8452 04:29:31,800 --> 04:29:33,720 on F makes sense 8453 04:29:33,720 --> 04:29:35,880 so let's go ahead select this one 8454 04:29:35,880 --> 04:29:37,560 then as usual let's make sure to save 8455 04:29:37,560 --> 04:29:39,120 the asset which in turn is going to 8456 04:29:39,120 --> 04:29:40,680 generate C sharp plus and compound the 8457 04:29:40,680 --> 04:29:42,000 code okay great 8458 04:29:42,000 --> 04:29:43,859 now we can go here into our game input 8459 04:29:43,859 --> 04:29:45,359 class and let's do the exact same thing 8460 04:29:45,359 --> 04:29:47,880 with it for the interact action so first 8461 04:29:47,880 --> 04:29:49,500 of all let's listen to it so let's go 8462 04:29:49,500 --> 04:29:51,060 inside the player input actions inside 8463 04:29:51,060 --> 04:29:53,040 the player action map so this one is the 8464 04:29:53,040 --> 04:29:55,260 interact alternate and let's listen to 8465 04:29:55,260 --> 04:29:56,760 the performed event 8466 04:29:56,760 --> 04:29:58,439 okay and when we have that let's fire 8467 04:29:58,439 --> 04:29:59,939 off an event pretty much the same thing 8468 04:29:59,939 --> 04:30:04,460 so interact alternate action 8469 04:30:05,460 --> 04:30:07,199 and down here let's just fire off this 8470 04:30:07,199 --> 04:30:08,880 event so 8471 04:30:08,880 --> 04:30:11,819 let's invoke using this and even RX dot 8472 04:30:11,819 --> 04:30:13,859 empty 8473 04:30:13,859 --> 04:30:15,720 okay so we have the input for the 8474 04:30:15,720 --> 04:30:17,100 interact alternate 8475 04:30:17,100 --> 04:30:19,319 now let's go on the player to listen the 8476 04:30:19,319 --> 04:30:20,819 same way we're listening to the regular 8477 04:30:20,819 --> 04:30:22,920 interact action 8478 04:30:22,920 --> 04:30:25,080 so over here on the player script let's 8479 04:30:25,080 --> 04:30:26,640 see how we're doing things so we go into 8480 04:30:26,640 --> 04:30:28,500 game input and listen to that so it's 8481 04:30:28,500 --> 04:30:30,659 the same thing game input and on 8482 04:30:30,659 --> 04:30:32,580 interact alternate action let's listen 8483 04:30:32,580 --> 04:30:34,319 to this one and when this one happens 8484 04:30:34,319 --> 04:30:36,120 lets you pretty much exactly the same 8485 04:30:36,120 --> 04:30:37,739 thing except we're just going to call a 8486 04:30:37,739 --> 04:30:39,239 different function 8487 04:30:39,239 --> 04:30:41,100 so instead of interacting let's call 8488 04:30:41,100 --> 04:30:43,260 interact Alternate which in turn 8489 04:30:43,260 --> 04:30:44,760 obviously means we need to Define this 8490 04:30:44,760 --> 04:30:45,840 function 8491 04:30:45,840 --> 04:30:48,779 so let's go into our base counter 8492 04:30:48,779 --> 04:30:50,640 so here we are on the base counter we've 8493 04:30:50,640 --> 04:30:52,319 got the interact and let's make another 8494 04:30:52,319 --> 04:30:54,060 one exactly the same just different name 8495 04:30:54,060 --> 04:30:57,319 interact alternate 8496 04:30:57,779 --> 04:30:59,939 okay that's it and now we are only going 8497 04:30:59,939 --> 04:31:01,620 to implement this in the ones that need 8498 04:31:01,620 --> 04:31:03,359 implementation 8499 04:31:03,359 --> 04:31:05,159 so for example on The Cutting counter 8500 04:31:05,159 --> 04:31:07,260 over here let's write down so public 8501 04:31:07,260 --> 04:31:08,939 override 8502 04:31:08,939 --> 04:31:10,739 and let's override the interact 8503 04:31:10,739 --> 04:31:12,180 alternate 8504 04:31:12,180 --> 04:31:14,460 and now here let's check check if 8505 04:31:14,460 --> 04:31:16,620 there's something placed on here so if 8506 04:31:16,620 --> 04:31:18,479 there's a kitchen object placed on this 8507 04:31:18,479 --> 04:31:19,439 counter 8508 04:31:19,439 --> 04:31:23,180 if so then let's basically cut it 8509 04:31:29,279 --> 04:31:31,260 and for cutting it the simplest way is 8510 04:31:31,260 --> 04:31:33,540 really to destroy whatever object is on 8511 04:31:33,540 --> 04:31:35,939 there and just spawn the slice object 8512 04:31:35,939 --> 04:31:37,859 so let's handle destroying a kitchen 8513 04:31:37,859 --> 04:31:39,000 object 8514 04:31:39,000 --> 04:31:40,680 for handling that let's go over here on 8515 04:31:40,680 --> 04:31:42,180 the kitchen object script 8516 04:31:42,180 --> 04:31:44,040 and let's make a simple function for 8517 04:31:44,040 --> 04:31:46,080 this object to destroy itself so let's 8518 04:31:46,080 --> 04:31:48,239 go up here make it public return void 8519 04:31:48,239 --> 04:31:49,979 and for name I like to use the name 8520 04:31:49,979 --> 04:31:52,260 destroy itself to make it destroy this 8521 04:31:52,260 --> 04:31:53,760 object 8522 04:31:53,760 --> 04:31:55,380 and really all we need to do is just 8523 04:31:55,380 --> 04:31:57,120 destroy and call destroy on this game 8524 04:31:57,120 --> 04:31:58,020 object 8525 04:31:58,020 --> 04:32:00,000 however before we do let's make sure to 8526 04:32:00,000 --> 04:32:01,800 clear the parent so let's go into the 8527 04:32:01,800 --> 04:32:03,540 kitchen object parent clear it and then 8528 04:32:03,540 --> 04:32:05,279 destroy the game object okay that's 8529 04:32:05,279 --> 04:32:07,140 great it's really this simple 8530 04:32:07,140 --> 04:32:09,420 and then on the cutting counter let's 8531 04:32:09,420 --> 04:32:11,040 get the kitchen object that is on here 8532 04:32:11,040 --> 04:32:13,080 and tell it to destroy itself okay so 8533 04:32:13,080 --> 04:32:14,640 let's raise the object 8534 04:32:14,640 --> 04:32:16,680 and after we do let's just spawn the 8535 04:32:16,680 --> 04:32:19,020 slices object so for now just keep 8536 04:32:19,020 --> 04:32:20,460 things simple let's make a direct 8537 04:32:20,460 --> 04:32:22,439 reference up here let's make a 8538 04:32:22,439 --> 04:32:24,540 serialized film 8539 04:32:24,540 --> 04:32:26,640 let's make it a type kitchen object so 8540 04:32:26,640 --> 04:32:29,939 and for the cut kitchen object the cell 8541 04:32:29,939 --> 04:32:32,460 okay so we have this then here in the 8542 04:32:32,460 --> 04:32:33,720 editor and let's make sure to drag the 8543 04:32:33,720 --> 04:32:36,060 reference so let's go inside the cutting 8544 04:32:36,060 --> 04:32:38,100 counter and let's open up the prefab and 8545 04:32:38,100 --> 04:32:40,439 inside let's assign this one that means 8546 04:32:40,439 --> 04:32:41,760 we need to create the object so let's 8547 04:32:41,760 --> 04:32:44,040 actually do that first 8548 04:32:44,040 --> 04:32:45,720 so let's create a brand new kitchen 8549 04:32:45,720 --> 04:32:48,180 object to sell let's come out for the 8550 04:32:48,180 --> 04:32:50,220 tomato slices 8551 04:32:50,220 --> 04:32:51,960 then if we do this we need to create the 8552 04:32:51,960 --> 04:32:53,760 prefab so let's once again do the same 8553 04:32:53,760 --> 04:32:56,279 thing tomato slices make the prefab 8554 04:32:56,279 --> 04:32:58,979 let's go inside this prefab let's modify 8555 04:32:58,979 --> 04:33:00,779 the visual so use the tomato slices 8556 04:33:00,779 --> 04:33:03,479 visual okay and drag the reference for 8557 04:33:03,479 --> 04:33:05,340 the other kitchen object for the tomato 8558 04:33:05,340 --> 04:33:06,958 slices okay 8559 04:33:06,958 --> 04:33:09,299 so the visual prefab is good and let's 8560 04:33:09,299 --> 04:33:11,820 just go into the kitchen object let's 8561 04:33:11,820 --> 04:33:13,740 just make sure to drag the prefab 8562 04:33:13,740 --> 04:33:15,958 reference then let's assign the tomato 8563 04:33:15,958 --> 04:33:18,599 slices icon and just come with tomato 8564 04:33:18,599 --> 04:33:20,458 slices 8565 04:33:20,458 --> 04:33:22,379 okay so we have the kitchen object so 8566 04:33:22,379 --> 04:33:24,660 now we can go into the kitchen counting 8567 04:33:24,660 --> 04:33:27,419 counter and over here let's open up and 8568 04:33:27,419 --> 04:33:29,699 set this one to the tomato slices 8569 04:33:29,699 --> 04:33:31,799 okay so we have all the references let's 8570 04:33:31,799 --> 04:33:33,719 go back outside save it 8571 04:33:33,719 --> 04:33:35,458 and back over here in our code so we 8572 04:33:35,458 --> 04:33:37,141 have this now we just need to spawn this 8573 04:33:37,141 --> 04:33:38,219 object 8574 04:33:38,219 --> 04:33:39,719 so we're really just going to spawn it 8575 04:33:39,719 --> 04:33:40,980 pretty much exactly like we did over 8576 04:33:40,980 --> 04:33:43,080 here on the container so we just go into 8577 04:33:43,080 --> 04:33:44,699 the description object spawn the prefab 8578 04:33:44,699 --> 04:33:46,080 and set the appearance so let's do 8579 04:33:46,080 --> 04:33:47,458 exactly that 8580 04:33:47,458 --> 04:33:50,400 over here we destroy the object then we 8581 04:33:50,400 --> 04:33:53,039 instantiate the cut kitchen object and 8582 04:33:53,039 --> 04:33:54,778 instead of getting into the player let's 8583 04:33:54,778 --> 04:33:56,458 put it on this 8584 04:33:56,458 --> 04:33:58,799 okay so that's it we should be able to 8585 04:33:58,799 --> 04:34:00,900 place a tomato directly on top of the 8586 04:34:00,900 --> 04:34:02,458 cutting counter and it should be able to 8587 04:34:02,458 --> 04:34:04,379 transform from a tomato into a tomato 8588 04:34:04,379 --> 04:34:05,938 slices 8589 04:34:05,938 --> 04:34:07,859 okay so here we are let me pick up a 8590 04:34:07,859 --> 04:34:09,958 tomato go up there drop it and okay that 8591 04:34:09,958 --> 04:34:12,419 works now if I press the onton track key 8592 04:34:12,419 --> 04:34:15,118 press it and if there go it did work the 8593 04:34:15,118 --> 04:34:16,561 Tomato was destroyed and the tomato 8594 04:34:16,561 --> 04:34:18,660 slices were spawn and I can pick them up 8595 04:34:18,660 --> 04:34:19,980 place them anywhere and yep everything 8596 04:34:19,980 --> 04:34:23,039 works alright awesome so with this the 8597 04:34:23,039 --> 04:34:25,320 basics are fully working let's just 8598 04:34:25,320 --> 04:34:27,299 briefly clean up this code 8599 04:34:27,299 --> 04:34:29,039 we already saw a little bit of code 8600 04:34:29,039 --> 04:34:31,320 duplication so the cutting counter is 8601 04:34:31,320 --> 04:34:32,759 going to spawn an object and the 8602 04:34:32,759 --> 04:34:34,259 container counter is also spawning an 8603 04:34:34,259 --> 04:34:36,299 object so we're copy pasting these two 8604 04:34:36,299 --> 04:34:38,219 lines of code in multiple places so 8605 04:34:38,219 --> 04:34:39,539 instead of doing that let's put it in 8606 04:34:39,539 --> 04:34:41,039 just one place 8607 04:34:41,039 --> 04:34:43,141 and actually a good place to put this is 8608 04:34:43,141 --> 04:34:45,180 on the kitchen object list itself so it 8609 04:34:45,180 --> 04:34:46,740 makes sense that this one is responsible 8610 04:34:46,740 --> 04:34:48,660 for spawning more objects 8611 04:34:48,660 --> 04:34:51,180 so let's put it over here however let us 8612 04:34:51,180 --> 04:34:53,580 not make it a regular function instead 8613 04:34:53,580 --> 04:34:55,980 let us make it a static function again 8614 04:34:55,980 --> 04:34:57,900 just like we saw for The Singletons by 8615 04:34:57,900 --> 04:34:59,340 making it static it means that the 8616 04:34:59,340 --> 04:35:00,840 function is going to belong to the class 8617 04:35:00,840 --> 04:35:03,419 itself as opposed to any instance so 8618 04:35:03,419 --> 04:35:05,039 let's go all the way down to the bottom 8619 04:35:05,039 --> 04:35:06,480 of the file personally I like to put 8620 04:35:06,480 --> 04:35:08,699 settings at the end and over here let's 8621 04:35:08,699 --> 04:35:10,799 make public make it static we're going 8622 04:35:10,799 --> 04:35:13,020 to return a kitchen object and let's 8623 04:35:13,020 --> 04:35:16,561 call it just spawn kitchen object 8624 04:35:16,561 --> 04:35:19,141 and for our parameters let's receive the 8625 04:35:19,141 --> 04:35:21,240 kitchen object that so 8626 04:35:21,240 --> 04:35:22,799 and let's also receive the kitchen 8627 04:35:22,799 --> 04:35:25,020 object parent 8628 04:35:25,020 --> 04:35:26,580 okay so that's it and we're going to do 8629 04:35:26,580 --> 04:35:28,080 the exact same thing so let's go into 8630 04:35:28,080 --> 04:35:29,759 the cutting counter and copy the code 8631 04:35:29,759 --> 04:35:31,859 that we're using and over here just 8632 04:35:31,859 --> 04:35:34,080 paste it in there so we go inside here 8633 04:35:34,080 --> 04:35:35,641 spawn the prefab and set it on this 8634 04:35:35,641 --> 04:35:36,599 parent 8635 04:35:36,599 --> 04:35:40,020 and finally let's return it 8636 04:35:40,020 --> 04:35:42,000 so let's return the kitchen object over 8637 04:35:42,000 --> 04:35:43,919 here let's pick it up so the kitchen 8638 04:35:43,919 --> 04:35:45,900 object 8639 04:35:45,900 --> 04:35:49,379 we get it and then we do kitchen object 8640 04:35:49,379 --> 04:35:51,958 set the parent and finally we return the 8641 04:35:51,958 --> 04:35:54,480 kitchen object 8642 04:35:54,480 --> 04:35:56,340 all right so that's it here we have a 8643 04:35:56,340 --> 04:35:57,900 super simple function that we can call 8644 04:35:57,900 --> 04:36:00,480 very easily it won't automatically spawn 8645 04:36:00,480 --> 04:36:02,278 an object and set to parents so now 8646 04:36:02,278 --> 04:36:04,020 let's just call this from somewhere so 8647 04:36:04,020 --> 04:36:05,458 over here on the cutting counter instead 8648 04:36:05,458 --> 04:36:07,020 of doing all this let's just go into the 8649 04:36:07,020 --> 04:36:09,240 kitchen object again remember let's go 8650 04:36:09,240 --> 04:36:11,039 through the class name itself and not 8651 04:36:11,039 --> 04:36:13,320 any instance and over here let's call 8652 04:36:13,320 --> 04:36:15,118 the function pass in the cut kitchen 8653 04:36:15,118 --> 04:36:17,278 object the cell and for the parent it's 8654 04:36:17,278 --> 04:36:18,480 going to be this 8655 04:36:18,480 --> 04:36:20,219 all right so that is now much much 8656 04:36:20,219 --> 04:36:22,020 simpler and let's do the same thing over 8657 04:36:22,020 --> 04:36:24,299 here on the container counter so if the 8658 04:36:24,299 --> 04:36:26,641 player is not carrying anything 8659 04:36:26,641 --> 04:36:29,219 let's give the player this object and 8660 04:36:29,219 --> 04:36:32,580 give it to the player just like this 8661 04:36:32,580 --> 04:36:34,080 as usual when we do some kind of 8662 04:36:34,080 --> 04:36:35,699 refactoring let's do a quick test make 8663 04:36:35,699 --> 04:36:37,259 sure everything still works exactly the 8664 04:36:37,259 --> 04:36:38,039 same 8665 04:36:38,039 --> 04:36:39,900 okay so here we are and if I go to the 8666 04:36:39,900 --> 04:36:41,340 counter and pick it up yep it does work 8667 04:36:41,340 --> 04:36:43,080 to spawn the object now I can drop it in 8668 04:36:43,080 --> 04:36:44,699 there I can cut it and yep there you go 8669 04:36:44,699 --> 04:36:46,799 everything does work all right so far so 8670 04:36:46,799 --> 04:36:47,759 good 8671 04:36:47,759 --> 04:36:49,379 so with all this basically we have 8672 04:36:49,379 --> 04:36:51,299 created a brand new counter where we can 8673 04:36:51,299 --> 04:36:53,820 cut objects however right now there's 8674 04:36:53,820 --> 04:36:56,458 obviously one huge layering funnel if I 8675 04:36:56,458 --> 04:36:58,259 now pick up a cabbage and I drop it on 8676 04:36:58,259 --> 04:36:59,641 the cutting counter and I interact with 8677 04:36:59,641 --> 04:37:01,438 it that cabbage has suddenly magically 8678 04:37:01,438 --> 04:37:04,199 turned into tomato slices now that is 8679 04:37:04,199 --> 04:37:06,660 obviously not intended so for that let's 8680 04:37:06,660 --> 04:37:08,641 define a proper cutting recipe and let's 8681 04:37:08,641 --> 04:37:11,039 do that in the next lecture 8682 04:37:11,039 --> 04:37:12,840 hello and welcome I'm your code monkey 8683 04:37:12,840 --> 04:37:14,759 in this lecture we're going to create 8684 04:37:14,759 --> 04:37:16,980 another scriptable object type this one 8685 04:37:16,980 --> 04:37:18,840 is going to be for handling our cutting 8686 04:37:18,840 --> 04:37:19,859 recipes 8687 04:37:19,859 --> 04:37:21,840 so here's our game I can pick up a 8688 04:37:21,840 --> 04:37:23,520 tomato drop it on the cutting counter 8689 04:37:23,520 --> 04:37:25,379 cut it there you go slice Tomatoes 8690 04:37:25,379 --> 04:37:27,840 however if I could pick up a cabbage go 8691 04:37:27,840 --> 04:37:29,400 there cut it and there you go cabbage 8692 04:37:29,400 --> 04:37:31,740 turns into tomatoes so we have an 8693 04:37:31,740 --> 04:37:33,419 obvious issue The Cutting object is 8694 04:37:33,419 --> 04:37:34,919 currently hard-coded instead of being 8695 04:37:34,919 --> 04:37:37,080 based on the object we put on top of it 8696 04:37:37,080 --> 04:37:38,820 so to solve that let's make another 8697 04:37:38,820 --> 04:37:40,980 scribble object type like I mentioned 8698 04:37:40,980 --> 04:37:42,719 scribble objects are excellent for 8699 04:37:42,719 --> 04:37:44,759 storing and organizing data so it's 8700 04:37:44,759 --> 04:37:46,980 perfect for this use case basically we 8701 04:37:46,980 --> 04:37:48,539 want a script mode object to hold a 8702 04:37:48,539 --> 04:37:50,340 reference to the regular object and the 8703 04:37:50,340 --> 04:37:52,919 cut object so we can then identify the 8704 04:37:52,919 --> 04:37:55,199 input in order to spawn the output okay 8705 04:37:55,199 --> 04:37:57,419 so let's build that let's create a brand 8706 04:37:57,419 --> 04:37:58,799 new c-sharp script 8707 04:37:58,799 --> 04:38:01,618 call it the cutting recipe so 8708 04:38:01,618 --> 04:38:03,419 and let's open it 8709 04:38:03,419 --> 04:38:05,278 okay so now here on let's do exactly 8710 04:38:05,278 --> 04:38:06,958 that so something extremely simple so 8711 04:38:06,958 --> 04:38:08,520 instead of modern behavior this one is a 8712 04:38:08,520 --> 04:38:10,618 script mode object let's add the create 8713 04:38:10,618 --> 04:38:13,080 asset menu and finally for the fields 8714 04:38:13,080 --> 04:38:15,299 let's do just an input and output so 8715 04:38:15,299 --> 04:38:17,160 we've got of type kitchen object so 8716 04:38:17,160 --> 04:38:19,379 let's go for the input and another one 8717 04:38:19,379 --> 04:38:21,000 for the output 8718 04:38:21,000 --> 04:38:23,580 okay so that's really it super simple 8719 04:38:23,580 --> 04:38:25,320 now here in the editor before we create 8720 04:38:25,320 --> 04:38:26,938 and let's keep things organized so let's 8721 04:38:26,938 --> 04:38:28,680 make another folder 8722 04:38:28,680 --> 04:38:32,099 let's make it for the cutting recipe so 8723 04:38:32,099 --> 04:38:34,199 and inside let's frequently create a new 8724 04:38:34,199 --> 04:38:35,278 cutting recipe 8725 04:38:35,278 --> 04:38:40,759 let's call it tomato two tomato slices 8726 04:38:40,799 --> 04:38:42,299 and over here let's select the reference 8727 04:38:42,299 --> 04:38:43,980 so the input is going to be our tomato 8728 04:38:43,980 --> 04:38:46,680 and the output the tomato slices 8729 04:38:46,680 --> 04:38:48,180 okay so this is how we're going to 8730 04:38:48,180 --> 04:38:49,259 handle things 8731 04:38:49,259 --> 04:38:51,061 so let's go ahead and make actually the 8732 04:38:51,061 --> 04:38:53,219 final kitchen object that sews 8733 04:38:53,219 --> 04:38:55,740 so let's make yet another one a kitchen 8734 04:38:55,740 --> 04:38:57,180 object to sell 8735 04:38:57,180 --> 04:39:00,419 let's make it for the Cabbage slices 8736 04:39:00,419 --> 04:39:02,458 and then let's have another one for the 8737 04:39:02,458 --> 04:39:04,259 cheese slices 8738 04:39:04,259 --> 04:39:06,299 okay so now let's make these so as usual 8739 04:39:06,299 --> 04:39:08,458 let's if we get tomato make the cheese 8740 04:39:08,458 --> 04:39:10,980 slices and another one for the Cabbage 8741 04:39:10,980 --> 04:39:12,419 slices 8742 04:39:12,419 --> 04:39:14,879 let's go inside of it and first of all 8743 04:39:14,879 --> 04:39:16,740 drag the kitchen object as so so this 8744 04:39:16,740 --> 04:39:18,660 one is the Cabbage slices 8745 04:39:18,660 --> 04:39:21,240 and let's go modify the visual so 8746 04:39:21,240 --> 04:39:23,039 instead of this one the Cabbage slices 8747 04:39:23,039 --> 04:39:24,719 okay 8748 04:39:24,719 --> 04:39:26,879 so we have this let's save the prefab go 8749 04:39:26,879 --> 04:39:29,278 outside then the other one we made the 8750 04:39:29,278 --> 04:39:31,379 cheese slices so let's swap this out 8751 04:39:31,379 --> 04:39:34,740 let's find the cheese slices 8752 04:39:34,740 --> 04:39:37,320 and modify the kitchen object as well 8753 04:39:37,320 --> 04:39:39,060 okay 8754 04:39:39,060 --> 04:39:42,240 so finally just assign the references so 8755 04:39:42,240 --> 04:39:44,340 on the cheese slices drag the cheese 8756 04:39:44,340 --> 04:39:48,180 slices prefab let's assign the icon and 8757 04:39:48,180 --> 04:39:51,000 call it cheese slices 8758 04:39:51,000 --> 04:39:53,878 okay so finally on the Cabbage slices so 8759 04:39:53,878 --> 04:39:56,520 these are the Cabbage slices 8760 04:39:56,520 --> 04:39:59,760 let's pick up the icon and let's drag 8761 04:39:59,760 --> 04:40:02,280 the prefab reference okay so far so good 8762 04:40:02,280 --> 04:40:04,740 we have created our new icons 8763 04:40:04,740 --> 04:40:06,840 and over here let's just make all of the 8764 04:40:06,840 --> 04:40:08,640 other cutting recipes so we've got two 8765 04:40:08,640 --> 04:40:10,740 more so one is going to be the cheese 8766 04:40:10,740 --> 04:40:13,980 block onto cheese slices and the other 8767 04:40:13,980 --> 04:40:15,900 one is going to be cabbage onto cabbage 8768 04:40:15,900 --> 04:40:17,280 slices 8769 04:40:17,280 --> 04:40:19,620 so we need is just to drag drop the 8770 04:40:19,620 --> 04:40:21,840 scriptable objects so for this one 8771 04:40:21,840 --> 04:40:23,700 cabbage let's drop the cabbage on the 8772 04:40:23,700 --> 04:40:26,160 input cabbage slices on the output for 8773 04:40:26,160 --> 04:40:28,680 cheese mug that's the cheese Wok on the 8774 04:40:28,680 --> 04:40:30,360 input and the cheese slices on the 8775 04:40:30,360 --> 04:40:31,378 output 8776 04:40:31,378 --> 04:40:34,080 okay great all of our data is now stored 8777 04:40:34,080 --> 04:40:36,180 in some really nice script mode objects 8778 04:40:36,180 --> 04:40:38,218 so now let's go here into our cutting 8779 04:40:38,218 --> 04:40:39,180 counter 8780 04:40:39,180 --> 04:40:41,100 instead of having a hard-coded kitchen 8781 04:40:41,100 --> 04:40:43,798 object let's receive a field of type 8782 04:40:43,798 --> 04:40:46,378 cutting rest BSO except we're going to 8783 04:40:46,378 --> 04:40:48,000 have multiple so let's actually make an 8784 04:40:48,000 --> 04:40:49,440 array of this 8785 04:40:49,440 --> 04:40:53,520 call it the cutting recipe so array 8786 04:40:53,520 --> 04:40:55,320 now for the interaction this is picking 8787 04:40:55,320 --> 04:40:56,520 up and dropping things so let's leave 8788 04:40:56,520 --> 04:40:58,140 that the same for now and over here on 8789 04:40:58,140 --> 04:40:59,280 the alternate 8790 04:40:59,280 --> 04:41:01,020 basically we need to find out which 8791 04:41:01,020 --> 04:41:03,298 recipe we should apply to this 8792 04:41:03,298 --> 04:41:05,160 so how I didn't find that is pretty 8793 04:41:05,160 --> 04:41:06,958 simple so we've got the kitchen object 8794 04:41:06,958 --> 04:41:08,820 that is placed on this object and we've 8795 04:41:08,820 --> 04:41:10,378 got a list of cutting recipes which in 8796 04:41:10,378 --> 04:41:12,298 turn has the input so we just need to 8797 04:41:12,298 --> 04:41:13,860 cycle through all the recipes in order 8798 04:41:13,860 --> 04:41:15,480 to find the one where the input matches 8799 04:41:15,480 --> 04:41:17,520 okay so let's go down here make a 8800 04:41:17,520 --> 04:41:19,260 function to do just that let's make it 8801 04:41:19,260 --> 04:41:20,760 private we're going to return a kitchen 8802 04:41:20,760 --> 04:41:23,340 object as so let's come with get output 8803 04:41:23,340 --> 04:41:25,798 for input so we give it a certain input 8804 04:41:25,798 --> 04:41:27,298 and Returns the one that matches that 8805 04:41:27,298 --> 04:41:28,138 one 8806 04:41:28,138 --> 04:41:31,020 so it turns a kitchen object as so for 8807 04:41:31,020 --> 04:41:34,798 the input kitchen object as well 8808 04:41:34,798 --> 04:41:36,780 here on let's cycle so do a for each 8809 04:41:36,780 --> 04:41:39,360 cutting recipe so in the cutting recipe 8810 04:41:39,360 --> 04:41:41,340 so right so let's cycle through all 8811 04:41:41,340 --> 04:41:43,798 these and just check if the cutting 8812 04:41:43,798 --> 04:41:46,798 recipe so if this one dot input matches 8813 04:41:46,798 --> 04:41:48,718 the input that we received 8814 04:41:48,718 --> 04:41:50,940 if so then this is the one we want so 8815 04:41:50,940 --> 04:41:53,420 let's return the cutting recipe 8816 04:41:53,420 --> 04:41:55,920 so.output and to make sure that the 8817 04:41:55,920 --> 04:41:59,160 function Works down here let's return no 8818 04:41:59,160 --> 04:42:01,560 okay so that's it we give it an input 8819 04:42:01,560 --> 04:42:03,600 and we get back the output 8820 04:42:03,600 --> 04:42:05,520 so now here we just need to make sure to 8821 04:42:05,520 --> 04:42:07,020 do it before we destroy the current 8822 04:42:07,020 --> 04:42:09,000 kitchen object 8823 04:42:09,000 --> 04:42:11,160 so let's store a kitchen object as so 8824 04:42:11,160 --> 04:42:14,638 for the output kitchen object SL and we 8825 04:42:14,638 --> 04:42:16,620 just get the output from the input and 8826 04:42:16,620 --> 04:42:18,240 for the input pass in the get kitchen 8827 04:42:18,240 --> 04:42:20,458 object so that's the one inside of this 8828 04:42:20,458 --> 04:42:22,260 cutting counter and let's get the 8829 04:42:22,260 --> 04:42:24,480 kitchen object this out so that gives us 8830 04:42:24,480 --> 04:42:26,638 the output and then we just spawn that 8831 04:42:26,638 --> 04:42:27,540 output 8832 04:42:27,540 --> 04:42:30,120 okay so that's it let's test 8833 04:42:30,120 --> 04:42:32,280 finally back in the scene let's just go 8834 04:42:32,280 --> 04:42:33,958 inside the prefab and over here on 8835 04:42:33,958 --> 04:42:35,340 cutting counter we need to make sure to 8836 04:42:35,340 --> 04:42:36,900 add all the recipes 8837 04:42:36,900 --> 04:42:39,480 so let's add so the cabbage 8838 04:42:39,480 --> 04:42:41,878 then a second one for cheese Mock and 8839 04:42:41,878 --> 04:42:44,040 finally for the Tomato okay so there are 8840 04:42:44,040 --> 04:42:46,200 of our recipes let's go outside save the 8841 04:42:46,200 --> 04:42:48,600 changes and let's test okay so over here 8842 04:42:48,600 --> 04:42:50,700 let's pick up a tomato go up there slice 8843 04:42:50,700 --> 04:42:52,320 it there you go got some tomato slices 8844 04:42:52,320 --> 04:42:54,540 now pick up some cheese go here slice it 8845 04:42:54,540 --> 04:42:55,980 and there you go got some cheese slices 8846 04:42:55,980 --> 04:42:58,200 and finally the Cabbage go up there 8847 04:42:58,200 --> 04:42:59,878 slice it and there you go some cabbage 8848 04:42:59,878 --> 04:43:02,458 slices all right awesome 8849 04:43:02,458 --> 04:43:04,100 so everything is working perfectly 8850 04:43:04,100 --> 04:43:06,480 however now let's say that I want to 8851 04:43:06,480 --> 04:43:08,458 pick up some bread and bread should not 8852 04:43:08,458 --> 04:43:10,920 really be able to be cut so if I go 8853 04:43:10,920 --> 04:43:12,840 ahead and I cut it and there you go 8854 04:43:12,840 --> 04:43:15,120 there's our air we have no recipe that 8855 04:43:15,120 --> 04:43:16,740 takes bread as an input So that 8856 04:43:16,740 --> 04:43:18,480 obviously leads to a known reference 8857 04:43:18,480 --> 04:43:19,560 exception 8858 04:43:19,560 --> 04:43:22,020 now here we have two options for solving 8859 04:43:22,020 --> 04:43:23,100 this problem 8860 04:43:23,100 --> 04:43:25,500 one option is simply over here when we 8861 04:43:25,500 --> 04:43:27,298 do the interact alternate 8862 04:43:27,298 --> 04:43:29,280 we get the output for the input and if 8863 04:43:29,280 --> 04:43:31,500 this one returns null then we just don't 8864 04:43:31,500 --> 04:43:32,458 cut it 8865 04:43:32,458 --> 04:43:34,138 so we don't destroy it and we don't 8866 04:43:34,138 --> 04:43:36,000 spawn it or alternatively we can 8867 04:43:36,000 --> 04:43:37,500 actually add some Foundation over here 8868 04:43:37,500 --> 04:43:39,420 when dropping objects so we can make 8869 04:43:39,420 --> 04:43:41,160 sure that we only drop valid cutable 8870 04:43:41,160 --> 04:43:43,500 objects now both approaches are valid 8871 04:43:43,500 --> 04:43:44,940 and actually we do need to implement 8872 04:43:44,940 --> 04:43:46,920 both them we'll see why in a bit 8873 04:43:46,920 --> 04:43:48,958 so let's do both starting off with the 8874 04:43:48,958 --> 04:43:50,580 validating the drop 8875 04:43:50,580 --> 04:43:52,200 so first we check if there is no kitchen 8876 04:43:52,200 --> 04:43:54,480 object on this cutting counter then we 8877 04:43:54,480 --> 04:43:55,620 check if the player is carrying 8878 04:43:55,620 --> 04:43:57,240 something and then we drop it from the 8879 04:43:57,240 --> 04:43:58,440 player on this 8880 04:43:58,440 --> 04:44:00,660 so over here let's just check if there's 8881 04:44:00,660 --> 04:44:02,940 any recipe that has whatever the player 8882 04:44:02,940 --> 04:44:04,560 has as an input 8883 04:44:04,560 --> 04:44:06,718 so let's go down here make a function to 8884 04:44:06,718 --> 04:44:08,940 do that private let's return a bone and 8885 04:44:08,940 --> 04:44:12,420 call it has recipe with input 8886 04:44:12,420 --> 04:44:14,580 and we're going to receive a kitchen 8887 04:44:14,580 --> 04:44:17,280 object episode for the input kitchen 8888 04:44:17,280 --> 04:44:19,200 object lesson 8889 04:44:19,200 --> 04:44:20,638 and over here lets you pretty much 8890 04:44:20,638 --> 04:44:22,980 literally the same logic so we have this 8891 04:44:22,980 --> 04:44:24,840 and if we find a match then let's return 8892 04:44:24,840 --> 04:44:26,940 true so there is a recipe with that 8893 04:44:26,940 --> 04:44:30,060 input if not return false so now up here 8894 04:44:30,060 --> 04:44:31,620 when the player is carrying something 8895 04:44:31,620 --> 04:44:33,600 let's check 8896 04:44:33,600 --> 04:44:37,440 if has recipe with input and give it the 8897 04:44:37,440 --> 04:44:39,298 player get the kitchen object the player 8898 04:44:39,298 --> 04:44:41,340 is holding and get the kitchen object as 8899 04:44:41,340 --> 04:44:42,420 so 8900 04:44:42,420 --> 04:44:44,280 so if there's any recipe that takes 8901 04:44:44,280 --> 04:44:45,958 whatever the player is carrying as an 8902 04:44:45,958 --> 04:44:47,580 input 8903 04:44:47,580 --> 04:44:50,900 if so then we drop it 8904 04:44:55,560 --> 04:44:57,480 okay so like this let's test and see if 8905 04:44:57,480 --> 04:44:59,280 we can drop the bread 8906 04:44:59,280 --> 04:45:01,378 okay so let's pick up some bread go 8907 04:45:01,378 --> 04:45:03,120 ahead drop it and nope does not work 8908 04:45:03,120 --> 04:45:04,740 pick up some cheese and yep that one 8909 04:45:04,740 --> 04:45:06,060 does work 8910 04:45:06,060 --> 04:45:08,160 however now we actually also need the 8911 04:45:08,160 --> 04:45:10,260 other validation that I mentioned the 8912 04:45:10,260 --> 04:45:11,878 reason is because if we place a valid 8913 04:45:11,878 --> 04:45:13,860 option like for example the cheese there 8914 04:45:13,860 --> 04:45:16,080 so that works and I can cut it and yep 8915 04:45:16,080 --> 04:45:18,780 that does work however Now the recipe 8916 04:45:18,780 --> 04:45:21,060 the cheese moth became cheese slices and 8917 04:45:21,060 --> 04:45:22,620 now cheese slice is no longer an input 8918 04:45:22,620 --> 04:45:24,718 to any cutting recipe so now if I try 8919 04:45:24,718 --> 04:45:25,980 cutting again 8920 04:45:25,980 --> 04:45:28,740 I've got another no reference exception 8921 04:45:28,740 --> 04:45:30,660 so we need to validate putting objects 8922 04:45:30,660 --> 04:45:32,340 on top of it and also actually cutting 8923 04:45:32,340 --> 04:45:34,260 them Technologic is also pretty simple 8924 04:45:34,260 --> 04:45:36,000 so let's go down to the interact 8925 04:45:36,000 --> 04:45:38,280 alternate so we just check if there's a 8926 04:45:38,280 --> 04:45:40,500 kitchen object on The Cutting counter 8927 04:45:40,500 --> 04:45:43,560 and has recipe input 8928 04:45:43,560 --> 04:45:46,080 and let's get this kitchen object get 8929 04:45:46,080 --> 04:45:48,540 kitchen object as so just like this 8930 04:45:48,540 --> 04:45:50,878 so we're only going to cut if there is a 8931 04:45:50,878 --> 04:45:55,440 kitchen object here and it can be cut 8932 04:45:55,440 --> 04:45:57,480 okay so let's test 8933 04:45:57,480 --> 04:45:59,218 so first of all the other one let's pick 8934 04:45:59,218 --> 04:46:00,840 up bread and nope cannot travel okay 8935 04:46:00,840 --> 04:46:02,580 great now pick up some cheese and I can 8936 04:46:02,580 --> 04:46:05,340 drop now interact cut now cut again and 8937 04:46:05,340 --> 04:46:07,798 yep there you go no more errors all 8938 04:46:07,798 --> 04:46:10,200 right awesome okay so here we have 8939 04:46:10,200 --> 04:46:12,298 everything working perfectly I can pick 8940 04:46:12,298 --> 04:46:14,218 up a cabbage go up there cut it into 8941 04:46:14,218 --> 04:46:16,798 slices I can slice some cheese and I can 8942 04:46:16,798 --> 04:46:18,180 even slice some Tomatoes everything 8943 04:46:18,180 --> 04:46:20,340 works perfectly now the one thing 8944 04:46:20,340 --> 04:46:21,958 missing from our design is we don't 8945 04:46:21,958 --> 04:46:23,520 actually want this action to be instant 8946 04:46:23,520 --> 04:46:25,378 we don't want to just press a button 8947 04:46:25,378 --> 04:46:27,600 everything slices instantly instead we 8948 04:46:27,600 --> 04:46:29,218 want to have the player press the button 8949 04:46:29,218 --> 04:46:31,440 a few times in order to actually cut so 8950 04:46:31,440 --> 04:46:34,080 let's do all that in the next lecture 8951 04:46:34,080 --> 04:46:36,060 hello and welcome I'm your code monkey 8952 04:46:36,060 --> 04:46:38,400 in this lecture we're going to add the 8953 04:46:38,400 --> 04:46:40,020 mechanic for the player to be able to 8954 04:46:40,020 --> 04:46:41,820 cut multiple times in order to actually 8955 04:46:41,820 --> 04:46:43,320 cut an object 8956 04:46:43,320 --> 04:46:45,240 okay so we have our cutting counter I 8957 04:46:45,240 --> 04:46:47,100 can drop a tomato and press button there 8958 04:46:47,100 --> 04:46:49,080 you go it cuts it straight away now we 8959 04:46:49,080 --> 04:46:50,940 want the exact same logic but we want it 8960 04:46:50,940 --> 04:46:52,860 to take a few Cuts before the cut object 8961 04:46:52,860 --> 04:46:54,000 is spawned 8962 04:46:54,000 --> 04:46:55,860 so let's start off by going here onto 8963 04:46:55,860 --> 04:46:57,900 the cutting counter and basically let's 8964 04:46:57,900 --> 04:47:00,180 keep track of some kind of progress 8965 04:47:00,180 --> 04:47:01,860 basically the way we do that is pretty 8966 04:47:01,860 --> 04:47:03,958 arbitrary it's up to you to decide for 8967 04:47:03,958 --> 04:47:05,820 example you could use a normalized float 8968 04:47:05,820 --> 04:47:08,100 however for cutting since this is going 8969 04:47:08,100 --> 04:47:09,540 to be a discrete action let's actually 8970 04:47:09,540 --> 04:47:11,878 count the numbers with an end so let's 8971 04:47:11,878 --> 04:47:13,740 store a private end just call it cutting 8972 04:47:13,740 --> 04:47:15,660 progress 8973 04:47:15,660 --> 04:47:17,760 okay so now let's begin by actually 8974 04:47:17,760 --> 04:47:19,500 initializing this progress so when the 8975 04:47:19,500 --> 04:47:21,060 player drops something on there let's 8976 04:47:21,060 --> 04:47:23,160 set this one to zero 8977 04:47:23,160 --> 04:47:25,020 and then down here when we have the 8978 04:47:25,020 --> 04:47:27,660 interact alternate we do our logic and 8979 04:47:27,660 --> 04:47:29,638 when we do let's just increase this by 8980 04:47:29,638 --> 04:47:30,840 one 8981 04:47:30,840 --> 04:47:32,520 and now we need to know if the object 8982 04:47:32,520 --> 04:47:34,138 has been cut so we need somewhere to 8983 04:47:34,138 --> 04:47:36,600 Define some kind of maximum 8984 04:47:36,600 --> 04:47:38,400 and for that we can actually do it 8985 04:47:38,400 --> 04:47:41,040 directly on the recipe so so inside the 8986 04:47:41,040 --> 04:47:43,740 cutting rest PSO over here we've got the 8987 04:47:43,740 --> 04:47:45,180 input we've got the output and let's 8988 04:47:45,180 --> 04:47:46,980 also Define an end 8989 04:47:46,980 --> 04:47:50,040 for The Cutting progress Max 8990 04:47:50,040 --> 04:47:51,660 okay that's it 8991 04:47:51,660 --> 04:47:54,060 and back here in the editor let's go 8992 04:47:54,060 --> 04:47:55,980 into the Tomato to tomato slices let's 8993 04:47:55,980 --> 04:47:58,260 say this one takes just three Cuts then 8994 04:47:58,260 --> 04:47:59,878 for the cheese let's also take three 8995 04:47:59,878 --> 04:48:01,620 cuts and for the Cabbage let's say it's 8996 04:48:01,620 --> 04:48:03,120 a bit thicker so let's say it takes five 8997 04:48:03,120 --> 04:48:04,320 cuts 8998 04:48:04,320 --> 04:48:07,320 okay so back in the cutting counter here 8999 04:48:07,320 --> 04:48:09,420 down here we are adding to our cutting 9000 04:48:09,420 --> 04:48:10,500 progress 9001 04:48:10,500 --> 04:48:12,480 so then we just need the recipe so in 9002 04:48:12,480 --> 04:48:14,638 order to grab the maximum so on 9003 04:48:14,638 --> 04:48:15,958 sectionally go down here and actually 9004 04:48:15,958 --> 04:48:17,638 make a different function so this one 9005 04:48:17,638 --> 04:48:19,860 just returns a Boolean this one a 9006 04:48:19,860 --> 04:48:21,480 kitchen object or so let's make another 9007 04:48:21,480 --> 04:48:23,760 one this one is going to return a 9008 04:48:23,760 --> 04:48:25,798 cutting recipe so 9009 04:48:25,798 --> 04:48:31,160 so get the cutting recipe so with input 9010 04:48:31,620 --> 04:48:33,360 and we're going to receive as usual the 9011 04:48:33,360 --> 04:48:36,980 kitchen objects so for the input 9012 04:48:37,740 --> 04:48:39,540 I'm really going to do the exact same 9013 04:48:39,540 --> 04:48:41,458 thing that we did up here next time 9014 04:48:41,458 --> 04:48:42,780 instead of returning the output let's 9015 04:48:42,780 --> 04:48:44,700 return the recipe itself 9016 04:48:44,700 --> 04:48:46,440 okay so now that we have this more 9017 04:48:46,440 --> 04:48:48,240 logical one we can actually get rid of 9018 04:48:48,240 --> 04:48:50,100 all this copy paste code 9019 04:48:50,100 --> 04:48:52,378 so over here we just get the cutting 9020 04:48:52,378 --> 04:48:55,138 recipe so 9021 04:48:55,138 --> 04:48:59,638 and we just get it and pass in the input 9022 04:48:59,638 --> 04:49:02,280 so we have this one over here if this 9023 04:49:02,280 --> 04:49:04,500 one is not no then we're going to return 9024 04:49:04,500 --> 04:49:06,120 this on the output 9025 04:49:06,120 --> 04:49:07,798 and if not we're just going to return 9026 04:49:07,798 --> 04:49:09,120 null 9027 04:49:09,120 --> 04:49:11,160 okay so we're doing the exact same logic 9028 04:49:11,160 --> 04:49:13,500 just a bit similar okay and up here 9029 04:49:13,500 --> 04:49:15,780 pretty much the same thing 9030 04:49:15,780 --> 04:49:18,718 so has recipe with input let's get the 9031 04:49:18,718 --> 04:49:20,520 cutting recipe a cell 9032 04:49:20,520 --> 04:49:22,378 and basically just return if this one is 9033 04:49:22,378 --> 04:49:24,660 not known 9034 04:49:24,660 --> 04:49:26,638 okay so we have our three nice sample 9035 04:49:26,638 --> 04:49:28,860 functions so let's just use this one to 9036 04:49:28,860 --> 04:49:30,718 get the cutting rest BSO so let's 9037 04:49:30,718 --> 04:49:33,120 actually copy this and go up here so we 9038 04:49:33,120 --> 04:49:35,218 do the cutting progress then let's pick 9039 04:49:35,218 --> 04:49:37,200 it up the one for this input so the 9040 04:49:37,200 --> 04:49:39,240 input is going to be this one the object 9041 04:49:39,240 --> 04:49:41,580 currently on the cutting counter and 9042 04:49:41,580 --> 04:49:42,958 over here we already know that there's 9043 04:49:42,958 --> 04:49:44,400 going to be a recipe with this input 9044 04:49:44,400 --> 04:49:46,620 since we've gone through this if 9045 04:49:46,620 --> 04:49:48,718 so then we can just check if the cutting 9046 04:49:48,718 --> 04:49:51,420 progress is bigger or equal to The 9047 04:49:51,420 --> 04:49:54,480 Cutting recipe so and let's grab the 9048 04:49:54,480 --> 04:49:56,958 maximum 9049 04:49:57,240 --> 04:50:00,180 if so then yep we do spawn it 9050 04:50:00,180 --> 04:50:02,340 okay so that's it some very simple logic 9051 04:50:02,340 --> 04:50:03,780 Let's test 9052 04:50:03,780 --> 04:50:05,940 so here we are let's pick up a tomato go 9053 04:50:05,940 --> 04:50:07,500 up there and okay now I'm going to press 9054 04:50:07,500 --> 04:50:10,080 enter direct okay press once and yep 9055 04:50:10,080 --> 04:50:12,480 okay so far so good nothing now two 9056 04:50:12,480 --> 04:50:15,298 times and Alpha press a third time boom 9057 04:50:15,298 --> 04:50:16,860 any up there you go got the nice slices 9058 04:50:16,860 --> 04:50:19,440 now for cheese same thing one two three 9059 04:50:19,440 --> 04:50:21,420 yep it works and finally for the 9060 04:50:21,420 --> 04:50:23,878 Cambridge this one should be five so one 9061 04:50:23,878 --> 04:50:26,940 two three four and five any up there you 9062 04:50:26,940 --> 04:50:29,100 go everything does work perfectly all 9063 04:50:29,100 --> 04:50:30,480 right awesome 9064 04:50:30,480 --> 04:50:32,520 so with this we now have progress in our 9065 04:50:32,520 --> 04:50:34,440 cutting logic although of course just 9066 04:50:34,440 --> 04:50:35,820 like this it's not very good for the 9067 04:50:35,820 --> 04:50:37,798 player the player has no way of knowing 9068 04:50:37,798 --> 04:50:39,840 what exactly is going on so we need some 9069 04:50:39,840 --> 04:50:41,638 kind of visual feedback so for that 9070 04:50:41,638 --> 04:50:43,378 let's add a really nice visual progress 9071 04:50:43,378 --> 04:50:45,060 bar and for doing this we're also going 9072 04:50:45,060 --> 04:50:46,680 to learn about a really awesome Unity 9073 04:50:46,680 --> 04:50:49,260 feature these are World canvases 9074 04:50:49,260 --> 04:50:51,298 so before we make the world canvas on 9075 04:50:51,298 --> 04:50:52,860 The Cutting counter let's actually set 9076 04:50:52,860 --> 04:50:54,180 something up over here on the scene 9077 04:50:54,180 --> 04:50:55,138 itself 9078 04:50:55,138 --> 04:50:57,180 let's first create a regular canvas 9079 04:50:57,180 --> 04:50:58,860 we're only going to use this in a couple 9080 04:50:58,860 --> 04:51:00,540 of lectures but let's first do that one 9081 04:51:00,540 --> 04:51:02,160 just for now 9082 04:51:02,160 --> 04:51:04,920 so let's go on the plus button go into 9083 04:51:04,920 --> 04:51:07,920 UI and let's create a brand new canvas 9084 04:51:07,920 --> 04:51:09,540 okay so there you go that creates a 9085 04:51:09,540 --> 04:51:11,400 canvas and an event system 9086 04:51:11,400 --> 04:51:12,780 like I said we're only going to worry 9087 04:51:12,780 --> 04:51:14,340 about this in a little bit but for now 9088 04:51:14,340 --> 04:51:16,200 let's just leave those as is 9089 04:51:16,200 --> 04:51:17,760 and also since we're here creating some 9090 04:51:17,760 --> 04:51:19,680 objects let's also take some time to 9091 04:51:19,680 --> 04:51:21,360 organize our hurricane 9092 04:51:21,360 --> 04:51:23,218 Unity suddenly doesn't really have any 9093 04:51:23,218 --> 04:51:25,560 folder objects so you can't organize the 9094 04:51:25,560 --> 04:51:28,080 hierarchy in any folders however you can 9095 04:51:28,080 --> 04:51:29,820 use empty game objects essentially as 9096 04:51:29,820 --> 04:51:31,020 folders 9097 04:51:31,020 --> 04:51:32,940 so let's make a brand new empty game 9098 04:51:32,940 --> 04:51:35,520 object let's call it counters 9099 04:51:35,520 --> 04:51:37,320 and now very importantly for empty 9100 04:51:37,320 --> 04:51:38,820 folder objects make sure you put them on 9101 04:51:38,820 --> 04:51:41,218 zero zero zero so nothing breaks 9102 04:51:41,218 --> 04:51:43,080 so make sure you put it on there before 9103 04:51:43,080 --> 04:51:44,760 you drag the counters 9104 04:51:44,760 --> 04:51:46,500 and now let's just drag on the counters 9105 04:51:46,500 --> 04:51:48,000 inside so all the clear counters put 9106 04:51:48,000 --> 04:51:50,340 them outside this one also drag it 9107 04:51:50,340 --> 04:51:52,560 inside and all of these counters put 9108 04:51:52,560 --> 04:51:54,298 them all inside so there you go now 9109 04:51:54,298 --> 04:51:56,458 hierarchy is quite a bit more clean 9110 04:51:56,458 --> 04:51:58,200 okay so now let's make the cutting 9111 04:51:58,200 --> 04:52:00,000 progress so let's click on the cutting 9112 04:52:00,000 --> 04:52:01,138 counter 9113 04:52:01,138 --> 04:52:03,718 and let's go inside our prefab so let's 9114 04:52:03,718 --> 04:52:05,520 go inside of it 9115 04:52:05,520 --> 04:52:07,440 now over here let's right click on the 9116 04:52:07,440 --> 04:52:09,480 hierarchy and we're going to create a UI 9117 04:52:09,480 --> 04:52:11,218 let's create another canvas 9118 04:52:11,218 --> 04:52:12,780 now for this one let's give it a name 9119 04:52:12,780 --> 04:52:15,480 let's name it the progress bar UI and 9120 04:52:15,480 --> 04:52:16,860 for this one over here on the inspector 9121 04:52:16,860 --> 04:52:18,540 for the settings instead of being screen 9122 04:52:18,540 --> 04:52:20,700 space overlay let's make this one a 9123 04:52:20,700 --> 04:52:22,320 world space canvas 9124 04:52:22,320 --> 04:52:24,060 basically screen space means that it 9125 04:52:24,060 --> 04:52:25,740 would occupy the entire screen whereas 9126 04:52:25,740 --> 04:52:27,480 World space means that this exists in 9127 04:52:27,480 --> 04:52:29,760 the world in whatever position it is 9128 04:52:29,760 --> 04:52:31,620 so let's make it World space and over 9129 04:52:31,620 --> 04:52:34,260 here the fields actually unlock so let's 9130 04:52:34,260 --> 04:52:36,718 put the positions on zero and for the 9131 04:52:36,718 --> 04:52:38,218 width and height let's also put it on 9132 04:52:38,218 --> 04:52:39,900 zero 9133 04:52:39,900 --> 04:52:41,760 so basically the canvas is going to be 9134 04:52:41,760 --> 04:52:43,740 exactly over here by the way the 9135 04:52:43,740 --> 04:52:45,600 shortcut that I just used was the F in 9136 04:52:45,600 --> 04:52:47,280 order to focus on the object 9137 04:52:47,280 --> 04:52:49,620 so this useful if you're zoomed out or 9138 04:52:49,620 --> 04:52:51,718 zoomed in way too much okay 9139 04:52:51,718 --> 04:52:53,400 so we have this and we want the bar to 9140 04:52:53,400 --> 04:52:54,600 be a little bit above so let's actually 9141 04:52:54,600 --> 04:52:56,820 lift it up on the Y by a little bit so 9142 04:52:56,820 --> 04:53:00,000 over here let's put it on y of 2.5 okay 9143 04:53:00,000 --> 04:53:01,560 now I said the going with this is to 9144 04:53:01,560 --> 04:53:03,420 make a progress bar so inside the 9145 04:53:03,420 --> 04:53:05,458 progress bar UI let's create a new UI 9146 04:53:05,458 --> 04:53:09,540 image let's name this one our bar 9147 04:53:09,540 --> 04:53:12,180 let's put it with a width of one and a 9148 04:53:12,180 --> 04:53:14,458 height maybe of 0.2 9149 04:53:14,458 --> 04:53:16,440 so there you go just a really thin bar 9150 04:53:16,440 --> 04:53:18,180 and for the color you can play round 9151 04:53:18,180 --> 04:53:20,700 tinted with any color you want now for 9152 04:53:20,700 --> 04:53:22,500 progress I think maybe a blue or a 9153 04:53:22,500 --> 04:53:23,878 yellow something like that makes sense 9154 04:53:23,878 --> 04:53:26,100 so let's go with the yellow kind of like 9155 04:53:26,100 --> 04:53:27,360 this 9156 04:53:27,360 --> 04:53:29,400 okay so there's our really nice progress 9157 04:53:29,400 --> 04:53:30,420 bar 9158 04:53:30,420 --> 04:53:32,520 and for this let's actually use one 9159 04:53:32,520 --> 04:53:33,958 really nice trick for making a super 9160 04:53:33,958 --> 04:53:36,360 easy progress bar the image component 9161 04:53:36,360 --> 04:53:38,580 has a really easy way of making a slider 9162 04:53:38,580 --> 04:53:41,040 image however it only actually works if 9163 04:53:41,040 --> 04:53:42,958 you assign an image over here 9164 04:53:42,958 --> 04:53:44,458 so let's assign one in order to be able 9165 04:53:44,458 --> 04:53:45,900 to see those options 9166 04:53:45,900 --> 04:53:48,000 and for that in the project files 9167 04:53:48,000 --> 04:53:50,458 there's a texture white one by one this 9168 04:53:50,458 --> 04:53:52,138 is literally just a one by one white 9169 04:53:52,138 --> 04:53:53,520 pixel 9170 04:53:53,520 --> 04:53:55,620 so here it is just a one by one image if 9171 04:53:55,620 --> 04:53:56,878 only white 9172 04:53:56,878 --> 04:53:58,680 and as soon as we assign it we do see 9173 04:53:58,680 --> 04:54:00,420 over here the image type so we see a 9174 04:54:00,420 --> 04:54:02,400 bunch more options and the one that we 9175 04:54:02,400 --> 04:54:04,860 want is to set the Sprite as filled this 9176 04:54:04,860 --> 04:54:06,420 one lets you do some really cool really 9177 04:54:06,420 --> 04:54:08,820 easy effects for example you can make it 9178 04:54:08,820 --> 04:54:10,560 radial and look at what happens in there 9179 04:54:10,560 --> 04:54:12,360 as I modify over here on the film Mount 9180 04:54:12,360 --> 04:54:14,280 so as I go down look at that it's 9181 04:54:14,280 --> 04:54:16,500 radiantly filling so for some kind of 9182 04:54:16,500 --> 04:54:17,940 circular progress bar this would be 9183 04:54:17,940 --> 04:54:20,218 excellent but in our case what we really 9184 04:54:20,218 --> 04:54:22,620 want is just a horizontal bar so we're 9185 04:54:22,620 --> 04:54:24,000 here for the film method instead of 9186 04:54:24,000 --> 04:54:25,980 Radion let's go with horizontal 9187 04:54:25,980 --> 04:54:27,360 and if there you go now by playing 9188 04:54:27,360 --> 04:54:28,920 around this we have a really nice 9189 04:54:28,920 --> 04:54:30,480 progress bar 9190 04:54:30,480 --> 04:54:31,860 then if you want you can modify on left 9191 04:54:31,860 --> 04:54:33,240 to right right and left but yep like 9192 04:54:33,240 --> 04:54:34,920 this it looks great 9193 04:54:34,920 --> 04:54:36,540 now in order to modify this visual 9194 04:54:36,540 --> 04:54:37,620 really only we're going to need is 9195 04:54:37,620 --> 04:54:39,840 modify over here the film Mount this one 9196 04:54:39,840 --> 04:54:41,940 is a normalized value so between 0 and 1 9197 04:54:41,940 --> 04:54:43,740 so 0 is commonly empty one is commonly 9198 04:54:43,740 --> 04:54:46,320 full however one issue with this is when 9199 04:54:46,320 --> 04:54:48,240 the bar is empty then we can pretty much 9200 04:54:48,240 --> 04:54:50,820 not see so we can see the actual size of 9201 04:54:50,820 --> 04:54:52,440 the bar we can see what size it should 9202 04:54:52,440 --> 04:54:53,160 be 9203 04:54:53,160 --> 04:54:54,780 so with this it's pretty difficult to 9204 04:54:54,780 --> 04:54:57,120 see how far along we are but something 9205 04:54:57,120 --> 04:54:58,798 that is pretty simple we can really just 9206 04:54:58,798 --> 04:55:00,420 add some kind of background 9207 04:55:00,420 --> 04:55:02,760 so let's duplicate the bar let's name 9208 04:55:02,760 --> 04:55:04,798 this one the background 9209 04:55:04,798 --> 04:55:06,600 for this one for the image type we don't 9210 04:55:06,600 --> 04:55:07,860 want anything so let's leave it on 9211 04:55:07,860 --> 04:55:09,958 SIMPLE and for the color let's put it on 9212 04:55:09,958 --> 04:55:12,958 kind of a dark gray okay great and now 9213 04:55:12,958 --> 04:55:15,060 here's one very very important thing is 9214 04:55:15,060 --> 04:55:16,860 over here on the hierarchy let's click 9215 04:55:16,860 --> 04:55:19,260 and drag and place it above the bar 9216 04:55:19,260 --> 04:55:20,878 the reason why that is super important 9217 04:55:20,878 --> 04:55:22,860 is because the Sorting order and how it 9218 04:55:22,860 --> 04:55:24,840 works in unity basically when it comes 9219 04:55:24,840 --> 04:55:27,180 to UI elements inside a canvas the 9220 04:55:27,180 --> 04:55:29,100 Sorting order is based on The Horde in 9221 04:55:29,100 --> 04:55:31,200 the hierarchy basically it renders from 9222 04:55:31,200 --> 04:55:32,520 top to bottom 9223 04:55:32,520 --> 04:55:34,440 so the bar on top the background this is 9224 04:55:34,440 --> 04:55:36,240 going to render first and then the one 9225 04:55:36,240 --> 04:55:37,620 below it the bar is going to render 9226 04:55:37,620 --> 04:55:39,120 afterwards which means it's going to 9227 04:55:39,120 --> 04:55:40,500 render on top 9228 04:55:40,500 --> 04:55:42,060 so for the background we want to be 9229 04:55:42,060 --> 04:55:43,680 behind so place it above on the 9230 04:55:43,680 --> 04:55:45,600 hierarchy and that way it renders the 9231 04:55:45,600 --> 04:55:47,878 background and then renders the bar also 9232 04:55:47,878 --> 04:55:49,860 by the way for 2D Sprites Unity has 9233 04:55:49,860 --> 04:55:51,718 another different sorting method it's 9234 04:55:51,718 --> 04:55:53,458 all based on sorting layers and sorting 9235 04:55:53,458 --> 04:55:54,360 orders 9236 04:55:54,360 --> 04:55:56,040 I have video on that topic if you're 9237 04:55:56,040 --> 04:55:57,540 interested in 2D games 9238 04:55:57,540 --> 04:55:59,580 okay so with this we have the background 9239 04:55:59,580 --> 04:56:01,500 and then we have our film bar this way 9240 04:56:01,500 --> 04:56:02,700 we can see if the progress is being 9241 04:56:02,700 --> 04:56:04,020 filmed or not 9242 04:56:04,020 --> 04:56:05,878 also one more tiny thing that I like to 9243 04:56:05,878 --> 04:56:08,040 add is Unity has some really nice really 9244 04:56:08,040 --> 04:56:09,780 easy to add effects 9245 04:56:09,780 --> 04:56:11,638 so you can go into that component and 9246 04:56:11,638 --> 04:56:13,920 let's search for a shadow 9247 04:56:13,920 --> 04:56:15,540 this one does exactly what you expected 9248 04:56:15,540 --> 04:56:17,458 as a nice drop shadow over here on the 9249 04:56:17,458 --> 04:56:19,798 effect distance let's put it on 0.1.1 in 9250 04:56:19,798 --> 04:56:21,298 order to see 9251 04:56:21,298 --> 04:56:23,040 next one let's not do it on this one 9252 04:56:23,040 --> 04:56:24,600 we'll do it on the background so let's 9253 04:56:24,600 --> 04:56:26,340 get rid of this instead of going to the 9254 04:56:26,340 --> 04:56:27,780 background over here let's add the same 9255 04:56:27,780 --> 04:56:28,560 shadow 9256 04:56:28,560 --> 04:56:30,600 so if you put it on point one and minus 9257 04:56:30,600 --> 04:56:32,280 point one you better go a nice simple 9258 04:56:32,280 --> 04:56:34,740 and drop shadow or the other one that I 9259 04:56:34,740 --> 04:56:36,600 prefer so instead of the Shadow let's 9260 04:56:36,600 --> 04:56:39,360 add a really nice outline once again for 9261 04:56:39,360 --> 04:56:41,820 the effect distance 0.1.1 or maybe 9262 04:56:41,820 --> 04:56:44,940 actually 0.05 just to be just a tiny bit 9263 04:56:44,940 --> 04:56:46,920 and let's raise it on the alpha so there 9264 04:56:46,920 --> 04:56:49,680 you go nice little outline tour bar this 9265 04:56:49,680 --> 04:56:51,060 is just a visual thing so you don't have 9266 04:56:51,060 --> 04:56:52,500 to add this but personally I find that 9267 04:56:52,500 --> 04:56:54,120 it looks pretty good 9268 04:56:54,120 --> 04:56:55,740 so with all of this we have our Visual 9269 04:56:55,740 --> 04:56:57,660 and perfectly set up we've got our nice 9270 04:56:57,660 --> 04:56:59,458 bar all we need to do is play around the 9271 04:56:59,458 --> 04:57:01,200 filament in order to fill it 9272 04:57:01,200 --> 04:57:03,060 so now all we need to do is to connect 9273 04:57:03,060 --> 04:57:04,798 this to the logic but as usual let's 9274 04:57:04,798 --> 04:57:06,420 make sure to write some good clean code 9275 04:57:06,420 --> 04:57:08,878 so we do not want the cutting counter to 9276 04:57:08,878 --> 04:57:10,980 directly touch on this image 9277 04:57:10,980 --> 04:57:12,958 instead let's make a script to handle on 9278 04:57:12,958 --> 04:57:14,400 that so let's right click create a new 9279 04:57:14,400 --> 04:57:16,980 c-sharp script call it the progress bar 9280 04:57:16,980 --> 04:57:18,840 UI 9281 04:57:18,840 --> 04:57:20,940 and just personally as a rule I like to 9282 04:57:20,940 --> 04:57:23,700 open the UI to any UI script 9283 04:57:23,700 --> 04:57:25,500 you don't have to do that it's just a 9284 04:57:25,500 --> 04:57:27,060 rule that I personally find helpful to 9285 04:57:27,060 --> 04:57:29,040 follow that way just by looking at these 9286 04:57:29,040 --> 04:57:30,480 scripts I can immediately see this one 9287 04:57:30,480 --> 04:57:32,400 is a UI this one is script and logic and 9288 04:57:32,400 --> 04:57:33,600 so on 9289 04:57:33,600 --> 04:57:35,878 so on the progress bar UI on the main 9290 04:57:35,878 --> 04:57:38,100 game object let's attach the script and 9291 04:57:38,100 --> 04:57:39,420 let's open it 9292 04:57:39,420 --> 04:57:41,940 okay so now here we're going to need a 9293 04:57:41,940 --> 04:57:44,218 reference to our image 9294 04:57:44,218 --> 04:57:47,040 so let's add a serialized field private 9295 04:57:47,040 --> 04:57:49,080 and we're going to need the image type 9296 04:57:49,080 --> 04:57:51,120 and importantly this is inside using 9297 04:57:51,120 --> 04:57:52,920 Unity engine.ui so let's go up here 9298 04:57:52,920 --> 04:57:56,760 using Unity engine dot UI so we have our 9299 04:57:56,760 --> 04:57:59,100 image component okay great let's call it 9300 04:57:59,100 --> 04:58:01,378 the bar image 9301 04:58:01,378 --> 04:58:04,020 so we have a reference and now with this 9302 04:58:04,020 --> 04:58:05,700 obviously we need to have some kind of 9303 04:58:05,700 --> 04:58:07,260 reference to the counter so we know when 9304 04:58:07,260 --> 04:58:09,298 the progress changes so it's really the 9305 04:58:09,298 --> 04:58:10,798 same thing that we've already done so 9306 04:58:10,798 --> 04:58:12,600 many times throughout this course so 9307 04:58:12,600 --> 04:58:14,540 let's set a film up here serialize film 9308 04:58:14,540 --> 04:58:18,000 private cutting counter for our cutting 9309 04:58:18,000 --> 04:58:19,740 counter 9310 04:58:19,740 --> 04:58:21,420 then over here in the editor let's write 9311 04:58:21,420 --> 04:58:23,040 new references so drag the reference to 9312 04:58:23,040 --> 04:58:24,958 The Cutting counter and another one to 9313 04:58:24,958 --> 04:58:26,940 the bar image okay great 9314 04:58:26,940 --> 04:58:28,798 now we just need some kind of event to 9315 04:58:28,798 --> 04:58:30,718 update the bar image 9316 04:58:30,718 --> 04:58:32,520 so let's go over here into our cutting 9317 04:58:32,520 --> 04:58:34,500 count script let's make an event to 9318 04:58:34,500 --> 04:58:37,260 spawn that so public event let's use the 9319 04:58:37,260 --> 04:58:39,660 event handler the default standard 9320 04:58:39,660 --> 04:58:43,798 let's go with on progress change 9321 04:58:43,798 --> 04:58:45,540 and let's also make a nice event artist 9322 04:58:45,540 --> 04:58:47,100 to be able to send the current progress 9323 04:58:47,100 --> 04:58:48,298 amount 9324 04:58:48,298 --> 04:58:51,180 so let's make a public class on progress 9325 04:58:51,180 --> 04:58:53,820 changed event arcs and let's extend 9326 04:58:53,820 --> 04:58:55,500 event arcs 9327 04:58:55,500 --> 04:58:57,298 and then inside and let's put the 9328 04:58:57,298 --> 04:58:58,680 current progress 9329 04:58:58,680 --> 04:59:00,958 however let's also pass in the progress 9330 04:59:00,958 --> 04:59:02,760 as normalized since that's the what the 9331 04:59:02,760 --> 04:59:04,560 bar will use 9332 04:59:04,560 --> 04:59:08,160 so public Cloud progress normalized 9333 04:59:08,160 --> 04:59:10,138 and we're going to make this event of 9334 04:59:10,138 --> 04:59:11,340 this type 9335 04:59:11,340 --> 04:59:13,980 okay great so we have our event 9336 04:59:13,980 --> 04:59:16,020 now whenever we modify the progress we 9337 04:59:16,020 --> 04:59:17,218 just need to fire this event so over 9338 04:59:17,218 --> 04:59:19,138 here when resetting the progress let's 9339 04:59:19,138 --> 04:59:21,718 fire it so let's invoke pass in this 9340 04:59:21,718 --> 04:59:24,718 instantiate our event args and pass in 9341 04:59:24,718 --> 04:59:27,120 the progress normalized and to get the 9342 04:59:27,120 --> 04:59:28,680 normalized progress sectionally very 9343 04:59:28,680 --> 04:59:30,480 simple basically we just need to divide 9344 04:59:30,480 --> 04:59:32,458 the current progress by the maximum so 9345 04:59:32,458 --> 04:59:34,500 cutting progress divided by cutting 9346 04:59:34,500 --> 04:59:36,540 progress Max which is actually inside 9347 04:59:36,540 --> 04:59:38,700 the rest BSO so we need to pick that one 9348 04:59:38,700 --> 04:59:39,718 up 9349 04:59:39,718 --> 04:59:42,000 so let's go down there to pick up the 9350 04:59:42,000 --> 04:59:44,760 cutting progress recipe 9351 04:59:44,760 --> 04:59:47,160 so we picked this one up and we go in 9352 04:59:47,160 --> 04:59:49,020 there and get the maximum 9353 04:59:49,020 --> 04:59:51,000 however over here we also need to be 9354 04:59:51,000 --> 04:59:52,980 very careful because there is one sneaky 9355 04:59:52,980 --> 04:59:55,020 issue here this has to do with how 9356 04:59:55,020 --> 04:59:57,240 c-sharp works and how instar divided 9357 04:59:57,240 --> 04:59:58,798 with other ends 9358 04:59:58,798 --> 05:00:00,718 for example if we had a cutting progress 9359 05:00:00,718 --> 05:00:02,700 of one and cutting progress Max of five 9360 05:00:02,700 --> 05:00:04,860 you would think one divided by 5 would 9361 05:00:04,860 --> 05:00:07,440 equal 0.2 however if we actually did 9362 05:00:07,440 --> 05:00:09,240 that over here we would actually get a 9363 05:00:09,240 --> 05:00:11,458 zero and the reason for that is because 9364 05:00:11,458 --> 05:00:13,200 we are dividing two ends cutting 9365 05:00:13,200 --> 05:00:14,638 progress is an end cutting progress Max 9366 05:00:14,638 --> 05:00:17,100 is also an INT and if you divide an end 9367 05:00:17,100 --> 05:00:19,378 by an end then the end result will also 9368 05:00:19,378 --> 05:00:20,458 be an end 9369 05:00:20,458 --> 05:00:22,798 since you cannot Define 0.2 in an end 9370 05:00:22,798 --> 05:00:24,958 the decimal gets cut down and you end up 9371 05:00:24,958 --> 05:00:27,180 with just zero so that would not be 9372 05:00:27,180 --> 05:00:29,218 correct in order to get the right value 9373 05:00:29,218 --> 05:00:30,780 from this calculation we need to make 9374 05:00:30,780 --> 05:00:32,400 sure to convert one of these values onto 9375 05:00:32,400 --> 05:00:34,620 a float so that's really simple we just 9376 05:00:34,620 --> 05:00:36,298 cast one of them so just cast this one 9377 05:00:36,298 --> 05:00:38,700 to the float just like that 9378 05:00:38,700 --> 05:00:40,260 basically now this one will first be 9379 05:00:40,260 --> 05:00:42,060 cast to a float and then we're going to 9380 05:00:42,060 --> 05:00:43,740 have a float divided by an end and the 9381 05:00:43,740 --> 05:00:46,320 end result won't be afloat so if you 9382 05:00:46,320 --> 05:00:47,760 ever do some math and you get some weird 9383 05:00:47,760 --> 05:00:49,440 results always make sure to check the 9384 05:00:49,440 --> 05:00:50,700 type of your numbers 9385 05:00:50,700 --> 05:00:53,280 okay so here we are correctly firing the 9386 05:00:53,280 --> 05:00:55,080 event and then down here when adding our 9387 05:00:55,080 --> 05:00:57,718 progress let's do the same thing let's 9388 05:00:57,718 --> 05:01:00,298 also fire on the event 9389 05:01:00,298 --> 05:01:02,218 so now we can go back into our progress 9390 05:01:02,218 --> 05:01:03,718 bar UI 9391 05:01:03,718 --> 05:01:05,340 and over here let's listen to the event 9392 05:01:05,340 --> 05:01:07,440 and again remember that if we're 9393 05:01:07,440 --> 05:01:09,540 accessing an external reference let's do 9394 05:01:09,540 --> 05:01:12,000 that around start and not an awake 9395 05:01:12,000 --> 05:01:14,340 so cutting counter listen to the on 9396 05:01:14,340 --> 05:01:16,980 progress changed event 9397 05:01:16,980 --> 05:01:18,718 when that happens let's just go bar 9398 05:01:18,718 --> 05:01:20,520 image and set the fill amount to what we 9399 05:01:20,520 --> 05:01:22,080 received from the event so the progress 9400 05:01:22,080 --> 05:01:23,218 normalized 9401 05:01:23,218 --> 05:01:25,920 okay so that's really it and also appear 9402 05:01:25,920 --> 05:01:28,740 on start let's initialize it as 0f so 9403 05:01:28,740 --> 05:01:30,718 the bar is nice and empty 9404 05:01:30,718 --> 05:01:32,520 okay so let's test 9405 05:01:32,520 --> 05:01:34,138 back in the editor let's just go back 9406 05:01:34,138 --> 05:01:35,760 into the scenes make sure the prefab has 9407 05:01:35,760 --> 05:01:37,680 been saved and let's head on play 9408 05:01:37,680 --> 05:01:39,780 and right away yep we do see the bar yep 9409 05:01:39,780 --> 05:01:41,760 it is empty now pick up some cheese drop 9410 05:01:41,760 --> 05:01:44,280 it and if I cut and if there go add a 9411 05:01:44,280 --> 05:01:45,540 little bit of progress now a bit more 9412 05:01:45,540 --> 05:01:48,240 and there you go there's our cheese 9413 05:01:48,240 --> 05:01:51,120 okay great everything does work now 9414 05:01:51,120 --> 05:01:53,040 let's add just one more tiny bonus thing 9415 05:01:53,040 --> 05:01:55,320 we can add some extra logic in order to 9416 05:01:55,320 --> 05:01:56,820 hide this visual if the bar is either 9417 05:01:56,820 --> 05:01:58,798 completely empty or completely full that 9418 05:01:58,798 --> 05:02:00,420 is actually pretty simple 9419 05:02:00,420 --> 05:02:03,060 over here on the progress bar UI script 9420 05:02:03,060 --> 05:02:04,798 let's just make some basic show and 9421 05:02:04,798 --> 05:02:05,878 height functions 9422 05:02:05,878 --> 05:02:08,940 so private void show and then we're 9423 05:02:08,940 --> 05:02:11,540 going to have 9424 05:02:11,878 --> 05:02:14,940 a private void Hind 9425 05:02:14,940 --> 05:02:16,740 on these one just game objects that 9426 05:02:16,740 --> 05:02:19,020 active this one set it to true and this 9427 05:02:19,020 --> 05:02:20,638 one set it to false 9428 05:02:20,638 --> 05:02:22,560 now on start we subscribe to the event 9429 05:02:22,560 --> 05:02:26,040 and then let's hide it okay 9430 05:02:26,040 --> 05:02:27,900 also here it's very important make sure 9431 05:02:27,900 --> 05:02:29,580 you hide it after you listen to the 9432 05:02:29,580 --> 05:02:31,798 event if for example You Can't Hide on 9433 05:02:31,798 --> 05:02:33,540 awake that would disable the game object 9434 05:02:33,540 --> 05:02:34,980 and the start would never run so it 9435 05:02:34,980 --> 05:02:36,480 would never listen to the event 9436 05:02:36,480 --> 05:02:38,700 so if you have reset the game object as 9437 05:02:38,700 --> 05:02:41,040 inactive make sure you do it only after 9438 05:02:41,040 --> 05:02:42,900 you're listening to whatever events you 9439 05:02:42,900 --> 05:02:45,120 want so we have this that's great and 9440 05:02:45,120 --> 05:02:47,040 then when the progress changes 9441 05:02:47,040 --> 05:02:49,740 let's just do a basic test so if e dot 9442 05:02:49,740 --> 05:02:53,218 progress normalized equals zero f or if 9443 05:02:53,218 --> 05:02:55,138 the progress normalized equals one F so 9444 05:02:55,138 --> 05:02:56,340 if the bar is similarly empty or 9445 05:02:56,340 --> 05:02:57,780 completely full 9446 05:02:57,780 --> 05:03:01,260 if so then let's hide it and if not then 9447 05:03:01,260 --> 05:03:04,040 let's show it 9448 05:03:04,440 --> 05:03:06,780 okay that's it let's test 9449 05:03:06,780 --> 05:03:08,638 okay and yep by default starts off 9450 05:03:08,638 --> 05:03:10,440 hidden let's pick up the Tomato go up 9451 05:03:10,440 --> 05:03:12,660 there and yep still hidden now I cut and 9452 05:03:12,660 --> 05:03:14,280 there you go there it is cut again and 9453 05:03:14,280 --> 05:03:16,260 yep there you go it hides itself okay 9454 05:03:16,260 --> 05:03:18,718 great so we've got a nice little visual 9455 05:03:18,718 --> 05:03:20,878 let's do just one more final thing let's 9456 05:03:20,878 --> 05:03:23,040 add a really nice animation 9457 05:03:23,040 --> 05:03:25,440 if we go inside the cutting counter and 9458 05:03:25,440 --> 05:03:27,000 we'll look at the cutting counter visual 9459 05:03:27,000 --> 05:03:28,620 over here note how it already has an 9460 05:03:28,620 --> 05:03:29,520 animator 9461 05:03:29,520 --> 05:03:31,440 just like we did for the container 9462 05:03:31,440 --> 05:03:33,120 counter it's all very simple 9463 05:03:33,120 --> 05:03:35,400 so basically just has a cut parameter 9464 05:03:35,400 --> 05:03:37,080 when that happens it just cuts the 9465 05:03:37,080 --> 05:03:39,540 counter so just plays a simple animation 9466 05:03:39,540 --> 05:03:41,040 since it's going to be pretty much 9467 05:03:41,040 --> 05:03:42,660 exactly like the container counter and 9468 05:03:42,660 --> 05:03:45,000 let's actually duplicate that script so 9469 05:03:45,000 --> 05:03:47,040 let's go down find that script so the 9470 05:03:47,040 --> 05:03:48,240 container comes to visual let's 9471 05:03:48,240 --> 05:03:50,520 duplicate this so Ctrl d 9472 05:03:50,520 --> 05:03:53,218 let's rename this to The Cutting counter 9473 05:03:53,218 --> 05:03:54,600 visual 9474 05:03:54,600 --> 05:03:56,100 okay let's open 9475 05:03:56,100 --> 05:03:57,840 and over here let's rename the script so 9476 05:03:57,840 --> 05:04:00,060 the cutting countervision okay great 9477 05:04:00,060 --> 05:04:02,280 then for the parameter let's rename this 9478 05:04:02,280 --> 05:04:03,900 instead of open close is going to be 9479 05:04:03,900 --> 05:04:05,160 called cut 9480 05:04:05,160 --> 05:04:08,040 and for the string it's cut again make 9481 05:04:08,040 --> 05:04:09,780 sure you write it case sensitive make 9482 05:04:09,780 --> 05:04:11,218 sure it's all correct 9483 05:04:11,218 --> 05:04:12,958 then instead of having a container come 9484 05:04:12,958 --> 05:04:14,940 through we've got a cutting counter and 9485 05:04:14,940 --> 05:04:17,040 a cutting counter 9486 05:04:17,040 --> 05:04:18,900 and finally we just need to listen to 9487 05:04:18,900 --> 05:04:21,120 the correct event so technically we 9488 05:04:21,120 --> 05:04:22,560 couldn't listen to the unprogressed 9489 05:04:22,560 --> 05:04:24,540 changed however that one also gets fired 9490 05:04:24,540 --> 05:04:25,740 over here when the cutting progress is 9491 05:04:25,740 --> 05:04:27,480 zero we don't want the current mission 9492 05:04:27,480 --> 05:04:29,700 to play when this happens so let's just 9493 05:04:29,700 --> 05:04:31,980 make another simple event so a public 9494 05:04:31,980 --> 05:04:34,080 event event handler 9495 05:04:34,080 --> 05:04:36,900 let's call this just on cut 9496 05:04:36,900 --> 05:04:39,180 okay and then down here when we have our 9497 05:04:39,180 --> 05:04:41,218 cutting progress so we cut and let's 9498 05:04:41,218 --> 05:04:44,180 just invoke this event 9499 05:04:44,638 --> 05:04:47,040 okay that's it super simple 9500 05:04:47,040 --> 05:04:48,780 so now on The Cutting counter visual 9501 05:04:48,780 --> 05:04:50,700 let's go into the cutting counter and 9502 05:04:50,700 --> 05:04:52,620 into the uncut event let's listen to 9503 05:04:52,620 --> 05:04:54,958 this and we're going to set the trigger 9504 05:04:54,958 --> 05:04:57,180 example like this so get rid of the 9505 05:04:57,180 --> 05:05:00,060 container counter like this 9506 05:05:00,060 --> 05:05:02,760 okay there you go a very simple script 9507 05:05:02,760 --> 05:05:04,378 so now here back in the scene view 9508 05:05:04,378 --> 05:05:07,200 inside the container counter prefab 9509 05:05:07,200 --> 05:05:09,000 let's just go inside the visual let's 9510 05:05:09,000 --> 05:05:10,680 attach The Cutting counter visual just 9511 05:05:10,680 --> 05:05:12,000 need to drag The Cutting counter 9512 05:05:12,000 --> 05:05:14,218 reference and that's it let's exit the 9513 05:05:14,218 --> 05:05:16,980 prefab save it and let's play okay so 9514 05:05:16,980 --> 05:05:18,840 now let's pick up a cabbage go up there 9515 05:05:18,840 --> 05:05:21,060 drop it and aren't interact and if there 9516 05:05:21,060 --> 05:05:23,340 you go we've got a nice little animation 9517 05:05:23,340 --> 05:05:26,160 all right awesome so I can drop things I 9518 05:05:26,160 --> 05:05:27,958 can cut them and everything works 9519 05:05:27,958 --> 05:05:28,980 perfectly 9520 05:05:28,980 --> 05:05:30,540 all right 9521 05:05:30,540 --> 05:05:32,820 so here we added a cutting progress to 9522 05:05:32,820 --> 05:05:35,040 our cutting counter and we also learned 9523 05:05:35,040 --> 05:05:36,540 about yet another very useful ENT 9524 05:05:36,540 --> 05:05:39,240 feature called World canvases 9525 05:05:39,240 --> 05:05:40,860 and at the same time you might have also 9526 05:05:40,860 --> 05:05:42,540 noticed that the canvas is looking at 9527 05:05:42,540 --> 05:05:43,798 the camera in kind of a weird way 9528 05:05:43,798 --> 05:05:45,860 basically just pointing straight forward 9529 05:05:45,860 --> 05:05:48,360 this can sometimes make it difficult to 9530 05:05:48,360 --> 05:05:50,160 see so let's work on that in the next 9531 05:05:50,160 --> 05:05:51,600 lecture 9532 05:05:51,600 --> 05:05:53,520 hello and welcome I'm your code monkey 9533 05:05:53,520 --> 05:05:55,798 in this lecture we're going to build a 9534 05:05:55,798 --> 05:05:57,900 very simple but very useful script to 9535 05:05:57,900 --> 05:05:59,280 make an object look straight at the 9536 05:05:59,280 --> 05:06:01,320 camera with various options 9537 05:06:01,320 --> 05:06:03,420 okay so we previously made the cutting 9538 05:06:03,420 --> 05:06:05,040 counter and when I placed something yep 9539 05:06:05,040 --> 05:06:07,020 there's a nice progress bar 9540 05:06:07,020 --> 05:06:09,298 so now that this is working let's do one 9541 05:06:09,298 --> 05:06:11,700 more thing right now look at how the bar 9542 05:06:11,700 --> 05:06:13,620 is oriented it's looking quite a bit 9543 05:06:13,620 --> 05:06:15,298 slanted that's because we have a 9544 05:06:15,298 --> 05:06:16,798 perspective camera and it's looking from 9545 05:06:16,798 --> 05:06:17,940 top down 9546 05:06:17,940 --> 05:06:19,440 now this is one of those things that is 9547 05:06:19,440 --> 05:06:20,878 kind of personal preference so maybe you 9548 05:06:20,878 --> 05:06:22,620 don't like it just like this 9549 05:06:22,620 --> 05:06:24,240 but a lot of the times you want these 9550 05:06:24,240 --> 05:06:26,040 World UI elements to face the camera 9551 05:06:26,040 --> 05:06:28,020 just like a regular UI 9552 05:06:28,020 --> 05:06:29,820 one example of this problem is for 9553 05:06:29,820 --> 05:06:31,500 example let me pick up the cutting 9554 05:06:31,500 --> 05:06:33,600 counter duplicated and let's put one 9555 05:06:33,600 --> 05:06:37,740 down here so rotate it upwards 9556 05:06:37,740 --> 05:06:41,820 okay let's put it on 4.50 and minus 5. 9557 05:06:41,820 --> 05:06:43,860 now if I place something on there and I 9558 05:06:43,860 --> 05:06:45,480 cut it yep like that the bar is Now 9559 05:06:45,480 --> 05:06:47,940 inverted so let's make a simple script 9560 05:06:47,940 --> 05:06:49,860 to solve this problem 9561 05:06:49,860 --> 05:06:51,958 let's go into our scripts create a new 9562 05:06:51,958 --> 05:06:55,620 c-sharp script call it look at camera 9563 05:06:55,620 --> 05:06:57,600 let's go on to The Cutting counter 9564 05:06:57,600 --> 05:06:59,878 prefab let's open it up go inside on the 9565 05:06:59,878 --> 05:07:01,798 progress bar let's attach the script so 9566 05:07:01,798 --> 05:07:03,600 the unlocked camera okay now let's open 9567 05:07:03,600 --> 05:07:06,360 so from here let's use an interesting 9568 05:07:06,360 --> 05:07:08,940 function so let's use a private void 9569 05:07:08,940 --> 05:07:11,520 late update so not update we have the 9570 05:07:11,520 --> 05:07:14,100 late update so if this is the first time 9571 05:07:14,100 --> 05:07:15,900 you're hearing about this like the name 9572 05:07:15,900 --> 05:07:17,638 flies this one is going to run after the 9573 05:07:17,638 --> 05:07:20,340 regular update so every single update 9574 05:07:20,340 --> 05:07:22,138 and all the objects is going to run and 9575 05:07:22,138 --> 05:07:24,240 then on the late updates so kind of like 9576 05:07:24,240 --> 05:07:25,860 you've got awake and start you have 9577 05:07:25,860 --> 05:07:27,958 update and late update why this is 9578 05:07:27,958 --> 05:07:30,420 useful specifically for this script is 9579 05:07:30,420 --> 05:07:32,040 because for this element you really want 9580 05:07:32,040 --> 05:07:34,200 us to run the orienting logic you want 9581 05:07:34,200 --> 05:07:35,940 that to be done after whatever that 9582 05:07:35,940 --> 05:07:38,040 object does in the update in this case 9583 05:07:38,040 --> 05:07:39,660 this object will never move so it's not 9584 05:07:39,660 --> 05:07:40,798 really an issue 9585 05:07:40,798 --> 05:07:42,718 but for example if you had some kind of 9586 05:07:42,718 --> 05:07:44,638 moving vehicle with a warm cameras on 9587 05:07:44,638 --> 05:07:46,440 top if you have that you would want to 9588 05:07:46,440 --> 05:07:47,940 set the Warren canvas and location to 9589 05:07:47,940 --> 05:07:49,980 unlock the camera after the vehicle had 9590 05:07:49,980 --> 05:07:52,138 moved otherwise the canvas would not 9591 05:07:52,138 --> 05:07:54,298 look perfect so anyways because that 9592 05:07:54,298 --> 05:07:56,940 here we're doing on late update and now 9593 05:07:56,940 --> 05:07:58,740 we can just look straight the camera so 9594 05:07:58,740 --> 05:08:02,718 we can just do transform dot lookup 9595 05:08:03,540 --> 05:08:05,218 and for the Target passing the camera 9596 05:08:05,218 --> 05:08:07,500 Dot main.transform 9597 05:08:07,500 --> 05:08:09,540 this function makes this transform look 9598 05:08:09,540 --> 05:08:11,280 at another transform or another point so 9599 05:08:11,280 --> 05:08:12,480 this will make it look straight at the 9600 05:08:12,480 --> 05:08:13,200 camera 9601 05:08:13,200 --> 05:08:15,600 also by the way one quick note here in 9602 05:08:15,600 --> 05:08:17,160 some other tutorials you might see 9603 05:08:17,160 --> 05:08:18,780 people telling you not to use 9604 05:08:18,780 --> 05:08:21,120 camera.main the reason for that is 9605 05:08:21,120 --> 05:08:22,920 because this field did not used to be 9606 05:08:22,920 --> 05:08:25,138 cached so every time you use this it 9607 05:08:25,138 --> 05:08:26,580 would cycle through every single game 9608 05:08:26,580 --> 05:08:28,260 object in the scene until it found the 9609 05:08:28,260 --> 05:08:30,298 main camera so that was obviously really 9610 05:08:30,298 --> 05:08:32,340 bad for performance but nowadays this 9611 05:08:32,340 --> 05:08:33,958 field is now cached by default on the 9612 05:08:33,958 --> 05:08:35,878 ENT backend so you no longer need to 9613 05:08:35,878 --> 05:08:37,740 Cache it yourself accessing it directly 9614 05:08:37,740 --> 05:08:39,540 just like this is now fine 9615 05:08:39,540 --> 05:08:41,940 okay so with this let's test 9616 05:08:41,940 --> 05:08:44,160 just make sure to save the prefab and 9617 05:08:44,160 --> 05:08:45,780 let's hit on play 9618 05:08:45,780 --> 05:08:47,878 let's go ahead pick up a cabbage put it 9619 05:08:47,878 --> 05:08:49,440 up there and if they're young look at 9620 05:08:49,440 --> 05:08:50,760 that how it's looking straight at the 9621 05:08:50,760 --> 05:08:52,860 camera and for this one down here same 9622 05:08:52,860 --> 05:08:54,600 thing cut it any up there you go both of 9623 05:08:54,600 --> 05:08:56,580 them are looking straight at the camera 9624 05:08:56,580 --> 05:08:58,920 okay so that's great 9625 05:08:58,920 --> 05:09:00,540 you can also see exactly what it's doing 9626 05:09:00,540 --> 05:09:02,580 if we try to move the camera again we're 9627 05:09:02,580 --> 05:09:04,020 using cinemachine so let's move the 9628 05:09:04,020 --> 05:09:05,458 virtual camera 9629 05:09:05,458 --> 05:09:07,320 so over here if I just play around with 9630 05:09:07,320 --> 05:09:09,958 the position.x look at that look how as 9631 05:09:09,958 --> 05:09:11,940 I move the camera yep the objects are 9632 05:09:11,940 --> 05:09:13,740 perfectly looking straight at the camera 9633 05:09:13,740 --> 05:09:16,020 so that's great that's what we want but 9634 05:09:16,020 --> 05:09:18,120 also you might notice one thing notice 9635 05:09:18,120 --> 05:09:20,520 under the bars are actually inverted 9636 05:09:20,520 --> 05:09:22,080 instead of going left to right they're 9637 05:09:22,080 --> 05:09:23,700 actually going right and left basically 9638 05:09:23,700 --> 05:09:25,440 this has to do with how the canvas by 9639 05:09:25,440 --> 05:09:26,820 default assumes you are essentially 9640 05:09:26,820 --> 05:09:28,500 going to look at it from behind instead 9641 05:09:28,500 --> 05:09:30,900 of looking forward so that is why when 9642 05:09:30,900 --> 05:09:32,400 this game object is pointing straight at 9643 05:09:32,400 --> 05:09:34,500 the camera it's essentially inverted 9644 05:09:34,500 --> 05:09:36,120 so to sum this is actually quite simple 9645 05:09:36,120 --> 05:09:37,920 we basically just need to look in the 9646 05:09:37,920 --> 05:09:39,660 exact opposite direction 9647 05:09:39,660 --> 05:09:41,520 but at the same time sometimes we might 9648 05:09:41,520 --> 05:09:43,080 want this exact Behavior having 9649 05:09:43,080 --> 05:09:44,280 something looks right at the camera 9650 05:09:44,280 --> 05:09:46,020 maybe we do want it to be inverted 9651 05:09:46,020 --> 05:09:48,540 sometimes so for that let's make a nice 9652 05:09:48,540 --> 05:09:50,340 complete script with all of our possible 9653 05:09:50,340 --> 05:09:52,680 options and for the finding options it's 9654 05:09:52,680 --> 05:09:54,600 also an excellent way to learn about one 9655 05:09:54,600 --> 05:09:57,660 more thing which are c-sharp enums enums 9656 05:09:57,660 --> 05:09:59,700 are an enumeration meaning a fixed set 9657 05:09:59,700 --> 05:10:01,020 of options that you can have of 9658 05:10:01,020 --> 05:10:01,980 something 9659 05:10:01,980 --> 05:10:03,660 so these are really useful when you have 9660 05:10:03,660 --> 05:10:05,760 a fixed set of something like for 9661 05:10:05,760 --> 05:10:07,560 example maybe a fixed number of options 9662 05:10:07,560 --> 05:10:10,020 so for example up here let's make it 9663 05:10:10,020 --> 05:10:12,540 private make it an enum and let's call 9664 05:10:12,540 --> 05:10:14,878 it mode and then inside we can Define 9665 05:10:14,878 --> 05:10:17,340 all of our options so let's say we have 9666 05:10:17,340 --> 05:10:19,260 the regular look at it and then look at 9667 05:10:19,260 --> 05:10:20,638 inverted 9668 05:10:20,638 --> 05:10:22,980 okay so we have these two options in our 9669 05:10:22,980 --> 05:10:25,138 enum now let's do a field of this type 9670 05:10:25,138 --> 05:10:26,878 and expose it in the editor 9671 05:10:26,878 --> 05:10:29,218 so let's make a serialized film private 9672 05:10:29,218 --> 05:10:31,980 of type mode and call it mode 9673 05:10:31,980 --> 05:10:34,020 okay let's save this and look what this 9674 05:10:34,020 --> 05:10:36,420 looks like in the editor and if we go 9675 05:10:36,420 --> 05:10:38,340 inside the cutting counter and we'll 9676 05:10:38,340 --> 05:10:39,840 look at the progress bar 9677 05:10:39,840 --> 05:10:41,638 even look at that the mode shows up and 9678 05:10:41,638 --> 05:10:43,500 it shows up as a really nice drop down 9679 05:10:43,500 --> 05:10:45,958 menu so since we have a limited number 9680 05:10:45,958 --> 05:10:47,580 of options we've got a really nice menu 9681 05:10:47,580 --> 05:10:49,260 where we can choose each round if you 9682 05:10:49,260 --> 05:10:50,100 want 9683 05:10:50,100 --> 05:10:51,780 so that's really awesome that's one of 9684 05:10:51,780 --> 05:10:53,638 the benefits of enums they are really 9685 05:10:53,638 --> 05:10:55,980 easy to use over here in the editor 9686 05:10:55,980 --> 05:10:57,600 now back in the code here and let's 9687 05:10:57,600 --> 05:10:59,160 decide which one to use 9688 05:10:59,160 --> 05:11:01,260 so on The Late update let me just do a 9689 05:11:01,260 --> 05:11:04,320 switch on our mode in case we are on the 9690 05:11:04,320 --> 05:11:06,120 regular look at mode then let's see 9691 05:11:06,120 --> 05:11:08,400 exactly this let's simply look in in 9692 05:11:08,400 --> 05:11:11,458 case we are on the look at invertent 9693 05:11:11,458 --> 05:11:12,958 for this we just want to look at the 9694 05:11:12,958 --> 05:11:14,218 inverse position so that's actually 9695 05:11:14,218 --> 05:11:16,440 pretty easy we just calculate the 9696 05:11:16,440 --> 05:11:18,360 direction Vector from the camera to this 9697 05:11:18,360 --> 05:11:19,200 object 9698 05:11:19,200 --> 05:11:23,218 so a vector 3 call it deer from camera 9699 05:11:23,218 --> 05:11:25,200 and to get direction from the camera we 9700 05:11:25,200 --> 05:11:26,458 start from this object so this 9701 05:11:26,458 --> 05:11:28,560 transformed that position subtract the 9702 05:11:28,560 --> 05:11:31,560 camera dot main transform position 9703 05:11:31,560 --> 05:11:33,900 so this gives us the direction pointing 9704 05:11:33,900 --> 05:11:35,878 from the camera and then just to 9705 05:11:35,878 --> 05:11:38,100 transform down look at 9706 05:11:38,100 --> 05:11:39,480 and instead of looking at the camera 9707 05:11:39,480 --> 05:11:41,160 let's look at the opposite position so 9708 05:11:41,160 --> 05:11:42,958 let's look at transform that position so 9709 05:11:42,958 --> 05:11:44,820 our current position points the 9710 05:11:44,820 --> 05:11:46,138 direction from the camera so we're going 9711 05:11:46,138 --> 05:11:47,638 to be looking at the exact opposite 9712 05:11:47,638 --> 05:11:48,540 point 9713 05:11:48,540 --> 05:11:50,940 okay so that's it let's test 9714 05:11:50,940 --> 05:11:52,740 and right now by default we have the 9715 05:11:52,740 --> 05:11:55,320 regular look at so let's just see it 9716 05:11:55,320 --> 05:11:57,480 let's just play some objects okay so 9717 05:11:57,480 --> 05:11:59,638 right now it's still inverting 9718 05:11:59,638 --> 05:12:01,440 and something real nice is you can play 9719 05:12:01,440 --> 05:12:03,180 around the enums even as the game is 9720 05:12:03,180 --> 05:12:04,798 running so let's go inside the cutting 9721 05:12:04,798 --> 05:12:06,900 counter on the progress bar UI for this 9722 05:12:06,900 --> 05:12:08,218 one let's swap from Lookout to unlock 9723 05:12:08,218 --> 05:12:10,320 inverten anything like that that one is 9724 05:12:10,320 --> 05:12:11,760 now looking perfectly 9725 05:12:11,760 --> 05:12:13,740 so this one is using Lookout and this 9726 05:12:13,740 --> 05:12:15,600 one using look at inverted 9727 05:12:15,600 --> 05:12:17,760 okay great it's all working 9728 05:12:17,760 --> 05:12:19,320 however yet another thing that is all 9729 05:12:19,320 --> 05:12:21,060 about personal preference 9730 05:12:21,060 --> 05:12:23,760 note how the visual has a slight slant 9731 05:12:23,760 --> 05:12:25,980 this is due to how the visual section 9732 05:12:25,980 --> 05:12:27,718 looking directly at the center of the 9733 05:12:27,718 --> 05:12:28,920 camera 9734 05:12:28,920 --> 05:12:30,540 so you can really see it if I move the 9735 05:12:30,540 --> 05:12:32,760 camera left and right how it Slants 9736 05:12:32,760 --> 05:12:34,920 going left or going right 9737 05:12:34,920 --> 05:12:36,718 again the Zone personal preference it's 9738 05:12:36,718 --> 05:12:38,458 just a visual so maybe you do want this 9739 05:12:38,458 --> 05:12:40,980 look but let's see another method so 9740 05:12:40,980 --> 05:12:42,420 over here in our modes let's add two 9741 05:12:42,420 --> 05:12:44,878 more let's add camera forward and Camera 9742 05:12:44,878 --> 05:12:47,100 forward inverted 9743 05:12:47,100 --> 05:12:49,378 and then down here on our late update 9744 05:12:49,378 --> 05:12:51,240 let's add those so the camera forward 9745 05:12:51,240 --> 05:12:53,400 and then we have the camera forward 9746 05:12:53,400 --> 05:12:54,900 inversion 9747 05:12:54,900 --> 05:12:56,458 so for this one for the camera forward 9748 05:12:56,458 --> 05:12:57,840 super simple let's just take this 9749 05:12:57,840 --> 05:12:59,638 transform use the forward which again 9750 05:12:59,638 --> 05:13:01,798 you can get or you can set it and let's 9751 05:13:01,798 --> 05:13:03,420 set it to the exact same one as the 9752 05:13:03,420 --> 05:13:06,480 camera Dot main.transform.4 9753 05:13:06,480 --> 05:13:08,520 and for the inverting example the same 9754 05:13:08,520 --> 05:13:11,760 thing X7 set of four do we do minus four 9755 05:13:11,760 --> 05:13:14,160 okay so let's see what this looks like 9756 05:13:14,160 --> 05:13:15,958 okay so here's the game with both 9757 05:13:15,958 --> 05:13:17,940 counters they're both currently using 9758 05:13:17,940 --> 05:13:19,980 the unlockit mode now if we put a look 9759 05:13:19,980 --> 05:13:21,480 at inverting yep that one goes left to 9760 05:13:21,480 --> 05:13:23,280 right okay great now if I put camera 4 9761 05:13:23,280 --> 05:13:25,260 in give a look at that now that one is 9762 05:13:25,260 --> 05:13:26,458 perfectly straight 9763 05:13:26,458 --> 05:13:28,560 so even as I move the virtual camera on 9764 05:13:28,560 --> 05:13:30,298 left and right look how that one is 9765 05:13:30,298 --> 05:13:32,160 always perfectly facing the camera as if 9766 05:13:32,160 --> 05:13:34,860 it was a regular UI owned 9767 05:13:34,860 --> 05:13:36,480 and for the inverter does the exact same 9768 05:13:36,480 --> 05:13:38,820 thing but invert and so just like that 9769 05:13:38,820 --> 05:13:40,798 so that's it these are the four modes 9770 05:13:40,798 --> 05:13:42,600 again these are all just visual elements 9771 05:13:42,600 --> 05:13:44,820 so pick whatever you prefer for me I'm 9772 05:13:44,820 --> 05:13:46,440 going to be using this one the camera.4 9773 05:13:46,440 --> 05:13:47,638 so that everything is perfectly 9774 05:13:47,638 --> 05:13:49,920 horizontal so I'm just going to make 9775 05:13:49,920 --> 05:13:52,138 sure to go inside the prefab and on the 9776 05:13:52,138 --> 05:13:53,878 prefab itself modified and set it as 9777 05:13:53,878 --> 05:13:55,560 camera.4 9778 05:13:55,560 --> 05:13:57,660 and now if I add the cheese there yep 9779 05:13:57,660 --> 05:13:59,520 looks great and if I had a cabbage here 9780 05:13:59,520 --> 05:14:01,680 and yep it also looks right 9781 05:14:01,680 --> 05:14:03,958 all right so here we created a really 9782 05:14:03,958 --> 05:14:05,940 nice useful generic script to make an 9783 05:14:05,940 --> 05:14:07,500 object look straight at the camera in 9784 05:14:07,500 --> 05:14:09,718 various ways note how this one has 9785 05:14:09,718 --> 05:14:11,638 nothing to do with canvas or a progress 9786 05:14:11,638 --> 05:14:13,920 bar or anything it's really a generic 9787 05:14:13,920 --> 05:14:15,360 script to look at the camera so you can 9788 05:14:15,360 --> 05:14:17,160 apply this to anything where you want it 9789 05:14:17,160 --> 05:14:18,360 to look at the camera 9790 05:14:18,360 --> 05:14:20,520 okay so with that the cutting counter is 9791 05:14:20,520 --> 05:14:21,660 fully done 9792 05:14:21,660 --> 05:14:23,700 now let's handle the trash counter in 9793 05:14:23,700 --> 05:14:25,320 the next lecture 9794 05:14:25,320 --> 05:14:27,900 hello and welcome I'm your code monkey 9795 05:14:27,900 --> 05:14:29,820 in this lecture let's create the trash 9796 05:14:29,820 --> 05:14:31,680 counter this one is actually pretty 9797 05:14:31,680 --> 05:14:33,240 simple it's how we're going to drop 9798 05:14:33,240 --> 05:14:35,580 something and just destroy it okay so 9799 05:14:35,580 --> 05:14:37,138 making the trash counter is going to be 9800 05:14:37,138 --> 05:14:39,718 super super easy once again going to be 9801 05:14:39,718 --> 05:14:41,458 another great practical example of the 9802 05:14:41,458 --> 05:14:43,020 power of writing good clean code and 9803 05:14:43,020 --> 05:14:44,700 having good organization in your project 9804 05:14:44,700 --> 05:14:46,980 so let's do the same thing that we've 9805 05:14:46,980 --> 05:14:48,780 already done a bunch of times so first 9806 05:14:48,780 --> 05:14:51,000 of all let's make the prefab variant so 9807 05:14:51,000 --> 05:14:52,620 let's right click on the base counter 9808 05:14:52,620 --> 05:14:54,600 and create a brand new prefab variant 9809 05:14:54,600 --> 05:14:58,080 come with the trash counter 9810 05:14:58,080 --> 05:15:00,958 okay let's go inside and first of all 9811 05:15:00,958 --> 05:15:03,000 let's drag the visual so find the visual 9812 05:15:03,000 --> 05:15:05,820 prefab on the trash counter okay then 9813 05:15:05,820 --> 05:15:07,980 let's duplicate it to make the selecting 9814 05:15:07,980 --> 05:15:10,920 so let's rename this to selected 9815 05:15:10,920 --> 05:15:13,740 let's add the selected counter visual 9816 05:15:13,740 --> 05:15:17,580 let's add the visual inside of it and on 9817 05:15:17,580 --> 05:15:20,360 the visual let's select the other 9818 05:15:20,360 --> 05:15:23,040 material so the counter selected and 9819 05:15:23,040 --> 05:15:25,620 finally on the selected put it one 9820 05:15:25,620 --> 05:15:28,560 percent bigger 1.01 9821 05:15:28,560 --> 05:15:31,740 and start off with visual disabled okay 9822 05:15:31,740 --> 05:15:33,600 so that's the basics just like we've 9823 05:15:33,600 --> 05:15:35,638 already done so many times now let's 9824 05:15:35,638 --> 05:15:37,680 make this script to run this so let's 9825 05:15:37,680 --> 05:15:39,360 frequently create a new c-sharp script 9826 05:15:39,360 --> 05:15:42,000 call it the trash counter 9827 05:15:42,000 --> 05:15:43,378 and by the way here we're already 9828 05:15:43,378 --> 05:15:44,940 starting to have quite a bunch of 9829 05:15:44,940 --> 05:15:46,500 scripts so we should probably organize 9830 05:15:46,500 --> 05:15:49,320 the scripts folder so let's make a new 9831 05:15:49,320 --> 05:15:52,680 folder let's come with counters 9832 05:15:52,680 --> 05:15:55,320 and let's make another one and call it 9833 05:15:55,320 --> 05:15:57,840 scriptable objects 9834 05:15:57,840 --> 05:15:59,580 so on the counters let's drag the base 9835 05:15:59,580 --> 05:16:01,920 counter clear counter the container the 9836 05:16:01,920 --> 05:16:03,540 container visual The Cutting The Cutting 9837 05:16:03,540 --> 05:16:06,180 visual then down here the trash counter 9838 05:16:06,180 --> 05:16:08,100 okay let's drag them all onto the 9839 05:16:08,100 --> 05:16:10,138 counters folder and on these critical 9840 05:16:10,138 --> 05:16:12,060 objects let's put the cutting recipe and 9841 05:16:12,060 --> 05:16:14,400 the kitchen object as so okay now our 9842 05:16:14,400 --> 05:16:16,260 phone there is a bit more organized so 9843 05:16:16,260 --> 05:16:18,298 let's open up the trash counter 9844 05:16:18,298 --> 05:16:20,820 and over here as usual let's begin by 9845 05:16:20,820 --> 05:16:24,298 extending the base counter okay great 9846 05:16:24,298 --> 05:16:25,920 then let's implement the regular 9847 05:16:25,920 --> 05:16:29,700 interaction so override the interact 9848 05:16:29,700 --> 05:16:31,378 and on this one again it's going to be 9849 05:16:31,378 --> 05:16:33,540 super simple we just check if the player 9850 05:16:33,540 --> 05:16:34,980 is holding something and if so we 9851 05:16:34,980 --> 05:16:37,560 destroy it so just check if player that 9852 05:16:37,560 --> 05:16:39,900 has kitchen object so if the player is 9853 05:16:39,900 --> 05:16:41,820 holding something go into the player get 9854 05:16:41,820 --> 05:16:43,500 the kitchen object the player is holding 9855 05:16:43,500 --> 05:16:46,980 and simply call destroy itself 9856 05:16:46,980 --> 05:16:49,440 and that's it it's this simple back in 9857 05:16:49,440 --> 05:16:51,180 the editorial let's just attach a script 9858 05:16:51,180 --> 05:16:53,340 let's make sure to drag the countertop 9859 05:16:53,340 --> 05:16:55,500 Point reference and on the selected drag 9860 05:16:55,500 --> 05:16:57,360 the base counter reference 9861 05:16:57,360 --> 05:16:59,340 okay with this it should be working so 9862 05:16:59,340 --> 05:17:01,020 let's exit the scene let's save the 9863 05:17:01,020 --> 05:17:03,298 prefab and let's drag it over here onto 9864 05:17:03,298 --> 05:17:05,100 our scene so let's drag the trash 9865 05:17:05,100 --> 05:17:07,560 counter and put it maybe somewhere over 9866 05:17:07,560 --> 05:17:08,940 here on the corner 9867 05:17:08,940 --> 05:17:11,820 so let's put it here on an X of 7 y 0 9868 05:17:11,820 --> 05:17:14,700 and -3.5 9869 05:17:14,700 --> 05:17:16,440 then let's also fill out these spots 9870 05:17:16,440 --> 05:17:18,718 down here so let's duplicate the clear 9871 05:17:18,718 --> 05:17:21,180 counter put one in there put another one 9872 05:17:21,180 --> 05:17:22,620 in there 9873 05:17:22,620 --> 05:17:24,660 let's put another one on the side and 9874 05:17:24,660 --> 05:17:26,218 for the crash counter and let's align it 9875 05:17:26,218 --> 05:17:28,378 so let's put it a bit more to the side 9876 05:17:28,378 --> 05:17:31,378 so on 7.5 okay great and let's put it 9877 05:17:31,378 --> 05:17:33,780 inside the counters and now we can test 9878 05:17:33,780 --> 05:17:35,580 okay so let's see if we can interact 9879 05:17:35,580 --> 05:17:37,440 with it and yep as I approach yep I do 9880 05:17:37,440 --> 05:17:39,180 see it highlighted okay great and if I 9881 05:17:39,180 --> 05:17:40,680 interact obviously nothing happens since 9882 05:17:40,680 --> 05:17:42,900 the player isn't holding anything now if 9883 05:17:42,900 --> 05:17:44,280 I pick something up let's say a tomato 9884 05:17:44,280 --> 05:17:46,200 and I don't want this tomato so I want 9885 05:17:46,200 --> 05:17:47,878 to trash it and if there you go it does 9886 05:17:47,878 --> 05:17:50,520 get trashed all right awesome so this is 9887 05:17:50,520 --> 05:17:52,920 literally it like I said this is once 9888 05:17:52,920 --> 05:17:54,600 again another excellent example of the 9889 05:17:54,600 --> 05:17:56,638 power of writing good clean code this 9890 05:17:56,638 --> 05:17:58,500 was super simple to implement because we 9891 05:17:58,500 --> 05:18:00,298 have a really nice structure for how all 9892 05:18:00,298 --> 05:18:02,700 of our Counters work also because our 9893 05:18:02,700 --> 05:18:04,560 interaction system is very well built 9894 05:18:04,560 --> 05:18:06,660 also because the kitchen object system 9895 05:18:06,660 --> 05:18:09,000 is very well made it's because of all of 9896 05:18:09,000 --> 05:18:10,920 that great very clean code that we were 9897 05:18:10,920 --> 05:18:12,780 able to implement a brand new counter in 9898 05:18:12,780 --> 05:18:14,820 literally about 60 seconds 9899 05:18:14,820 --> 05:18:16,798 so once again I hope that by following 9900 05:18:16,798 --> 05:18:18,360 this course you know understand why I'm 9901 05:18:18,360 --> 05:18:19,560 always talking about the importance of 9902 05:18:19,560 --> 05:18:21,600 writing good clean code it's exactly 9903 05:18:21,600 --> 05:18:23,400 because this if you write your code 9904 05:18:23,400 --> 05:18:25,138 correctly it makes developing the game 9905 05:18:25,138 --> 05:18:27,600 so much easier at first it might seem 9906 05:18:27,600 --> 05:18:29,040 like the quick and dirty approach is 9907 05:18:29,040 --> 05:18:30,718 faster and usually in the beginning it 9908 05:18:30,718 --> 05:18:32,700 is faster but as soon as you add some 9909 05:18:32,700 --> 05:18:34,440 complexity the quick and dirty approach 9910 05:18:34,440 --> 05:18:36,660 suddenly won't scale whereas the 9911 05:18:36,660 --> 05:18:38,340 well-built clean code approach this one 9912 05:18:38,340 --> 05:18:40,620 will continue scaling very well so here 9913 05:18:40,620 --> 05:18:42,718 we have a fully functional trash bin so 9914 05:18:42,718 --> 05:18:45,240 we can dispose of unwanted objects next 9915 05:18:45,240 --> 05:18:47,400 let's build a much much more complex 9916 05:18:47,400 --> 05:18:49,798 Hunter let's build a stove counter which 9917 05:18:49,798 --> 05:18:51,298 also requires building a really nice 9918 05:18:51,298 --> 05:18:53,700 State machine so let's do that in the 9919 05:18:53,700 --> 05:18:55,080 next lecture 9920 05:18:55,080 --> 05:18:56,878 hey again another quick intermission 9921 05:18:56,878 --> 05:18:58,798 you're past the halfway point so 9922 05:18:58,798 --> 05:19:01,138 congrats again by now I really hope 9923 05:19:01,138 --> 05:19:02,580 you've already learned a ton from the 9924 05:19:02,580 --> 05:19:04,200 course we've already covered lots of 9925 05:19:04,200 --> 05:19:06,420 topics and built a ton of systems I hope 9926 05:19:06,420 --> 05:19:07,740 you've been following the website as you 9927 05:19:07,740 --> 05:19:08,940 go through the lectures and I hope 9928 05:19:08,940 --> 05:19:10,320 reading the frequently asked questions 9929 05:19:10,320 --> 05:19:12,600 that I sent you in some way let me know 9930 05:19:12,600 --> 05:19:13,740 in the comments how you've used the 9931 05:19:13,740 --> 05:19:16,620 course website did you just read the FAQ 9932 05:19:16,620 --> 05:19:18,120 or did you also download some project 9933 05:19:18,120 --> 05:19:20,520 files let me know I'm curious to know if 9934 05:19:20,520 --> 05:19:22,440 you enjoy my teaching song also look at 9935 05:19:22,440 --> 05:19:23,940 my other courses after finishing this 9936 05:19:23,940 --> 05:19:25,980 one especially the turn-based strategy 9937 05:19:25,980 --> 05:19:27,360 course that one is an excellent 9938 05:19:27,360 --> 05:19:29,280 follow-up for this one okay there's 9939 05:19:29,280 --> 05:19:30,718 still quite a bit more for us to build 9940 05:19:30,718 --> 05:19:32,638 and learn so let's continue in the next 9941 05:19:32,638 --> 05:19:33,958 lecture 9942 05:19:33,958 --> 05:19:36,060 hello and welcome I'm your code monkey 9943 05:19:36,060 --> 05:19:38,100 in this lecture we're going to build the 9944 05:19:38,100 --> 05:19:40,500 stove counter so we want to place some 9945 05:19:40,500 --> 05:19:42,540 uncooked meat then we wait for a bit for 9946 05:19:42,540 --> 05:19:44,580 it to be cooked however if we weigh too 9947 05:19:44,580 --> 05:19:46,200 much it's going to get burnt so let's 9948 05:19:46,200 --> 05:19:48,180 Implement that alright so as usual let's 9949 05:19:48,180 --> 05:19:49,920 first begin by making our counter so 9950 05:19:49,920 --> 05:19:51,600 let's go inside the prefabs the counters 9951 05:19:51,600 --> 05:19:53,160 let's right click on the base counter 9952 05:19:53,160 --> 05:19:55,500 and create new prefab variant call this 9953 05:19:55,500 --> 05:19:58,020 the stove counter and as usual let's go 9954 05:19:58,020 --> 05:20:00,780 inside of it let's find the visual so 9955 05:20:00,780 --> 05:20:02,580 inside the prefab visuals it counters 9956 05:20:02,580 --> 05:20:04,680 visuals here is the stove counter so 9957 05:20:04,680 --> 05:20:07,020 let's drag it then let's duplicate this 9958 05:20:07,020 --> 05:20:09,900 rename this one the selecton let's set 9959 05:20:09,900 --> 05:20:11,458 the component the selected counter 9960 05:20:11,458 --> 05:20:12,540 visual 9961 05:20:12,540 --> 05:20:15,600 then let's go inside on all of these and 9962 05:20:15,600 --> 05:20:17,280 by the way this visual actually has some 9963 05:20:17,280 --> 05:20:18,360 nice visuals that we're going to 9964 05:20:18,360 --> 05:20:19,798 implement in a little bit but for the 9965 05:20:19,798 --> 05:20:21,660 selected we really just want the static 9966 05:20:21,660 --> 05:20:23,400 objects so let's pick up all of these 9967 05:20:23,400 --> 05:20:24,900 and let's select the counter slide 9968 05:20:24,900 --> 05:20:27,298 visual okay nice and white then let's 9969 05:20:27,298 --> 05:20:28,980 lock over here the parents so I can 9970 05:20:28,980 --> 05:20:30,718 select all of these and drag all of them 9971 05:20:30,718 --> 05:20:32,520 okay great and start off with all of 9972 05:20:32,520 --> 05:20:34,680 them disabled okay so that's the basic 9973 05:20:34,680 --> 05:20:36,060 setup as usual 9974 05:20:36,060 --> 05:20:38,340 just for the Counterpoint 9975 05:20:38,340 --> 05:20:40,560 since this one has a nice little sub on 9976 05:20:40,560 --> 05:20:42,840 top let's lift it up by a little bit so 9977 05:20:42,840 --> 05:20:45,600 put it on a y of 1.456 9978 05:20:45,600 --> 05:20:48,298 okay that looks pretty good just move it 9979 05:20:48,298 --> 05:20:50,700 a little bit to the center okay great 9980 05:20:50,700 --> 05:20:52,920 so now let's make our script so let's go 9981 05:20:52,920 --> 05:20:54,718 inside our scripts folder we've got our 9982 05:20:54,718 --> 05:20:56,400 counters so in here let's create the 9983 05:20:56,400 --> 05:20:58,260 brand new c-sharp script for the stove 9984 05:20:58,260 --> 05:21:01,200 counter let's wait for it to compile 9985 05:21:01,200 --> 05:21:04,080 let's attach the script and open okay so 9986 05:21:04,080 --> 05:21:06,120 here as usual let's extend the base 9987 05:21:06,120 --> 05:21:07,440 counter 9988 05:21:07,440 --> 05:21:09,298 now like I said the going for this one 9989 05:21:09,298 --> 05:21:11,280 is to be able to cook our meat and for 9990 05:21:11,280 --> 05:21:13,500 that it's going to be based on a timer 9991 05:21:13,500 --> 05:21:15,180 and to actually cook the meat we're 9992 05:21:15,180 --> 05:21:16,798 going to need to know which one is the 9993 05:21:16,798 --> 05:21:18,420 uncooked meat type and which one is the 9994 05:21:18,420 --> 05:21:19,740 cook me type 9995 05:21:19,740 --> 05:21:21,480 so for that we really want the exact 9996 05:21:21,480 --> 05:21:22,920 same logic that we did for the cutting 9997 05:21:22,920 --> 05:21:25,138 action we want some kind of place where 9998 05:21:25,138 --> 05:21:27,120 we can store an input and output as well 9999 05:21:27,120 --> 05:21:29,218 as a cook timer so for that let's 10000 05:21:29,218 --> 05:21:30,660 actually just duplicate so let's go 10001 05:21:30,660 --> 05:21:32,100 inside our scribble objects for The 10002 05:21:32,100 --> 05:21:33,718 Cutting recipe and let's duplicate this 10003 05:21:33,718 --> 05:21:36,298 one so Ctrl D and let's name this one 10004 05:21:36,298 --> 05:21:38,638 the frying recipe so 10005 05:21:38,638 --> 05:21:40,378 okay let's go inside 10006 05:21:40,378 --> 05:21:42,240 and over here let's rename the object 10007 05:21:42,240 --> 05:21:44,340 then we have an input we have an output 10008 05:21:44,340 --> 05:21:46,440 and then a set of progress let's have 10009 05:21:46,440 --> 05:21:49,080 the frying timer Max and since this one 10010 05:21:49,080 --> 05:21:51,000 is a timer instead of an in let's make 10011 05:21:51,000 --> 05:21:53,340 it a float okay so that's it pretty 10012 05:21:53,340 --> 05:21:55,680 simple then back here in the editor 10013 05:21:55,680 --> 05:21:57,180 let's create our script mode object so 10014 05:21:57,180 --> 05:21:58,920 let's go inside let's make a nice folder 10015 05:21:58,920 --> 05:22:04,638 so a folder for the frying recipe so 10016 05:22:06,420 --> 05:22:08,218 and inside let's create one so let's 10017 05:22:08,218 --> 05:22:10,560 create a brand new frying recipe so for 10018 05:22:10,560 --> 05:22:12,298 this one let's call it meat Patty 10019 05:22:12,298 --> 05:22:16,138 uncooked into meat Patty cooked 10020 05:22:16,138 --> 05:22:18,298 then for the inputs let's choose the 10021 05:22:18,298 --> 05:22:20,218 meat Patty uncooked now we have to make 10022 05:22:20,218 --> 05:22:22,378 the other one so let's go ahead and make 10023 05:22:22,378 --> 05:22:24,958 that one let's duplicate this one rename 10024 05:22:24,958 --> 05:22:27,480 it to the meat Patty cooked 10025 05:22:27,480 --> 05:22:30,060 and the object name meat Patty cooked 10026 05:22:30,060 --> 05:22:32,878 let's select the different Sprites so 10027 05:22:32,878 --> 05:22:34,680 this one is going to be the meat Patty 10028 05:22:34,680 --> 05:22:35,760 cooked okay 10029 05:22:35,760 --> 05:22:37,798 and finally for the prefab let's also 10030 05:22:37,798 --> 05:22:41,040 make it so for the meat Patty cooked 10031 05:22:41,040 --> 05:22:43,440 let's go inside of it and also make sure 10032 05:22:43,440 --> 05:22:45,180 to save changes on our stove counter 10033 05:22:45,180 --> 05:22:47,218 it's okay now in here let's get rid of 10034 05:22:47,218 --> 05:22:49,680 this Visual and use the other visual so 10035 05:22:49,680 --> 05:22:51,840 we want to meet Patty cooked and let's 10036 05:22:51,840 --> 05:22:54,660 make sure to drag the script monk object 10037 05:22:54,660 --> 05:22:56,280 okay so it's all good here and let's go 10038 05:22:56,280 --> 05:22:58,560 back outside save it and finally over 10039 05:22:58,560 --> 05:23:00,540 here on meat Patty cooked let's just 10040 05:23:00,540 --> 05:23:02,580 grab the prefab reference so there you 10041 05:23:02,580 --> 05:23:04,200 go that one okay so this one is working 10042 05:23:04,200 --> 05:23:05,218 and since we're here and let's actually 10043 05:23:05,218 --> 05:23:07,080 make the other one right away 10044 05:23:07,080 --> 05:23:10,798 so let's make the meat Patty burned so 10045 05:23:10,798 --> 05:23:13,020 the prefab and let's also duplicate this 10046 05:23:13,020 --> 05:23:16,378 to make the meat Patty burned then on 10047 05:23:16,378 --> 05:23:18,540 the text let's rename this to Burnt 10048 05:23:18,540 --> 05:23:21,600 let's choose the burn icon 10049 05:23:21,600 --> 05:23:23,760 and for the prefab let's go into our 10050 05:23:23,760 --> 05:23:26,040 meat Patty burned and swap it out for 10051 05:23:26,040 --> 05:23:28,200 the burned one so there you go nice and 10052 05:23:28,200 --> 05:23:30,480 charred and over here swap it for the 10053 05:23:30,480 --> 05:23:33,480 meat Patty burned okay let's save it and 10054 05:23:33,480 --> 05:23:34,980 finally down here just make sure 10055 05:23:34,980 --> 05:23:37,820 everything is correct 10056 05:23:38,360 --> 05:23:41,638 object the transform prefab just like 10057 05:23:41,638 --> 05:23:44,160 that okay so all of our burn references 10058 05:23:44,160 --> 05:23:46,020 over here all of our cooked and over 10059 05:23:46,020 --> 05:23:48,180 here all of our uncut and again when 10060 05:23:48,180 --> 05:23:49,620 going through this process always make 10061 05:23:49,620 --> 05:23:51,000 sure that you match all the references 10062 05:23:51,000 --> 05:23:52,798 on the certain objects and also over 10063 05:23:52,798 --> 05:23:55,020 here on the kitchen objects so meet 10064 05:23:55,020 --> 05:23:57,180 Patty burn yep meet Patty burn for the 10065 05:23:57,180 --> 05:23:58,980 uncooked the uncooked and for the coke 10066 05:23:58,980 --> 05:24:00,540 there it is okay everything is good 10067 05:24:00,540 --> 05:24:02,638 great so now we can go back over here 10068 05:24:02,638 --> 05:24:04,440 into our frying recipe so and for the 10069 05:24:04,440 --> 05:24:06,480 output let's output the meat Patty 10070 05:24:06,480 --> 05:24:08,400 cooked and for the frying timer let's 10071 05:24:08,400 --> 05:24:09,840 put it on three seconds 10072 05:24:09,840 --> 05:24:12,780 okay so that's it great now back in the 10073 05:24:12,780 --> 05:24:15,000 code here on the stove counter let's add 10074 05:24:15,000 --> 05:24:17,100 an array of our frying recipes so a 10075 05:24:17,100 --> 05:24:19,260 serialized field private it's going to 10076 05:24:19,260 --> 05:24:21,360 be an array of frying recipe so frying 10077 05:24:21,360 --> 05:24:23,400 recipe so array make omelette frying 10078 05:24:23,400 --> 05:24:26,700 recipe so a ring okay great then back 10079 05:24:26,700 --> 05:24:28,500 here in the editor let's go inside the 10080 05:24:28,500 --> 05:24:31,200 stove counter let's make sure to drag 10081 05:24:31,200 --> 05:24:33,900 that so let's drag the mid Patty from 10082 05:24:33,900 --> 05:24:36,000 uncooked into cut okay let's also drag 10083 05:24:36,000 --> 05:24:38,340 the counter top point and finally since 10084 05:24:38,340 --> 05:24:39,718 we already made the script over here on 10085 05:24:39,718 --> 05:24:41,218 the selected we can also drag the 10086 05:24:41,218 --> 05:24:43,740 selector okay so our stove prefab should 10087 05:24:43,740 --> 05:24:45,780 be working okay let's go outside make 10088 05:24:45,780 --> 05:24:47,760 sure to save the prefab okay now let's 10089 05:24:47,760 --> 05:24:49,860 continue with the rest of the script 10090 05:24:49,860 --> 05:24:53,218 so let's make our override so override 10091 05:24:53,218 --> 05:24:54,958 the interact action 10092 05:24:54,958 --> 05:24:57,480 and when we interact with it let's 10093 05:24:57,480 --> 05:24:59,100 validate dropping the object just like 10094 05:24:59,100 --> 05:25:02,340 we did on the cutting counter 10095 05:25:02,340 --> 05:25:04,138 so let's go over here into our cutting 10096 05:25:04,138 --> 05:25:06,120 count script and let's just copy pretty 10097 05:25:06,120 --> 05:25:07,798 much the exact same thing so let's copy 10098 05:25:07,798 --> 05:25:10,020 all of this interact code let's go over 10099 05:25:10,020 --> 05:25:11,700 here in the stove counter and just paste 10100 05:25:11,700 --> 05:25:14,280 it now we also need to copy in our 10101 05:25:14,280 --> 05:25:15,120 recipe 10102 05:25:15,120 --> 05:25:17,160 so over here on the cutting counter 10103 05:25:17,160 --> 05:25:19,200 let's copy paste those functions so 10104 05:25:19,200 --> 05:25:21,180 these functions go into the cell counter 10105 05:25:21,180 --> 05:25:22,740 and over here on let's face them they're 10106 05:25:22,740 --> 05:25:24,840 going to work pretty much the same thing 10107 05:25:24,840 --> 05:25:26,700 so we get an input except instead of 10108 05:25:26,700 --> 05:25:28,920 being a cutting recipe so we're going to 10109 05:25:28,920 --> 05:25:31,320 have a frying recipe so so let's replace 10110 05:25:31,320 --> 05:25:33,298 all the cutting recipe references with 10111 05:25:33,298 --> 05:25:35,218 frying recipe reference 10112 05:25:35,218 --> 05:25:37,138 then for the array this one is the 10113 05:25:37,138 --> 05:25:39,000 frying rasps array and obviously let's 10114 05:25:39,000 --> 05:25:41,940 rename these so Ctrl R to rename all of 10115 05:25:41,940 --> 05:25:44,638 them into frying recipe so 10116 05:25:44,638 --> 05:25:46,320 let's also rename the function instead 10117 05:25:46,320 --> 05:25:48,240 of get cutting rest BSO it's the frying 10118 05:25:48,240 --> 05:25:50,340 recipe so okay so there's no more 10119 05:25:50,340 --> 05:25:52,378 mentions of cutting over here so let's 10120 05:25:52,378 --> 05:25:54,120 use this function up here and up here 10121 05:25:54,120 --> 05:25:56,580 and just make sure to rename these the 10122 05:25:56,580 --> 05:26:00,020 frying recipe as so 10123 05:26:00,540 --> 05:26:02,638 and down here on same thing so the 10124 05:26:02,638 --> 05:26:05,820 frying recipe so okay so down here we 10125 05:26:05,820 --> 05:26:07,440 have no more mentions of any cutting 10126 05:26:07,440 --> 05:26:09,298 let's just go up here and solve all 10127 05:26:09,298 --> 05:26:11,580 these problems so first we check if 10128 05:26:11,580 --> 05:26:13,080 there's no kitchen object here and if 10129 05:26:13,080 --> 05:26:14,638 the player is carrying something then we 10130 05:26:14,638 --> 05:26:16,080 see if what the pointer is carrying 10131 05:26:16,080 --> 05:26:18,958 matches any kind of frying recipe if so 10132 05:26:18,958 --> 05:26:20,160 then the player is carrying something 10133 05:26:20,160 --> 05:26:22,798 that can be primed then we set the 10134 05:26:22,798 --> 05:26:24,718 parent and for now let's not worry about 10135 05:26:24,718 --> 05:26:26,040 the progress 10136 05:26:26,040 --> 05:26:28,200 so let's just get rid of all this just 10137 05:26:28,200 --> 05:26:30,540 like this okay so with this we should be 10138 05:26:30,540 --> 05:26:32,638 able to drop but only in uncooked meat 10139 05:26:32,638 --> 05:26:34,378 so back in the afternoon let's just set 10140 05:26:34,378 --> 05:26:36,298 up our scene so let's drag a stove 10141 05:26:36,298 --> 05:26:38,340 counter onto our scene let's put over 10142 05:26:38,340 --> 05:26:42,900 there on X of 6 y of 0 and 3.5 alright 10143 05:26:42,900 --> 05:26:45,660 so let's test okay so now if I pick up 10144 05:26:45,660 --> 05:26:47,580 some cheese I go up there and I drop it 10145 05:26:47,580 --> 05:26:50,040 and nope doesn't work okay great but if 10146 05:26:50,040 --> 05:26:51,780 I pick up some uncooked meat and I go 10147 05:26:51,780 --> 05:26:53,340 and I drop it and yep that does work 10148 05:26:53,340 --> 05:26:55,860 okay great so it works and I can only 10149 05:26:55,860 --> 05:26:57,660 drop the actual objects and matchy 10150 05:26:57,660 --> 05:26:59,820 recipe now unlike the cutting counter 10151 05:26:59,820 --> 05:27:01,740 this one will not be based on a player 10152 05:27:01,740 --> 05:27:04,138 alt interaction and actually over here 10153 05:27:04,138 --> 05:27:06,480 and let's fix this minor issue 10154 05:27:06,480 --> 05:27:09,000 basically we added this debug.log error 10155 05:27:09,000 --> 05:27:11,280 to the base interact because pretty much 10156 05:27:11,280 --> 05:27:12,540 every single counter is going to 10157 05:27:12,540 --> 05:27:14,760 implement this interact function but not 10158 05:27:14,760 --> 05:27:16,138 all encounters are going to have the 10159 05:27:16,138 --> 05:27:17,820 interact alternate action 10160 05:27:17,820 --> 05:27:19,980 so this one lets us do nothing let's not 10161 05:27:19,980 --> 05:27:22,320 spawn error okay just a quick fix 10162 05:27:22,320 --> 05:27:24,420 so like I said the stove counter this 10163 05:27:24,420 --> 05:27:26,218 one is going to be based on a simple 10164 05:27:26,218 --> 05:27:28,560 timer and for making some time based 10165 05:27:28,560 --> 05:27:30,240 logic basically we have two approaches 10166 05:27:30,240 --> 05:27:32,878 one approach is to use a simple foil 10167 05:27:32,878 --> 05:27:35,458 timer or you can also use a co-routine 10168 05:27:35,458 --> 05:27:37,320 now a lot of tutorials will teach you 10169 05:27:37,320 --> 05:27:39,360 how to use a co-routine and that's not 10170 05:27:39,360 --> 05:27:41,400 necessarily a bad practice it does work 10171 05:27:41,400 --> 05:27:44,040 it does achieve desired result so to do 10172 05:27:44,040 --> 05:27:45,660 that you would just make a function like 10173 05:27:45,660 --> 05:27:47,400 Freight timer 10174 05:27:47,400 --> 05:27:49,798 so you'd make a private you have to 10175 05:27:49,798 --> 05:27:52,138 return I in numerator 10176 05:27:52,138 --> 05:27:54,420 then call it something like handle fry 10177 05:27:54,420 --> 05:27:56,660 timer 10178 05:27:56,940 --> 05:28:00,420 then inside you can do a yield return 10179 05:28:00,420 --> 05:28:04,520 and return a new weight for seconds 10180 05:28:06,120 --> 05:28:08,400 and to start this co-routine you would 10181 05:28:08,400 --> 05:28:10,798 do maybe on start you would call start 10182 05:28:10,798 --> 05:28:13,520 Co routine 10183 05:28:14,520 --> 05:28:17,400 and start the handle for right hammer 10184 05:28:17,400 --> 05:28:19,200 so this one approach this is definitely 10185 05:28:19,200 --> 05:28:21,180 perfectly foundly timer code 10186 05:28:21,180 --> 05:28:23,280 however personally I am not a fan of 10187 05:28:23,280 --> 05:28:25,080 co-routines it's not because of 10188 05:28:25,080 --> 05:28:27,180 performance or anything it's simply 10189 05:28:27,180 --> 05:28:28,740 because I don't like the pattern that 10190 05:28:28,740 --> 05:28:31,020 they force you to use I don't like being 10191 05:28:31,020 --> 05:28:32,638 forced to make a function that returns I 10192 05:28:32,638 --> 05:28:35,100 numerator I don't like using yield 10193 05:28:35,100 --> 05:28:37,920 return I don't like having to use the 10194 05:28:37,920 --> 05:28:39,958 start core routine function I don't like 10195 05:28:39,958 --> 05:28:41,340 being forced to use this on a 10196 05:28:41,340 --> 05:28:43,500 monobehavior object those are all 10197 05:28:43,500 --> 05:28:45,120 requirements for making a CO routine 10198 05:28:45,120 --> 05:28:47,760 work and personally I find those are way 10199 05:28:47,760 --> 05:28:49,620 too many requirements that create a very 10200 05:28:49,620 --> 05:28:51,240 strange pattern that I really don't like 10201 05:28:51,240 --> 05:28:53,940 so that's really the only reason I don't 10202 05:28:53,940 --> 05:28:55,560 like Co routines because I find this 10203 05:28:55,560 --> 05:28:57,840 pattern to be quite a lot convoluted so 10204 05:28:57,840 --> 05:28:59,218 instead of core routines what I like to 10205 05:28:59,218 --> 05:29:02,700 use are simple basic flow timers so just 10206 05:29:02,700 --> 05:29:04,440 make a simple and private void update 10207 05:29:04,440 --> 05:29:06,660 then we just need to keep track of a 10208 05:29:06,660 --> 05:29:08,878 certain timer so for example a simple 10209 05:29:08,878 --> 05:29:11,700 private float frying timer 10210 05:29:11,700 --> 05:29:13,440 then on the update let's first check 10211 05:29:13,440 --> 05:29:15,120 that we have an object so it has a 10212 05:29:15,120 --> 05:29:16,740 kitchen object if we have a kitchen 10213 05:29:16,740 --> 05:29:19,378 object then let's increase the timer by 10214 05:29:19,378 --> 05:29:21,780 time dot of time by the way here when 10215 05:29:21,780 --> 05:29:23,580 working with a timer you can increase or 10216 05:29:23,580 --> 05:29:25,798 decrease it's pretty arbitrary both ways 10217 05:29:25,798 --> 05:29:27,840 work the obvious difference is only if 10218 05:29:27,840 --> 05:29:29,580 you test if it's above the max or if 10219 05:29:29,580 --> 05:29:31,560 it's under zero in here for frying it 10220 05:29:31,560 --> 05:29:33,000 does make sense to start at zero and 10221 05:29:33,000 --> 05:29:35,100 then the defraying timer Max 10222 05:29:35,100 --> 05:29:37,500 so either that and if the frying timer 10223 05:29:37,500 --> 05:29:40,020 if it is bigger than the maximum 10224 05:29:40,020 --> 05:29:42,180 so let's get the frying rest PSO frying 10225 05:29:42,180 --> 05:29:43,680 recipe so 10226 05:29:43,680 --> 05:29:45,840 let's get the frying recipe so with 10227 05:29:45,840 --> 05:29:47,760 input so let's get this kitchen object 10228 05:29:47,760 --> 05:29:50,160 and get the kitchen object itself okay 10229 05:29:50,160 --> 05:29:52,378 so we go into the frying rest BSO and we 10230 05:29:52,378 --> 05:29:54,958 get the frying timer Max okay so if it's 10231 05:29:54,958 --> 05:29:56,458 above the max then this one has been 10232 05:29:56,458 --> 05:29:58,500 fried so here I'll let you see what we 10233 05:29:58,500 --> 05:30:00,660 did on the cutting counter 10234 05:30:00,660 --> 05:30:02,700 so let's get this kitchen object and 10235 05:30:02,700 --> 05:30:04,560 tunnel to destroy itself 10236 05:30:04,560 --> 05:30:06,180 and then let's go into the kitchen 10237 05:30:06,180 --> 05:30:07,740 object class in order to spawn another 10238 05:30:07,740 --> 05:30:09,840 kitchen object let's go into the frying 10239 05:30:09,840 --> 05:30:12,180 recipe and spawn the output 10240 05:30:12,180 --> 05:30:13,980 and we're going to spawn it inside of 10241 05:30:13,980 --> 05:30:16,260 this counter 10242 05:30:16,260 --> 05:30:17,820 right so that's it this should already 10243 05:30:17,820 --> 05:30:20,160 be working we don't have a visual yet so 10244 05:30:20,160 --> 05:30:21,780 let's add a debug log 10245 05:30:21,780 --> 05:30:24,540 so here just say debug.log on the frying 10246 05:30:24,540 --> 05:30:25,680 timer 10247 05:30:25,680 --> 05:30:28,440 and up here let's also just reset the 10248 05:30:28,440 --> 05:30:30,060 timer so frying time now let's put it on 10249 05:30:30,060 --> 05:30:32,820 zero f and let's also do a debug.log and 10250 05:30:32,820 --> 05:30:34,080 say fried 10251 05:30:34,080 --> 05:30:35,760 however like this you might already be 10252 05:30:35,760 --> 05:30:37,138 guessing that we're going to have a 10253 05:30:37,138 --> 05:30:38,940 bunch of bugs but still let's just test 10254 05:30:38,940 --> 05:30:40,260 it just like this 10255 05:30:40,260 --> 05:30:42,600 okay so over here I can move around I 10256 05:30:42,600 --> 05:30:44,218 can pick up some uncooked meat I can 10257 05:30:44,218 --> 05:30:46,500 drop it there and after a little bit 10258 05:30:46,500 --> 05:30:48,718 there you go there's the timers and if 10259 05:30:48,718 --> 05:30:50,160 there you go it did work you can see the 10260 05:30:50,160 --> 05:30:52,440 timer increase until three then it was 10261 05:30:52,440 --> 05:30:54,480 fried then it was reset and then we've 10262 05:30:54,480 --> 05:30:56,340 got a known reference exception 10263 05:30:56,340 --> 05:30:58,200 basically this is the exact same problem 10264 05:30:58,200 --> 05:31:00,360 that we had on the cutting counter where 10265 05:31:00,360 --> 05:31:02,400 first we put an object like tomato and 10266 05:31:02,400 --> 05:31:04,680 that is indeed an input for a recipe so 10267 05:31:04,680 --> 05:31:06,540 we cut tomato into slices but then the 10268 05:31:06,540 --> 05:31:08,400 slices are not an input for any recipe 10269 05:31:08,400 --> 05:31:10,798 so over here we put some uncooked meat 10270 05:31:10,798 --> 05:31:12,780 so that's great we frying which means we 10271 05:31:12,780 --> 05:31:14,340 destroy the uncooked meat and we spawn 10272 05:31:14,340 --> 05:31:16,378 the cooked meat but then next time the 10273 05:31:16,378 --> 05:31:17,760 cooked meat is not an input for anything 10274 05:31:17,760 --> 05:31:19,500 so obviously this one is going to return 10275 05:31:19,500 --> 05:31:22,320 no one thing we can do to sort of solve 10276 05:31:22,320 --> 05:31:24,298 this problem which is also going to be 10277 05:31:24,298 --> 05:31:25,920 beneficial in terms of performance is 10278 05:31:25,920 --> 05:31:28,440 simply caching this field so let's go 10279 05:31:28,440 --> 05:31:30,660 here to find a frying recipe a cell 10280 05:31:30,660 --> 05:31:32,940 frying recipe so 10281 05:31:32,940 --> 05:31:34,680 instead of constantly getting it on 10282 05:31:34,680 --> 05:31:36,360 every single update which might be a bit 10283 05:31:36,360 --> 05:31:38,458 costly in terms of performance instead 10284 05:31:38,458 --> 05:31:40,080 of this let's just get it over here when 10285 05:31:40,080 --> 05:31:42,240 the player drops something so the player 10286 05:31:42,240 --> 05:31:43,980 drops something and we assign the Frank 10287 05:31:43,980 --> 05:31:45,958 rest BSO so we sign it cache the value 10288 05:31:45,958 --> 05:31:48,000 and then do this okay that should have 10289 05:31:48,000 --> 05:31:50,218 fixed the non-reference problem but we 10290 05:31:50,218 --> 05:31:51,600 still have a bunch more problems but 10291 05:31:51,600 --> 05:31:53,878 still let's test it out okay so here 10292 05:31:53,878 --> 05:31:56,280 let's pick up some meat put it there and 10293 05:31:56,280 --> 05:31:57,718 let's look at the timer and if there you 10294 05:31:57,718 --> 05:31:59,160 go everything is cooking great any of 10295 05:31:59,160 --> 05:32:01,020 their yo it finished it cooked and the 10296 05:32:01,020 --> 05:32:02,638 time was reset and now it's finishing 10297 05:32:02,638 --> 05:32:04,920 it's cooking and so on so this is 10298 05:32:04,920 --> 05:32:06,540 obviously another pretty serious problem 10299 05:32:06,540 --> 05:32:08,280 basically it's constantly frying the 10300 05:32:08,280 --> 05:32:09,900 meat and spawning more and more objects 10301 05:32:09,900 --> 05:32:12,180 instead of constantly spawning from the 10302 05:32:12,180 --> 05:32:14,580 same recipe what we want is for the 10303 05:32:14,580 --> 05:32:16,860 stove to First fry the object but then 10304 05:32:16,860 --> 05:32:18,780 if the object is fried then we want to 10305 05:32:18,780 --> 05:32:21,000 burn it so really that means that we 10306 05:32:21,000 --> 05:32:22,560 want the stove to have multiple States 10307 05:32:22,560 --> 05:32:24,780 meaning that we're going to need to make 10308 05:32:24,780 --> 05:32:26,820 a simple State machine so let's do just 10309 05:32:26,820 --> 05:32:28,680 that now if you're a beginner the 10310 05:32:28,680 --> 05:32:30,298 concept of a state machine might seem 10311 05:32:30,298 --> 05:32:31,560 daunting at first but it's actually 10312 05:32:31,560 --> 05:32:33,780 extremely simple at least to make a very 10313 05:32:33,780 --> 05:32:36,180 basic one all we need is really just a 10314 05:32:36,180 --> 05:32:37,980 bunch of saints so to define those 10315 05:32:37,980 --> 05:32:39,540 States let's go up here and make a 10316 05:32:39,540 --> 05:32:42,360 simple enum so let's make a private enum 10317 05:32:42,360 --> 05:32:44,218 call it state 10318 05:32:44,218 --> 05:32:46,138 and now let's put all the states for our 10319 05:32:46,138 --> 05:32:47,940 state machine now for the server let's 10320 05:32:47,940 --> 05:32:49,620 say we have idle when there's nothing on 10321 05:32:49,620 --> 05:32:50,340 top 10322 05:32:50,340 --> 05:32:52,200 then let's say we have a frying state 10323 05:32:52,200 --> 05:32:54,000 for when the ingredient is actually 10324 05:32:54,000 --> 05:32:56,580 being fried then we have fried for when 10325 05:32:56,580 --> 05:32:58,138 the ingredient has already been cooked 10326 05:32:58,138 --> 05:33:00,000 but it's still getting some heat and 10327 05:33:00,000 --> 05:33:01,560 finally if we leave it too long in that 10328 05:33:01,560 --> 05:33:03,420 state then everything ends up burned 10329 05:33:03,420 --> 05:33:05,700 okay so these are all of our states for 10330 05:33:05,700 --> 05:33:06,900 our state machine 10331 05:33:06,900 --> 05:33:08,458 and how to make the actual stick machine 10332 05:33:08,458 --> 05:33:10,138 it's actually quite simple first of all 10333 05:33:10,138 --> 05:33:11,700 we just need to store the current state 10334 05:33:11,700 --> 05:33:14,400 so here make a private of type State and 10335 05:33:14,400 --> 05:33:15,840 sort the current state 10336 05:33:15,840 --> 05:33:17,878 and then on update let's just do a 10337 05:33:17,878 --> 05:33:20,160 switch on the current state 10338 05:33:20,160 --> 05:33:21,540 okay now here basically we're going to 10339 05:33:21,540 --> 05:33:22,798 do different logic depending on the 10340 05:33:22,798 --> 05:33:24,180 state that we're at 10341 05:33:24,180 --> 05:33:26,100 so let's say if we're I don't we do 10342 05:33:26,100 --> 05:33:28,560 something then if we are frying we're 10343 05:33:28,560 --> 05:33:30,780 going to do something else then if we 10344 05:33:30,780 --> 05:33:33,660 are on the front also something else and 10345 05:33:33,660 --> 05:33:35,458 finally if we are on Burn do something 10346 05:33:35,458 --> 05:33:36,480 else 10347 05:33:36,480 --> 05:33:39,180 so here are all of our states and the 10348 05:33:39,180 --> 05:33:41,638 logic that we did down here this is the 10349 05:33:41,638 --> 05:33:43,620 frame logic so let's actually just copy 10350 05:33:43,620 --> 05:33:44,700 on this 10351 05:33:44,700 --> 05:33:46,560 and let's face it inside the frying 10352 05:33:46,560 --> 05:33:49,500 logic and for the seed machine we're 10353 05:33:49,500 --> 05:33:51,240 only going to run any of these states if 10354 05:33:51,240 --> 05:33:52,980 there's a kitchen object inside of it so 10355 05:33:52,980 --> 05:33:54,600 it's actually put that switch in there 10356 05:33:54,600 --> 05:33:55,980 just like this 10357 05:33:55,980 --> 05:33:58,138 okay so that's it so when I don't we're 10358 05:33:58,138 --> 05:33:59,700 not doing anything and when frying we're 10359 05:33:59,700 --> 05:34:01,320 going to run our frying timer we're 10360 05:34:01,320 --> 05:34:03,180 going to fry the object let's also get 10361 05:34:03,180 --> 05:34:04,440 rid of the low we no longer need this 10362 05:34:04,440 --> 05:34:06,298 then we destroy the current object and 10363 05:34:06,298 --> 05:34:08,520 we spawn a brand new object now what we 10364 05:34:08,520 --> 05:34:10,080 need is to handle over here the State 10365 05:34:10,080 --> 05:34:12,480 field we need to modify this winching in 10366 05:34:12,480 --> 05:34:14,340 Saints so first of all let's handle the 10367 05:34:14,340 --> 05:34:17,760 start so let's make a private void start 10368 05:34:17,760 --> 05:34:20,100 and on start let's begin with the state 10369 05:34:20,100 --> 05:34:23,218 on state DOT Idol okay great then down 10370 05:34:23,218 --> 05:34:24,718 here when we interact when the player 10371 05:34:24,718 --> 05:34:26,218 drops something when the player drops 10372 05:34:26,218 --> 05:34:27,780 something that can be fried 10373 05:34:27,780 --> 05:34:30,120 over here on let's set the state and put 10374 05:34:30,120 --> 05:34:32,340 it on state DOT frame 10375 05:34:32,340 --> 05:34:33,660 and over here we should also probably 10376 05:34:33,660 --> 05:34:35,638 reset the timer so let's set the frying 10377 05:34:35,638 --> 05:34:38,100 timer back into zero f okay we set the 10378 05:34:38,100 --> 05:34:40,920 timer and we reset the state finally up 10379 05:34:40,920 --> 05:34:43,020 here let's not reset the timer since 10380 05:34:43,020 --> 05:34:44,280 we're resetting the timer down there 10381 05:34:44,280 --> 05:34:46,440 since it makes more sense down there so 10382 05:34:46,440 --> 05:34:48,060 we do the frying the frying timer we end 10383 05:34:48,060 --> 05:34:49,680 the frying and then obviously we need to 10384 05:34:49,680 --> 05:34:51,600 modify the state so modify State and put 10385 05:34:51,600 --> 05:34:53,340 it on state DOT fright 10386 05:34:53,340 --> 05:34:55,440 okay so that's the basics of our state 10387 05:34:55,440 --> 05:34:57,540 machine with this everything should be 10388 05:34:57,540 --> 05:34:58,920 working just the same as previously 10389 05:34:58,920 --> 05:35:01,020 except we're only going to fry once so 10390 05:35:01,020 --> 05:35:02,458 let's actually just put them out here 10391 05:35:02,458 --> 05:35:04,080 debug the hog 10392 05:35:04,080 --> 05:35:06,958 object Pride 10393 05:35:06,958 --> 05:35:09,480 and let's put one down here outside of 10394 05:35:09,480 --> 05:35:12,180 the save machine just do a debug.log on 10395 05:35:12,180 --> 05:35:14,600 the state 10396 05:35:14,878 --> 05:35:16,980 okay like this let's test 10397 05:35:16,980 --> 05:35:19,138 okay so here we are let's pick up some 10398 05:35:19,138 --> 05:35:21,240 meat and drop it on there and there you 10399 05:35:21,240 --> 05:35:22,980 go it goes from idle directly into 10400 05:35:22,980 --> 05:35:25,620 frying and then it's fried and after you 10401 05:35:25,620 --> 05:35:27,600 go now it stays on fried so it no longer 10402 05:35:27,600 --> 05:35:29,040 goes on frying and it's no longer 10403 05:35:29,040 --> 05:35:30,660 spawning any more objects it went from 10404 05:35:30,660 --> 05:35:32,100 frying into fried and yep everything 10405 05:35:32,100 --> 05:35:34,378 worked alright awesome 10406 05:35:34,378 --> 05:35:36,298 so we have the Frank State working 10407 05:35:36,298 --> 05:35:38,340 perfectly now let's handle the burning 10408 05:35:38,340 --> 05:35:39,958 in terms of logic it's really going to 10409 05:35:39,958 --> 05:35:41,340 be the exact same thing 10410 05:35:41,340 --> 05:35:43,620 we're going to have a frying timer so 10411 05:35:43,620 --> 05:35:45,600 let's copy this code and paste it down 10412 05:35:45,600 --> 05:35:48,420 here now technically we could reuse the 10413 05:35:48,420 --> 05:35:50,760 exact same float timer but that would be 10414 05:35:50,760 --> 05:35:52,798 a bit confusing so let's keep our code 10415 05:35:52,798 --> 05:35:54,600 as clear as possible and really just 10416 05:35:54,600 --> 05:35:56,100 make a different timer with a more 10417 05:35:56,100 --> 05:35:57,480 descriptive name 10418 05:35:57,480 --> 05:36:00,000 so pure a private float called The 10419 05:36:00,000 --> 05:36:01,740 Burning timer 10420 05:36:01,740 --> 05:36:03,900 then let's initialize this timer so when 10421 05:36:03,900 --> 05:36:06,298 we go into the fried State let's set the 10422 05:36:06,298 --> 05:36:08,820 timer the burning timer into zero then 10423 05:36:08,820 --> 05:36:10,740 down here let's use this Burning timer 10424 05:36:10,740 --> 05:36:13,440 okay great when timers and lapse and the 10425 05:36:13,440 --> 05:36:15,060 object is spawn let's go into the 10426 05:36:15,060 --> 05:36:16,080 Burnside 10427 05:36:16,080 --> 05:36:18,420 and obviously we need another recipe 10428 05:36:18,420 --> 05:36:20,218 so let's make another scriptable object 10429 05:36:20,218 --> 05:36:23,100 back in the editor let's find the frying 10430 05:36:23,100 --> 05:36:25,740 recipe so let's duplicate this call it 10431 05:36:25,740 --> 05:36:28,020 the burning recipe so 10432 05:36:28,020 --> 05:36:29,700 then over here let's modify the name 10433 05:36:29,700 --> 05:36:31,440 instead of frying timer Max let's call 10434 05:36:31,440 --> 05:36:34,320 it burning timer Max okay great so now 10435 05:36:34,320 --> 05:36:36,060 over here on the stove let's use pretty 10436 05:36:36,060 --> 05:36:38,218 much the exact same thing and let's make 10437 05:36:38,218 --> 05:36:40,740 over here private of burning recipe so 10438 05:36:40,740 --> 05:36:43,260 the burning recipe so 10439 05:36:43,260 --> 05:36:45,600 then down here we just need a function 10440 05:36:45,600 --> 05:36:47,280 to get the burning recipe so so let's 10441 05:36:47,280 --> 05:36:50,280 copy this and paste it over here this 10442 05:36:50,280 --> 05:36:52,378 one's going to return a burning rest BSO 10443 05:36:52,378 --> 05:36:54,480 so let's replace this and this 10444 05:36:54,480 --> 05:36:58,500 rename this into burning recipe so we're 10445 05:36:58,500 --> 05:36:59,820 going to need an array and over here 10446 05:36:59,820 --> 05:37:01,320 let's just change the name instead of 10447 05:37:01,320 --> 05:37:05,360 frying recipe so the burning recipe so 10448 05:37:05,820 --> 05:37:08,218 let's just find a new array so let's go 10449 05:37:08,218 --> 05:37:09,718 all the way up here make another array 10450 05:37:09,718 --> 05:37:12,900 an array of burning recipe so and this 10451 05:37:12,900 --> 05:37:15,180 is the burning recipe SL ring and 10452 05:37:15,180 --> 05:37:16,798 finally if we go down here let's use 10453 05:37:16,798 --> 05:37:19,260 this array okay that's it so now let's 10454 05:37:19,260 --> 05:37:21,480 use this function to set our burning 10455 05:37:21,480 --> 05:37:24,660 rest BSL so when we set it to find let's 10456 05:37:24,660 --> 05:37:27,420 set the burning recipe so and let's get 10457 05:37:27,420 --> 05:37:28,920 it with the input and the input is going 10458 05:37:28,920 --> 05:37:31,020 to be the object that is on here so the 10459 05:37:31,020 --> 05:37:32,700 kitchen object dot get the kitchen 10460 05:37:32,700 --> 05:37:35,600 object.so 10461 05:37:36,660 --> 05:37:39,120 okay so we're initializing our fright 10462 05:37:39,120 --> 05:37:40,440 State and setting up the burning recipe 10463 05:37:40,440 --> 05:37:43,920 so and over here we use that one dot Max 10464 05:37:43,920 --> 05:37:45,958 and we get into that one and use the 10465 05:37:45,958 --> 05:37:48,060 output so over there object frying over 10466 05:37:48,060 --> 05:37:50,580 here object burned all right so that's 10467 05:37:50,580 --> 05:37:52,320 pretty much it we modified everything to 10468 05:37:52,320 --> 05:37:54,240 say burning timer over here we are 10469 05:37:54,240 --> 05:37:56,100 correctly initializing so we go through 10470 05:37:56,100 --> 05:37:57,600 the burning timer through the burning 10471 05:37:57,600 --> 05:37:59,280 rest PSO which we are grabbing up here 10472 05:37:59,280 --> 05:38:01,500 then we spawn the output on the burning 10473 05:38:01,500 --> 05:38:04,200 rest BSO and we go into state.burn okay 10474 05:38:04,200 --> 05:38:05,878 so all that's left is just filling in 10475 05:38:05,878 --> 05:38:08,340 this array so back in the editor over 10476 05:38:08,340 --> 05:38:10,080 here on let's make the object so let's 10477 05:38:10,080 --> 05:38:13,138 make a brand new folder for the burning 10478 05:38:13,138 --> 05:38:15,780 recipe and so and now inside let's 10479 05:38:15,780 --> 05:38:18,420 create a new Burning recipe so call this 10480 05:38:18,420 --> 05:38:22,200 one the meat Patty cooked into meat 10481 05:38:22,200 --> 05:38:24,840 Patty burned and over here let's set the 10482 05:38:24,840 --> 05:38:27,000 input so the meat Patty cooked onto the 10483 05:38:27,000 --> 05:38:29,638 meat Patty burned and for timer let's 10484 05:38:29,638 --> 05:38:31,138 make it take a bit longer to burn so 10485 05:38:31,138 --> 05:38:33,180 let's say five seconds okay that's great 10486 05:38:33,180 --> 05:38:34,798 let's just drag the reference so let's 10487 05:38:34,798 --> 05:38:36,480 go into the stove counter and let's make 10488 05:38:36,480 --> 05:38:38,760 sure to open up and go inside the prefab 10489 05:38:38,760 --> 05:38:40,680 and over here on the prefab just write 10490 05:38:40,680 --> 05:38:42,780 the burning recipe okay that's great 10491 05:38:42,780 --> 05:38:44,940 let's go outside save the prefab and 10492 05:38:44,940 --> 05:38:47,280 let's test alright so here we are let's 10493 05:38:47,280 --> 05:38:49,200 pick up some meat drop it on there and 10494 05:38:49,200 --> 05:38:51,000 look over there it's frying and after a 10495 05:38:51,000 --> 05:38:52,980 bit yep it's right there you would spawn 10496 05:38:52,980 --> 05:38:54,900 that one and now if we wait for five 10497 05:38:54,900 --> 05:38:56,820 seconds it should go from frying to burn 10498 05:38:56,820 --> 05:38:58,320 any up there you go that one is charred 10499 05:38:58,320 --> 05:38:59,700 everything is burned everything is great 10500 05:38:59,700 --> 05:39:02,160 all right awesome so everything worked 10501 05:39:02,160 --> 05:39:04,200 as intended with this song of our logic 10502 05:39:04,200 --> 05:39:05,878 is working now let's handle on picking 10503 05:39:05,878 --> 05:39:07,680 up objects from the stove now 10504 05:39:07,680 --> 05:39:09,600 technically it's already working so I 10505 05:39:09,600 --> 05:39:11,580 can approach yourself and pick it up the 10506 05:39:11,580 --> 05:39:12,900 object and there you go drop it in there 10507 05:39:12,900 --> 05:39:15,540 so that does work however if we look 10508 05:39:15,540 --> 05:39:16,860 over here in the log the state machine 10509 05:39:16,860 --> 05:39:19,080 is now in the wrong state so over here 10510 05:39:19,080 --> 05:39:22,260 let's do a quick fix let's go down into 10511 05:39:22,260 --> 05:39:24,120 the interact action okay so here it is 10512 05:39:24,120 --> 05:39:26,100 so if there's no kitchen object then the 10513 05:39:26,100 --> 05:39:28,320 player places it okay that's good but if 10514 05:39:28,320 --> 05:39:29,820 there is a kitchen object so if there's 10515 05:39:29,820 --> 05:39:31,980 something on the stove counter when the 10516 05:39:31,980 --> 05:39:33,660 player picks it up let's also manually 10517 05:39:33,660 --> 05:39:34,920 set the state 10518 05:39:34,920 --> 05:39:38,040 and put the state back into idle just 10519 05:39:38,040 --> 05:39:41,040 like this okay that's it so let's test 10520 05:39:41,040 --> 05:39:42,840 okay so over here let's pick up some 10521 05:39:42,840 --> 05:39:44,878 meat put it in there it's cooking and 10522 05:39:44,878 --> 05:39:46,798 let's wait until it gets finished yep 10523 05:39:46,798 --> 05:39:48,000 there you go it's done pick it up and 10524 05:39:48,000 --> 05:39:50,100 there you go out now if I want I can put 10525 05:39:50,100 --> 05:39:51,360 another one and if there you go the 10526 05:39:51,360 --> 05:39:53,100 logic is reset and everything is back to 10527 05:39:53,100 --> 05:39:55,500 normal okay great so often logic is 10528 05:39:55,500 --> 05:39:57,840 working perfectly now let's just get rid 10529 05:39:57,840 --> 05:39:59,400 of our logs so we don't need this so 10530 05:39:59,400 --> 05:40:01,680 let's get rid of that debugging log this 10531 05:40:01,680 --> 05:40:03,420 one and this one okay great everything 10532 05:40:03,420 --> 05:40:06,000 is nice and clean and now let's add some 10533 05:40:06,000 --> 05:40:08,820 nice fun visuals so if we go inside the 10534 05:40:08,820 --> 05:40:10,798 stove counter and over here is the 10535 05:40:10,798 --> 05:40:13,440 visual and I include these two prefabs 10536 05:40:13,440 --> 05:40:15,780 inside the visual so one of them this 10537 05:40:15,780 --> 05:40:18,180 one the stove on visual this one is just 10538 05:40:18,180 --> 05:40:20,700 a glowing red square now again there's a 10539 05:40:20,700 --> 05:40:22,500 weird bug on this specific empty version 10540 05:40:22,500 --> 05:40:24,360 so post processing isn't showing over 10541 05:40:24,360 --> 05:40:26,400 here on scene view but if I leave it 10542 05:40:26,400 --> 05:40:28,680 enabled and I go back outside 10543 05:40:28,680 --> 05:40:30,718 and now from work in the game view if 10544 05:40:30,718 --> 05:40:32,280 there you go there's a nice glowing red 10545 05:40:32,280 --> 05:40:34,138 square if you don't see glowing make 10546 05:40:34,138 --> 05:40:35,700 sure you add the balloon post Crossing 10547 05:40:35,700 --> 05:40:36,420 effect 10548 05:40:36,420 --> 05:40:37,980 so if you missed something you can go 10549 05:40:37,980 --> 05:40:39,480 back into the post-processing lecture 10550 05:40:39,480 --> 05:40:40,680 and make sure everything is set up 10551 05:40:40,680 --> 05:40:43,020 correctly so there's a nice glowing red 10552 05:40:43,020 --> 05:40:44,218 square and there's also a bunch of 10553 05:40:44,218 --> 05:40:46,260 particles so you can name on this one 10554 05:40:46,260 --> 05:40:47,820 press on restart and there you go just 10555 05:40:47,820 --> 05:40:49,980 some nice particles just jumping up this 10556 05:40:49,980 --> 05:40:52,440 was made with the unity particle system 10557 05:40:52,440 --> 05:40:54,180 so for example on the hierarchy you can 10558 05:40:54,180 --> 05:40:56,280 right click go up here into effects and 10559 05:40:56,280 --> 05:40:58,440 you can create a particle system 10560 05:40:58,440 --> 05:41:00,780 so that's what this is it has a particle 10561 05:41:00,780 --> 05:41:02,638 system over here you can see all of the 10562 05:41:02,638 --> 05:41:04,560 various settings for these particles 10563 05:41:04,560 --> 05:41:07,260 they just jump up and fall down so for 10564 05:41:07,260 --> 05:41:09,180 jumping up that is the emission you can 10565 05:41:09,180 --> 05:41:10,980 actually see a visual over there of the 10566 05:41:10,980 --> 05:41:12,900 cone that is the spawning cone which you 10567 05:41:12,900 --> 05:41:15,480 can find over here on the shape so in 10568 05:41:15,480 --> 05:41:17,100 the shape it has the shape of a cone 10569 05:41:17,100 --> 05:41:19,138 then you can see the radius radius 10570 05:41:19,138 --> 05:41:20,520 thickness and so on so that is from 10571 05:41:20,520 --> 05:41:22,560 where the objects are being spawned then 10572 05:41:22,560 --> 05:41:24,298 up here you can see the lifetime of each 10573 05:41:24,298 --> 05:41:26,638 object so each particle is going to last 10574 05:41:26,638 --> 05:41:28,260 for 0.7 seconds 10575 05:41:28,260 --> 05:41:29,820 you can all see the speed so that's 10576 05:41:29,820 --> 05:41:31,980 speed at which they come from there the 10577 05:41:31,980 --> 05:41:33,600 start size that's how big they are on 10578 05:41:33,600 --> 05:41:34,378 start 10579 05:41:34,378 --> 05:41:36,840 and note how the particles are spawning 10580 05:41:36,840 --> 05:41:39,120 jumping up and falling down 10581 05:41:39,120 --> 05:41:40,680 so that Falling Down is over here the 10582 05:41:40,680 --> 05:41:43,200 gravity modifier if you put it at zero 10583 05:41:43,200 --> 05:41:44,878 then they just keep going up and if you 10584 05:41:44,878 --> 05:41:46,920 put a two yep they go up and they fall 10585 05:41:46,920 --> 05:41:47,820 down 10586 05:41:47,820 --> 05:41:49,560 next down here on the emission this is 10587 05:41:49,560 --> 05:41:51,480 how many are being spawned so if I put 10588 05:41:51,480 --> 05:41:53,340 this on 200 there you go tons and tons 10589 05:41:53,340 --> 05:41:56,040 of particles next is over here the size 10590 05:41:56,040 --> 05:41:58,020 of our lifetime so this one has just a 10591 05:41:58,020 --> 05:42:00,180 basic curve so they started off on font 10592 05:42:00,180 --> 05:42:03,360 size and over the x-axis this one is in 10593 05:42:03,360 --> 05:42:05,458 a lifetime so as the particle goes from 10594 05:42:05,458 --> 05:42:06,718 the beginning until the end their life 10595 05:42:06,718 --> 05:42:08,160 they basically go down on size so that 10596 05:42:08,160 --> 05:42:09,540 is why they become quite a bit smaller 10597 05:42:09,540 --> 05:42:11,458 also by the way this one down here this 10598 05:42:11,458 --> 05:42:13,860 one is called an animation curve this is 10599 05:42:13,860 --> 05:42:16,080 another really useful ENT feature I have 10600 05:42:16,080 --> 05:42:17,820 a dedicated video on animation curves 10601 05:42:17,820 --> 05:42:19,620 and finally down here just have the 10602 05:42:19,620 --> 05:42:21,540 renderer so it's just using some basic 10603 05:42:21,540 --> 05:42:23,520 particles so we can inspect the material 10604 05:42:23,520 --> 05:42:25,620 simple in the assets and there you go 10605 05:42:25,620 --> 05:42:27,240 we're just using the default particle 10606 05:42:27,240 --> 05:42:29,638 material just with the alpha on half and 10607 05:42:29,638 --> 05:42:31,440 that's pretty much it so as you can see 10608 05:42:31,440 --> 05:42:33,540 just a very basic very simple particle 10609 05:42:33,540 --> 05:42:36,060 system now all we really want to do is 10610 05:42:36,060 --> 05:42:38,218 just for both of these we want to enable 10611 05:42:38,218 --> 05:42:40,020 or disable them depending on if the 10612 05:42:40,020 --> 05:42:42,540 stove is on or not so let's make a 10613 05:42:42,540 --> 05:42:44,160 script to handle the visuals so let's go 10614 05:42:44,160 --> 05:42:45,958 down and create a brand new c-sharp 10615 05:42:45,958 --> 05:42:48,420 script let's go with the stove counter 10616 05:42:48,420 --> 05:42:50,520 visual then let's go into the stove 10617 05:42:50,520 --> 05:42:52,260 counter Visual and let's attach the 10618 05:42:52,260 --> 05:42:53,218 script 10619 05:42:53,218 --> 05:42:55,740 so here it is attach it and open right 10620 05:42:55,740 --> 05:42:57,600 so now here we just need references to 10621 05:42:57,600 --> 05:42:59,820 those two objects so as usual let's make 10622 05:42:59,820 --> 05:43:02,218 a basic serialized film let's make it of 10623 05:43:02,218 --> 05:43:04,020 type game object 10624 05:43:04,020 --> 05:43:07,020 for the stove on game object and the 10625 05:43:07,020 --> 05:43:10,260 other one is the particles game object 10626 05:43:10,260 --> 05:43:12,718 okay let's save and back here in the 10627 05:43:12,718 --> 05:43:14,400 editor let's drag the references so the 10628 05:43:14,400 --> 05:43:16,138 stove on Visual and the sizzling 10629 05:43:16,138 --> 05:43:18,540 particles okay great so now all we 10630 05:43:18,540 --> 05:43:20,400 really need to know is know when to turn 10631 05:43:20,400 --> 05:43:22,740 these on or off and for that is really 10632 05:43:22,740 --> 05:43:24,360 going to be based on the state over here 10633 05:43:24,360 --> 05:43:26,638 on the stove counter so if it is on the 10634 05:43:26,638 --> 05:43:28,320 state frying or fried then we want to 10635 05:43:28,320 --> 05:43:30,240 show them if it is on idle or burned we 10636 05:43:30,240 --> 05:43:32,218 want to hide them but as usual we don't 10637 05:43:32,218 --> 05:43:33,840 want to mix the logic and Visions 10638 05:43:33,840 --> 05:43:36,000 directly so let's do that through a 10639 05:43:36,000 --> 05:43:37,200 really nice event 10640 05:43:37,200 --> 05:43:40,378 let's make a public event let's use a 10641 05:43:40,378 --> 05:43:43,138 standard event handler let's call it on 10642 05:43:43,138 --> 05:43:45,120 stay changed 10643 05:43:45,120 --> 05:43:47,218 and let's also include the state on the 10644 05:43:47,218 --> 05:43:48,840 event Arc so let's make a public class 10645 05:43:48,840 --> 05:43:53,040 call it on state change event args and 10646 05:43:53,040 --> 05:43:56,218 let's expand event arcs and then in here 10647 05:43:56,218 --> 05:43:58,680 let's just put a public state 10648 05:43:58,680 --> 05:44:00,298 for our state 10649 05:44:00,298 --> 05:44:02,340 however here we also have a really nice 10650 05:44:02,340 --> 05:44:04,378 error so this one is telling you there's 10651 05:44:04,378 --> 05:44:06,660 inconsistent accessibility basically 10652 05:44:06,660 --> 05:44:08,638 that's because we made this one public 10653 05:44:08,638 --> 05:44:10,620 so any class link for his Mr visual 10654 05:44:10,620 --> 05:44:13,200 class can indeed see this class however 10655 05:44:13,200 --> 05:44:15,180 from outside that class cannot see the 10656 05:44:15,180 --> 05:44:16,378 private state 10657 05:44:16,378 --> 05:44:18,360 so that is why we have inconsistent 10658 05:44:18,360 --> 05:44:20,400 accessibility we cannot have something 10659 05:44:20,400 --> 05:44:22,500 public which inside has something of a 10660 05:44:22,500 --> 05:44:24,420 specific type which is private 10661 05:44:24,420 --> 05:44:26,100 so in order to make this work we need to 10662 05:44:26,100 --> 05:44:28,200 modify this state and make it public so 10663 05:44:28,200 --> 05:44:30,298 that the other classes can see it okay 10664 05:44:30,298 --> 05:44:31,860 so that's great now let's just fire this 10665 05:44:31,860 --> 05:44:34,260 event whenever the state changes so over 10666 05:44:34,260 --> 05:44:35,878 here when you go into the frying State 10667 05:44:35,878 --> 05:44:38,760 let's go and invoke and as usual just 10668 05:44:38,760 --> 05:44:40,378 this 10669 05:44:40,378 --> 05:44:42,420 and I actually forgot to add that so 10670 05:44:42,420 --> 05:44:44,700 let's go up here let's use the one with 10671 05:44:44,700 --> 05:44:46,558 generics so the on state change event 10672 05:44:46,558 --> 05:44:48,840 arcs okay great so then down here we 10673 05:44:48,840 --> 05:44:51,360 invoke the event let's create of this 10674 05:44:51,360 --> 05:44:52,260 time 10675 05:44:52,260 --> 05:44:54,480 and inside passing the state equals this 10676 05:44:54,480 --> 05:44:55,500 state 10677 05:44:55,500 --> 05:44:57,958 okay so this one we need so then down 10678 05:44:57,958 --> 05:44:59,820 here go into the burn State let's fire 10679 05:44:59,820 --> 05:45:02,040 the event and down here frying fire the 10680 05:45:02,040 --> 05:45:04,378 vent and on idle fried event alright 10681 05:45:04,378 --> 05:45:06,058 that's it so we have all of our state 10682 05:45:06,058 --> 05:45:08,638 logic and over here on the stove counter 10683 05:45:08,638 --> 05:45:10,860 visual obviously we need a reference to 10684 05:45:10,860 --> 05:45:13,200 the counter so let's add that so a 10685 05:45:13,200 --> 05:45:15,600 serialized field private 10686 05:45:15,600 --> 05:45:18,058 maker of type stove counter for the 10687 05:45:18,058 --> 05:45:20,940 stove counter and then we can do an as 10688 05:45:20,940 --> 05:45:22,620 usual for accessing external references 10689 05:45:22,620 --> 05:45:25,020 let's do it on start go into the stove 10690 05:45:25,020 --> 05:45:27,540 counter and let's listen to the on say 10691 05:45:27,540 --> 05:45:29,218 change event 10692 05:45:29,218 --> 05:45:30,958 and over here it's going to be very 10693 05:45:30,958 --> 05:45:32,940 simple we just want to show if it's on 10694 05:45:32,940 --> 05:45:35,580 the state frying or fried and if not we 10695 05:45:35,580 --> 05:45:37,260 don't want to show so let's define a 10696 05:45:37,260 --> 05:45:39,180 bone called show visual 10697 05:45:39,180 --> 05:45:40,860 and this one is going to true if the E 10698 05:45:40,860 --> 05:45:44,520 dot State equals the state DOT frying or 10699 05:45:44,520 --> 05:45:46,740 E dot State equals 10700 05:45:46,740 --> 05:45:49,440 the state DOT fried 10701 05:45:49,440 --> 05:45:50,940 so if it's either of these then this is 10702 05:45:50,940 --> 05:45:52,200 going to be true if not it's going to be 10703 05:45:52,200 --> 05:45:54,600 false so then let's just go into the 10704 05:45:54,600 --> 05:45:57,000 stove on game object 10705 05:45:57,000 --> 05:46:00,180 and constant active and pass in this 10706 05:46:00,180 --> 05:46:02,100 and same thing for the other for the 10707 05:46:02,100 --> 05:46:04,080 particles game object okay that's it 10708 05:46:04,080 --> 05:46:05,820 super simple let's just drag this 10709 05:46:05,820 --> 05:46:07,980 reference so over here inside the prefab 10710 05:46:07,980 --> 05:46:10,080 just drag the reference let's leave the 10711 05:46:10,080 --> 05:46:12,420 prefab save the changes and let's hit on 10712 05:46:12,420 --> 05:46:14,520 play and all right so it starts off 10713 05:46:14,520 --> 05:46:16,378 disabled okay so there's no visuals now 10714 05:46:16,378 --> 05:46:17,820 if I pick it up and I drop it and there 10715 05:46:17,820 --> 05:46:19,980 you go a nice visual so the glowing red 10716 05:46:19,980 --> 05:46:21,660 hot and the particles and now it's 10717 05:46:21,660 --> 05:46:23,340 running and if I leave it until it burns 10718 05:46:23,340 --> 05:46:25,080 when it burns and it's going to turn it 10719 05:46:25,080 --> 05:46:26,940 off and if there go turns off 10720 05:46:26,940 --> 05:46:29,040 all right awesome so now if I pick it up 10721 05:46:29,040 --> 05:46:32,100 wait until it gets cooked so let's go 10722 05:46:32,100 --> 05:46:33,718 pick it up and the other you go turns it 10723 05:46:33,718 --> 05:46:34,378 off 10724 05:46:34,378 --> 05:46:36,180 all right awesome we've got a really 10725 05:46:36,180 --> 05:46:38,580 nice visual all that's left is to have a 10726 05:46:38,580 --> 05:46:40,860 proper visual progress bar and with this 10727 05:46:40,860 --> 05:46:42,120 we actually have another interesting 10728 05:46:42,120 --> 05:46:43,500 clean code question 10729 05:46:43,500 --> 05:46:45,360 right now the progress bar that we made 10730 05:46:45,360 --> 05:46:47,458 over here on the cutting counter that 10731 05:46:47,458 --> 05:46:49,620 one is great so we would like to reuse 10732 05:46:49,620 --> 05:46:52,080 that however if we look over here on the 10733 05:46:52,080 --> 05:46:54,540 progress bar UI we can see this is only 10734 05:46:54,540 --> 05:46:56,340 working with the specific type cutting 10735 05:46:56,340 --> 05:46:57,298 counter 10736 05:46:57,298 --> 05:46:59,340 so by default this will not work with a 10737 05:46:59,340 --> 05:47:01,558 stealth counter so as usual we have 10738 05:47:01,558 --> 05:47:03,298 multiple approaches to solving this 10739 05:47:03,298 --> 05:47:05,340 problem one option would be to Simply 10740 05:47:05,340 --> 05:47:07,860 commonly duplicate the script then we 10741 05:47:07,860 --> 05:47:09,000 would make a completely different 10742 05:47:09,000 --> 05:47:10,680 progress bar UI class that would work 10743 05:47:10,680 --> 05:47:12,420 only with the stealth counter so that's 10744 05:47:12,420 --> 05:47:14,638 one approach that would work and that 10745 05:47:14,638 --> 05:47:16,378 approach might be good if you want the 10746 05:47:16,378 --> 05:47:18,000 progress bar to behave very very 10747 05:47:18,000 --> 05:47:18,958 differently 10748 05:47:18,958 --> 05:47:20,638 but over here I want both of them to 10749 05:47:20,638 --> 05:47:22,920 behave exactly the same so instead of 10750 05:47:22,920 --> 05:47:25,080 having some code application we can 10751 05:47:25,080 --> 05:47:26,820 write some good clean code but doing 10752 05:47:26,820 --> 05:47:28,680 exactly what we did with regards to the 10753 05:47:28,680 --> 05:47:31,020 kitchen object parent meaning we can use 10754 05:47:31,020 --> 05:47:32,760 a nice interface we can then Implement 10755 05:47:32,760 --> 05:47:34,500 on anything that has some kind of 10756 05:47:34,500 --> 05:47:37,320 progress so let's do exactly that first 10757 05:47:37,320 --> 05:47:39,000 of all let's actually go inside the 10758 05:47:39,000 --> 05:47:40,620 cutting counter so let's go inside the 10759 05:47:40,620 --> 05:47:42,298 prefab then over here we've got the 10760 05:47:42,298 --> 05:47:43,740 progress bar and this one is just a 10761 05:47:43,740 --> 05:47:45,420 regular game object but since we're 10762 05:47:45,420 --> 05:47:47,040 going to reuse this let's make this a 10763 05:47:47,040 --> 05:47:49,378 proper prefab so let's find over here 10764 05:47:49,378 --> 05:47:51,180 all of our prefabs and just drag the 10765 05:47:51,180 --> 05:47:52,980 progress bar UI inside the prefabs 10766 05:47:52,980 --> 05:47:54,840 folder okay great so this is now a 10767 05:47:54,840 --> 05:47:57,120 proper prefab now let's define our 10768 05:47:57,120 --> 05:47:59,160 interface so let's create a brand new 10769 05:47:59,160 --> 05:48:01,378 c-sharp script as usual interface start 10770 05:48:01,378 --> 05:48:03,718 with I so let's go on I and for this one 10771 05:48:03,718 --> 05:48:05,520 we wanted to represent anything that has 10772 05:48:05,520 --> 05:48:07,200 progress so let's just call it literally 10773 05:48:07,200 --> 05:48:09,120 has progress 10774 05:48:09,120 --> 05:48:11,160 personally I like to use the word has to 10775 05:48:11,160 --> 05:48:12,718 indicate that a certain object has 10776 05:48:12,718 --> 05:48:15,180 certain Behavior so in this case objects 10777 05:48:15,180 --> 05:48:16,680 that implement this interface will have 10778 05:48:16,680 --> 05:48:18,718 some kind of progress Behavior so now 10779 05:48:18,718 --> 05:48:20,400 over here for the interface let's first 10780 05:48:20,400 --> 05:48:22,020 make it so this one does not extend 10781 05:48:22,020 --> 05:48:23,638 amount of behavior instead of a quest 10782 05:48:23,638 --> 05:48:26,458 this one is an interface okay great so 10783 05:48:26,458 --> 05:48:27,958 now for the functions that we're going 10784 05:48:27,958 --> 05:48:30,180 to need if we look in the progress bar 10785 05:48:30,180 --> 05:48:31,558 and we'll look at the cutting counter 10786 05:48:31,558 --> 05:48:33,058 references we can see the only one is 10787 05:48:33,058 --> 05:48:35,580 literally just this so we just have to 10788 05:48:35,580 --> 05:48:37,500 listen to the event and then the rest of 10789 05:48:37,500 --> 05:48:39,600 progress bar Works inside of it so real 10790 05:48:39,600 --> 05:48:41,100 and interface is the only thing we need 10791 05:48:41,100 --> 05:48:42,900 to Define so let's actually go inside 10792 05:48:42,900 --> 05:48:44,940 the cutting counter so here we have the 10793 05:48:44,940 --> 05:48:46,620 unprogress change event and then we have 10794 05:48:46,620 --> 05:48:48,360 this so we can literally just copy this 10795 05:48:48,360 --> 05:48:50,940 go into the I has progress and let's put 10796 05:48:50,940 --> 05:48:52,260 exactly this 10797 05:48:52,260 --> 05:48:54,120 okay that's it that is literally all we 10798 05:48:54,120 --> 05:48:56,520 need now if we wanted we can also make a 10799 05:48:56,520 --> 05:48:57,958 function to expose the progress amount 10800 05:48:57,958 --> 05:49:00,000 but since we included over here on the 10801 05:49:00,000 --> 05:49:01,798 event then we really don't need it just 10802 05:49:01,798 --> 05:49:03,840 this is enough now let's go over here on 10803 05:49:03,840 --> 05:49:06,058 the progress bar UI script instead of 10804 05:49:06,058 --> 05:49:07,320 working with the type cutting counter 10805 05:49:07,320 --> 05:49:09,420 instead let's work with a type that has 10806 05:49:09,420 --> 05:49:12,058 I has progress so let's rename this Q 10807 05:49:12,058 --> 05:49:14,160 has progress 10808 05:49:14,160 --> 05:49:15,660 and it's going to have the exact same 10809 05:49:15,660 --> 05:49:18,058 event the only difference is over here 10810 05:49:18,058 --> 05:49:19,860 instead of the event RX being the one 10811 05:49:19,860 --> 05:49:21,360 inside the cutting counter is the one 10812 05:49:21,360 --> 05:49:22,740 inside the eye has progress so let's 10813 05:49:22,740 --> 05:49:25,080 make sure to change this I has progress 10814 05:49:25,080 --> 05:49:27,420 okay so the signature matches let's just 10815 05:49:27,420 --> 05:49:29,160 obviously rename this 10816 05:49:29,160 --> 05:49:30,780 so let's rename instead of cutting 10817 05:49:30,780 --> 05:49:33,718 counter let's rename has progress on 10818 05:49:33,718 --> 05:49:35,700 progress change and that's pretty much 10819 05:49:35,700 --> 05:49:37,620 it we don't have any more errors so 10820 05:49:37,620 --> 05:49:39,000 everything over here is now working 10821 05:49:39,000 --> 05:49:41,700 nicely with our interface and back here 10822 05:49:41,700 --> 05:49:43,138 in the editor once we're still inside 10823 05:49:43,138 --> 05:49:44,700 the cutting counter 10824 05:49:44,700 --> 05:49:46,920 suddenly interfaces do have one downside 10825 05:49:46,920 --> 05:49:48,480 when it comes to Unity 10826 05:49:48,480 --> 05:49:50,638 if we look in the progress bar UI down 10827 05:49:50,638 --> 05:49:52,798 there we can see the progress bar UI and 10828 05:49:52,798 --> 05:49:54,120 previously we had the counter field 10829 05:49:54,120 --> 05:49:56,760 exposed in the editor however now by 10830 05:49:56,760 --> 05:49:58,680 changing into an interface there we have 10831 05:49:58,680 --> 05:50:00,500 the issue the film does not show up here 10832 05:50:00,500 --> 05:50:02,760 interfaces do not show up in the editor 10833 05:50:02,760 --> 05:50:04,680 because Unity basically has no way of 10834 05:50:04,680 --> 05:50:05,940 knowing that the interface won't be 10835 05:50:05,940 --> 05:50:07,680 implemented by some kind of game object 10836 05:50:07,680 --> 05:50:09,780 so sadly this is the one thing that 10837 05:50:09,780 --> 05:50:12,000 doesn't work very well with unity the 10838 05:50:12,000 --> 05:50:13,260 solution that I normally do is actually 10839 05:50:13,260 --> 05:50:15,660 pretty simple instead of exposing the 10840 05:50:15,660 --> 05:50:17,458 interface which does not work and said 10841 05:50:17,458 --> 05:50:19,200 let's just make this a regular private 10842 05:50:19,200 --> 05:50:19,860 field 10843 05:50:19,860 --> 05:50:21,660 and then let's make a serialized film 10844 05:50:21,660 --> 05:50:23,160 and for this one let's make it a type 10845 05:50:23,160 --> 05:50:25,200 game object and let's call it has 10846 05:50:25,200 --> 05:50:27,718 progress game object 10847 05:50:27,718 --> 05:50:29,520 okay so like this we have a regular 10848 05:50:29,520 --> 05:50:31,080 serialized field with a regular game 10849 05:50:31,080 --> 05:50:33,240 object so if you look here yep we do 10850 05:50:33,240 --> 05:50:35,580 have that field so now we can indeed 10851 05:50:35,580 --> 05:50:37,798 Drag The Cutting counter reference and 10852 05:50:37,798 --> 05:50:39,180 then over here in the code in order to 10853 05:50:39,180 --> 05:50:40,680 get the has progress that is super 10854 05:50:40,680 --> 05:50:43,200 simple has progress we just go into the 10855 05:50:43,200 --> 05:50:44,820 hash progress game object and get 10856 05:50:44,820 --> 05:50:47,520 component of type I has progress 10857 05:50:47,520 --> 05:50:50,040 okay so that's it now our code does work 10858 05:50:50,040 --> 05:50:52,080 however of course one big potential 10859 05:50:52,080 --> 05:50:53,940 issue with this is that over here we 10860 05:50:53,940 --> 05:50:56,218 have a field of type game object meaning 10861 05:50:56,218 --> 05:50:58,138 that we have no guarantee that this 10862 05:50:58,138 --> 05:50:59,638 field does have a component that 10863 05:50:59,638 --> 05:51:01,680 implements the interface so we cannot 10864 05:51:01,680 --> 05:51:03,120 make sure that we drag the correct 10865 05:51:03,120 --> 05:51:04,920 reference we can drag any reference 10866 05:51:04,920 --> 05:51:06,600 doesn't have to have our progress 10867 05:51:06,600 --> 05:51:08,820 interface so in order to keep our sound 10868 05:51:08,820 --> 05:51:10,920 safe let's add a nice safety warning so 10869 05:51:10,920 --> 05:51:14,160 over here if has progress equals no so 10870 05:51:14,160 --> 05:51:15,600 if this one is known that means that 10871 05:51:15,600 --> 05:51:17,100 that game object does not have any 10872 05:51:17,100 --> 05:51:19,260 progress interface if so let's do a 10873 05:51:19,260 --> 05:51:22,020 debug download error 10874 05:51:22,020 --> 05:51:25,080 and let's say the game object and let's 10875 05:51:25,080 --> 05:51:28,218 pass in this game object 10876 05:51:29,280 --> 05:51:31,740 does not have a component that 10877 05:51:31,740 --> 05:51:35,458 implements I has progress 10878 05:51:35,458 --> 05:51:37,260 so this way if we make a mistake we 10879 05:51:37,260 --> 05:51:38,580 won't have a nice error message 10880 05:51:38,580 --> 05:51:40,798 basically this is the one workaround 10881 05:51:40,798 --> 05:51:42,480 that you need to use since Unity does 10882 05:51:42,480 --> 05:51:44,940 not support dragging references in the 10883 05:51:44,940 --> 05:51:46,920 editor if they are interface references 10884 05:51:46,920 --> 05:51:49,320 okay so with that everything is good so 10885 05:51:49,320 --> 05:51:51,360 all of our progress bar UI this should 10886 05:51:51,360 --> 05:51:53,580 all be working perfectly we just need to 10887 05:51:53,580 --> 05:51:55,320 go over here into our cutting count 10888 05:51:55,320 --> 05:51:57,540 script and let's make it so that we 10889 05:51:57,540 --> 05:51:59,280 Implement our interface so I has 10890 05:51:59,280 --> 05:52:01,200 progress and we got an error just 10891 05:52:01,200 --> 05:52:03,540 because even though we did Define that 10892 05:52:03,540 --> 05:52:04,798 interface remember the on progress 10893 05:52:04,798 --> 05:52:07,138 change again keep in mind that the types 10894 05:52:07,138 --> 05:52:09,420 depend on not just their name but where 10895 05:52:09,420 --> 05:52:11,280 they're at so this type that we have 10896 05:52:11,280 --> 05:52:12,718 here is the one that we Define here 10897 05:52:12,718 --> 05:52:14,700 which is not the same one that we have 10898 05:52:14,700 --> 05:52:16,260 here so even though they have the exact 10899 05:52:16,260 --> 05:52:17,700 same name because they are in different 10900 05:52:17,700 --> 05:52:19,440 places they are actually different types 10901 05:52:19,440 --> 05:52:21,180 so we need to make sure to use the type 10902 05:52:21,180 --> 05:52:22,920 in the interface over here let's just go 10903 05:52:22,920 --> 05:52:25,020 into the I has progress and use that 10904 05:52:25,020 --> 05:52:27,000 exact type and get rid of this one okay 10905 05:52:27,000 --> 05:52:28,378 so that's it that's the change we need 10906 05:52:28,378 --> 05:52:30,540 and down here when firing let's just 10907 05:52:30,540 --> 05:52:32,638 fire with that type and down here the 10908 05:52:32,638 --> 05:52:35,100 same thing with that type okay great so 10909 05:52:35,100 --> 05:52:37,320 like the this The Cutting counter should 10910 05:52:37,320 --> 05:52:38,820 still be working exactly the same as 10911 05:52:38,820 --> 05:52:40,980 previously again when refactoring any 10912 05:52:40,980 --> 05:52:42,718 code always do a quick test and let's do 10913 05:52:42,718 --> 05:52:44,878 that let's make sure to save our counter 10914 05:52:44,878 --> 05:52:46,740 save the prefab go back outside head on 10915 05:52:46,740 --> 05:52:48,900 play now let's pick up some cheese put 10916 05:52:48,900 --> 05:52:50,218 it there cut and there you go the 10917 05:52:50,218 --> 05:52:52,500 progress bar still does work okay great 10918 05:52:52,500 --> 05:52:54,480 now let's apply it to the stove and that 10919 05:52:54,480 --> 05:52:55,620 is actually going to be very simple 10920 05:52:55,620 --> 05:52:57,900 first let's go inside the stove so let's 10921 05:52:57,900 --> 05:52:59,700 find the stove counter let's open it up 10922 05:52:59,700 --> 05:53:01,798 go inside the prefab and over here let's 10923 05:53:01,798 --> 05:53:04,080 drag the progress bar UI prefab so let's 10924 05:53:04,080 --> 05:53:06,180 drag that then down here we already have 10925 05:53:06,180 --> 05:53:07,680 the has progress game object so let's 10926 05:53:07,680 --> 05:53:09,360 drag the stove counter and that's it 10927 05:53:09,360 --> 05:53:10,980 there's nothing else we need to touch 10928 05:53:10,980 --> 05:53:13,680 here we just need to go over here into 10929 05:53:13,680 --> 05:53:15,240 the stove counter and as usual let's 10930 05:53:15,240 --> 05:53:17,458 implement the interface so the eye has 10931 05:53:17,458 --> 05:53:18,540 progress 10932 05:53:18,540 --> 05:53:19,980 and now let's implement it pretty much 10933 05:53:19,980 --> 05:53:21,480 just like we did on the cutting counter 10934 05:53:21,480 --> 05:53:23,878 so we can actually just copy this so we 10935 05:53:23,878 --> 05:53:25,260 just need to implement the event so 10936 05:53:25,260 --> 05:53:27,480 that's it and now for firing the event 10937 05:53:27,480 --> 05:53:29,878 let's go down and see where we are 10938 05:53:29,878 --> 05:53:32,760 modifying all of our timers so let's go 10939 05:53:32,760 --> 05:53:34,200 down to when the player drops something 10940 05:53:34,200 --> 05:53:36,900 so we do the on say change and now let's 10941 05:53:36,900 --> 05:53:40,200 invoke this event so this and for the 10942 05:53:40,200 --> 05:53:42,540 progress bar for the progress normalize 10943 05:53:42,540 --> 05:53:44,160 this one is very simple so just frying 10944 05:53:44,160 --> 05:53:47,520 timer divided by the frying recipe so 10945 05:53:47,520 --> 05:53:49,798 dot frying timer Max 10946 05:53:49,798 --> 05:53:51,420 okay that's it we are modifying the 10947 05:53:51,420 --> 05:53:53,580 progress now let's go up here when we 10948 05:53:53,580 --> 05:53:55,920 are in the Frank State and when we do 10949 05:53:55,920 --> 05:53:57,958 let's fire off the on progress change 10950 05:53:57,958 --> 05:54:00,660 event okay great and finally down here 10951 05:54:00,660 --> 05:54:02,878 when we have defined over here let's 10952 05:54:02,878 --> 05:54:05,280 also fire except obviously we have the 10953 05:54:05,280 --> 05:54:08,218 burning timer and the burning timer Max 10954 05:54:08,218 --> 05:54:10,620 and then just to make sure that the bar 10955 05:54:10,620 --> 05:54:12,120 actually hides itself when we go into 10956 05:54:12,120 --> 05:54:14,218 burned let's also find an event this one 10957 05:54:14,218 --> 05:54:15,540 doesn't have a timer so let's just put 10958 05:54:15,540 --> 05:54:18,240 it on xeraf okay that's really it 10959 05:54:18,240 --> 05:54:20,400 we don't need to touch the progress bar 10960 05:54:20,400 --> 05:54:22,920 UI at all Let's test this just make sure 10961 05:54:22,920 --> 05:54:25,020 to save the prefab let's go back outside 10962 05:54:25,020 --> 05:54:27,600 and hit on point and right away yep the 10963 05:54:27,600 --> 05:54:29,400 bar is indeed hidden now if I pick up 10964 05:54:29,400 --> 05:54:31,200 some meat and I drop it and there you go 10965 05:54:31,200 --> 05:54:34,020 got a really nice bar going up any up 10966 05:54:34,020 --> 05:54:35,700 going up on the burning site and let's 10967 05:54:35,700 --> 05:54:36,900 get to the end let's see if the bar 10968 05:54:36,900 --> 05:54:38,878 hides so it gets to the end and you have 10969 05:54:38,878 --> 05:54:40,860 to go the bar that's high all right 10970 05:54:40,860 --> 05:54:43,080 awesome and if I pick up something 10971 05:54:43,080 --> 05:54:44,878 actually this was the one event that we 10972 05:54:44,878 --> 05:54:47,340 forgot so let's fix that so let's just 10973 05:54:47,340 --> 05:54:48,600 copy the one where we set the progress 10974 05:54:48,600 --> 05:54:50,160 normalized to zero and over here if the 10975 05:54:50,160 --> 05:54:52,260 player picks up something let's add the 10976 05:54:52,260 --> 05:54:54,180 progress back into zero 10977 05:54:54,180 --> 05:54:56,280 so here we are let's pick up some meat 10978 05:54:56,280 --> 05:54:58,620 drop it on there okay let's wait for it 10979 05:54:58,620 --> 05:55:00,600 to be cooked okay it's cooked now before 10980 05:55:00,600 --> 05:55:02,458 it burns pick it up and there you go the 10981 05:55:02,458 --> 05:55:05,700 bar is gone all right awesome okay so 10982 05:55:05,700 --> 05:55:07,980 here we have again another example of 10983 05:55:07,980 --> 05:55:10,200 the power of writing good clean code we 10984 05:55:10,200 --> 05:55:12,298 made a nice generic progress bar and we 10985 05:55:12,298 --> 05:55:13,680 very easily made it work with a 10986 05:55:13,680 --> 05:55:15,540 completely different counter which of 10987 05:55:15,540 --> 05:55:16,798 course would also work with literally 10988 05:55:16,798 --> 05:55:18,360 anything that implements that interface 10989 05:55:18,360 --> 05:55:20,458 doesn't have to be a counter now let me 10990 05:55:20,458 --> 05:55:22,558 make one note here basically I showed 10991 05:55:22,558 --> 05:55:24,120 you how to make a generic progress bar 10992 05:55:24,120 --> 05:55:26,340 and reuse it but let's say you want to 10993 05:55:26,340 --> 05:55:28,260 do something specific just for the solve 10994 05:55:28,260 --> 05:55:30,480 well one approach like I mentioned is to 10995 05:55:30,480 --> 05:55:32,160 duplicate the code and make a progress 10996 05:55:32,160 --> 05:55:34,620 bar that works only with the solve but 10997 05:55:34,620 --> 05:55:36,298 another approach is to Simply add more 10998 05:55:36,298 --> 05:55:37,798 elements on top 10999 05:55:37,798 --> 05:55:39,900 for example during the Polish stage 11000 05:55:39,900 --> 05:55:41,878 we're going to do exactly that 11001 05:55:41,878 --> 05:55:43,860 we're going to add an extra UI element 11002 05:55:43,860 --> 05:55:45,360 that won't show up to one of the player 11003 05:55:45,360 --> 05:55:47,400 when the food is about to burn so I just 11004 05:55:47,400 --> 05:55:48,900 want to point out how you can mix and 11005 05:55:48,900 --> 05:55:50,700 match both them you can have both 11006 05:55:50,700 --> 05:55:52,620 generic components coupled with specific 11007 05:55:52,620 --> 05:55:53,638 components 11008 05:55:53,638 --> 05:55:55,320 but for now our progress bar everything 11009 05:55:55,320 --> 05:55:57,480 is looking pretty good so let's leave 11010 05:55:57,480 --> 05:55:58,860 that burn warning just for the police 11011 05:55:58,860 --> 05:56:01,320 age now the next very important thing we 11012 05:56:01,320 --> 05:56:03,120 need is some points so let's do that in 11013 05:56:03,120 --> 05:56:04,620 the next lecture 11014 05:56:04,620 --> 05:56:07,558 hello and welcome I'm your kudmaki in 11015 05:56:07,558 --> 05:56:09,000 this lecture we're going to create the 11016 05:56:09,000 --> 05:56:10,920 plates counter this one is just going to 11017 05:56:10,920 --> 05:56:12,718 spawn some points which we can then pick 11018 05:56:12,718 --> 05:56:15,360 up to grab some objects okay so let's 11019 05:56:15,360 --> 05:56:17,400 begin making the counter as usual so 11020 05:56:17,400 --> 05:56:19,378 let's go inside our prefabs inside our 11021 05:56:19,378 --> 05:56:21,058 counters right click the base counter 11022 05:56:21,058 --> 05:56:23,700 make a new prefab variant 11023 05:56:23,700 --> 05:56:26,218 called the plates counter 11024 05:56:26,218 --> 05:56:29,160 let's go inside and let's drag the 11025 05:56:29,160 --> 05:56:31,020 visual for the plates counter let's go 11026 05:56:31,020 --> 05:56:32,580 into scene view so we can see it okay 11027 05:56:32,580 --> 05:56:34,740 let's duplicate this make this the 11028 05:56:34,740 --> 05:56:37,680 selected let's go inside and we can 11029 05:56:37,680 --> 05:56:39,240 actually hide the Eternal Sprite we only 11030 05:56:39,240 --> 05:56:40,620 need this one so on this one let's 11031 05:56:40,620 --> 05:56:42,900 modify it for the counter selected on 11032 05:56:42,900 --> 05:56:44,878 the selected let's make it just one 11033 05:56:44,878 --> 05:56:47,280 percent bigger and let's add the 11034 05:56:47,280 --> 05:56:49,500 selected counter Vision okay then inside 11035 05:56:49,500 --> 05:56:51,180 obviously drag the reference for the 11036 05:56:51,180 --> 05:56:53,520 kitchen counter okay that's our basic 11037 05:56:53,520 --> 05:56:55,260 setup now let's make our script to run 11038 05:56:55,260 --> 05:56:57,480 this so let's create a brand new c-sharp 11039 05:56:57,480 --> 05:57:00,718 script for the plates counter let's 11040 05:57:00,718 --> 05:57:02,878 attach the scrub to the plates counter 11041 05:57:02,878 --> 05:57:05,700 and open okay now here as usual let's 11042 05:57:05,700 --> 05:57:08,458 extend our base counter and then first 11043 05:57:08,458 --> 05:57:11,100 let's handle the spawn timer logic so 11044 05:57:11,100 --> 05:57:12,780 basically we want to spawn some plates 11045 05:57:12,780 --> 05:57:14,760 every once amount of time 11046 05:57:14,760 --> 05:57:17,458 somewhat sorry simple float for the 11047 05:57:17,458 --> 05:57:20,400 spawn plate timer then let's make a 11048 05:57:20,400 --> 05:57:22,200 simple update on timer let's increase 11049 05:57:22,200 --> 05:57:24,480 the spawn point timer by time dot of 11050 05:57:24,480 --> 05:57:26,780 time 11051 05:57:27,240 --> 05:57:29,280 and then just check if it's above a 11052 05:57:29,280 --> 05:57:31,860 certain maximum 11053 05:57:31,860 --> 05:57:34,138 so if it is above something in this case 11054 05:57:34,138 --> 05:57:36,180 we're going to have a fixed value 11055 05:57:36,180 --> 05:57:37,860 but still like I mentioned in the very 11056 05:57:37,860 --> 05:57:39,840 beginning of this course let us not use 11057 05:57:39,840 --> 05:57:41,400 magic numbers here you should never use 11058 05:57:41,400 --> 05:57:42,718 magic numbers 11059 05:57:42,718 --> 05:57:44,580 instead if you wanted to make it edible 11060 05:57:44,580 --> 05:57:46,200 you could also make it up here as the 11061 05:57:46,200 --> 05:57:48,120 serialized field but in my case for 11062 05:57:48,120 --> 05:57:49,440 design that I'm going for I'm perfectly 11063 05:57:49,440 --> 05:57:51,058 content with having a fixed value so 11064 05:57:51,058 --> 05:57:53,940 just appear pretty simple the spawn 11065 05:57:53,940 --> 05:57:56,940 complete timer Max and let's define it 11066 05:57:56,940 --> 05:57:58,440 to 4f 11067 05:57:58,440 --> 05:58:01,500 and let's use it over here okay great so 11068 05:58:01,500 --> 05:58:02,820 this is what we want 11069 05:58:02,820 --> 05:58:04,680 however for spawning it's actually going 11070 05:58:04,680 --> 05:58:07,320 to be a bit tricky the plate is supposed 11071 05:58:07,320 --> 05:58:09,780 to be a kitchen object the player should 11072 05:58:09,780 --> 05:58:12,180 be able to carry the plate and right now 11073 05:58:12,180 --> 05:58:13,980 for design that we Define is that each 11074 05:58:13,980 --> 05:58:15,900 kitchen object can only have one parent 11075 05:58:15,900 --> 05:58:18,240 and each parent can only have one object 11076 05:58:18,240 --> 05:58:20,218 but over here we want to spawn multiple 11077 05:58:20,218 --> 05:58:22,260 objects now let's quickly see what 11078 05:58:22,260 --> 05:58:23,820 happens if we try spawning multiple as 11079 05:58:23,820 --> 05:58:25,798 usual so let's just go into the kitchen 11080 05:58:25,798 --> 05:58:28,320 object spawn a kitchen object which 11081 05:58:28,320 --> 05:58:30,660 means we need the plate so so let's do 11082 05:58:30,660 --> 05:58:33,180 it up here as usual a serialized film 11083 05:58:33,180 --> 05:58:36,180 private kitchen object so for the Plate 11084 05:58:36,180 --> 05:58:40,040 Kitchen object SL 11085 05:58:40,440 --> 05:58:42,120 so we're going to need to make this and 11086 05:58:42,120 --> 05:58:43,558 then we're just going to spawn this 11087 05:58:43,558 --> 05:58:46,020 object on this 11088 05:58:46,020 --> 05:58:47,940 okay so this is going to throw an error 11089 05:58:47,940 --> 05:58:49,920 but so let's see let's first create the 11090 05:58:49,920 --> 05:58:50,760 object 11091 05:58:50,760 --> 05:58:53,458 over here let's go inside our objects 11092 05:58:53,458 --> 05:58:55,080 our kitchen objects let's create a brand 11093 05:58:55,080 --> 05:58:57,298 new kitchen object call it just the 11094 05:58:57,298 --> 05:58:59,580 plate for the object name this one is a 11095 05:58:59,580 --> 05:59:02,280 plate for the Sprite let's go with the 11096 05:59:02,280 --> 05:59:04,500 plate Sprite and for the prefab let's 11097 05:59:04,500 --> 05:59:06,958 make it so let's duplicate one of these 11098 05:59:06,958 --> 05:59:09,120 called the plate 11099 05:59:09,120 --> 05:59:11,760 let's go inside it and obviously make 11100 05:59:11,760 --> 05:59:14,340 sure to change say the changes then over 11101 05:59:14,340 --> 05:59:16,860 here let's drag the plate visual get rid 11102 05:59:16,860 --> 05:59:19,320 of the tomato and on the plate let's 11103 05:59:19,320 --> 05:59:21,840 make sure to assign the plate and 11104 05:59:21,840 --> 05:59:23,820 finally let's exit this let's make sure 11105 05:59:23,820 --> 05:59:25,620 to save it and on the plate let's drag 11106 05:59:25,620 --> 05:59:28,200 the plate prefab okay so we have the 11107 05:59:28,200 --> 05:59:30,180 kitchen object so now let's just go 11108 05:59:30,180 --> 05:59:32,940 inside our plates counter and over here 11109 05:59:32,940 --> 05:59:35,160 let's drag the reference so the 11110 05:59:35,160 --> 05:59:36,900 reference to the play kitchen object 11111 05:59:36,900 --> 05:59:38,580 let's also drag the reference to the 11112 05:59:38,580 --> 05:59:40,440 counter top point then on the selected 11113 05:59:40,440 --> 05:59:42,298 drag the reference to our base counter 11114 05:59:42,298 --> 05:59:44,160 and finally start off with a selected 11115 05:59:44,160 --> 05:59:46,138 disabled okay so this should be working 11116 05:59:46,138 --> 05:59:48,000 let's just add a plate counter over here 11117 05:59:48,000 --> 05:59:50,340 onto our scene so let's pick up a police 11118 05:59:50,340 --> 05:59:51,660 counter and put it somewhere in here 11119 05:59:51,660 --> 05:59:54,540 over there on the side so on an X of 7.5 11120 05:59:54,540 --> 05:59:58,620 then 0 and let's say on zero Maybe 11121 05:59:58,620 --> 06:00:00,360 let's make sure we have space for one 11122 06:00:00,360 --> 06:00:02,100 more counter over there so let's 11123 06:00:02,100 --> 06:00:04,260 duplicate this empty counter and let's 11124 06:00:04,260 --> 06:00:05,700 put it over there pointing to the side 11125 06:00:05,700 --> 06:00:10,260 so this one is on 7.50 and -2 11126 06:00:10,260 --> 06:00:11,878 okay so now let's just make sure that 11127 06:00:11,878 --> 06:00:14,160 they perfectly match so let's put this 11128 06:00:14,160 --> 06:00:17,218 one on a set of minus 0.5 okay so let's 11129 06:00:17,218 --> 06:00:19,260 test all right so here we are and look 11130 06:00:19,260 --> 06:00:22,020 at that and after four seconds if there 11131 06:00:22,020 --> 06:00:24,240 go it spawns the object and then it 11132 06:00:24,240 --> 06:00:25,740 immediately tried to spawn another one 11133 06:00:25,740 --> 06:00:27,180 and there you go we have the error 11134 06:00:27,180 --> 06:00:29,280 kitchen object parent only has a kitchen 11135 06:00:29,280 --> 06:00:31,680 object basically the way we designed our 11136 06:00:31,680 --> 06:00:33,298 game and set up the code assumes that a 11137 06:00:33,298 --> 06:00:35,400 single encounter will only hold a single 11138 06:00:35,400 --> 06:00:37,620 kitchen object so we cannot have 11139 06:00:37,620 --> 06:00:40,138 multiple plates on the same counter now 11140 06:00:40,138 --> 06:00:41,340 when solution for this problem is 11141 06:00:41,340 --> 06:00:43,558 actually quite simple when we spawn the 11142 06:00:43,558 --> 06:00:46,138 plates instead let's not spawn a kitchen 11143 06:00:46,138 --> 06:00:48,360 object instead we're just going to spawn 11144 06:00:48,360 --> 06:00:50,638 a dumb visual then when the player 11145 06:00:50,638 --> 06:00:52,378 interacts with the counter that is when 11146 06:00:52,378 --> 06:00:53,820 we're going to spawn the proper kitchen 11147 06:00:53,820 --> 06:00:56,458 object so let's do that although again 11148 06:00:56,458 --> 06:00:57,840 let's keep the logic and division 11149 06:00:57,840 --> 06:01:00,058 separate so over here let's first just 11150 06:01:00,058 --> 06:01:02,040 handle the logic so we just need to keep 11151 06:01:02,040 --> 06:01:04,620 track of how many points respond so for 11152 06:01:04,620 --> 06:01:06,240 that let's start up here you private end 11153 06:01:06,240 --> 06:01:09,718 for the plates spawn amount and let's 11154 06:01:09,718 --> 06:01:11,520 also do another private end for the 11155 06:01:11,520 --> 06:01:15,138 plates Pawn amount Max 11156 06:01:17,100 --> 06:01:18,900 and let's say we can spawn at most four 11157 06:01:18,900 --> 06:01:19,920 plates 11158 06:01:19,920 --> 06:01:21,600 okay so over here instead of spawning 11159 06:01:21,600 --> 06:01:23,340 the object let's first of all actually 11160 06:01:23,340 --> 06:01:25,200 reset the timer 11161 06:01:25,200 --> 06:01:27,718 so let's put it back to zero zero and on 11162 06:01:27,718 --> 06:01:30,240 the plate spawn the mount let's check if 11163 06:01:30,240 --> 06:01:34,458 this one is under the plate spawn Max 11164 06:01:34,680 --> 06:01:37,260 and if so 11165 06:01:37,260 --> 06:01:39,600 let's go into the plate spawn amount and 11166 06:01:39,600 --> 06:01:41,940 increase it by one okay so that's logic 11167 06:01:41,940 --> 06:01:43,680 super simple now let's send the visual 11168 06:01:43,680 --> 06:01:46,558 so let's first make our script so let's 11169 06:01:46,558 --> 06:01:48,840 create a brand new c-sharp script for 11170 06:01:48,840 --> 06:01:51,780 the plates counter visual 11171 06:01:51,780 --> 06:01:53,760 now let's make sure that the visual so 11172 06:01:53,760 --> 06:01:56,040 let's go inside the prefab and over here 11173 06:01:56,040 --> 06:01:57,480 we've got the visual let's attach it 11174 06:01:57,480 --> 06:01:59,760 okay open now here basically the first 11175 06:01:59,760 --> 06:02:01,440 thing we need is we need to know where 11176 06:02:01,440 --> 06:02:02,940 to spawn the visuals 11177 06:02:02,940 --> 06:02:04,680 so let's actually add a reference to our 11178 06:02:04,680 --> 06:02:06,240 counter top point 11179 06:02:06,240 --> 06:02:08,638 so let's add a serialized film for 11180 06:02:08,638 --> 06:02:11,340 private transform for the counter top 11181 06:02:11,340 --> 06:02:13,860 point then let's also add a reference 11182 06:02:13,860 --> 06:02:15,480 for the prefab we're going to spawn so 11183 06:02:15,480 --> 06:02:17,280 let's call it the plate visual prefab 11184 06:02:17,280 --> 06:02:19,500 then here in the editor let's drag the 11185 06:02:19,500 --> 06:02:21,360 references so the countertop Point Place 11186 06:02:21,360 --> 06:02:23,160 it in there and for the plate vision 11187 06:02:23,160 --> 06:02:26,160 prefab let's go a pair and find the 11188 06:02:26,160 --> 06:02:28,138 visuals for the kitchen object so these 11189 06:02:28,138 --> 06:02:29,760 are just the visuals and let's write the 11190 06:02:29,760 --> 06:02:31,860 plate visual so the plate visual not the 11191 06:02:31,860 --> 06:02:33,958 Plate Kitchen object okay now back in 11192 06:02:33,958 --> 06:02:35,520 the code here we obviously need to know 11193 06:02:35,520 --> 06:02:37,740 when I play this Bond so let's go into 11194 06:02:37,740 --> 06:02:39,718 the plates counter and make a nice event 11195 06:02:39,718 --> 06:02:42,660 so fun week event event handler as usual 11196 06:02:42,660 --> 06:02:45,660 on plate spawned 11197 06:02:45,660 --> 06:02:47,700 and down here let's just find the event 11198 06:02:47,700 --> 06:02:50,900 so we just invoke 11199 06:02:51,120 --> 06:02:55,798 with this and eventar is not empty 11200 06:02:55,798 --> 06:02:58,138 okay that's it very simple and then on 11201 06:02:58,138 --> 06:02:59,400 the other script over here let's just 11202 06:02:59,400 --> 06:03:01,378 listen to it which also means that we 11203 06:03:01,378 --> 06:03:03,120 need a reference to our counter so let's 11204 06:03:03,120 --> 06:03:05,878 add up here the plates counter for the 11205 06:03:05,878 --> 06:03:07,920 plates counter so we're going to need to 11206 06:03:07,920 --> 06:03:09,958 drag the reference and then on start 11207 06:03:09,958 --> 06:03:12,000 let's listen to the on plate spawned 11208 06:03:12,000 --> 06:03:12,840 event 11209 06:03:12,840 --> 06:03:14,520 and when that happens then let's spawn 11210 06:03:14,520 --> 06:03:17,400 so let's call instantiate on the plate 11211 06:03:17,400 --> 06:03:19,080 visual prefab 11212 06:03:19,080 --> 06:03:21,000 let's put it inside the counter top 11213 06:03:21,000 --> 06:03:23,160 point so this is the transform for the 11214 06:03:23,160 --> 06:03:26,580 plate visual transform and that's pretty 11215 06:03:26,580 --> 06:03:28,798 much it okay so unlike this it should be 11216 06:03:28,798 --> 06:03:29,700 working 11217 06:03:29,700 --> 06:03:31,320 when the plate is spawned we should be 11218 06:03:31,320 --> 06:03:33,298 spawning a brand new visual back in the 11219 06:03:33,298 --> 06:03:34,860 editor we just need to drag the plates 11220 06:03:34,860 --> 06:03:37,080 counter reference like that let's exit 11221 06:03:37,080 --> 06:03:39,840 save the prefab and let's test okay so 11222 06:03:39,840 --> 06:03:41,760 here we are and if we wait for four 11223 06:03:41,760 --> 06:03:43,200 seconds we should be able to see a play 11224 06:03:43,200 --> 06:03:45,180 spawn yep there you go and if we wait 11225 06:03:45,180 --> 06:03:47,400 for a little bit more we should also be 11226 06:03:47,400 --> 06:03:49,100 able to see some more play Swing spawn 11227 06:03:49,100 --> 06:03:51,420 except we can't really see them that's 11228 06:03:51,420 --> 06:03:52,920 because we're spawning them on the exact 11229 06:03:52,920 --> 06:03:55,320 same spot every time but if we pause the 11230 06:03:55,320 --> 06:03:57,120 game and over here I'm looking the 11231 06:03:57,120 --> 06:03:59,340 hierarchy and find the plate counter and 11232 06:03:59,340 --> 06:04:01,260 inside the counter top Point yep we do 11233 06:04:01,260 --> 06:04:03,600 have four visions and if we wait for 11234 06:04:03,600 --> 06:04:05,400 longer then nope it's not going to spawn 11235 06:04:05,400 --> 06:04:07,020 anymore it's only going to spawn four 11236 06:04:07,020 --> 06:04:08,820 plates okay great 11237 06:04:08,820 --> 06:04:10,680 so some of the visual let yourself set 11238 06:04:10,680 --> 06:04:13,260 them by a tiny bit to know how much we 11239 06:04:13,260 --> 06:04:14,878 shouldn't offset let's keep track of how 11240 06:04:14,878 --> 06:04:16,740 many plates haven't spawned 11241 06:04:16,740 --> 06:04:18,540 so let's store up here on the visual 11242 06:04:18,540 --> 06:04:21,360 script in list of Game object 11243 06:04:21,360 --> 06:04:23,820 call it the plate visual game object 11244 06:04:23,820 --> 06:04:25,500 list 11245 06:04:25,500 --> 06:04:27,240 let's also make sure that you initialize 11246 06:04:27,240 --> 06:04:29,520 this so it lets you on awake let's 11247 06:04:29,520 --> 06:04:31,440 initialize this list 11248 06:04:31,440 --> 06:04:33,600 and then when we spawn them okay so here 11249 06:04:33,600 --> 06:04:35,878 we have the object that we spawned now 11250 06:04:35,878 --> 06:04:37,680 basically we just need to modify the low 11251 06:04:37,680 --> 06:04:39,120 composition 11252 06:04:39,120 --> 06:04:41,280 and let's put it on new Vector 3 on the 11253 06:04:41,280 --> 06:04:43,860 X so let's put it on zero then on the Z 11254 06:04:43,860 --> 06:04:45,660 we're also going to have zero and then 11255 06:04:45,660 --> 06:04:47,218 over here on the one let's offset it by 11256 06:04:47,218 --> 06:04:48,900 a certain amount and basically it's 11257 06:04:48,900 --> 06:04:50,400 going to be based on how many plates 11258 06:04:50,400 --> 06:04:51,840 have been spawned 11259 06:04:51,840 --> 06:04:53,878 so let's define up here a float for the 11260 06:04:53,878 --> 06:04:56,580 plate offset y let's put it at save 0.1 11261 06:04:56,580 --> 06:04:58,080 f 11262 06:04:58,080 --> 06:04:59,700 and over here we're going to offset it 11263 06:04:59,700 --> 06:05:01,680 by this much multiplied by how many 11264 06:05:01,680 --> 06:05:03,240 plates have been spawned so we can go 11265 06:05:03,240 --> 06:05:05,400 into our visual list account so you can 11266 06:05:05,400 --> 06:05:07,080 delete this and then we just need to add 11267 06:05:07,080 --> 06:05:09,660 it to the list so let's add this plate 11268 06:05:09,660 --> 06:05:12,718 visual transform.game object okay so now 11269 06:05:12,718 --> 06:05:14,580 each game object should respond at a 11270 06:05:14,580 --> 06:05:16,680 different height so let's see so here we 11271 06:05:16,680 --> 06:05:18,420 are and if we wait for four seconds we 11272 06:05:18,420 --> 06:05:20,040 should be able to see a plate and there 11273 06:05:20,040 --> 06:05:22,080 you go and now after four seconds we 11274 06:05:22,080 --> 06:05:23,700 should be able to see another one placed 11275 06:05:23,700 --> 06:05:25,620 slightly above and yep there it is okay 11276 06:05:25,620 --> 06:05:26,580 great 11277 06:05:26,580 --> 06:05:29,160 so everything is spawning perfectly both 11278 06:05:29,160 --> 06:05:30,840 in the logic as well as the visual now 11279 06:05:30,840 --> 06:05:33,058 let's actually pick up a plate so on the 11280 06:05:33,058 --> 06:05:34,680 plates counter as usual let's implement 11281 06:05:34,680 --> 06:05:35,940 the interact 11282 06:05:35,940 --> 06:05:38,820 so let's do a public let's override the 11283 06:05:38,820 --> 06:05:40,320 interact function 11284 06:05:40,320 --> 06:05:42,718 and now for picking up let's first see 11285 06:05:42,718 --> 06:05:45,480 if the player is actually empty-handed 11286 06:05:45,480 --> 06:05:48,360 so if and we check the player has 11287 06:05:48,360 --> 06:05:50,400 kitchen object so if the player does not 11288 06:05:50,400 --> 06:05:52,860 have a kitchen object 11289 06:05:52,860 --> 06:05:55,500 then the player is empty-handed okay 11290 06:05:55,500 --> 06:05:58,020 great then let's see if we have a plate 11291 06:05:58,020 --> 06:06:00,660 that we can give them so if the plate 11292 06:06:00,660 --> 06:06:02,760 spawned the mount if it is bigger than 11293 06:06:02,760 --> 06:06:04,860 zero 11294 06:06:04,860 --> 06:06:08,218 then there's at least one plate here and 11295 06:06:08,218 --> 06:06:10,558 if so let's give it to the player so how 11296 06:06:10,558 --> 06:06:12,780 we do that is one over here for logic 11297 06:06:12,780 --> 06:06:15,420 let's just increase it by one then let's 11298 06:06:15,420 --> 06:06:17,218 actually spawn the object so on the 11299 06:06:17,218 --> 06:06:19,680 kitchen object let's spawn the Plate 11300 06:06:19,680 --> 06:06:22,138 Kitchen object so and spawn it on the 11301 06:06:22,138 --> 06:06:23,100 player 11302 06:06:23,100 --> 06:06:24,900 and finally we just need to update the 11303 06:06:24,900 --> 06:06:27,540 visuals so let's make another event 11304 06:06:27,540 --> 06:06:30,540 so up here on plane spawn and on plate 11305 06:06:30,540 --> 06:06:32,040 removed 11306 06:06:32,040 --> 06:06:34,500 okay we have this event and then down 11307 06:06:34,500 --> 06:06:36,058 here on let's just whenever the player 11308 06:06:36,058 --> 06:06:38,340 picks it up let's invoke this with this 11309 06:06:38,340 --> 06:06:41,580 an event RX dot empty 11310 06:06:41,580 --> 06:06:43,378 okay great so now the visual let's 11311 06:06:43,378 --> 06:06:45,420 listen to this so we're here on start 11312 06:06:45,420 --> 06:06:47,940 for the plates counter listen to this 11313 06:06:47,940 --> 06:06:48,840 event 11314 06:06:48,840 --> 06:06:50,820 and when this event happens we just want 11315 06:06:50,820 --> 06:06:52,798 to destroy the very last plate 11316 06:06:52,798 --> 06:06:54,660 so let's grab the game object for the 11317 06:06:54,660 --> 06:06:56,878 played game object and recently just 11318 06:06:56,878 --> 06:06:59,218 going to go into our list so the plate 11319 06:06:59,218 --> 06:07:01,080 visual game object list 11320 06:07:01,080 --> 06:07:03,660 and let's pick up the very last one 11321 06:07:03,660 --> 06:07:05,878 so let's go into the list.count minus 11322 06:07:05,878 --> 06:07:07,378 one so this is going to be the very last 11323 06:07:07,378 --> 06:07:09,420 element of the list then let's remove 11324 06:07:09,420 --> 06:07:11,458 this one from the list so Point dot 11325 06:07:11,458 --> 06:07:14,280 remove this one that we just grabbed and 11326 06:07:14,280 --> 06:07:17,100 then we simply call destroy on this one 11327 06:07:17,100 --> 06:07:19,500 all right so that's it super simple 11328 06:07:19,500 --> 06:07:21,120 so we're here on the plates counter we 11329 06:07:21,120 --> 06:07:23,040 do all of our checks we cut it down by 11330 06:07:23,040 --> 06:07:23,820 one 11331 06:07:23,820 --> 06:07:25,740 we spawn the actual kitchen object then 11332 06:07:25,740 --> 06:07:27,420 we fire the event and over here the 11333 06:07:27,420 --> 06:07:29,400 event listens and updates a visual okay 11334 06:07:29,400 --> 06:07:30,540 let's test 11335 06:07:30,540 --> 06:07:32,638 so here we are let's wait for a play to 11336 06:07:32,638 --> 06:07:34,558 be spawned and when this phone there it 11337 06:07:34,558 --> 06:07:36,000 is I'm going to pick it up and if there 11338 06:07:36,000 --> 06:07:37,558 go the player is now carrying a plate 11339 06:07:37,558 --> 06:07:39,000 let's drop it here and there you go 11340 06:07:39,000 --> 06:07:40,440 there's another one now let's wait for a 11341 06:07:40,440 --> 06:07:42,360 bunch more to be spawned okay so the 11342 06:07:42,360 --> 06:07:43,980 plates counter is full now if I pick up 11343 06:07:43,980 --> 06:07:45,840 it should only eliminate the last visual 11344 06:07:45,840 --> 06:07:47,580 pick it up any of there you go it'll 11345 06:07:47,580 --> 06:07:49,440 eliminate that one now I can drop it in 11346 06:07:49,440 --> 06:07:51,480 there any other ones one all right 11347 06:07:51,480 --> 06:07:54,120 awesome okay so that's really it for the 11348 06:07:54,120 --> 06:07:56,040 basics of the play counter it 11349 06:07:56,040 --> 06:07:57,718 periodically spawns some points which 11350 06:07:57,718 --> 06:07:59,340 the player can then pick up 11351 06:07:59,340 --> 06:08:01,200 now in the next lecture we're going to 11352 06:08:01,200 --> 06:08:02,760 add the ability for the player to be 11353 06:08:02,760 --> 06:08:04,320 holding a plate and pick up another 11354 06:08:04,320 --> 06:08:06,600 object onto the plate 11355 06:08:06,600 --> 06:08:08,520 hello and welcome I'm your code monkey 11356 06:08:08,520 --> 06:08:10,620 in this lecture we're going to add the 11357 06:08:10,620 --> 06:08:12,480 ability for the player to be carrying a 11358 06:08:12,480 --> 06:08:14,218 plate and pick up objects onto that 11359 06:08:14,218 --> 06:08:16,798 plate okay so here we already have the 11360 06:08:16,798 --> 06:08:18,840 plate counter working it has some basic 11361 06:08:18,840 --> 06:08:21,120 logic after a bunch of time it spawns a 11362 06:08:21,120 --> 06:08:23,458 plate it spawns up to a certain maximum 11363 06:08:23,458 --> 06:08:26,100 and I can pick up a plate and if the 11364 06:08:26,100 --> 06:08:27,360 player is carrying a plate so I can put 11365 06:08:27,360 --> 06:08:28,320 it anywhere 11366 06:08:28,320 --> 06:08:30,120 then I can for example pick up some 11367 06:08:30,120 --> 06:08:32,760 Tomatoes slice them and pick them up 11368 06:08:32,760 --> 06:08:34,860 however now I am not able to place the 11369 06:08:34,860 --> 06:08:36,780 tomatoes on the plate so let's add that 11370 06:08:36,780 --> 06:08:39,240 logic let's begin over here on the clear 11371 06:08:39,240 --> 06:08:41,340 counter script first we're testing if 11372 06:08:41,340 --> 06:08:43,138 there is no catch an object here and the 11373 06:08:43,138 --> 06:08:44,218 player is carrying something that the 11374 06:08:44,218 --> 06:08:46,080 player drops something in there but then 11375 06:08:46,080 --> 06:08:47,400 we're testing if there is a kitchen 11376 06:08:47,400 --> 06:08:48,958 object here and if the player is 11377 06:08:48,958 --> 06:08:50,760 carrying something so it's over here 11378 06:08:50,760 --> 06:08:52,020 that we want to check if there's 11379 06:08:52,020 --> 06:08:53,340 something that the player is carrying if 11380 06:08:53,340 --> 06:08:55,500 it is a plate now our plate is also 11381 06:08:55,500 --> 06:08:58,138 going to have a bit of custom logic so 11382 06:08:58,138 --> 06:09:00,058 to help both identify and hold that 11383 06:09:00,058 --> 06:09:01,980 custom logic let's make a proper script 11384 06:09:01,980 --> 06:09:03,120 to handle it 11385 06:09:03,120 --> 06:09:05,280 so back in India let's create a brand 11386 06:09:05,280 --> 06:09:07,860 new script currently the Plate Kitchen 11387 06:09:07,860 --> 06:09:09,058 object 11388 06:09:09,058 --> 06:09:11,638 and let's open this now over here on 11389 06:09:11,638 --> 06:09:13,138 this one instead of extending Model 11390 06:09:13,138 --> 06:09:15,240 Behavior we're going to extend kitchen 11391 06:09:15,240 --> 06:09:16,620 object 11392 06:09:16,620 --> 06:09:18,360 so the plate is really just a more 11393 06:09:18,360 --> 06:09:20,700 specific type of a kitchen object 11394 06:09:20,700 --> 06:09:22,558 again like I mentioned quite a while ago 11395 06:09:22,558 --> 06:09:23,820 you want to be very careful with 11396 06:09:23,820 --> 06:09:25,860 inheritance you need to have a very good 11397 06:09:25,860 --> 06:09:28,260 reason to do it here we want the play to 11398 06:09:28,260 --> 06:09:29,940 behave exactly like a kitchen object 11399 06:09:29,940 --> 06:09:32,040 just with a tiny bit of extra logic so 11400 06:09:32,040 --> 06:09:33,420 in this case it makes perfect sense 11401 06:09:33,420 --> 06:09:36,058 let's just go ahead and save this and 11402 06:09:36,058 --> 06:09:38,458 wait for ENT to compile and over here 11403 06:09:38,458 --> 06:09:40,860 let's find our kitchen object with the 11404 06:09:40,860 --> 06:09:42,900 plate so here it is the prefab as you 11405 06:09:42,900 --> 06:09:44,280 can see we have a kitchen object now 11406 06:09:44,280 --> 06:09:45,780 instead of having that one let's replace 11407 06:09:45,780 --> 06:09:48,058 that with the play kitchen object and 11408 06:09:48,058 --> 06:09:49,798 since we are extending kitchen object we 11409 06:09:49,798 --> 06:09:51,240 have the same Fields so let's make sure 11410 06:09:51,240 --> 06:09:53,638 to add the kitchen object as so and get 11411 06:09:53,638 --> 06:09:56,040 rid of the other one okay great so now 11412 06:09:56,040 --> 06:09:58,080 back here on the on your counter when 11413 06:09:58,080 --> 06:09:59,638 there is a kitchen object here and the 11414 06:09:59,638 --> 06:10:01,680 player is carrying something we can 11415 06:10:01,680 --> 06:10:03,480 check if the player is holding a plate 11416 06:10:03,480 --> 06:10:05,820 and for that we can check the type 11417 06:10:05,820 --> 06:10:08,580 so if let's go into the player and let's 11418 06:10:08,580 --> 06:10:10,200 get the kitchen object the player is 11419 06:10:10,200 --> 06:10:12,660 holding and we test if this object is of 11420 06:10:12,660 --> 06:10:15,298 type Plate Kitchen object 11421 06:10:15,298 --> 06:10:17,638 if so then that means player is holding 11422 06:10:17,638 --> 06:10:19,740 a plate and if that is the case then we 11423 06:10:19,740 --> 06:10:21,240 basically want to give the player 11424 06:10:21,240 --> 06:10:23,520 whatever object is over here we want to 11425 06:10:23,520 --> 06:10:25,320 add it to the plate so let's go into the 11426 06:10:25,320 --> 06:10:27,298 plate script to add that function so 11427 06:10:27,298 --> 06:10:29,280 over here let's make a public Point 11428 06:10:29,280 --> 06:10:32,718 let's call it add ingredient 11429 06:10:35,100 --> 06:10:37,138 as a parameter we're going to receive a 11430 06:10:37,138 --> 06:10:39,420 kitchen object as so we really only care 11431 06:10:39,420 --> 06:10:40,860 about the type we're going to destroy 11432 06:10:40,860 --> 06:10:42,420 the actual kitchen object like we've 11433 06:10:42,420 --> 06:10:43,980 been doing when creating different types 11434 06:10:43,980 --> 06:10:45,660 so the plate is really just going to 11435 06:10:45,660 --> 06:10:47,940 store in list of types so here let's 11436 06:10:47,940 --> 06:10:50,160 store a list of kitchen object a cell 11437 06:10:50,160 --> 06:10:54,240 for the kitchen object that sell list 11438 06:10:54,240 --> 06:10:56,400 then when we add the ingredient let's 11439 06:10:56,400 --> 06:10:58,020 just add it to the list so this kitchen 11440 06:10:58,020 --> 06:10:59,878 object is so let's also make sure to 11441 06:10:59,878 --> 06:11:01,320 initialize the list so let's see what 11442 06:11:01,320 --> 06:11:04,500 I'm awake let's initialize our list and 11443 06:11:04,500 --> 06:11:06,058 now from the other side we just need to 11444 06:11:06,058 --> 06:11:07,798 call this so over here on the clear 11445 06:11:07,798 --> 06:11:09,420 counter if the player is holding a plate 11446 06:11:09,420 --> 06:11:11,580 let's first get the type of plate so 11447 06:11:11,580 --> 06:11:13,860 play kitchen object or the Plate Kitchen 11448 06:11:13,860 --> 06:11:16,500 object we go into the player to get the 11449 06:11:16,500 --> 06:11:19,320 kitchen object and we cast this as a 11450 06:11:19,320 --> 06:11:21,058 plate kitchen object 11451 06:11:21,058 --> 06:11:22,860 okay so we have this and then over here 11452 06:11:22,860 --> 06:11:24,660 let's call add ingredient 11453 06:11:24,660 --> 06:11:26,700 and let's add whatever is currently on 11454 06:11:26,700 --> 06:11:28,440 this counter so let's get the kitchen 11455 06:11:28,440 --> 06:11:30,718 object and get the kitchen object itself 11456 06:11:30,718 --> 06:11:32,940 okay so we're adding it to the plate and 11457 06:11:32,940 --> 06:11:34,740 then let's destroy what is here so get 11458 06:11:34,740 --> 06:11:37,080 kitchen object and destroy itself 11459 06:11:37,080 --> 06:11:38,700 okay so that's it so if there is 11460 06:11:38,700 --> 06:11:40,260 something here and if the player is 11461 06:11:40,260 --> 06:11:41,458 holding something and that's something 11462 06:11:41,458 --> 06:11:43,500 the player is holding as a plate if so 11463 06:11:43,500 --> 06:11:44,760 we're going to add that ingredient to 11464 06:11:44,760 --> 06:11:46,500 the plate and then destroy the object in 11465 06:11:46,500 --> 06:11:48,958 here so let's test okay so here let's 11466 06:11:48,958 --> 06:11:51,240 pick up a tomato let's slice it let's 11467 06:11:51,240 --> 06:11:52,740 put it on a clear kitchen counter 11468 06:11:52,740 --> 06:11:53,940 because that's the only one where we 11469 06:11:53,940 --> 06:11:56,218 added logic so on this one let's pick up 11470 06:11:56,218 --> 06:11:58,440 a plate and now whilst I'm carrying the 11471 06:11:58,440 --> 06:12:00,058 plate and if I approach and I interact 11472 06:12:00,058 --> 06:12:01,680 with it and if there you go it does work 11473 06:12:01,680 --> 06:12:03,660 the object vanished from the counter and 11474 06:12:03,660 --> 06:12:05,638 supposedly was added to the plate again 11475 06:12:05,638 --> 06:12:07,500 we can use a really nice debug inspector 11476 06:12:07,500 --> 06:12:09,900 to see it so let's pause the game Let's 11477 06:12:09,900 --> 06:12:12,120 select the plate let's see the play 11478 06:12:12,120 --> 06:12:13,860 kitchen object so here it is this one 11479 06:12:13,860 --> 06:12:16,680 and let's change the inspector into 11480 06:12:16,680 --> 06:12:19,200 debug mode and down here yep we do see 11481 06:12:19,200 --> 06:12:20,700 the kitchen object that's on list and it 11482 06:12:20,700 --> 06:12:22,558 does have some tomato slices okay 11483 06:12:22,558 --> 06:12:24,780 awesome so with this here we have our 11484 06:12:24,780 --> 06:12:25,860 basics 11485 06:12:25,860 --> 06:12:27,840 we can have some ingredients and we can 11486 06:12:27,840 --> 06:12:29,878 basically pick it up from a plate now 11487 06:12:29,878 --> 06:12:31,680 one thing about our plate this is where 11488 06:12:31,680 --> 06:12:33,240 we're basically going to carry the final 11489 06:12:33,240 --> 06:12:34,740 recipe that we're going to deliver to 11490 06:12:34,740 --> 06:12:36,718 the customers and based on the design 11491 06:12:36,718 --> 06:12:38,400 that I defined I want something pretty 11492 06:12:38,400 --> 06:12:40,440 simple meaning for the design that I'm 11493 06:12:40,440 --> 06:12:41,878 going for there won't be any kind of 11494 06:12:41,878 --> 06:12:44,580 double burgers or double cheese so each 11495 06:12:44,580 --> 06:12:46,920 final recipe will only have at most one 11496 06:12:46,920 --> 06:12:48,298 of each ingredient 11497 06:12:48,298 --> 06:12:50,100 so let's add some basic logic just to 11498 06:12:50,100 --> 06:12:52,440 prevent adding duplicates over here on 11499 06:12:52,440 --> 06:12:54,180 the Plate Kitchen object when we add an 11500 06:12:54,180 --> 06:12:55,200 ingredient 11501 06:12:55,200 --> 06:12:57,120 since the function will now not 11502 06:12:57,120 --> 06:12:59,040 necessarily succeed every time let's 11503 06:12:59,040 --> 06:13:01,320 actually rename this and again use a 11504 06:13:01,320 --> 06:13:03,360 very useful Visual Studio shortcut so 11505 06:13:03,360 --> 06:13:05,520 you can press Ctrl RR or right click and 11506 06:13:05,520 --> 06:13:06,718 let's rename 11507 06:13:06,718 --> 06:13:08,400 since this function will no longer 11508 06:13:08,400 --> 06:13:10,378 succeed we're just going to try to add 11509 06:13:10,378 --> 06:13:12,958 an ingredient so try add ingredient and 11510 06:13:12,958 --> 06:13:14,820 then let's also make it return a buoying 11511 06:13:14,820 --> 06:13:16,740 basically for any function where you're 11512 06:13:16,740 --> 06:13:18,420 not sure if it won't succeed I like to 11513 06:13:18,420 --> 06:13:20,638 add try and make it return ball so this 11514 06:13:20,638 --> 06:13:21,900 way it works pretty much exactly like 11515 06:13:21,900 --> 06:13:23,458 the try again component that we've 11516 06:13:23,458 --> 06:13:25,920 already seen so many times so it tries 11517 06:13:25,920 --> 06:13:27,420 to do something and returns whether it 11518 06:13:27,420 --> 06:13:29,340 succeeds or not so over here instead of 11519 06:13:29,340 --> 06:13:31,138 always adding the ingredient let's see 11520 06:13:31,138 --> 06:13:33,360 if this one is a duplicate so let's do 11521 06:13:33,360 --> 06:13:35,400 an if and let's go into the list and 11522 06:13:35,400 --> 06:13:37,558 check if the contains and if the list 11523 06:13:37,558 --> 06:13:39,298 summary contains this kitchen object as 11524 06:13:39,298 --> 06:13:40,200 well 11525 06:13:40,200 --> 06:13:43,440 if though then already has this type so 11526 06:13:43,440 --> 06:13:46,740 let's return false and if not 11527 06:13:46,740 --> 06:13:48,420 then that means it's a brand new 11528 06:13:48,420 --> 06:13:49,378 ingredient 11529 06:13:49,378 --> 06:13:52,020 so let's add it and return true okay so 11530 06:13:52,020 --> 06:13:54,240 that's it now let's go over here onto 11531 06:13:54,240 --> 06:13:56,760 the clear counter so we try to add the 11532 06:13:56,760 --> 06:13:58,558 ingredient but then we only want to 11533 06:13:58,558 --> 06:14:00,058 destroy if this one succeeds so let's 11534 06:14:00,058 --> 06:14:02,700 put this one inside an if so if we do 11535 06:14:02,700 --> 06:14:04,440 manage to add the ingredients 11536 06:14:04,440 --> 06:14:06,958 then yes let's destroy itself if not 11537 06:14:06,958 --> 06:14:09,058 then we don't destroy anything okay so 11538 06:14:09,058 --> 06:14:10,020 let's test 11539 06:14:10,020 --> 06:14:12,240 so let's go ahead and slice two tomatoes 11540 06:14:12,240 --> 06:14:14,878 so one slice it put it here then another 11541 06:14:14,878 --> 06:14:17,760 one slice it and put it here now let's 11542 06:14:17,760 --> 06:14:19,500 pick up a plate go up here try to pick 11543 06:14:19,500 --> 06:14:21,180 up this one and yep it does work now for 11544 06:14:21,180 --> 06:14:23,040 this one and I hope it doesn't work okay 11545 06:14:23,040 --> 06:14:25,980 great now one more thing in our logic we 11546 06:14:25,980 --> 06:14:28,200 only want to pick up certain things like 11547 06:14:28,200 --> 06:14:29,820 I said only things that won't be used in 11548 06:14:29,820 --> 06:14:31,080 the final recipe 11549 06:14:31,080 --> 06:14:33,298 for example no customer is ever going to 11550 06:14:33,298 --> 06:14:35,638 request a full entire tomato the recipes 11551 06:14:35,638 --> 06:14:37,860 only have sliced tomatoes so we should 11552 06:14:37,860 --> 06:14:39,240 not be able to drop a foam tomato 11553 06:14:39,240 --> 06:14:41,100 directly on top of a plate so let's 11554 06:14:41,100 --> 06:14:43,080 change that so over here on the plate 11555 06:14:43,080 --> 06:14:44,700 script let's basically just create a 11556 06:14:44,700 --> 06:14:47,340 list of our valid ingredients 11557 06:14:47,340 --> 06:14:50,160 so let's make a serialized film private 11558 06:14:50,160 --> 06:14:53,280 make it a list of kitchen object SL 11559 06:14:53,280 --> 06:14:55,500 ope and call it the valid kitchen object 11560 06:14:55,500 --> 06:14:58,620 SL list okay so we have this list and 11561 06:14:58,620 --> 06:15:00,058 over here in the editor let's just write 11562 06:15:00,058 --> 06:15:01,920 the ones that we want so let's first of 11563 06:15:01,920 --> 06:15:04,680 all select the plate object okay here is 11564 06:15:04,680 --> 06:15:06,660 the flight prefab and over here we've 11565 06:15:06,660 --> 06:15:08,820 got all of our kitchen objects so let's 11566 06:15:08,820 --> 06:15:10,138 just write the ones that we want to add 11567 06:15:10,138 --> 06:15:11,280 to the point 11568 06:15:11,280 --> 06:15:13,080 so the final recipes will have some 11569 06:15:13,080 --> 06:15:15,298 bread yep but they will not have entire 11570 06:15:15,298 --> 06:15:16,798 cabbages they will only have cabbage 11571 06:15:16,798 --> 06:15:19,980 slices same thing no cheese only slices 11572 06:15:19,980 --> 06:15:22,138 for the meat we're only going to be able 11573 06:15:22,138 --> 06:15:24,540 to add meat cooked but also meat burned 11574 06:15:24,540 --> 06:15:27,000 then we're not going to be able to add a 11575 06:15:27,000 --> 06:15:28,740 plate onto a plate of course not and 11576 06:15:28,740 --> 06:15:30,298 finally inside of a tomato just tomato 11577 06:15:30,298 --> 06:15:33,120 slices okay that's our Vellum list and 11578 06:15:33,120 --> 06:15:34,860 over here again it's very simple 11579 06:15:34,860 --> 06:15:36,780 so we can just go if the evaluate 11580 06:15:36,780 --> 06:15:39,000 kitchen object that's on list if this 11581 06:15:39,000 --> 06:15:41,580 one contains the one that we want to add 11582 06:15:41,580 --> 06:15:44,340 then we can add it but if not then let's 11583 06:15:44,340 --> 06:15:45,780 return phones 11584 06:15:45,780 --> 06:15:48,240 not a valid ingredient 11585 06:15:48,240 --> 06:15:51,058 okay so let's test alright so let's pick 11586 06:15:51,058 --> 06:15:53,280 up a tomato and also some tomato slices 11587 06:15:53,280 --> 06:15:55,620 and now if I pick up a plate and I go 11588 06:15:55,620 --> 06:15:57,298 into the Tomato nope doesn't work but 11589 06:15:57,298 --> 06:15:59,280 the slices yep it does work okay great 11590 06:15:59,280 --> 06:16:01,860 so here we have all of our basic plate 11591 06:16:01,860 --> 06:16:03,900 rooms everything is working perfectly 11592 06:16:03,900 --> 06:16:05,458 but it's only working over here with the 11593 06:16:05,458 --> 06:16:07,378 clear counter so let's do a little bit 11594 06:16:07,378 --> 06:16:09,120 of code cleanup and then let's add this 11595 06:16:09,120 --> 06:16:11,280 logic to all the other counters so first 11596 06:16:11,280 --> 06:16:13,558 to clean up this cone over here we are 11597 06:16:13,558 --> 06:16:15,058 testing if this is a plain kitchen 11598 06:16:15,058 --> 06:16:17,638 object then we cast to an object and 11599 06:16:17,638 --> 06:16:19,200 then we count the function so let's 11600 06:16:19,200 --> 06:16:20,820 simplify all this 11601 06:16:20,820 --> 06:16:22,620 and let's do it just like yinty does 11602 06:16:22,620 --> 06:16:23,760 with their try and get the component 11603 06:16:23,760 --> 06:16:26,160 function so let's make a custom function 11604 06:16:26,160 --> 06:16:28,378 that takes an output parameter the best 11605 06:16:28,378 --> 06:16:30,180 place to put it is on the kitchen object 11606 06:16:30,180 --> 06:16:32,160 so here we've got the kitchen object 11607 06:16:32,160 --> 06:16:34,680 script okay great let's scroll down and 11608 06:16:34,680 --> 06:16:37,080 make a nice function here so let's make 11609 06:16:37,080 --> 06:16:39,298 it public we're going to return Boolean 11610 06:16:39,298 --> 06:16:40,920 in case this succeeds or not let's 11611 06:16:40,920 --> 06:16:43,500 currently try get plate and over here 11612 06:16:43,500 --> 06:16:45,718 let's make an out parameter so don't 11613 06:16:45,718 --> 06:16:47,878 forget the out keyword let's return of 11614 06:16:47,878 --> 06:16:50,280 type Plate Kitchen object for the play 11615 06:16:50,280 --> 06:16:52,620 kitchen object then over here we do 11616 06:16:52,620 --> 06:16:54,660 examine what we did so we test if this 11617 06:16:54,660 --> 06:16:57,660 object is a plate kitchen object 11618 06:16:57,660 --> 06:16:59,458 if so then let's set the play kitchen 11619 06:16:59,458 --> 06:17:01,920 object equals this as a play kitchen 11620 06:17:01,920 --> 06:17:04,920 object and we return true but if not 11621 06:17:04,920 --> 06:17:06,780 then this is not a plate so let's return 11622 06:17:06,780 --> 06:17:09,180 false and one thing when working with 11623 06:17:09,180 --> 06:17:10,980 output parameters you always need to 11624 06:17:10,980 --> 06:17:13,020 make sure to set the output before you 11625 06:17:13,020 --> 06:17:14,458 exit the function 11626 06:17:14,458 --> 06:17:16,080 so over here that's the error that it's 11627 06:17:16,080 --> 06:17:17,040 telling us 11628 06:17:17,040 --> 06:17:19,200 we must assign it to something when we 11629 06:17:19,200 --> 06:17:21,298 return so over here we don't have a play 11630 06:17:21,298 --> 06:17:23,520 kitchen object so to solve this we just 11631 06:17:23,520 --> 06:17:26,340 set this to no okay great now over here 11632 06:17:26,340 --> 06:17:27,780 on the clear counter instead of doing 11633 06:17:27,780 --> 06:17:30,240 all this basically let's ask the player 11634 06:17:30,240 --> 06:17:32,400 if this is a kitchen object 11635 06:17:32,400 --> 06:17:35,820 so let's try to get the plate 11636 06:17:35,820 --> 06:17:38,160 out Plate Kitchen object for the Plate 11637 06:17:38,160 --> 06:17:40,200 Kitchen object 11638 06:17:40,200 --> 06:17:41,820 so you try to get it then we try to add 11639 06:17:41,820 --> 06:17:43,860 the ingredient and so on now obviously 11640 06:17:43,860 --> 06:17:45,360 we could further simplify things by 11641 06:17:45,360 --> 06:17:46,860 making a function that would try to get 11642 06:17:46,860 --> 06:17:48,120 the plate and try to add the ingredient 11643 06:17:48,120 --> 06:17:50,520 that could work but since some counters 11644 06:17:50,520 --> 06:17:51,718 are going to have a bit more custom 11645 06:17:51,718 --> 06:17:53,820 logic I think keeping them separate like 11646 06:17:53,820 --> 06:17:55,740 this makes more sense so first we try to 11647 06:17:55,740 --> 06:17:57,240 get the plate then we try to add the 11648 06:17:57,240 --> 06:17:59,218 ingredients so let's apply the same 11649 06:17:59,218 --> 06:18:01,260 logic to The Cutting counter 11650 06:18:01,260 --> 06:18:03,000 so over here on the cutting counter 11651 06:18:03,000 --> 06:18:05,218 let's scroll down to where there is a 11652 06:18:05,218 --> 06:18:06,420 kitchen object here and the point is 11653 06:18:06,420 --> 06:18:08,040 carrying something so on the earlier 11654 06:18:08,040 --> 06:18:10,200 counter we just want to copy all of this 11655 06:18:10,200 --> 06:18:12,240 so let's go over here and we do the 11656 06:18:12,240 --> 06:18:14,700 exact same thing okay that's it and the 11657 06:18:14,700 --> 06:18:16,260 other counter from where we can pick up 11658 06:18:16,260 --> 06:18:19,020 things is from the stove counter 11659 06:18:19,020 --> 06:18:21,298 so here we are on the stove let's scroll 11660 06:18:21,298 --> 06:18:23,100 down until we find the interaction okay 11661 06:18:23,100 --> 06:18:24,298 there's something here The Player's 11662 06:18:24,298 --> 06:18:25,798 carrying something so it's over here 11663 06:18:25,798 --> 06:18:27,360 let's do that and do the exact same 11664 06:18:27,360 --> 06:18:29,280 thing except on the stove again let's 11665 06:18:29,280 --> 06:18:30,600 remember that this is using a save 11666 06:18:30,600 --> 06:18:32,340 machine so when we pick up something 11667 06:18:32,340 --> 06:18:33,600 let's do pretty much the same thing that 11668 06:18:33,600 --> 06:18:36,298 we did here so let's make sure to reset 11669 06:18:36,298 --> 06:18:39,298 the State Fire the events and so on okay 11670 06:18:39,298 --> 06:18:40,920 so those are the only counters that we 11671 06:18:40,920 --> 06:18:42,840 need to implement we cannot drop things 11672 06:18:42,840 --> 06:18:44,700 on top of a container we cannot drop 11673 06:18:44,700 --> 06:18:46,558 things on top of the plate counter or 11674 06:18:46,558 --> 06:18:48,180 the trash so these are the only three 11675 06:18:48,180 --> 06:18:49,980 types that we need to implement so with 11676 06:18:49,980 --> 06:18:52,200 this let's test okay so let's begin with 11677 06:18:52,200 --> 06:18:53,700 some meat so let's pick up some meat put 11678 06:18:53,700 --> 06:18:55,680 it on the stove let's pick up a plate 11679 06:18:55,680 --> 06:18:57,540 wait for it to cook pick it up any up 11680 06:18:57,540 --> 06:18:59,520 there you go it does work now it says 11681 06:18:59,520 --> 06:19:00,900 the cut encounters and let's pick up 11682 06:19:00,900 --> 06:19:02,878 some cheese and let's slice it pick up 11683 06:19:02,878 --> 06:19:04,920 some plate and go any up there you go it 11684 06:19:04,920 --> 06:19:07,138 does work and again if we inspect we can 11685 06:19:07,138 --> 06:19:08,580 make sure that it is indeed working so 11686 06:19:08,580 --> 06:19:10,740 let's get into the plate and let's put 11687 06:19:10,740 --> 06:19:12,840 this on debug inspector and if there we 11688 06:19:12,840 --> 06:19:14,580 do see this one has a meat Patty cooked 11689 06:19:14,580 --> 06:19:17,458 and some cheese slices okay great now 11690 06:19:17,458 --> 06:19:19,138 the last piece of logic that we need is 11691 06:19:19,138 --> 06:19:21,180 pretty much the opposite so right now it 11692 06:19:21,180 --> 06:19:23,040 works if there's a sliced object on the 11693 06:19:23,040 --> 06:19:24,840 plate and the player is holding a plate 11694 06:19:24,840 --> 06:19:27,180 object but now we want the opposite so 11695 06:19:27,180 --> 06:19:29,580 let's say there's a plate in here and we 11696 06:19:29,580 --> 06:19:31,320 slice some cheese and now I want to drop 11697 06:19:31,320 --> 06:19:33,180 the cheese on the plate so let's do that 11698 06:19:33,180 --> 06:19:35,100 and basically for this one this one is 11699 06:19:35,100 --> 06:19:36,120 only going to happen on the clear 11700 06:19:36,120 --> 06:19:38,458 counter that's the only counter type 11701 06:19:38,458 --> 06:19:40,740 that can have a plate on top of it so 11702 06:19:40,740 --> 06:19:43,020 over here on the clear counter then we 11703 06:19:43,020 --> 06:19:44,700 check if there is no object there but 11704 06:19:44,700 --> 06:19:46,020 that's not what we want we want if 11705 06:19:46,020 --> 06:19:47,580 there's a plate on the counter so if 11706 06:19:47,580 --> 06:19:49,440 there is an object there and if the 11707 06:19:49,440 --> 06:19:50,940 player is carrying something 11708 06:19:50,940 --> 06:19:52,558 then we check if the player is holding a 11709 06:19:52,558 --> 06:19:55,378 plate but if not so if the player is not 11710 06:19:55,378 --> 06:19:56,940 holding a plate 11711 06:19:56,940 --> 06:20:00,240 so player is not carrying plate but 11712 06:20:00,240 --> 06:20:02,700 something else over here we need pretty 11713 06:20:02,700 --> 06:20:04,200 much exact same logic except just 11714 06:20:04,200 --> 06:20:05,820 testing for the object on this counter 11715 06:20:05,820 --> 06:20:07,920 so let's do if let's get the kitchen 11716 06:20:07,920 --> 06:20:10,378 object on this counter this one try to 11717 06:20:10,378 --> 06:20:12,718 get the plate so out play kitchen 11718 06:20:12,718 --> 06:20:15,120 objects for the Plate Kitchen object so 11719 06:20:15,120 --> 06:20:19,260 if so if so there's a plate over here 11720 06:20:19,260 --> 06:20:21,958 that means the counter is holding a 11721 06:20:21,958 --> 06:20:23,638 plate 11722 06:20:23,638 --> 06:20:25,680 so then let's go into this play kitchen 11723 06:20:25,680 --> 06:20:27,958 object let's add the ingredient 11724 06:20:27,958 --> 06:20:29,520 and we're going to try to add whatever 11725 06:20:29,520 --> 06:20:31,740 the player is currently carrying so the 11726 06:20:31,740 --> 06:20:34,740 player dot get kitchen object 11727 06:20:34,740 --> 06:20:38,718 and get the kitchen object as so 11728 06:20:39,540 --> 06:20:42,600 so we're going to try to add this 11729 06:20:42,600 --> 06:20:44,458 and if we can add then we're just going 11730 06:20:44,458 --> 06:20:47,638 to destroy whatever is on the player 11731 06:20:47,638 --> 06:20:49,860 okay that's it and over here we've got a 11732 06:20:49,860 --> 06:20:51,240 nice error just because we've defined it 11733 06:20:51,240 --> 06:20:53,340 with the same name appear so up here 11734 06:20:53,340 --> 06:20:55,260 we're already defining the variable and 11735 06:20:55,260 --> 06:20:56,940 over here we're defining the same 11736 06:20:56,940 --> 06:20:58,620 variable with the same name 11737 06:20:58,620 --> 06:21:00,058 so we can either give this a different 11738 06:21:00,058 --> 06:21:01,680 name or just not Define a brand new 11739 06:21:01,680 --> 06:21:03,480 variable here so just it's a fine up 11740 06:21:03,480 --> 06:21:05,638 here and we're using it here okay so 11741 06:21:05,638 --> 06:21:07,440 while logic is working now here make 11742 06:21:07,440 --> 06:21:08,878 very sure that you're not mixing 11743 06:21:08,878 --> 06:21:10,740 references keep in mind when you're 11744 06:21:10,740 --> 06:21:12,298 referencing the kitchen object on this 11745 06:21:12,298 --> 06:21:14,100 counter and the one on the player those 11746 06:21:14,100 --> 06:21:16,138 are two different things so over here if 11747 06:21:16,138 --> 06:21:17,580 the player is not carrying a plate but 11748 06:21:17,580 --> 06:21:19,558 something else then you check the 11749 06:21:19,558 --> 06:21:21,660 kitchen counter so over here you're not 11750 06:21:21,660 --> 06:21:22,860 checking the player but checking the 11751 06:21:22,860 --> 06:21:24,958 counter then you go into that point and 11752 06:21:24,958 --> 06:21:26,520 try to add the ingredient and you try to 11753 06:21:26,520 --> 06:21:27,900 add the one that the player is carrying 11754 06:21:27,900 --> 06:21:29,458 and then you destroy the one the player 11755 06:21:29,458 --> 06:21:31,200 is carrying so again be very careful 11756 06:21:31,200 --> 06:21:33,058 here make sure you don't mix references 11757 06:21:33,058 --> 06:21:35,040 so with this it should work so let's 11758 06:21:35,040 --> 06:21:36,900 make sure to save our script and let's 11759 06:21:36,900 --> 06:21:39,298 test okay so here we are let's first 11760 06:21:39,298 --> 06:21:41,218 pick up a nice plate let's drop the 11761 06:21:41,218 --> 06:21:42,900 plate in there pick up some bread drop 11762 06:21:42,900 --> 06:21:44,400 the bread any of there you go it does 11763 06:21:44,400 --> 06:21:46,798 work alright so now we can do a bit more 11764 06:21:46,798 --> 06:21:48,480 natural interactions so for example 11765 06:21:48,480 --> 06:21:49,980 let's pick up some meat and put it on 11766 06:21:49,980 --> 06:21:52,200 cooking and there you go the meat is 11767 06:21:52,200 --> 06:21:53,580 fried so now I'm currently carrying just 11768 06:21:53,580 --> 06:21:55,378 some meat so I place it there then I 11769 06:21:55,378 --> 06:21:56,820 pick up some bread and put some bread on 11770 06:21:56,820 --> 06:21:58,440 top of the meat and yep everything does 11771 06:21:58,440 --> 06:22:00,958 work policy okay so here we created the 11772 06:22:00,958 --> 06:22:02,878 plate and we created some custom logic 11773 06:22:02,878 --> 06:22:04,920 to Define what the plate can and cannot 11774 06:22:04,920 --> 06:22:07,138 account no that's left is actually being 11775 06:22:07,138 --> 06:22:08,878 able to see what is on the plane so 11776 06:22:08,878 --> 06:22:11,580 let's do that in the next lecture 11777 06:22:11,580 --> 06:22:13,378 hello and welcome I'm your code monkey 11778 06:22:13,378 --> 06:22:15,600 in this lecture we're going to add a 11779 06:22:15,600 --> 06:22:17,760 nice visual to our plate okay so right 11780 06:22:17,760 --> 06:22:19,138 now we can already pick up ingredients 11781 06:22:19,138 --> 06:22:20,760 under the plate so if I pick up the 11782 06:22:20,760 --> 06:22:22,440 plate and I pick up some cheese there 11783 06:22:22,440 --> 06:22:23,638 you go there's some cheese on the plate 11784 06:22:23,638 --> 06:22:25,920 but we cannot see it so let's solve that 11785 06:22:25,920 --> 06:22:27,420 and we were going to do that it's 11786 06:22:27,420 --> 06:22:29,458 actually in a very simple way 11787 06:22:29,458 --> 06:22:31,378 if you look in the included assets 11788 06:22:31,378 --> 06:22:33,600 inside the prefab visuals there's this 11789 06:22:33,600 --> 06:22:35,340 nice plate complete visual that I built 11790 06:22:35,340 --> 06:22:37,500 basically it's a foam burger that 11791 06:22:37,500 --> 06:22:39,298 contains all the ingredients what we're 11792 06:22:39,298 --> 06:22:40,558 going to do is actually very simple 11793 06:22:40,558 --> 06:22:42,480 we're just going to enable or disable 11794 06:22:42,480 --> 06:22:44,820 these game objects that's it so let's do 11795 06:22:44,820 --> 06:22:47,400 example that let's make a new c-sharp 11796 06:22:47,400 --> 06:22:50,700 script quality plate complete visual 11797 06:22:50,700 --> 06:22:53,458 let's attach a script over here and 11798 06:22:53,458 --> 06:22:54,780 let's also make sure to put this one 11799 06:22:54,780 --> 06:22:57,000 inside the plate so let's save this 11800 06:22:57,000 --> 06:22:59,638 prefab let's go inside the play prefab 11801 06:22:59,638 --> 06:23:02,218 so inside the prefabs here the kitchen 11802 06:23:02,218 --> 06:23:04,558 objects we've got the plate so inside of 11803 06:23:04,558 --> 06:23:06,298 the point let's drag that let's drag the 11804 06:23:06,298 --> 06:23:08,820 plate complete visual okay great so now 11805 06:23:08,820 --> 06:23:11,040 let's open up this script over here on 11806 06:23:11,040 --> 06:23:12,420 let's first have the reference to our 11807 06:23:12,420 --> 06:23:14,480 Plate Kitchen object 11808 06:23:14,480 --> 06:23:17,040 film private for the Plate Kitchen 11809 06:23:17,040 --> 06:23:19,320 object for the Plate Kitchen object 11810 06:23:19,320 --> 06:23:21,240 back in the editor let's drag the 11811 06:23:21,240 --> 06:23:23,218 reference okay great so now here 11812 06:23:23,218 --> 06:23:24,958 basically we need to update this visual 11813 06:23:24,958 --> 06:23:26,700 whenever the plate gets any ingredient 11814 06:23:26,700 --> 06:23:28,020 added to it 11815 06:23:28,020 --> 06:23:29,580 so let's go over here into the point 11816 06:23:29,580 --> 06:23:30,958 script and basically just need to fire 11817 06:23:30,958 --> 06:23:32,940 off an event when that happens 11818 06:23:32,940 --> 06:23:35,160 so let's make a public event event 11819 06:23:35,160 --> 06:23:37,740 handler and let's call it on ingredient 11820 06:23:37,740 --> 06:23:40,580 added 11821 06:23:41,160 --> 06:23:42,900 okay and for this one let's also make an 11822 06:23:42,900 --> 06:23:45,120 event RX to contain the data of what 11823 06:23:45,120 --> 06:23:47,100 object we added so let's make a public 11824 06:23:47,100 --> 06:23:51,540 class on ingredient added event args 11825 06:23:51,540 --> 06:23:55,138 let's extend event args and inside let's 11826 06:23:55,138 --> 06:23:57,480 make just a kitchen object a cell 11827 06:23:57,480 --> 06:24:00,420 kitchen object as well 11828 06:24:00,420 --> 06:24:02,760 okay great and let's make the event of 11829 06:24:02,760 --> 06:24:04,020 this time 11830 06:24:04,020 --> 06:24:05,820 all right so now let's just fire off 11831 06:24:05,820 --> 06:24:07,620 this event so down here when we try to 11832 06:24:07,620 --> 06:24:09,540 add an ingredient if we do add the 11833 06:24:09,540 --> 06:24:11,580 ingredient let's fire off this event so 11834 06:24:11,580 --> 06:24:14,100 let's invoke with this and let's create 11835 06:24:14,100 --> 06:24:15,718 a brand new one passing the kitchen 11836 06:24:15,718 --> 06:24:17,520 object as so as this kitchen I'll take 11837 06:24:17,520 --> 06:24:19,920 this off okay so we have our event 11838 06:24:19,920 --> 06:24:22,020 correctly being sent now we're here on 11839 06:24:22,020 --> 06:24:23,580 the play complete visual let's listen to 11840 06:24:23,580 --> 06:24:25,740 it again as always let's make sure to do 11841 06:24:25,740 --> 06:24:27,360 it only on start so the play kitchen 11842 06:24:27,360 --> 06:24:29,820 object on ingredient added let's listen 11843 06:24:29,820 --> 06:24:32,340 to this event and over here we just need 11844 06:24:32,340 --> 06:24:34,200 to either enable or disable the visuals 11845 06:24:34,200 --> 06:24:36,180 that relate to the kitchen object inside 11846 06:24:36,180 --> 06:24:38,280 over here the event arcs however of 11847 06:24:38,280 --> 06:24:40,200 course the question is how exactly do we 11848 06:24:40,200 --> 06:24:42,540 find them the point complete visual has 11849 06:24:42,540 --> 06:24:44,760 all these game objects how do we know 11850 06:24:44,760 --> 06:24:46,740 which one belongs to that kitchen object 11851 06:24:46,740 --> 06:24:49,320 now technically one way would be to do a 11852 06:24:49,320 --> 06:24:51,120 simple transform find and find the 11853 06:24:51,120 --> 06:24:53,400 channel objects by name technically that 11854 06:24:53,400 --> 06:24:55,320 would work but like I mentioned in the 11855 06:24:55,320 --> 06:24:57,058 beginning of the course strings are a 11856 06:24:57,058 --> 06:24:58,920 horrible way to identify things they are 11857 06:24:58,920 --> 06:25:01,378 very air prone so let's not do that 11858 06:25:01,378 --> 06:25:03,540 instead let's use a proper approach 11859 06:25:03,540 --> 06:25:05,280 where we can Define some kind of link 11860 06:25:05,280 --> 06:25:07,620 between a kitchen object a so and a game 11861 06:25:07,620 --> 06:25:09,780 object and we can do this very easily by 11862 06:25:09,780 --> 06:25:12,058 justifying a struct so here in our 11863 06:25:12,058 --> 06:25:14,100 script let's do exactly that let's 11864 06:25:14,100 --> 06:25:16,138 define a public 11865 06:25:16,138 --> 06:25:18,420 make it a struct 11866 06:25:18,420 --> 06:25:21,718 and name it kitchen object so underscore 11867 06:25:21,718 --> 06:25:24,500 game object 11868 06:25:25,138 --> 06:25:27,000 then inside it's very simple we just 11869 06:25:27,000 --> 06:25:31,040 have a kitchen object so field 11870 06:25:31,378 --> 06:25:35,840 and then also a game object field 11871 06:25:37,798 --> 06:25:40,200 that's it super simple by the way if you 11872 06:25:40,200 --> 06:25:41,940 don't know what is a struct basically 11873 06:25:41,940 --> 06:25:44,580 it's very similar to a class except it's 11874 06:25:44,580 --> 06:25:46,320 stored in different places in memory and 11875 06:25:46,320 --> 06:25:48,298 behaves somewhat differently 11876 06:25:48,298 --> 06:25:50,280 I have a very very important video on 11877 06:25:50,280 --> 06:25:51,480 that subject what is the difference 11878 06:25:51,480 --> 06:25:53,480 between value types and reference types 11879 06:25:53,480 --> 06:25:56,100 classes are reference types so when you 11880 06:25:56,100 --> 06:25:57,958 pass in a class into a parameter you are 11881 06:25:57,958 --> 06:25:59,600 passing in a reference to that object 11882 06:25:59,600 --> 06:26:02,280 whereas struts are value types so when 11883 06:26:02,280 --> 06:26:03,958 you pass in a struct onto a parameter 11884 06:26:03,958 --> 06:26:06,480 you are passing in a copy it's a bit of 11885 06:26:06,480 --> 06:26:08,040 a tricky thing so definitely make sure 11886 06:26:08,040 --> 06:26:09,660 you go watch that video for more details 11887 06:26:09,660 --> 06:26:11,040 so you don't get confused in the future 11888 06:26:11,040 --> 06:26:13,320 here I Define that as a struct simply as 11889 06:26:13,320 --> 06:26:15,120 kind of a teaching moment but also 11890 06:26:15,120 --> 06:26:16,798 because it just makes sense that if I 11891 06:26:16,798 --> 06:26:18,660 just want to store some data without any 11892 06:26:18,660 --> 06:26:20,520 logic then it should probably be a 11893 06:26:20,520 --> 06:26:22,378 struct and not a class although in this 11894 06:26:22,378 --> 06:26:24,360 case the class would work just as well 11895 06:26:24,360 --> 06:26:26,760 anyway so here we have a struct inside 11896 06:26:26,760 --> 06:26:28,260 the struct we have a field of type 11897 06:26:28,260 --> 06:26:30,058 kitchen object so another one of type 11898 06:26:30,058 --> 06:26:32,280 game object so now let's just make a 11899 06:26:32,280 --> 06:26:33,958 list of this type that we can expose in 11900 06:26:33,958 --> 06:26:36,058 the editor so here a serialized film 11901 06:26:36,058 --> 06:26:38,340 private let's make it a list of kitchen 11902 06:26:38,340 --> 06:26:41,100 objects so game object and call it 11903 06:26:41,100 --> 06:26:44,340 kitchen object so game object list 11904 06:26:44,340 --> 06:26:46,860 okay that's it super simple so let's 11905 06:26:46,860 --> 06:26:48,180 save and make sure this compounds so 11906 06:26:48,180 --> 06:26:49,680 actually let's just comment this out 11907 06:26:49,680 --> 06:26:51,840 just make sure our code compounds okay 11908 06:26:51,840 --> 06:26:53,760 and over here in the editor we see the 11909 06:26:53,760 --> 06:26:55,020 tricky thing when it comes to using 11910 06:26:55,020 --> 06:26:57,718 fields of custom types if we look in the 11911 06:26:57,718 --> 06:26:59,820 inspector no we don't see anything so we 11912 06:26:59,820 --> 06:27:01,200 cannot see our custom type in the 11913 06:27:01,200 --> 06:27:03,600 inspector if you make a custom time like 11914 06:27:03,600 --> 06:27:05,520 this front and you want to show it in 11915 06:27:05,520 --> 06:27:07,440 the inspector then you need to add the 11916 06:27:07,440 --> 06:27:09,958 attribute serializable which exists 11917 06:27:09,958 --> 06:27:12,780 inside system so let's go up here using 11918 06:27:12,780 --> 06:27:15,080 system 11919 06:27:15,480 --> 06:27:17,580 and let's say the attribute serializable 11920 06:27:17,580 --> 06:27:20,760 just like this okay so do this save and 11921 06:27:20,760 --> 06:27:23,160 let's look and if there you go now we do 11922 06:27:23,160 --> 06:27:25,138 see our custom struct so we've got a 11923 06:27:25,138 --> 06:27:26,700 list then we can click on the pause icon 11924 06:27:26,700 --> 06:27:27,718 and there you go we've got an element 11925 06:27:27,718 --> 06:27:29,280 and it does have a film for a kitchen 11926 06:27:29,280 --> 06:27:32,218 object so and one for a game object so 11927 06:27:32,218 --> 06:27:34,020 that's great with this now we have a 11928 06:27:34,020 --> 06:27:35,940 really nice place where we can link one 11929 06:27:35,940 --> 06:27:37,740 object to another so let's just do 11930 06:27:37,740 --> 06:27:39,420 exactly that so for example let's put 11931 06:27:39,420 --> 06:27:41,458 the bread over there and let's assign 11932 06:27:41,458 --> 06:27:42,780 the kitchen object as so for the one 11933 06:27:42,780 --> 06:27:44,940 with bread let's do the same thing for 11934 06:27:44,940 --> 06:27:47,400 all of the others so let's add a whole 11935 06:27:47,400 --> 06:27:49,500 bunch more Okay so we've got the bread 11936 06:27:49,500 --> 06:27:51,120 then we're going to have the meat Patty 11937 06:27:51,120 --> 06:27:54,298 cooked then the tomato slices then we 11938 06:27:54,298 --> 06:27:56,700 have the cheese slices the Cabbage 11939 06:27:56,700 --> 06:27:58,680 sliced and finally the meat Patty burned 11940 06:27:58,680 --> 06:28:00,540 so I've got number zero through five so 11941 06:28:00,540 --> 06:28:02,100 you have six elements and over here yep 11942 06:28:02,100 --> 06:28:04,020 we do got six so we have all of them we 11943 06:28:04,020 --> 06:28:06,298 can get rid of these last two okay great 11944 06:28:06,298 --> 06:28:08,520 and now let's assign the proper objects 11945 06:28:08,520 --> 06:28:10,378 so this one for the meat Patty cooked 11946 06:28:10,378 --> 06:28:13,860 then we've got the tomato slices then we 11947 06:28:13,860 --> 06:28:17,218 have the cheese slices then the Cabbage 11948 06:28:17,218 --> 06:28:19,860 slices and finally the meat Patty burned 11949 06:28:19,860 --> 06:28:21,840 okay great so all of the references 11950 06:28:21,840 --> 06:28:24,480 match now back in the code here so we 11951 06:28:24,480 --> 06:28:26,878 have this List fully filmed out and when 11952 06:28:26,878 --> 06:28:29,400 we have this really very simple we just 11953 06:28:29,400 --> 06:28:30,718 cycle through the list to find the right 11954 06:28:30,718 --> 06:28:33,240 game object it's similar to a 40 inch of 11955 06:28:33,240 --> 06:28:36,120 type kitchen object so game object 11956 06:28:36,120 --> 06:28:38,820 in our kitchen object so game object 11957 06:28:38,820 --> 06:28:41,820 list and we check if this kitchen object 11958 06:28:41,820 --> 06:28:43,980 is so dot kitchen object matches the one 11959 06:28:43,980 --> 06:28:45,780 that we received in the event 11960 06:28:45,780 --> 06:28:47,760 if they do match then go into this one 11961 06:28:47,760 --> 06:28:49,980 grab the game object and set active into 11962 06:28:49,980 --> 06:28:51,600 true 11963 06:28:51,600 --> 06:28:53,638 okay so that's it some very simple logic 11964 06:28:53,638 --> 06:28:55,680 and also we can start with them disable 11965 06:28:55,680 --> 06:28:58,020 them by default in the editor or just 11966 06:28:58,020 --> 06:28:59,520 over here just use something very simple 11967 06:28:59,520 --> 06:29:02,520 just do a for each second through every 11968 06:29:02,520 --> 06:29:04,980 single one of them and set every single 11969 06:29:04,980 --> 06:29:07,200 one of them to false so that they are 11970 06:29:07,200 --> 06:29:09,120 hidden okay so with this on the 11971 06:29:09,120 --> 06:29:10,378 ingredients on the plate should be 11972 06:29:10,378 --> 06:29:12,718 visible so here in the editor let's just 11973 06:29:12,718 --> 06:29:14,340 make sure all the references have been 11974 06:29:14,340 --> 06:29:16,620 set let's go back save the prefab and 11975 06:29:16,620 --> 06:29:18,660 let's set on play okay so here we are 11976 06:29:18,660 --> 06:29:20,400 and by default like that an empty plate 11977 06:29:20,400 --> 06:29:22,558 and yep it is empty and now let's slice 11978 06:29:22,558 --> 06:29:24,180 some cheese now let's Place some cheese 11979 06:29:24,180 --> 06:29:25,620 on there and there you go we've got some 11980 06:29:25,620 --> 06:29:28,020 cheese now let's pick up some bread drop 11981 06:29:28,020 --> 06:29:29,638 some bread and there you go got some 11982 06:29:29,638 --> 06:29:31,378 cheese and some bread 11983 06:29:31,378 --> 06:29:34,260 then let's cook some meat so let's cook 11984 06:29:34,260 --> 06:29:36,180 it and let's pick it up with a plate and 11985 06:29:36,180 --> 06:29:37,740 as soon as I go boom there you go I've 11986 06:29:37,740 --> 06:29:39,240 got a nice cheese butter 11987 06:29:39,240 --> 06:29:41,700 all right awesome so wait a second I'll 11988 06:29:41,700 --> 06:29:43,440 do a complete Burger so let's finish it 11989 06:29:43,440 --> 06:29:45,900 let's just add some more tomatoes so 11990 06:29:45,900 --> 06:29:48,298 slice them and add the tomatoes and 11991 06:29:48,298 --> 06:29:50,340 finally some sliced cabbages slice them 11992 06:29:50,340 --> 06:29:52,260 put them there and there you go here we 11993 06:29:52,260 --> 06:29:54,780 have a fully complete Burger okay so 11994 06:29:54,780 --> 06:29:56,520 that's great all of our vision logic is 11995 06:29:56,520 --> 06:29:59,160 indeed working however this visual is a 11996 06:29:59,160 --> 06:30:00,958 bit hard to see it's not very clear to 11997 06:30:00,958 --> 06:30:03,120 the player so just looking at it from 11998 06:30:03,120 --> 06:30:05,760 this distance does that have a tomato or 11999 06:30:05,760 --> 06:30:06,480 not 12000 06:30:06,480 --> 06:30:08,580 there's a tiny sliver of red in there 12001 06:30:08,580 --> 06:30:10,260 but you can't really see it 12002 06:30:10,260 --> 06:30:11,878 so we should probably add some nice 12003 06:30:11,878 --> 06:30:14,100 clear icons on top to clearly indicate 12004 06:30:14,100 --> 06:30:16,500 what exactly is on this plate so that's 12005 06:30:16,500 --> 06:30:18,058 exactly what we're going to do in the 12006 06:30:18,058 --> 06:30:19,860 next lecture 12007 06:30:19,860 --> 06:30:21,718 hello and welcome I'm your code monkey 12008 06:30:21,718 --> 06:30:24,058 in this lecture we're going to add some 12009 06:30:24,058 --> 06:30:25,920 really nice icons on top of our plate so 12010 06:30:25,920 --> 06:30:28,020 we can easily see what is on there okay 12011 06:30:28,020 --> 06:30:30,360 so for the icons let's do the exact same 12012 06:30:30,360 --> 06:30:31,798 thing that we did for the progress bar 12013 06:30:31,798 --> 06:30:34,680 meaning let's use a warm space canvas so 12014 06:30:34,680 --> 06:30:36,540 let's go inside our play kitchen after 12015 06:30:36,540 --> 06:30:38,458 prefab and over here on let's right 12016 06:30:38,458 --> 06:30:40,920 click let's create a brand new canvas 12017 06:30:40,920 --> 06:30:44,700 let's name this the plate icons UI then 12018 06:30:44,700 --> 06:30:46,320 for the settings let's make it World 12019 06:30:46,320 --> 06:30:48,420 space put it on zero zero everything 12020 06:30:48,420 --> 06:30:51,540 width and height also on zero then let's 12021 06:30:51,540 --> 06:30:53,580 lift it up a little bit so put it on a y 12022 06:30:53,580 --> 06:30:56,160 of one okay like that now inside let's 12023 06:30:56,160 --> 06:30:57,780 define an icon 12024 06:30:57,780 --> 06:30:59,580 so let's start by making an empty game 12025 06:30:59,580 --> 06:31:03,058 object call this just the icon template 12026 06:31:03,058 --> 06:31:06,240 let's put it with a size of 0.3.3 it's 12027 06:31:06,240 --> 06:31:08,458 okay something like that then inside 12028 06:31:08,458 --> 06:31:11,458 let's add a new UI image name this the 12029 06:31:11,458 --> 06:31:12,540 background 12030 06:31:12,540 --> 06:31:14,700 and make it stretch to film The 12031 06:31:14,700 --> 06:31:17,280 appearance so put 0 on everything okay 12032 06:31:17,280 --> 06:31:18,840 there's our background 12033 06:31:18,840 --> 06:31:20,820 for the background image instead of a 12034 06:31:20,820 --> 06:31:22,138 square and let's actually go with a 12035 06:31:22,138 --> 06:31:24,660 circle for that Unity actually has a 12036 06:31:24,660 --> 06:31:26,040 bunch of built-in Sprites that are 12037 06:31:26,040 --> 06:31:28,558 tatted in the last versions however it's 12038 06:31:28,558 --> 06:31:30,660 not actually over here by default 12039 06:31:30,660 --> 06:31:32,580 in order to see those default Sprites we 12040 06:31:32,580 --> 06:31:34,860 need to install the 2D Sprite package so 12041 06:31:34,860 --> 06:31:36,420 let's quickly just go into window 12042 06:31:36,420 --> 06:31:38,878 package manager let's make sure we are 12043 06:31:38,878 --> 06:31:40,680 in the UNT registry make sure we aren't 12044 06:31:40,680 --> 06:31:42,780 looking at all and over here let's find 12045 06:31:42,780 --> 06:31:44,700 the 2D Sprite package okay so let's 12046 06:31:44,700 --> 06:31:45,840 install this 12047 06:31:45,840 --> 06:31:48,420 okay there's the package so now if we go 12048 06:31:48,420 --> 06:31:49,920 into the background and we search for a 12049 06:31:49,920 --> 06:31:52,138 Sprite and over here make sure you click 12050 06:31:52,138 --> 06:31:54,360 to actually show the assets from the 12051 06:31:54,360 --> 06:31:56,160 packages and now we see a bunch of 12052 06:31:56,160 --> 06:31:58,320 default hexagons a bunch of isometric 12053 06:31:58,320 --> 06:32:01,200 tiles the square so on and if we search 12054 06:32:01,200 --> 06:32:03,120 for Circle yep here we've got a bunch of 12055 06:32:03,120 --> 06:32:05,100 circle so let's use this one over here 12056 06:32:05,100 --> 06:32:07,138 on this path so let's use it there you 12057 06:32:07,138 --> 06:32:09,360 go we have a nice circle now let's 12058 06:32:09,360 --> 06:32:11,160 duplicate this image and for the second 12059 06:32:11,160 --> 06:32:13,138 one let's name it icon 12060 06:32:13,138 --> 06:32:15,420 then for this one let's assign just a 12061 06:32:15,420 --> 06:32:17,340 random Sprite so let's say the bread 12062 06:32:17,340 --> 06:32:19,200 and again remember how the Sorting order 12063 06:32:19,200 --> 06:32:20,820 on the UI this one is based on the 12064 06:32:20,820 --> 06:32:22,378 ordering the hierarchy 12065 06:32:22,378 --> 06:32:25,020 so make sure that the icon is underneath 12066 06:32:25,020 --> 06:32:26,940 the background the hierarchy that way it 12067 06:32:26,940 --> 06:32:29,520 shows up on top okay so we have our icon 12068 06:32:29,520 --> 06:32:31,260 template that's great of course we're 12069 06:32:31,260 --> 06:32:33,058 going to dynamically generate all of 12070 06:32:33,058 --> 06:32:34,740 this through code we're going to have 12071 06:32:34,740 --> 06:32:36,840 multiple icons and for positioning them 12072 06:32:36,840 --> 06:32:38,520 Unity actually has some really useful 12073 06:32:38,520 --> 06:32:41,040 components let's select the plate icons 12074 06:32:41,040 --> 06:32:42,718 UI and over here now let's add a 12075 06:32:42,718 --> 06:32:45,058 component now for example a built-in 12076 06:32:45,058 --> 06:32:47,878 component is the grid layout group this 12077 06:32:47,878 --> 06:32:49,558 basically helps you position all the 12078 06:32:49,558 --> 06:32:51,780 charm objects so let's put the size of 12079 06:32:51,780 --> 06:32:54,600 the canvas over here on 0.9.9 okay so 12080 06:32:54,600 --> 06:32:56,580 there you go a nice Square window then 12081 06:32:56,580 --> 06:32:58,260 over here on the settings for this for 12082 06:32:58,260 --> 06:33:01,020 the cell size let's put it at 0.3.3 and 12083 06:33:01,020 --> 06:33:02,400 if there you go already shows up over 12084 06:33:02,400 --> 06:33:03,900 there on the corner 12085 06:33:03,900 --> 06:33:05,878 and we can see what it will look like if 12086 06:33:05,878 --> 06:33:07,378 we just duplicate this object so let's 12087 06:33:07,378 --> 06:33:09,480 make a bunch more templates and if there 12088 06:33:09,480 --> 06:33:11,340 you go that's what it looks like so as 12089 06:33:11,340 --> 06:33:12,540 you can see this component is super 12090 06:33:12,540 --> 06:33:14,400 useful for automatically positioning all 12091 06:33:14,400 --> 06:33:16,378 of the challenge objects now if we want 12092 06:33:16,378 --> 06:33:17,820 we can play around all of these we can 12093 06:33:17,820 --> 06:33:19,680 add a little bit of spacing on the XR on 12094 06:33:19,680 --> 06:33:21,780 the Y but let's actually leave both 12095 06:33:21,780 --> 06:33:23,820 those with zero let's leave everything 12096 06:33:23,820 --> 06:33:25,378 on defaults just over here on the 12097 06:33:25,378 --> 06:33:26,940 channel alignment let's put it on middle 12098 06:33:26,940 --> 06:33:29,280 Center okay so there you go that looks 12099 06:33:29,280 --> 06:33:31,020 pretty nice so you can see how this 12100 06:33:31,020 --> 06:33:32,638 built-in component is super useful 12101 06:33:32,638 --> 06:33:34,980 there's actually two more so this one 12102 06:33:34,980 --> 06:33:36,780 for the grid layout this is great when 12103 06:33:36,780 --> 06:33:38,458 you want to put things horizontally and 12104 06:33:38,458 --> 06:33:39,540 vertically 12105 06:33:39,540 --> 06:33:41,580 but if you just want horizontally then 12106 06:33:41,580 --> 06:33:43,798 there is the horizontal layout group and 12107 06:33:43,798 --> 06:33:45,180 if you just want vertically there's the 12108 06:33:45,180 --> 06:33:47,218 vertical layout group so all of these 12109 06:33:47,218 --> 06:33:48,540 components are really awesome really 12110 06:33:48,540 --> 06:33:51,180 useful okay so with this our objects are 12111 06:33:51,180 --> 06:33:53,940 placed and note how I named this an icon 12112 06:33:53,940 --> 06:33:56,340 template basically a template is just 12113 06:33:56,340 --> 06:33:58,020 what I call something that is kind of 12114 06:33:58,020 --> 06:33:59,820 like a prefab but not really a prefab 12115 06:33:59,820 --> 06:34:02,218 through code we're going to duplicate 12116 06:34:02,218 --> 06:34:04,020 this template and dynamically modify the 12117 06:34:04,020 --> 06:34:06,000 icon so we're going to use it very much 12118 06:34:06,000 --> 06:34:07,200 like a prefab 12119 06:34:07,200 --> 06:34:09,360 we could actually make this into a 12120 06:34:09,360 --> 06:34:11,100 proper prefab so I could just drag it 12121 06:34:11,100 --> 06:34:12,600 over here onto the project files and 12122 06:34:12,600 --> 06:34:14,940 make a regular prefab that could work 12123 06:34:14,940 --> 06:34:17,040 and the only reason why I prefer this 12124 06:34:17,040 --> 06:34:19,320 method of not using a prefab 12125 06:34:19,320 --> 06:34:21,480 he's just because this object this 12126 06:34:21,480 --> 06:34:23,280 template stays here on the object as 12127 06:34:23,280 --> 06:34:24,600 opposed to cluttering over here your 12128 06:34:24,600 --> 06:34:26,820 project files if you have tons of 12129 06:34:26,820 --> 06:34:28,620 single-use UI elements with tons of 12130 06:34:28,620 --> 06:34:30,298 objects you need to spawn you can end up 12131 06:34:30,298 --> 06:34:32,218 with tons and tons of prefabs and you 12132 06:34:32,218 --> 06:34:33,540 might not even know where each of those 12133 06:34:33,540 --> 06:34:35,700 is used whereas with this method the 12134 06:34:35,700 --> 06:34:37,320 template says exactly where it's used 12135 06:34:37,320 --> 06:34:39,420 and does not take an asset slot over 12136 06:34:39,420 --> 06:34:41,340 here on the project files so personally 12137 06:34:41,340 --> 06:34:43,320 this is just approach that I prefer for 12138 06:34:43,320 --> 06:34:45,540 spawning UI elements but like I said 12139 06:34:45,540 --> 06:34:47,458 prefabs work as well so if you prefer 12140 06:34:47,458 --> 06:34:49,798 using prefabs go ahead and make it okay 12141 06:34:49,798 --> 06:34:51,660 so let's make our script to run the 12142 06:34:51,660 --> 06:34:54,360 plate icons UI so let's go into our 12143 06:34:54,360 --> 06:34:56,638 scripts and on the scripts folder let's 12144 06:34:56,638 --> 06:34:58,138 create a brand new c-sharp script for 12145 06:34:58,138 --> 06:35:00,480 the plate icons UI over here let's 12146 06:35:00,480 --> 06:35:02,940 attach a script and open it okay so now 12147 06:35:02,940 --> 06:35:04,620 the first thing we need is a reference 12148 06:35:04,620 --> 06:35:06,000 to our plate 12149 06:35:06,000 --> 06:35:07,980 so let's begin by making a serialized 12150 06:35:07,980 --> 06:35:09,718 film private for the played kitchen 12151 06:35:09,718 --> 06:35:13,138 object for our play kitchen object 12152 06:35:13,138 --> 06:35:14,760 okay let's save it and drag the 12153 06:35:14,760 --> 06:35:16,620 reference so over here there's the point 12154 06:35:16,620 --> 06:35:18,180 icons let's just drag the plate 12155 06:35:18,180 --> 06:35:20,400 reference okay great now on the plate we 12156 06:35:20,400 --> 06:35:22,080 already made this event when an 12157 06:35:22,080 --> 06:35:24,420 ingredient is added so basically we just 12158 06:35:24,420 --> 06:35:25,920 need to listen to this in order to add 12159 06:35:25,920 --> 06:35:28,080 the new icon so over here on the UI 12160 06:35:28,080 --> 06:35:30,360 let's do as usual private void start and 12161 06:35:30,360 --> 06:35:31,920 on start let's go into the Plate Kitchen 12162 06:35:31,920 --> 06:35:34,260 object and listen to that event 12163 06:35:34,260 --> 06:35:36,058 and when that happens let's spawn an 12164 06:35:36,058 --> 06:35:38,160 icon although here let's actually use a 12165 06:35:38,160 --> 06:35:39,780 different method from the one we used on 12166 06:35:39,780 --> 06:35:42,058 the plaint visual over here on the plate 12167 06:35:42,058 --> 06:35:44,458 visual whenever we had the event we 12168 06:35:44,458 --> 06:35:46,260 really just modified the object that was 12169 06:35:46,260 --> 06:35:48,360 added so over here the equivalent would 12170 06:35:48,360 --> 06:35:50,580 be to spawn a new icon whenever that one 12171 06:35:50,580 --> 06:35:52,620 was added but instead of doing that 12172 06:35:52,620 --> 06:35:54,660 right now let's listen to this event and 12173 06:35:54,660 --> 06:35:56,458 when this happens let's update all the 12174 06:35:56,458 --> 06:35:58,558 icons in this display basically this 12175 06:35:58,558 --> 06:36:00,360 other method is useful when the contents 12176 06:36:00,360 --> 06:36:02,580 can be added as well as removed now in 12177 06:36:02,580 --> 06:36:03,718 this case they are never going to be 12178 06:36:03,718 --> 06:36:05,458 removed so in this case both methods 12179 06:36:05,458 --> 06:36:07,200 were fine but still I want to show you 12180 06:36:07,200 --> 06:36:08,878 the second method just so you can use it 12181 06:36:08,878 --> 06:36:10,798 when you need it so for that method we 12182 06:36:10,798 --> 06:36:12,298 just need to know exactly what is on the 12183 06:36:12,298 --> 06:36:14,340 plate so over here on the Plate Kitchen 12184 06:36:14,340 --> 06:36:16,080 object we just need to expose the 12185 06:36:16,080 --> 06:36:18,000 kitchen object as some list so let's do 12186 06:36:18,000 --> 06:36:19,860 example that so fun week we're going to 12187 06:36:19,860 --> 06:36:23,160 return a list of kitchen object SL 12188 06:36:23,160 --> 06:36:24,958 let's go and look get the kitchen object 12189 06:36:24,958 --> 06:36:27,480 the sewn list and we just return the 12190 06:36:27,480 --> 06:36:29,160 kitchen object that's always okay very 12191 06:36:29,160 --> 06:36:31,200 soon then over here on the planet icons 12192 06:36:31,200 --> 06:36:33,240 UI let's just make a function to update 12193 06:36:33,240 --> 06:36:35,700 the visuals so private Droid let's call 12194 06:36:35,700 --> 06:36:38,540 it update visual 12195 06:36:38,940 --> 06:36:41,100 and when we have the event let's call 12196 06:36:41,100 --> 06:36:43,740 our update visual okay 12197 06:36:43,740 --> 06:36:46,500 so now here let's basically just cycle 12198 06:36:46,500 --> 06:36:48,240 through all the ingredients so let's do 12199 06:36:48,240 --> 06:36:52,320 a 40 inch kitchen object so in the plate 12200 06:36:52,320 --> 06:36:54,780 and get the kitchen object the sewn list 12201 06:36:54,780 --> 06:36:57,000 okay so we're cycling through all the 12202 06:36:57,000 --> 06:36:59,340 ingredients on the plate and then we 12203 06:36:59,340 --> 06:37:01,138 want to duplicate our template so that 12204 06:37:01,138 --> 06:37:02,520 means we need a reference up here so 12205 06:37:02,520 --> 06:37:04,980 let's add a serialized film private type 12206 06:37:04,980 --> 06:37:07,260 transform complete the icon template 12207 06:37:07,260 --> 06:37:09,600 okay and let's save the code 12208 06:37:09,600 --> 06:37:11,400 and over here in the editor let's drag 12209 06:37:11,400 --> 06:37:13,020 the reference so let's drag the icon 12210 06:37:13,020 --> 06:37:14,760 template by the way I'll have the others 12211 06:37:14,760 --> 06:37:16,500 over here that's not a problem since 12212 06:37:16,500 --> 06:37:17,700 these are going to be destroyed those 12213 06:37:17,700 --> 06:37:19,620 we're going to see in a little bit the 12214 06:37:19,620 --> 06:37:20,940 only one that matters is the first one 12215 06:37:20,940 --> 06:37:23,218 okay so here we have the icon template 12216 06:37:23,218 --> 06:37:25,500 so to spawn it we do it just like we do 12217 06:37:25,500 --> 06:37:27,480 with any preform so we just call 12218 06:37:27,480 --> 06:37:30,840 instantiate pass in the icon template 12219 06:37:30,840 --> 06:37:32,638 and then transform parents so let's put 12220 06:37:32,638 --> 06:37:34,920 it as a child of this object this part 12221 06:37:34,920 --> 06:37:37,080 is important we need to make sure the 12222 06:37:37,080 --> 06:37:38,638 object is spawned as a child of this 12223 06:37:38,638 --> 06:37:40,440 object if over here you put something 12224 06:37:40,440 --> 06:37:42,480 like no then the template won't be 12225 06:37:42,480 --> 06:37:44,340 spawned as a mobile object so it won't 12226 06:37:44,340 --> 06:37:46,558 be somewhere in the world so in order to 12227 06:37:46,558 --> 06:37:48,058 make it positioned properly let's make 12228 06:37:48,058 --> 06:37:49,798 sure to use transform to become a child 12229 06:37:49,798 --> 06:37:52,200 of this object okay and then since we're 12230 06:37:52,200 --> 06:37:55,080 using the other script the green layout 12231 06:37:55,080 --> 06:37:56,820 group this is already going to be 12232 06:37:56,820 --> 06:37:58,920 automatically positioned so just like 12233 06:37:58,920 --> 06:38:01,320 this it should be spawning the icon and 12234 06:38:01,320 --> 06:38:03,000 with the icon spawned all that's left is 12235 06:38:03,000 --> 06:38:04,980 really just setting the image and now 12236 06:38:04,980 --> 06:38:06,600 again the quick and dirty approach would 12237 06:38:06,600 --> 06:38:08,820 be over here when we spawn let's say we 12238 06:38:08,820 --> 06:38:11,520 pick up the item transform 12239 06:38:11,520 --> 06:38:13,680 and over here we could go inside and do 12240 06:38:13,680 --> 06:38:16,680 a find in order to find the image in 12241 06:38:16,680 --> 06:38:18,420 order to get the component of Type image 12242 06:38:18,420 --> 06:38:20,940 and so on so that is one approach that 12243 06:38:20,940 --> 06:38:22,440 would be the quick and dairy approach 12244 06:38:22,440 --> 06:38:24,298 but again we want to do things properly 12245 06:38:24,298 --> 06:38:26,340 so let's do it the proper way instead so 12246 06:38:26,340 --> 06:38:27,600 instead of this 12247 06:38:27,600 --> 06:38:29,280 let's make a proper script that we're 12248 06:38:29,280 --> 06:38:31,378 going to run on the icon template so 12249 06:38:31,378 --> 06:38:33,120 let's create a new script so a new 12250 06:38:33,120 --> 06:38:35,760 c-sharp script come with the plate icon 12251 06:38:35,760 --> 06:38:38,820 single UI so this one represents just a 12252 06:38:38,820 --> 06:38:41,580 single icon let's go ahead and attach it 12253 06:38:41,580 --> 06:38:43,740 to the template so over here let's drag 12254 06:38:43,740 --> 06:38:45,540 it and now when using this template 12255 06:38:45,540 --> 06:38:47,638 method really the only one we need to 12256 06:38:47,638 --> 06:38:49,260 worry about is this one the other 12257 06:38:49,260 --> 06:38:51,000 duplicates we can just leave them they 12258 06:38:51,000 --> 06:38:52,740 don't really matter but don't just 12259 06:38:52,740 --> 06:38:54,480 avoiding confusion I'm actually going to 12260 06:38:54,480 --> 06:38:56,638 delete them it's okay we just have one 12261 06:38:56,638 --> 06:38:58,500 icon template okay and it has our script 12262 06:38:58,500 --> 06:39:00,600 okay let's open now over here let's 12263 06:39:00,600 --> 06:39:02,458 basically just make a function to set a 12264 06:39:02,458 --> 06:39:04,558 kitchen object or so so public void 12265 06:39:04,558 --> 06:39:09,440 let's go on set kitchen object so 12266 06:39:10,260 --> 06:39:12,360 we receive parameter of type kitchen 12267 06:39:12,360 --> 06:39:14,878 object that so okay great so then we 12268 06:39:14,878 --> 06:39:17,160 need to set the image so let's just go 12269 06:39:17,160 --> 06:39:19,378 into a serialized film private of Type 12270 06:39:19,378 --> 06:39:21,058 image which is inside the unity 12271 06:39:21,058 --> 06:39:22,680 engine.ui 12272 06:39:22,680 --> 06:39:24,780 so for this one for the image we have a 12273 06:39:24,780 --> 06:39:26,218 reference and then we set the 12274 06:39:26,218 --> 06:39:28,558 image.sprite go into the kitchen object 12275 06:39:28,558 --> 06:39:30,718 and grab the Sprites 12276 06:39:30,718 --> 06:39:32,580 okay so we need to do is drag this 12277 06:39:32,580 --> 06:39:34,620 reference so over here in our template 12278 06:39:34,620 --> 06:39:37,378 let's drag the icon image okay great so 12279 06:39:37,378 --> 06:39:39,480 now back here on the plate icon Ty so we 12280 06:39:39,480 --> 06:39:41,638 spawn it that's great then let's we get 12281 06:39:41,638 --> 06:39:44,458 component in order to get our script 12282 06:39:44,458 --> 06:39:47,700 so the plate icon signal UI okay and 12283 06:39:47,700 --> 06:39:49,680 then we just call set kitchen object so 12284 06:39:49,680 --> 06:39:52,860 and pass in this okay that's great this 12285 06:39:52,860 --> 06:39:55,020 is much better now again you might be 12286 06:39:55,020 --> 06:39:56,580 thinking that this method is a lot more 12287 06:39:56,580 --> 06:39:58,020 verbose than just setting the image 12288 06:39:58,020 --> 06:40:00,420 Sprite here we had to create another 12289 06:40:00,420 --> 06:40:02,820 completely new script we had to write 12290 06:40:02,820 --> 06:40:04,558 this logic and over here get it and use 12291 06:40:04,558 --> 06:40:06,540 it the quick and dirty approach would 12292 06:40:06,540 --> 06:40:08,580 indeed be quicker but remember that 12293 06:40:08,580 --> 06:40:10,440 while the equationary approach might be 12294 06:40:10,440 --> 06:40:12,298 faster at first it will mess you up over 12295 06:40:12,298 --> 06:40:14,878 time so just take a few extra seconds to 12296 06:40:14,878 --> 06:40:16,980 do things properly this approach is much 12297 06:40:16,980 --> 06:40:19,378 more scalable let's say for example on 12298 06:40:19,378 --> 06:40:20,940 this function you want to change not 12299 06:40:20,940 --> 06:40:22,680 just Sprite but also trigger some kind 12300 06:40:22,680 --> 06:40:24,718 of Spawn effect or animation with this 12301 06:40:24,718 --> 06:40:26,400 it's very simple we've got this function 12302 06:40:26,400 --> 06:40:27,958 right here we receive the kitchen object 12303 06:40:27,958 --> 06:40:29,638 of so and we can do whatever we want 12304 06:40:29,638 --> 06:40:31,798 with it so like this we have this grip 12305 06:40:31,798 --> 06:40:33,900 that is responsible for anything related 12306 06:40:33,900 --> 06:40:36,420 to the single template and if you've got 12307 06:40:36,420 --> 06:40:38,100 the general one which just spawns him 12308 06:40:38,100 --> 06:40:39,540 and just gives them the kitchen object 12309 06:40:39,540 --> 06:40:41,760 so so all of our logic is nicely 12310 06:40:41,760 --> 06:40:44,100 separate okay so just like this it 12311 06:40:44,100 --> 06:40:46,138 should already work however like this 12312 06:40:46,138 --> 06:40:47,700 you might already be thinking want to 12313 06:40:47,700 --> 06:40:50,040 spawn way too many icons and yep it will 12314 06:40:50,040 --> 06:40:51,660 basically every time we add an 12315 06:40:51,660 --> 06:40:53,160 ingredient we're updating the visual 12316 06:40:53,160 --> 06:40:54,900 where we're cycling through every single 12317 06:40:54,900 --> 06:40:57,120 one and spawning all of them so with 12318 06:40:57,120 --> 06:40:58,378 this we're constantly going to spawn 12319 06:40:58,378 --> 06:41:00,840 more and more items this is not what we 12320 06:41:00,840 --> 06:41:02,580 want over here on the update visual we 12321 06:41:02,580 --> 06:41:04,260 do want to update and spawn all of the 12322 06:41:04,260 --> 06:41:06,298 icons but before we do that we actually 12323 06:41:06,298 --> 06:41:08,458 need to clean it up we need to clean up 12324 06:41:08,458 --> 06:41:10,378 the icons from the previous event 12325 06:41:10,378 --> 06:41:12,360 so before we do that let's just cycle 12326 06:41:12,360 --> 06:41:13,798 through all the children on this 12327 06:41:13,798 --> 06:41:15,660 transform so that's pretty simple you 12328 06:41:15,660 --> 06:41:17,580 can just do a for each transformed child 12329 06:41:17,580 --> 06:41:19,798 in the transform 12330 06:41:19,798 --> 06:41:22,200 so this way Cycles through all the 12331 06:41:22,200 --> 06:41:24,900 children and then just call destroy on 12332 06:41:24,900 --> 06:41:27,058 this channel that game object so that 12333 06:41:27,058 --> 06:41:28,620 won't work that won't destroy all of the 12334 06:41:28,620 --> 06:41:30,718 previous children however of course we 12335 06:41:30,718 --> 06:41:33,298 also have one issue the icon template 12336 06:41:33,298 --> 06:41:35,340 itself is also a child 12337 06:41:35,340 --> 06:41:37,080 so if we do this we're going to destroy 12338 06:41:37,080 --> 06:41:38,820 the icon template which then over here 12339 06:41:38,820 --> 06:41:40,020 we're going to have an error because 12340 06:41:40,020 --> 06:41:42,298 we're going to instantiate no so we want 12341 06:41:42,298 --> 06:41:44,520 to destroy all the children except for 12342 06:41:44,520 --> 06:41:46,620 the template so over here that's pretty 12343 06:41:46,620 --> 06:41:49,080 simple we just check if the child equals 12344 06:41:49,080 --> 06:41:51,600 the icon template if so then let's just 12345 06:41:51,600 --> 06:41:53,940 skip it so we can just call continue and 12346 06:41:53,940 --> 06:41:55,440 there you go it skips 12347 06:41:55,440 --> 06:41:59,458 okay great so just one more final thing 12348 06:41:59,458 --> 06:42:01,260 if we leave the template like this 12349 06:42:01,260 --> 06:42:03,780 meaning the game object is enabled like 12350 06:42:03,780 --> 06:42:05,580 this the template will always be visible 12351 06:42:05,580 --> 06:42:07,920 plus whatever ingredients we have we 12352 06:42:07,920 --> 06:42:09,420 don't really want the template to be 12353 06:42:09,420 --> 06:42:11,280 visible this is just meant to be a 12354 06:42:11,280 --> 06:42:13,200 template that we can instantiate so 12355 06:42:13,200 --> 06:42:15,240 that's pretty simple to fix let's make a 12356 06:42:15,240 --> 06:42:17,100 private void awake and on a week let's 12357 06:42:17,100 --> 06:42:19,200 grab the icon template grab the game 12358 06:42:19,200 --> 06:42:22,558 object set active into false okay so now 12359 06:42:22,558 --> 06:42:24,240 the icon template won't be disabled so 12360 06:42:24,240 --> 06:42:26,458 it won't be visible and then over here 12361 06:42:26,458 --> 06:42:27,840 when we are instantiating the 12362 06:42:27,840 --> 06:42:29,700 instantiated ones will also be disabled 12363 06:42:29,700 --> 06:42:32,218 so let's make sure we go in there and 12364 06:42:32,218 --> 06:42:34,558 enable these all right that should do it 12365 06:42:34,558 --> 06:42:36,420 so all of our logic should be working 12366 06:42:36,420 --> 06:42:38,638 there's only one more tiny thing we need 12367 06:42:38,638 --> 06:42:40,860 to take care of this one is a world 12368 06:42:40,860 --> 06:42:42,900 canvas so like we saw with the progress 12369 06:42:42,900 --> 06:42:45,058 bar we need extra logic to make it look 12370 06:42:45,058 --> 06:42:47,100 towards the camera and thankfully we 12371 06:42:47,100 --> 06:42:48,600 already wrote an excellent generic 12372 06:42:48,600 --> 06:42:50,700 script to do just that so let's go into 12373 06:42:50,700 --> 06:42:53,040 the point icons UI and let's add a 12374 06:42:53,040 --> 06:42:54,900 component and let's add our very nice 12375 06:42:54,900 --> 06:42:57,240 look at camera something like this and 12376 06:42:57,240 --> 06:42:58,798 let's set the mode the same that we use 12377 06:42:58,798 --> 06:43:00,780 so let's put it camera.org okay so 12378 06:43:00,780 --> 06:43:02,160 everything is great everything should be 12379 06:43:02,160 --> 06:43:03,840 perfect so let's finally test let's 12380 06:43:03,840 --> 06:43:05,760 leave the scene save the prefab and hit 12381 06:43:05,760 --> 06:43:08,340 on play all right so let's go pick up a 12382 06:43:08,340 --> 06:43:09,718 plate and there you go there are no 12383 06:43:09,718 --> 06:43:11,520 icons visible okay that's great now I'm 12384 06:43:11,520 --> 06:43:13,320 going to place a bread on top of the 12385 06:43:13,320 --> 06:43:14,940 plate and there you go I've got a nice 12386 06:43:14,940 --> 06:43:17,280 bright icon okay great now let's make 12387 06:43:17,280 --> 06:43:19,680 some meat cook it and as soon as it's 12388 06:43:19,680 --> 06:43:21,240 done going to pick it up and there you 12389 06:43:21,240 --> 06:43:23,638 go I've got a bread and some meat now 12390 06:43:23,638 --> 06:43:25,440 let's put some cheese slice it put it 12391 06:43:25,440 --> 06:43:27,058 there and there you go now I can easily 12392 06:43:27,058 --> 06:43:29,100 see that plate has some bread some meat 12393 06:43:29,100 --> 06:43:31,020 and some cheese now let's just add the 12394 06:43:31,020 --> 06:43:32,760 rest of the ingredients to make a foam 12395 06:43:32,760 --> 06:43:34,740 Mega Burger so let's add some tomatoes 12396 06:43:34,740 --> 06:43:38,160 and add some nice cabbage slices any of 12397 06:43:38,160 --> 06:43:40,558 there you go it works perfectly so here 12398 06:43:40,558 --> 06:43:42,000 we have a complete burger with 12399 06:43:42,000 --> 06:43:43,680 everything and we can easily see on the 12400 06:43:43,680 --> 06:43:46,080 icons everything this contains alright 12401 06:43:46,080 --> 06:43:47,280 awesome 12402 06:43:47,280 --> 06:43:49,378 okay so here you'll learn how to make 12403 06:43:49,378 --> 06:43:51,240 yet another Super useful element that 12404 06:43:51,240 --> 06:43:52,798 you can easily add to all of your games 12405 06:43:52,798 --> 06:43:55,260 personally I use this kind of logica ton 12406 06:43:55,260 --> 06:43:58,260 in all kinds of UI things for example in 12407 06:43:58,260 --> 06:44:00,058 my upcoming steam game total warm 12408 06:44:00,058 --> 06:44:02,218 Liberation the items in the inventory 12409 06:44:02,218 --> 06:44:04,740 they're all added using this method so 12410 06:44:04,740 --> 06:44:06,480 there's a template and I duplicate that 12411 06:44:06,480 --> 06:44:08,280 template same thing for all of the 12412 06:44:08,280 --> 06:44:10,320 action buttons all of those are based on 12413 06:44:10,320 --> 06:44:12,120 having a template and duplicating it 12414 06:44:12,120 --> 06:44:14,040 it's a really easy way to do this kind 12415 06:44:14,040 --> 06:44:16,080 of thing with all that here we have a 12416 06:44:16,080 --> 06:44:17,820 phone plate and we can easily see what 12417 06:44:17,820 --> 06:44:20,100 is on there so with this the next 12418 06:44:20,100 --> 06:44:21,840 obvious step is to actually deliver some 12419 06:44:21,840 --> 06:44:23,638 orders so let's do that in the next 12420 06:44:23,638 --> 06:44:25,200 lecture 12421 06:44:25,200 --> 06:44:27,058 hello and welcome I'm your code monkey 12422 06:44:27,058 --> 06:44:28,980 in this lecture we're going to build the 12423 06:44:28,980 --> 06:44:30,660 delivery counter this is where we're 12424 06:44:30,660 --> 06:44:32,160 going to drop some items that the 12425 06:44:32,160 --> 06:44:33,540 customers have requested in order to 12426 06:44:33,540 --> 06:44:35,878 complete the orders also just for fun 12427 06:44:35,878 --> 06:44:37,378 we're going to learn how to use Shader 12428 06:44:37,378 --> 06:44:39,180 graph to make a simple custom Shader 12429 06:44:39,180 --> 06:44:41,280 okay so let's begin by making our 12430 06:44:41,280 --> 06:44:43,558 counter so let's go into our base 12431 06:44:43,558 --> 06:44:45,180 counter let's create a new prefab 12432 06:44:45,180 --> 06:44:48,480 variant for the delivery counter let's 12433 06:44:48,480 --> 06:44:50,940 go inside and now let's find the visual 12434 06:44:50,940 --> 06:44:53,638 the visual for delivery counter let's 12435 06:44:53,638 --> 06:44:56,458 duplicate it to make the selecting let's 12436 06:44:56,458 --> 06:45:00,000 go inside modify the material then on 12437 06:45:00,000 --> 06:45:01,920 the selected make it one percent bigger 12438 06:45:01,920 --> 06:45:04,378 one zero one add the component the 12439 06:45:04,378 --> 06:45:06,420 selected counter visual let's drag the 12440 06:45:06,420 --> 06:45:08,520 kitchen counter like that okay that's 12441 06:45:08,520 --> 06:45:10,980 our basic setup and also start with the 12442 06:45:10,980 --> 06:45:13,378 kitchen count disable okay great now 12443 06:45:13,378 --> 06:45:15,298 let's make a script to run this so let's 12444 06:45:15,298 --> 06:45:16,980 go into our counters folder and let's 12445 06:45:16,980 --> 06:45:19,320 create a brand new c-sharp script for 12446 06:45:19,320 --> 06:45:22,138 the delivery counter let's attach it and 12447 06:45:22,138 --> 06:45:24,660 open okay so now here as usual let's 12448 06:45:24,660 --> 06:45:27,180 begin by extending our base counter 12449 06:45:27,180 --> 06:45:30,540 class all right now let's override the 12450 06:45:30,540 --> 06:45:32,400 interact function 12451 06:45:32,400 --> 06:45:33,958 and for now let's actually do it it's 12452 06:45:33,958 --> 06:45:35,638 not like the trash counter meaning let's 12453 06:45:35,638 --> 06:45:38,040 just destroy the object so we just check 12454 06:45:38,040 --> 06:45:40,138 if the player is holding something so if 12455 06:45:40,138 --> 06:45:42,718 the player has a catch an object let's 12456 06:45:42,718 --> 06:45:44,280 go into the player the kitchen object 12457 06:45:44,280 --> 06:45:45,780 then let's destroy it 12458 06:45:45,780 --> 06:45:47,700 however another room over here for an 12459 06:45:47,700 --> 06:45:49,320 Oliver counter is this is only going to 12460 06:45:49,320 --> 06:45:51,600 accept plates so let's see if the player 12461 06:45:51,600 --> 06:45:54,298 is carrying a plate object so player get 12462 06:45:54,298 --> 06:45:57,120 kitchen object and test try to get the 12463 06:45:57,120 --> 06:45:59,940 plate so out played kitchen object for 12464 06:45:59,940 --> 06:46:02,040 the Plate Kitchen object 12465 06:46:02,040 --> 06:46:04,200 we try to get this and if it is a point 12466 06:46:04,200 --> 06:46:07,100 then we destroy it 12467 06:46:08,100 --> 06:46:10,920 okay that's it here in the editor let's 12468 06:46:10,920 --> 06:46:12,360 just compound the script and drag the 12469 06:46:12,360 --> 06:46:14,520 references so the countertop point and 12470 06:46:14,520 --> 06:46:16,740 on the selected let's drag the counter 12471 06:46:16,740 --> 06:46:18,900 reference and let's exit this save the 12472 06:46:18,900 --> 06:46:21,058 prefab and let's drop it over here on 12473 06:46:21,058 --> 06:46:23,458 the corner so let's find over here the 12474 06:46:23,458 --> 06:46:24,958 delivery counter and let's put it over 12475 06:46:24,958 --> 06:46:27,660 there hang on it on this side put it 12476 06:46:27,660 --> 06:46:29,760 like this let's also just quickly 12477 06:46:29,760 --> 06:46:31,680 reposition all of our counters since we 12478 06:46:31,680 --> 06:46:33,120 already have all the types that we're 12479 06:46:33,120 --> 06:46:34,978 going to use so on the lever counter 12480 06:46:34,978 --> 06:46:36,540 let's put it over here on this corner so 12481 06:46:36,540 --> 06:46:40,320 x 7.5 0 and Z of two then next to it 12482 06:46:40,320 --> 06:46:42,058 let's put the plates counter so over 12483 06:46:42,058 --> 06:46:43,138 there okay 12484 06:46:43,138 --> 06:46:45,298 then next week let's put a clear counter 12485 06:46:45,298 --> 06:46:48,000 after that let's put the trash counter 12486 06:46:48,000 --> 06:46:49,620 and then let's also put another empty 12487 06:46:49,620 --> 06:46:51,840 one there so let's duplicate this one 12488 06:46:51,840 --> 06:46:54,120 move it up to about this and put it like 12489 06:46:54,120 --> 06:46:55,978 that now we just need to move all of 12490 06:46:55,978 --> 06:46:58,320 these down here so just select all of 12491 06:46:58,320 --> 06:47:00,740 these counters and let's move them down 12492 06:47:00,740 --> 06:47:04,740 by about this okay so on minus 5.5 like 12493 06:47:04,740 --> 06:47:06,840 this okay so everything is nicely 12494 06:47:06,840 --> 06:47:09,058 positioned just over there right now we 12495 06:47:09,058 --> 06:47:10,558 cannot access that container so let's 12496 06:47:10,558 --> 06:47:12,780 actually modify those as well which by 12497 06:47:12,780 --> 06:47:14,638 the way over here there's the canvas in 12498 06:47:14,638 --> 06:47:15,900 front so as I click I'm actually 12499 06:47:15,900 --> 06:47:18,120 selecting the canvas in the hierarchy so 12500 06:47:18,120 --> 06:47:19,798 here's a quick empty tab on the 12501 06:47:19,798 --> 06:47:21,120 hierarchy on the left side you've got 12502 06:47:21,120 --> 06:47:22,978 these two buttons so one of them hides 12503 06:47:22,978 --> 06:47:24,240 the object and the other one simply 12504 06:47:24,240 --> 06:47:26,400 makes it unselectable so if I click on 12505 06:47:26,400 --> 06:47:27,840 this and I click through any of the 12506 06:47:27,840 --> 06:47:29,400 click goes through the canvas so that 12507 06:47:29,400 --> 06:47:31,200 makes it much easier to select over here 12508 06:47:31,200 --> 06:47:33,840 on the items in our scene so let you 12509 06:47:33,840 --> 06:47:36,420 select all of these okay all of these 12510 06:47:36,420 --> 06:47:39,360 now just push them all to the side and 12511 06:47:39,360 --> 06:47:40,978 make another empty one and put it over 12512 06:47:40,978 --> 06:47:43,080 here okay that's a nice layout now let's 12513 06:47:43,080 --> 06:47:45,120 just finish the rest so over here let's 12514 06:47:45,120 --> 06:47:47,218 just duplicate our empty counters and 12515 06:47:47,218 --> 06:47:49,978 place a bunch more let's put one more to 12516 06:47:49,978 --> 06:47:50,878 the side 12517 06:47:50,878 --> 06:47:52,500 and now these ones over here so let's 12518 06:47:52,500 --> 06:47:54,958 put it over there and rotate it here 12519 06:47:54,958 --> 06:47:57,120 and duplicate another one and another 12520 06:47:57,120 --> 06:47:58,080 one 12521 06:47:58,080 --> 06:48:01,378 and another one and just one more and 12522 06:48:01,378 --> 06:48:03,420 get rid of this one okay great so here 12523 06:48:03,420 --> 06:48:04,978 we have pretty much our complete map 12524 06:48:04,978 --> 06:48:07,320 let's also just move the camera tiny 12525 06:48:07,320 --> 06:48:08,820 tiny bit just make sure that it is 12526 06:48:08,820 --> 06:48:11,160 nicely organized so put it over there 12527 06:48:11,160 --> 06:48:12,718 just so everything is nice and centered 12528 06:48:12,718 --> 06:48:15,058 okay so there's our map now let's get 12529 06:48:15,058 --> 06:48:16,740 back to working on our delivery counter 12530 06:48:16,740 --> 06:48:18,900 we already added this code so let's just 12531 06:48:18,900 --> 06:48:21,058 quickly test so here we are and if I 12532 06:48:21,058 --> 06:48:22,260 pick up something like for example some 12533 06:48:22,260 --> 06:48:23,700 cheese go into the delivery counter and 12534 06:48:23,700 --> 06:48:25,080 interact and nope nothing happens 12535 06:48:25,080 --> 06:48:27,120 because that one only accepts plates now 12536 06:48:27,120 --> 06:48:28,860 if I pick up a plate go there don't wait 12537 06:48:28,860 --> 06:48:30,000 for any of there you go it does work 12538 06:48:30,000 --> 06:48:32,700 okay great so this is the basic logic 12539 06:48:32,700 --> 06:48:33,660 that we want 12540 06:48:33,660 --> 06:48:35,638 for defining the actual recipe and logic 12541 06:48:35,638 --> 06:48:36,900 we're actually only going to do that in 12542 06:48:36,900 --> 06:48:38,700 the next lecture but for now let's add 12543 06:48:38,700 --> 06:48:40,620 one more nice thing let's add a simple 12544 06:48:40,620 --> 06:48:42,840 custom visual over here using Shader 12545 06:48:42,840 --> 06:48:44,520 graph this is a great way for you to 12546 06:48:44,520 --> 06:48:45,958 learn the pottery of Shader graph and 12547 06:48:45,958 --> 06:48:48,000 just how easy it is to use this is a 12548 06:48:48,000 --> 06:48:49,620 visual tool for making shaders it's 12549 06:48:49,620 --> 06:48:52,200 really very easy personally I don't know 12550 06:48:52,200 --> 06:48:53,878 how to write shaders with code but I can 12551 06:48:53,878 --> 06:48:55,200 build some pretty nice things using 12552 06:48:55,200 --> 06:48:57,660 Shadow graph as usual I have a dedicated 12553 06:48:57,660 --> 06:48:59,638 video on it I also have an entire 12554 06:48:59,638 --> 06:49:01,260 playlist showcasing how to make all 12555 06:49:01,260 --> 06:49:03,180 kinds of interesting effects and even 12556 06:49:03,180 --> 06:49:05,040 one special video covering some changes 12557 06:49:05,040 --> 06:49:07,138 in recent shareware versions so over 12558 06:49:07,138 --> 06:49:08,638 here let's learn the basics how to use 12559 06:49:08,638 --> 06:49:10,740 it so first here in our project window 12560 06:49:10,740 --> 06:49:12,840 let's create a brand new folder let's 12561 06:49:12,840 --> 06:49:15,120 name it just shaders and now inside 12562 06:49:15,120 --> 06:49:17,878 let's create one so let's create then go 12563 06:49:17,878 --> 06:49:19,860 up here into sheet graph then we're 12564 06:49:19,860 --> 06:49:22,138 using urp so let's go inside there and 12565 06:49:22,138 --> 06:49:24,298 here we've got a bunch of options now 12566 06:49:24,298 --> 06:49:25,798 don't worry about picking the quote 12567 06:49:25,798 --> 06:49:27,718 unquote wrong option all this does is 12568 06:49:27,718 --> 06:49:29,820 just create a template so for example if 12569 06:49:29,820 --> 06:49:31,500 you accidentally create an unlit Shader 12570 06:49:31,500 --> 06:49:33,058 you can then easily swap it out from it 12571 06:49:33,058 --> 06:49:34,860 so right right now let's go with the 12572 06:49:34,860 --> 06:49:36,420 English hitter and for the name let's 12573 06:49:36,420 --> 06:49:38,160 name it moving visual 12574 06:49:38,160 --> 06:49:40,620 okay there's our shade Rafael now now 12575 06:49:40,620 --> 06:49:42,660 let's just double click to open it and 12576 06:49:42,660 --> 06:49:44,218 up here we have the nice shade graph 12577 06:49:44,218 --> 06:49:45,718 window by the way you can make this 12578 06:49:45,718 --> 06:49:47,700 phone screen so you can either right 12579 06:49:47,700 --> 06:49:49,500 click over there on the tab and maximize 12580 06:49:49,500 --> 06:49:51,660 or alternatively you can just click on 12581 06:49:51,660 --> 06:49:53,400 this window and then use the hotkey 12582 06:49:53,400 --> 06:49:55,798 shift space and if there you go it does 12583 06:49:55,798 --> 06:49:58,558 maximize okay great now by default we 12584 06:49:58,558 --> 06:49:59,940 have this down the center this is called 12585 06:49:59,940 --> 06:50:02,218 the master stack these are the actual 12586 06:50:02,218 --> 06:50:03,478 properties that we're going to need to 12587 06:50:03,478 --> 06:50:06,000 use then on the left side we have the 12588 06:50:06,000 --> 06:50:08,280 properties Blackboard on the right side 12589 06:50:08,280 --> 06:50:10,680 we've got the graph inspector and 12590 06:50:10,680 --> 06:50:12,180 finally down here we've got the main 12591 06:50:12,180 --> 06:50:13,920 preview all of these windows can be 12592 06:50:13,920 --> 06:50:15,780 scaled and also if you don't see these 12593 06:50:15,780 --> 06:50:17,820 windows or if you accidentally hide them 12594 06:50:17,820 --> 06:50:19,378 they're all appear on these three 12595 06:50:19,378 --> 06:50:21,000 buttons so the Blackboard that's on the 12596 06:50:21,000 --> 06:50:22,378 left the graph inspector and the main 12597 06:50:22,378 --> 06:50:24,420 preview okay so now here we've got a 12598 06:50:24,420 --> 06:50:25,978 nice empty board so we can add whatever 12599 06:50:25,978 --> 06:50:28,500 nodes we want so we can right click and 12600 06:50:28,500 --> 06:50:30,240 go into create node and then we can 12601 06:50:30,240 --> 06:50:31,620 write something or just click anywhere 12602 06:50:31,620 --> 06:50:33,840 and press on space and there you go now 12603 06:50:33,840 --> 06:50:35,700 we can cycle through and browse all of 12604 06:50:35,700 --> 06:50:37,440 these menus to see all of the nodes that 12605 06:50:37,440 --> 06:50:39,660 exist there's tons and tons of them or 12606 06:50:39,660 --> 06:50:41,218 alternatively just go up here and use 12607 06:50:41,218 --> 06:50:43,680 the search bar so for example let's find 12608 06:50:43,680 --> 06:50:45,840 the sample texture 2D node so here it is 12609 06:50:45,840 --> 06:50:48,540 this one okay we've got this node what 12610 06:50:48,540 --> 06:50:51,120 this one does is it takes a texture and 12611 06:50:51,120 --> 06:50:53,218 grabs the color from it so on the left 12612 06:50:53,218 --> 06:50:54,780 side of the node are the inputs and on 12613 06:50:54,780 --> 06:50:57,298 the right side are the outputs within 12614 06:50:57,298 --> 06:50:58,798 the parentheses you can actually see the 12615 06:50:58,798 --> 06:51:00,840 types so for the input texture this one 12616 06:51:00,840 --> 06:51:02,820 is of type T2 so that means it's a 12617 06:51:02,820 --> 06:51:04,920 textured 2D then on the output you can 12618 06:51:04,920 --> 06:51:06,780 see there's a 4 meaning it contains four 12619 06:51:06,780 --> 06:51:08,760 floats which in this case refers to the 12620 06:51:08,760 --> 06:51:11,280 four colors so that's red green blue and 12621 06:51:11,280 --> 06:51:13,798 Alpha so for an input we want a texture 12622 06:51:13,798 --> 06:51:15,478 so let's set it over here as a property 12623 06:51:15,478 --> 06:51:17,700 let's click on the plus icon and we've 12624 06:51:17,700 --> 06:51:20,218 got a whole bunch of types for texture 12625 06:51:20,218 --> 06:51:21,900 we want a textured 2D so let's go with 12626 06:51:21,900 --> 06:51:24,058 that and then for the name now usually 12627 06:51:24,058 --> 06:51:26,160 there are two standard names there's one 12628 06:51:26,160 --> 06:51:29,280 called main text or base map main tags 12629 06:51:29,280 --> 06:51:31,378 used to be the more common name but when 12630 06:51:31,378 --> 06:51:33,180 working with urp for some reason they 12631 06:51:33,180 --> 06:51:34,740 decided to name the main texture as base 12632 06:51:34,740 --> 06:51:36,718 map so we're here let's stick within the 12633 06:51:36,718 --> 06:51:38,520 urp standard and just call this basement 12634 06:51:38,520 --> 06:51:40,680 okay there's our property and if we 12635 06:51:40,680 --> 06:51:42,058 click the select it and on the right 12636 06:51:42,058 --> 06:51:44,040 side we can see the graph inspector and 12637 06:51:44,040 --> 06:51:45,840 we can see all the properties for this 12638 06:51:45,840 --> 06:51:47,760 Actron property so we see a name 12639 06:51:47,760 --> 06:51:49,378 reference and a bunch more things now 12640 06:51:49,378 --> 06:51:51,120 the really important one is over here 12641 06:51:51,120 --> 06:51:53,218 the reference this is the actual name 12642 06:51:53,218 --> 06:51:54,718 that you're going to use if you want to 12643 06:51:54,718 --> 06:51:56,160 interact with this Shader through code 12644 06:51:56,160 --> 06:51:58,080 the name on the property this one is 12645 06:51:58,080 --> 06:51:59,700 just a text ring so this can be whatever 12646 06:51:59,700 --> 06:52:01,620 you want you can even have spaces and so 12647 06:52:01,620 --> 06:52:03,718 on whereas the reference name this is 12648 06:52:03,718 --> 06:52:05,638 the really important one and by default 12649 06:52:05,638 --> 06:52:07,558 when you set up a name it should already 12650 06:52:07,558 --> 06:52:09,840 accept the correct reference usually the 12651 06:52:09,840 --> 06:52:11,280 standard is to name it just like the 12652 06:52:11,280 --> 06:52:13,500 name both without any spaces and with an 12653 06:52:13,500 --> 06:52:15,000 underscore in the beginning so just like 12654 06:52:15,000 --> 06:52:17,280 this okay then we can give it a default 12655 06:52:17,280 --> 06:52:19,320 texture so let's go ahead and select 12656 06:52:19,320 --> 06:52:20,700 something for example over here the 12657 06:52:20,700 --> 06:52:22,920 bread texture remember this is just the 12658 06:52:22,920 --> 06:52:25,558 default this will not be hard-coded 12659 06:52:25,558 --> 06:52:26,940 directly into the Shader we can then 12660 06:52:26,940 --> 06:52:29,100 modify this okay so we we have our nice 12661 06:52:29,100 --> 06:52:31,260 base map property definition now we can 12662 06:52:31,260 --> 06:52:32,760 just drag it over here on the board and 12663 06:52:32,760 --> 06:52:34,320 yep there it is and now we can just 12664 06:52:34,320 --> 06:52:35,820 click on the server icon in order to 12665 06:52:35,820 --> 06:52:37,378 drag a connection and let's connect it 12666 06:52:37,378 --> 06:52:39,120 over here onto the sample textures to 12667 06:52:39,120 --> 06:52:41,100 the input and yep right away we do see 12668 06:52:41,100 --> 06:52:42,660 it does work so we are correctly 12669 06:52:42,660 --> 06:52:45,058 sampling the texture however if you look 12670 06:52:45,058 --> 06:52:46,620 on the main preview over here there's 12671 06:52:46,620 --> 06:52:48,360 still nothing that's because we don't 12672 06:52:48,360 --> 06:52:50,700 have this node connect to anything we 12673 06:52:50,700 --> 06:52:52,260 need to connect it to the final Master 12674 06:52:52,260 --> 06:52:54,420 sack in order to render something so 12675 06:52:54,420 --> 06:52:55,978 again on the output over here we can see 12676 06:52:55,978 --> 06:52:57,958 a four so these are all of our colors 12677 06:52:57,958 --> 06:53:00,360 and actually one very useful node is the 12678 06:53:00,360 --> 06:53:02,400 preview since so many things in Shader 12679 06:53:02,400 --> 06:53:05,160 graph can be hard to visualize so we can 12680 06:53:05,160 --> 06:53:07,020 move these nodes around and let's add 12681 06:53:07,020 --> 06:53:08,520 the preview node 12682 06:53:08,520 --> 06:53:10,260 and this does examine that so you can 12683 06:53:10,260 --> 06:53:11,878 fit it an input and you can see down 12684 06:53:11,878 --> 06:53:14,280 here what that input contains so for 12685 06:53:14,280 --> 06:53:16,080 example let's drag just the red Channel 12686 06:53:16,080 --> 06:53:18,000 and if they go over there we can see the 12687 06:53:18,000 --> 06:53:20,160 red channel for this texture we can drag 12688 06:53:20,160 --> 06:53:22,260 the green channel the blue Channel or 12689 06:53:22,260 --> 06:53:24,478 look at the alpha Channel yep there you 12690 06:53:24,478 --> 06:53:26,580 go it does work so this preview node is 12691 06:53:26,580 --> 06:53:28,500 super useful for being able to see what 12692 06:53:28,500 --> 06:53:30,900 your Shader is actually doing over here 12693 06:53:30,900 --> 06:53:32,520 we have the colors so let's get rid of 12694 06:53:32,520 --> 06:53:34,620 the preview right now in order to make 12695 06:53:34,620 --> 06:53:35,940 it work we really just need to connect 12696 06:53:35,940 --> 06:53:38,400 the rgba and go up here into the base 12697 06:53:38,400 --> 06:53:41,100 color and right away it should work but 12698 06:53:41,100 --> 06:53:42,600 you might not be able to see anything 12699 06:53:42,600 --> 06:53:44,218 over here on the main preview 12700 06:53:44,218 --> 06:53:46,558 I believe this is a rendering bug in the 12701 06:53:46,558 --> 06:53:48,360 current Tech version so right now 12702 06:53:48,360 --> 06:53:49,620 nothing is shown 12703 06:53:49,620 --> 06:53:51,058 so if you still don't see anything it's 12704 06:53:51,058 --> 06:53:52,740 actually pretty simple just go up here 12705 06:53:52,740 --> 06:53:54,240 on the top left side and make sure to 12706 06:53:54,240 --> 06:53:56,878 save the ascent okay save it great then 12707 06:53:56,878 --> 06:53:59,520 let's exit from our maximize View and 12708 06:53:59,520 --> 06:54:01,978 now let's close this tab let's click on 12709 06:54:01,978 --> 06:54:04,080 play just to play the game now let's 12710 06:54:04,080 --> 06:54:06,120 stop playing and now if we open the 12711 06:54:06,120 --> 06:54:08,340 Shader again if there go now we do see 12712 06:54:08,340 --> 06:54:09,718 the Shader compiling over there that 12713 06:54:09,718 --> 06:54:11,878 color that is the Shader compilation and 12714 06:54:11,878 --> 06:54:13,440 after a little bit it should work let's 12715 06:54:13,440 --> 06:54:14,820 just maximize this 12716 06:54:14,820 --> 06:54:16,500 see if there you go there we do see our 12717 06:54:16,500 --> 06:54:17,940 texture okay great 12718 06:54:17,940 --> 06:54:19,740 so again it's just a simple rendering 12719 06:54:19,740 --> 06:54:21,420 plug on the current Tech version if 12720 06:54:21,420 --> 06:54:22,620 you're watching this video in the future 12721 06:54:22,620 --> 06:54:24,298 chances are you don't even have this box 12722 06:54:24,298 --> 06:54:26,280 so there's no need to worry okay so 12723 06:54:26,280 --> 06:54:27,780 right now we do see it working we can 12724 06:54:27,780 --> 06:54:29,458 see our bread texture and it's currently 12725 06:54:29,458 --> 06:54:31,978 being applied on a sphere for a use case 12726 06:54:31,978 --> 06:54:34,200 we're working with 2D textures so this 12727 06:54:34,200 --> 06:54:35,940 would be best to be seen on the Quan so 12728 06:54:35,940 --> 06:54:37,138 we can right click over here on the 12729 06:54:37,138 --> 06:54:38,458 preview in order to select the preview 12730 06:54:38,458 --> 06:54:40,558 mesh so let's go with a simple quad and 12731 06:54:40,558 --> 06:54:42,058 if there it is we have our Knight Squad 12732 06:54:42,058 --> 06:54:43,440 okay great 12733 06:54:43,440 --> 06:54:45,660 so over here we have our basic Shader 12734 06:54:45,660 --> 06:54:48,000 all it does is just shows the texture 12735 06:54:48,000 --> 06:54:50,878 that's it now it's actually use this and 12736 06:54:50,878 --> 06:54:52,798 first let's always make sure to save the 12737 06:54:52,798 --> 06:54:55,320 asset on the top left side on the moving 12738 06:54:55,320 --> 06:54:57,000 visual if you see an asterisk here that 12739 06:54:57,000 --> 06:54:59,218 means you have unsafe changes so always 12740 06:54:59,218 --> 06:55:01,020 make sure to save them in my case I 12741 06:55:01,020 --> 06:55:03,120 don't but still never hurts to save now 12742 06:55:03,120 --> 06:55:04,860 over here in scene view let's go inside 12743 06:55:04,860 --> 06:55:06,360 art only three counters and let's open 12744 06:55:06,360 --> 06:55:09,000 it and now for the display for our Arrow 12745 06:55:09,000 --> 06:55:11,580 let's make it a flat one so let's right 12746 06:55:11,580 --> 06:55:12,958 click in the hierarchy and let's create 12747 06:55:12,958 --> 06:55:15,298 a new 3D object and let's make it a quad 12748 06:55:15,298 --> 06:55:18,360 let's call this the delivery Arrow 12749 06:55:18,360 --> 06:55:20,160 let's place this on top of the counter 12750 06:55:20,160 --> 06:55:22,558 so let's rotate it to face upwards by 12751 06:55:22,558 --> 06:55:24,120 the way on the rotation make sure the 12752 06:55:24,120 --> 06:55:26,340 collar is facing upwards most shaders by 12753 06:55:26,340 --> 06:55:28,378 default they only render one face and 12754 06:55:28,378 --> 06:55:30,478 not the other one so make sure you put 12755 06:55:30,478 --> 06:55:32,218 the face with the collar upwards and not 12756 06:55:32,218 --> 06:55:33,900 the other one okay so let's rotate this 12757 06:55:33,900 --> 06:55:36,780 one upwards so there we go 90 over there 12758 06:55:36,780 --> 06:55:38,940 and let's just put it just exactly on 12759 06:55:38,940 --> 06:55:40,920 top of the counter so just enough so 12760 06:55:40,920 --> 06:55:43,200 that it's visible okay great so now 12761 06:55:43,200 --> 06:55:45,420 let's make a material for our Arrow so 12762 06:55:45,420 --> 06:55:47,400 let's go inside the materials folder and 12763 06:55:47,400 --> 06:55:49,200 over here let's create a brand new 12764 06:55:49,200 --> 06:55:50,218 material 12765 06:55:50,218 --> 06:55:52,920 let's call this the delivery Arrow let's 12766 06:55:52,920 --> 06:55:54,360 make sure to use this material on the 12767 06:55:54,360 --> 06:55:56,100 quad so let's just drag it over there on 12768 06:55:56,100 --> 06:55:57,958 the mesh render okay so it's using our 12769 06:55:57,958 --> 06:56:00,298 custom material and over here on this 12770 06:56:00,298 --> 06:56:02,638 Shader graph drop down menu over here we 12771 06:56:02,638 --> 06:56:04,680 can select what Shader we want to use so 12772 06:56:04,680 --> 06:56:06,240 in our case let's go inside the founder 12773 06:56:06,240 --> 06:56:08,940 Shader graphs and inside yep here we 12774 06:56:08,940 --> 06:56:11,040 have our moving visual Shader so let's 12775 06:56:11,040 --> 06:56:12,958 go ahead and use this and here right 12776 06:56:12,958 --> 06:56:15,058 away we do see that it does work here we 12777 06:56:15,058 --> 06:56:16,978 have our texture being drawn exactly on 12778 06:56:16,978 --> 06:56:19,860 top of our material okay so far so good 12779 06:56:19,860 --> 06:56:22,080 now again here remember one very very 12780 06:56:22,080 --> 06:56:24,298 important thing that I said the texture 12781 06:56:24,298 --> 06:56:25,978 that you define the Shader over here the 12782 06:56:25,978 --> 06:56:28,138 default for the property this one is 12783 06:56:28,138 --> 06:56:30,420 only the default the important one is 12784 06:56:30,420 --> 06:56:32,820 the one that we have on the material I'm 12785 06:56:32,820 --> 06:56:34,440 emphasizing this point because I've seen 12786 06:56:34,440 --> 06:56:36,478 a bunch of people make this mistake if 12787 06:56:36,478 --> 06:56:38,458 you modify default texture whilst inside 12788 06:56:38,458 --> 06:56:40,620 the Shader like for example if I change 12789 06:56:40,620 --> 06:56:42,420 here from bread let's say into the 12790 06:56:42,420 --> 06:56:43,558 Cabbage slices 12791 06:56:43,558 --> 06:56:46,320 if I modify that note how it does not 12792 06:56:46,320 --> 06:56:48,240 modify any materials that were created 12793 06:56:48,240 --> 06:56:51,058 we are only changing defaults so if you 12794 06:56:51,058 --> 06:56:52,320 want to change the texture that is 12795 06:56:52,320 --> 06:56:54,058 actually used make sure you change the 12796 06:56:54,058 --> 06:56:56,100 one on the material that you created and 12797 06:56:56,100 --> 06:56:58,080 not the defaults I changed the default 12798 06:56:58,080 --> 06:57:00,058 but did not change this Shader however 12799 06:57:00,058 --> 06:57:01,620 if I now were to make another material 12800 06:57:01,620 --> 06:57:04,378 which by the way here's a quick tip you 12801 06:57:04,378 --> 06:57:05,878 can recollect directly on the Shader 12802 06:57:05,878 --> 06:57:07,500 file and going to create and create new 12803 06:57:07,500 --> 06:57:09,000 material and it will automatically 12804 06:57:09,000 --> 06:57:10,680 create the material using that Shader 12805 06:57:10,680 --> 06:57:12,840 naturally here then update default just 12806 06:57:12,840 --> 06:57:15,120 because I didn't save the Shader so I 12807 06:57:15,120 --> 06:57:16,558 modified this one for the camera slices 12808 06:57:16,558 --> 06:57:18,958 and now if I save the asset and now if I 12809 06:57:18,958 --> 06:57:20,580 right click there and I create a brand 12810 06:57:20,580 --> 06:57:22,500 new material and yep now that one does 12811 06:57:22,500 --> 06:57:24,718 have the new default but again remember 12812 06:57:24,718 --> 06:57:26,700 what you said over here is just the 12813 06:57:26,700 --> 06:57:29,100 default what really matters is what is 12814 06:57:29,100 --> 06:57:31,138 on the material after the material has 12815 06:57:31,138 --> 06:57:33,000 been created modifying default here does 12816 06:57:33,000 --> 06:57:35,458 nothing so always keep that in mind in 12817 06:57:35,458 --> 06:57:37,200 most cases you want to be changing the 12818 06:57:37,200 --> 06:57:39,058 property on the material itself not the 12819 06:57:39,058 --> 06:57:41,100 default on the Shader okay let's just 12820 06:57:41,100 --> 06:57:42,900 clean up both of these all right so 12821 06:57:42,900 --> 06:57:44,940 let's continue now here we have our 12822 06:57:44,940 --> 06:57:46,740 Sprite working okay except we don't want 12823 06:57:46,740 --> 06:57:48,298 to show some bread so let's actually use 12824 06:57:48,298 --> 06:57:49,978 the proper Arrow Sprite so let's select 12825 06:57:49,978 --> 06:57:50,820 this one 12826 06:57:50,820 --> 06:57:52,558 and yep it does work it is printing the 12827 06:57:52,558 --> 06:57:54,958 Sprite however one obvious thing is that 12828 06:57:54,958 --> 06:57:56,400 the arrow is not transparent like it 12829 06:57:56,400 --> 06:57:58,798 should be so let's solve that back in 12830 06:57:58,798 --> 06:58:01,020 our Shader graph in order to make this a 12831 06:58:01,020 --> 06:58:02,340 transparent Shader we need to actually 12832 06:58:02,340 --> 06:58:04,260 go into the graph settings so on the 12833 06:58:04,260 --> 06:58:05,700 graph inspector go into graph settings 12834 06:58:05,700 --> 06:58:07,200 and over here you see a bunch of 12835 06:58:07,200 --> 06:58:08,638 settings that relate to the graph itself 12836 06:58:08,638 --> 06:58:10,620 and not any selected property so let's 12837 06:58:10,620 --> 06:58:12,478 go into graph settings for example like 12838 06:58:12,478 --> 06:58:13,860 I mentioned a while ago you can modify 12839 06:58:13,860 --> 06:58:16,320 between lit and lit and so on so this is 12840 06:58:16,320 --> 06:58:18,240 where you would change that you can also 12841 06:58:18,240 --> 06:58:20,458 appear at multiple targets so you can 12842 06:58:20,458 --> 06:58:22,080 create a Shader in Shader graph and make 12843 06:58:22,080 --> 06:58:23,520 it work with the Universe on random 12844 06:58:23,520 --> 06:58:25,138 pipeline or the high definition render 12845 06:58:25,138 --> 06:58:26,820 pipeline or the built-in render pipeline 12846 06:58:26,820 --> 06:58:28,320 all of those are supported through 12847 06:58:28,320 --> 06:58:30,478 Shader graph now for a goal in order to 12848 06:58:30,478 --> 06:58:32,218 make this a transparent Shader let's 12849 06:58:32,218 --> 06:58:33,540 just go over here onto service type 12850 06:58:33,540 --> 06:58:35,218 instead of opaque and let's change to 12851 06:58:35,218 --> 06:58:37,320 transparent and as soon as we do look 12852 06:58:37,320 --> 06:58:39,000 what happens there and if there go it 12853 06:58:39,000 --> 06:58:40,978 adds a brand new Alpha Channel if we 12854 06:58:40,978 --> 06:58:43,138 just save the asset right now and open 12855 06:58:43,138 --> 06:58:44,820 look at that it still doesn't work it's 12856 06:58:44,820 --> 06:58:46,920 still not transparent basically we made 12857 06:58:46,920 --> 06:58:48,718 this Shader transparent but now we need 12858 06:58:48,718 --> 06:58:50,700 to fit in the transparent Channel over 12859 06:58:50,700 --> 06:58:52,680 here onto the alpha this is the one 12860 06:58:52,680 --> 06:58:54,000 thing that is different from a previous 12861 06:58:54,000 --> 06:58:55,978 version of shadowgraph previously you 12862 06:58:55,978 --> 06:58:57,420 could just feed the alpha Channel over 12863 06:58:57,420 --> 06:58:59,458 here onto the base color and Shader 12864 06:58:59,458 --> 06:59:01,620 graph would automatically apply it but 12865 06:59:01,620 --> 06:59:03,360 in recent versions you need to add it 12866 06:59:03,360 --> 06:59:05,400 over here separately so if you have any 12867 06:59:05,400 --> 06:59:07,138 issues with transparency when following 12868 06:59:07,138 --> 06:59:08,760 some older share graph tutorials always 12869 06:59:08,760 --> 06:59:10,798 remember this change I covered that 12870 06:59:10,798 --> 06:59:12,420 along with some other changes in a very 12871 06:59:12,420 --> 06:59:13,978 useful video so if you're following 12872 06:59:13,978 --> 06:59:15,660 along some other shade graph tutorials 12873 06:59:15,660 --> 06:59:17,040 make sure you watch that video to learn 12874 06:59:17,040 --> 06:59:18,660 what you need to do to update them to 12875 06:59:18,660 --> 06:59:20,820 the latest version okay so here on the 12876 06:59:20,820 --> 06:59:22,200 similar texture we already have the 12877 06:59:22,200 --> 06:59:23,580 alpha channel so we just connect this 12878 06:59:23,580 --> 06:59:25,920 onto the master Alpha and right there we 12879 06:59:25,920 --> 06:59:28,020 already see it working let's just go 12880 06:59:28,020 --> 06:59:30,240 ahead save our asset and here in scene 12881 06:59:30,240 --> 06:59:32,878 view if there go now we do see our Arrow 12882 06:59:32,878 --> 06:59:35,280 now one more small thing you might 12883 06:59:35,280 --> 06:59:36,958 notice that from some angles it's not 12884 06:59:36,958 --> 06:59:39,120 exactly transparent basically it 12885 06:59:39,120 --> 06:59:40,620 actually is transparent but since we 12886 06:59:40,620 --> 06:59:42,298 made this in literature sometimes the 12887 06:59:42,298 --> 06:59:43,740 light might make the transparent Parts 12888 06:59:43,740 --> 06:59:46,020 visible one option to solve that is over 12889 06:59:46,020 --> 06:59:47,218 here on the graph settings instead of 12890 06:59:47,218 --> 06:59:49,260 making it lit let's make it unlit that 12891 06:59:49,260 --> 06:59:51,120 would work say up with the unload Shader 12892 06:59:51,120 --> 06:59:53,280 the transparency is perfect but if you 12893 06:59:53,280 --> 06:59:55,378 really want to keep it lit then the 12894 06:59:55,378 --> 06:59:56,760 other thing you can do is just over here 12895 06:59:56,760 --> 06:59:58,680 play around with these settings you've 12896 06:59:58,680 --> 07:00:00,420 got smoothness AO and so on and over 12897 07:00:00,420 --> 07:00:01,860 here you can even modify the workflow 12898 07:00:01,860 --> 07:00:03,900 mode so for transparency instead of 12899 07:00:03,900 --> 07:00:05,280 making it metallic let's go with a 12900 07:00:05,280 --> 07:00:07,500 specular workflow and then over here set 12901 07:00:07,500 --> 07:00:09,180 the smoothness to 1 and the ambient 12902 07:00:09,180 --> 07:00:11,400 occlusion down to zero and now if we 12903 07:00:11,400 --> 07:00:13,920 save this Shader look at that and yep 12904 07:00:13,920 --> 07:00:15,478 now the transparent parts are indeed 12905 07:00:15,478 --> 07:00:17,638 fully transparent finally over here on 12906 07:00:17,638 --> 07:00:19,320 the right side on the mesh render if you 12907 07:00:19,320 --> 07:00:20,760 want you might want to play around over 12908 07:00:20,760 --> 07:00:23,100 here with the cast Shadows so maybe you 12909 07:00:23,100 --> 07:00:24,540 don't want this one to cast Shadows 12910 07:00:24,540 --> 07:00:26,458 maybe you don't want it to impact light 12911 07:00:26,458 --> 07:00:28,680 probes and so on okay so with this we 12912 07:00:28,680 --> 07:00:30,600 have our nice transparent Arrow 12913 07:00:30,600 --> 07:00:32,100 let's make sure to save our delivery 12914 07:00:32,100 --> 07:00:33,660 counter so let's go outside back into 12915 07:00:33,660 --> 07:00:34,680 scenes 12916 07:00:34,680 --> 07:00:36,780 and let's head on playing and if there 12917 07:00:36,780 --> 07:00:38,458 you go we have our transparent counter 12918 07:00:38,458 --> 07:00:40,440 with our nice Arrow now we want the 12919 07:00:40,440 --> 07:00:42,660 arrow to actually move and doing that is 12920 07:00:42,660 --> 07:00:44,760 actually super simple going back here in 12921 07:00:44,760 --> 07:00:46,320 our shadow graph let's just modify 12922 07:00:46,320 --> 07:00:47,940 default just so we can see the arrow 12923 07:00:47,940 --> 07:00:49,978 that we want to see so let's select the 12924 07:00:49,978 --> 07:00:53,218 arrow Sprite okay there's our Arrow now 12925 07:00:53,218 --> 07:00:54,718 for moving over here on the simple 12926 07:00:54,718 --> 07:00:56,638 texture we've got an input for the UV 12927 07:00:56,638 --> 07:00:59,100 the UV is what defines what portion of 12928 07:00:59,100 --> 07:01:00,958 the texture we're going to grab which by 12929 07:01:00,958 --> 07:01:03,360 default just gets the whole texture so 12930 07:01:03,360 --> 07:01:05,520 since this field represents where we're 12931 07:01:05,520 --> 07:01:07,320 going to grab from texture by playing 12932 07:01:07,320 --> 07:01:08,820 around with this we can grab different 12933 07:01:08,820 --> 07:01:11,638 parts so to do that let's just add a 12934 07:01:11,638 --> 07:01:13,620 standard UV node so here it is this is 12935 07:01:13,620 --> 07:01:15,780 the standard UV channel so if we connect 12936 07:01:15,780 --> 07:01:17,160 this then nothing changes everything 12937 07:01:17,160 --> 07:01:19,620 still renders exactly the same but now 12938 07:01:19,620 --> 07:01:21,958 we can modify this and to do that we're 12939 07:01:21,958 --> 07:01:23,400 really just going to use some basic math 12940 07:01:23,400 --> 07:01:25,740 remember that when working with shaders 12941 07:01:25,740 --> 07:01:27,540 even though you do see colors everything 12942 07:01:27,540 --> 07:01:30,420 is really just numbers so uv2 is just 12943 07:01:30,420 --> 07:01:32,160 number the converges the number the 12944 07:01:32,160 --> 07:01:33,900 alpha is just a number so visually 12945 07:01:33,900 --> 07:01:35,638 everything might look like images might 12946 07:01:35,638 --> 07:01:37,200 look like colors but really in the end 12947 07:01:37,200 --> 07:01:39,478 it's all just numbers so for example how 12948 07:01:39,478 --> 07:01:41,100 do we move this texture well it's 12949 07:01:41,100 --> 07:01:42,780 actually pretty simple we just add a 12950 07:01:42,780 --> 07:01:45,058 number onto it so we're here on the UVM 12951 07:01:45,058 --> 07:01:48,000 let's just add an add node so this just 12952 07:01:48,000 --> 07:01:50,878 adds two numbers together very basic so 12953 07:01:50,878 --> 07:01:52,860 let's take the regular UV and let's add 12954 07:01:52,860 --> 07:01:55,080 something on top of it for example we 12955 07:01:55,080 --> 07:01:56,760 can make a vector two 12956 07:01:56,760 --> 07:01:59,340 and let's put it on say 0.10 12957 07:01:59,340 --> 07:02:01,860 and let's add this one onto this one and 12958 07:02:01,860 --> 07:02:03,360 now if we drag this one onto the input 12959 07:02:03,360 --> 07:02:04,620 and look over there on the preview what 12960 07:02:04,620 --> 07:02:06,478 happens and if they're going like that 12961 07:02:06,478 --> 07:02:08,580 it moves slightly to the left so if I 12962 07:02:08,580 --> 07:02:10,320 modify this one put it on zero there you 12963 07:02:10,320 --> 07:02:12,180 go and that point one on that point two 12964 07:02:12,180 --> 07:02:14,400 on that and so on so you can see that by 12965 07:02:14,400 --> 07:02:15,660 modifying here I'm essentially 12966 07:02:15,660 --> 07:02:18,058 offsetting the texture I'm offsetting on 12967 07:02:18,058 --> 07:02:20,040 the X and over here I can also offset it 12968 07:02:20,040 --> 07:02:22,020 on the y basically I'm offsetting the 12969 07:02:22,020 --> 07:02:24,120 texture by ten percent the UV is a 12970 07:02:24,120 --> 07:02:26,340 normalized value this is not pixels so 12971 07:02:26,340 --> 07:02:27,958 that is why point one is ten percent 12972 07:02:27,958 --> 07:02:30,600 regardless of how big the texture is and 12973 07:02:30,600 --> 07:02:32,760 if we go way past one then texture 12974 07:02:32,760 --> 07:02:34,920 essentially Loops back so this is really 12975 07:02:34,920 --> 07:02:36,058 all we need 12976 07:02:36,058 --> 07:02:38,458 for our moving Arrow we're going to have 12977 07:02:38,458 --> 07:02:40,920 zero on the Y and on the X we're going 12978 07:02:40,920 --> 07:02:42,540 to constantly either increase or 12979 07:02:42,540 --> 07:02:44,040 decrease that's how we're going to have 12980 07:02:44,040 --> 07:02:46,138 our moving Arrow so again the only issue 12981 07:02:46,138 --> 07:02:47,638 here is that I'm modifying this manually 12982 07:02:47,638 --> 07:02:49,440 we don't want a fixed amount on the 12983 07:02:49,440 --> 07:02:51,180 Shader instead we want a nice animation 12984 07:02:51,180 --> 07:02:53,580 so for that we have the very useful the 12985 07:02:53,580 --> 07:02:54,780 time node 12986 07:02:54,780 --> 07:02:57,360 this one has various time-based outputs 12987 07:02:57,360 --> 07:02:59,520 the one that we want for this case is a 12988 07:02:59,520 --> 07:03:01,860 time which is just the total time this 12989 07:03:01,860 --> 07:03:03,360 one is constantly increasing since the 12990 07:03:03,360 --> 07:03:04,620 start of the game by the number of 12991 07:03:04,620 --> 07:03:06,660 seconds so if you use this over here 12992 07:03:06,660 --> 07:03:08,700 directly on the end and they're gonna 12993 07:03:08,700 --> 07:03:09,958 look that texture is constantly 12994 07:03:09,958 --> 07:03:12,660 scrolling okay so that's great except 12995 07:03:12,660 --> 07:03:14,340 obviously we have one issue we don't 12996 07:03:14,340 --> 07:03:16,558 want it to scroll diagonally we only 12997 07:03:16,558 --> 07:03:18,660 want to scroll in One Direction so for 12998 07:03:18,660 --> 07:03:20,280 that we can essentially create a simple 12999 07:03:20,280 --> 07:03:23,040 property to act as our spin so let's 13000 07:03:23,040 --> 07:03:25,080 over here on the Blackboard let's create 13001 07:03:25,080 --> 07:03:27,240 a new Vector two column Tower speed 13002 07:03:27,240 --> 07:03:29,520 property and for the phone let's see if 13003 07:03:29,520 --> 07:03:32,520 I want to say 0.1 on the x0 on the Y and 13004 07:03:32,520 --> 07:03:34,500 now if I drag the speed over here onto 13005 07:03:34,500 --> 07:03:36,900 our Blackboard okay great this is 13006 07:03:36,900 --> 07:03:38,280 basically a multiplier so we just need 13007 07:03:38,280 --> 07:03:40,500 to multiply the time by this so let's 13008 07:03:40,500 --> 07:03:43,080 add a multiply node also by the way 13009 07:03:43,080 --> 07:03:44,760 quick tip over here on each node you've 13010 07:03:44,760 --> 07:03:46,080 got a nice little arrow so if you want 13011 07:03:46,080 --> 07:03:47,638 to make it a bit more compact so if you 13012 07:03:47,638 --> 07:03:49,200 don't actually need to see the preview 13013 07:03:49,200 --> 07:03:51,718 so make that and in this case let's take 13014 07:03:51,718 --> 07:03:54,298 our time multiply it by our speed and 13015 07:03:54,298 --> 07:03:55,920 then for the output pass it into the end 13016 07:03:55,920 --> 07:03:57,900 okay so like that now it is indeed 13017 07:03:57,900 --> 07:03:59,580 moving in this direction and over here 13018 07:03:59,580 --> 07:04:00,780 on the speed we can play around the 13019 07:04:00,780 --> 07:04:03,180 values so if we put that 0.5 now it's 13020 07:04:03,180 --> 07:04:05,700 moving faster and if I put it on the Y 13021 07:04:05,700 --> 07:04:07,740 now it's moving diagonally put zero on 13022 07:04:07,740 --> 07:04:08,878 the X and now it's only moving 13023 07:04:08,878 --> 07:04:11,160 vertically okay so this is really what 13024 07:04:11,160 --> 07:04:13,860 we want let's just go ahead save our 13025 07:04:13,860 --> 07:04:15,780 Shader and now let's just select our 13026 07:04:15,780 --> 07:04:17,940 delivery Arrow material and over here 13027 07:04:17,940 --> 07:04:20,160 yep we've got the spin if you don't see 13028 07:04:20,160 --> 07:04:21,240 it make sure they're on the speed 13029 07:04:21,240 --> 07:04:23,040 property over here you have it exposed 13030 07:04:23,040 --> 07:04:24,900 so we have the speed instead of moving 13031 07:04:24,900 --> 07:04:27,600 on the Y let's move on the X and 13032 07:04:27,600 --> 07:04:29,340 actually like this it's reverse going 13033 07:04:29,340 --> 07:04:31,260 backwards so over here we can just put a 13034 07:04:31,260 --> 07:04:32,760 negative value so let's put it on minus 13035 07:04:32,760 --> 07:04:34,680 one and if there go now the arrow is 13036 07:04:34,680 --> 07:04:37,200 moving perfectly also here let me make 13037 07:04:37,200 --> 07:04:39,298 one important note just in case you're 13038 07:04:39,298 --> 07:04:41,100 using this Shader with a custom texture 13039 07:04:41,100 --> 07:04:42,298 instead of the one included in the 13040 07:04:42,298 --> 07:04:44,218 course if you do that make sure that the 13041 07:04:44,218 --> 07:04:45,780 texture that you use over here I'm using 13042 07:04:45,780 --> 07:04:47,040 the arrow texture 13043 07:04:47,040 --> 07:04:49,020 over here on the Arrow import settings 13044 07:04:49,020 --> 07:04:51,540 down here under wrap mode make sure it 13045 07:04:51,540 --> 07:04:53,760 is set to repeat if you set it as clamp 13046 07:04:53,760 --> 07:04:55,558 you might get some weird visuals or 13047 07:04:55,558 --> 07:04:57,660 nothing at all in order for the texture 13048 07:04:57,660 --> 07:04:59,160 to constantly Loop and constantly repeat 13049 07:04:59,160 --> 07:05:00,660 itself that one needs to be set to 13050 07:05:00,660 --> 07:05:03,058 repeat okay so here it is in game and we 13051 07:05:03,058 --> 07:05:05,280 have a really nice moving texture for 13052 07:05:05,280 --> 07:05:07,320 that we created the simple but really 13053 07:05:07,320 --> 07:05:09,718 nice useful custom Shader definitely go 13054 07:05:09,718 --> 07:05:11,100 ahead and watch the various effects that 13055 07:05:11,100 --> 07:05:13,378 I made in the shadow graph playlist this 13056 07:05:13,378 --> 07:05:15,058 tool is super useful definitely make 13057 07:05:15,058 --> 07:05:17,100 sure you know how to use it I've used it 13058 07:05:17,100 --> 07:05:19,260 for making a building effect I've made 13059 07:05:19,260 --> 07:05:21,420 some nice outlines a really nice wind 13060 07:05:21,420 --> 07:05:23,400 Shader also a really interesting the 13061 07:05:23,400 --> 07:05:25,440 sound of effect and even a cool 13062 07:05:25,440 --> 07:05:27,058 transition Shader just like in the game 13063 07:05:27,058 --> 07:05:29,638 Hades so this really is a super powerful 13064 07:05:29,638 --> 07:05:31,080 tool make sure you watch that playlist 13065 07:05:31,080 --> 07:05:33,298 to really learn how to use it alright so 13066 07:05:33,298 --> 07:05:34,978 here we'll learn about share graph and 13067 07:05:34,978 --> 07:05:36,780 created a really nice custom Shader 13068 07:05:36,780 --> 07:05:38,940 however the delivery counter still only 13069 07:05:38,940 --> 07:05:41,400 has a visual so let's create some proper 13070 07:05:41,400 --> 07:05:43,320 Logic for generating and delivering the 13071 07:05:43,320 --> 07:05:46,260 correct recipes in the next lecture 13072 07:05:46,260 --> 07:05:48,180 hello and welcome I'm your code monkey 13073 07:05:48,180 --> 07:05:50,280 in this lecture we're going to build a 13074 07:05:50,280 --> 07:05:51,900 proper delivery manager that will 13075 07:05:51,900 --> 07:05:53,638 generate recipes that customers are 13076 07:05:53,638 --> 07:05:55,260 ordering and validate to see if the 13077 07:05:55,260 --> 07:05:57,298 player made the right dishes alright so 13078 07:05:57,298 --> 07:05:58,860 right now we have the player capable of 13079 07:05:58,860 --> 07:06:00,660 making dishes so for example I can put 13080 07:06:00,660 --> 07:06:02,700 some cheese cook some meat cut the 13081 07:06:02,700 --> 07:06:04,978 cheese and then pick up both of them 13082 07:06:04,978 --> 07:06:06,840 then let's say pick up some bread there 13083 07:06:06,840 --> 07:06:08,218 you go got a nice cheeseburger and 13084 07:06:08,218 --> 07:06:10,378 deliver it okay so that works but right 13085 07:06:10,378 --> 07:06:12,780 now they just vanish on delivery counter 13086 07:06:12,780 --> 07:06:14,820 so there's no recipe we need to follow 13087 07:06:14,820 --> 07:06:16,920 no validation none of that so let's add 13088 07:06:16,920 --> 07:06:19,020 both those things okay first of all 13089 07:06:19,020 --> 07:06:20,700 let's make our script so let's create a 13090 07:06:20,700 --> 07:06:22,740 brand new sharp script for the delivery 13091 07:06:22,740 --> 07:06:25,200 manager let's make a new game object to 13092 07:06:25,200 --> 07:06:26,878 run it so we need delivery manager 13093 07:06:26,878 --> 07:06:28,740 attached to script let's make sure to 13094 07:06:28,740 --> 07:06:30,360 keep things lean so reset the transform 13095 07:06:30,360 --> 07:06:32,100 and also by the way since we're here 13096 07:06:32,100 --> 07:06:33,600 let's go ahead and put the plates and 13097 07:06:33,600 --> 07:06:35,218 delivery counter inside the counter so 13098 07:06:35,218 --> 07:06:37,500 everything is nice and organized okay 13099 07:06:37,500 --> 07:06:40,320 great so let's open up this script now 13100 07:06:40,320 --> 07:06:42,180 here basically we need to Define some 13101 07:06:42,180 --> 07:06:43,920 sort of list to store all the recipes 13102 07:06:43,920 --> 07:06:46,080 that the customers are waiting for which 13103 07:06:46,080 --> 07:06:47,700 of course begs the question what type is 13104 07:06:47,700 --> 07:06:50,280 that going to be now technically one 13105 07:06:50,280 --> 07:06:52,020 thing we could do since a recipe is 13106 07:06:52,020 --> 07:06:53,580 around just a list of kitchen objects 13107 07:06:53,580 --> 07:06:56,520 over here we could have a list of list 13108 07:06:56,520 --> 07:06:58,978 of kitchen objects this would be our 13109 07:06:58,978 --> 07:07:01,020 recipe list technically that would work 13110 07:07:01,020 --> 07:07:02,878 but that really looks quite dirty 13111 07:07:02,878 --> 07:07:04,860 instead of having a list of lists we 13112 07:07:04,860 --> 07:07:06,478 should probably have a proper type for 13113 07:07:06,478 --> 07:07:08,458 this so let's write some good clean code 13114 07:07:08,458 --> 07:07:10,620 and Define a proper recipe Script Mod 13115 07:07:10,620 --> 07:07:12,718 object back in unity let's go inside 13116 07:07:12,718 --> 07:07:14,400 script knowledge's folder and create a 13117 07:07:14,400 --> 07:07:16,500 brand new one let's call this the recipe 13118 07:07:16,500 --> 07:07:19,200 so and over here let's make this a 13119 07:07:19,200 --> 07:07:21,660 script Mall object so extend script on 13120 07:07:21,660 --> 07:07:24,120 object make the create asset menu 13121 07:07:24,120 --> 07:07:26,218 and over here for the films for that 13122 07:07:26,218 --> 07:07:28,620 that we need well like I said a recipe 13123 07:07:28,620 --> 07:07:30,958 is just a list of ingredients so just 13124 07:07:30,958 --> 07:07:32,940 taking a list of kitchen object that 13125 07:07:32,940 --> 07:07:35,940 sell for the kitchen object SM list 13126 07:07:35,940 --> 07:07:37,558 okay that's it that's really all the 13127 07:07:37,558 --> 07:07:38,878 data that we need to define a recipe 13128 07:07:38,878 --> 07:07:41,100 just to be able to identify them for the 13129 07:07:41,100 --> 07:07:43,440 player let's also add a public string 13130 07:07:43,440 --> 07:07:45,360 for the recipe name 13131 07:07:45,360 --> 07:07:47,400 so just a nice name String okay great 13132 07:07:47,400 --> 07:07:49,680 now back in the editor let's define so 13133 07:07:49,680 --> 07:07:51,298 let's go inside the certain objects and 13134 07:07:51,298 --> 07:07:54,780 make a brand new one for our recipe so 13135 07:07:54,780 --> 07:07:57,180 and now inside let's create a brand new 13136 07:07:57,180 --> 07:07:59,520 recipe SL for this one let's call it 13137 07:07:59,520 --> 07:08:01,680 just burger and over here first of all 13138 07:08:01,680 --> 07:08:03,718 for the name just name it burger and 13139 07:08:03,718 --> 07:08:05,638 then for the kitchen object list well to 13140 07:08:05,638 --> 07:08:07,620 make a burger let's well first let's add 13141 07:08:07,620 --> 07:08:09,660 some meat and we want some cooked meat 13142 07:08:09,660 --> 07:08:11,700 we don't want to serve uncooked or burnt 13143 07:08:11,700 --> 07:08:13,978 meat so only the cooked meat then for a 13144 07:08:13,978 --> 07:08:15,540 simple Burger obviously we need some 13145 07:08:15,540 --> 07:08:17,700 bread and that's about it so some bread 13146 07:08:17,700 --> 07:08:19,620 some meat that's our very basic Burger 13147 07:08:19,620 --> 07:08:21,540 now let's also make another one so let's 13148 07:08:21,540 --> 07:08:23,040 duplicate this one and name this one the 13149 07:08:23,040 --> 07:08:25,440 cheeseburger over here let's name it 13150 07:08:25,440 --> 07:08:28,080 cheeseburger 13151 07:08:28,080 --> 07:08:31,378 and lightning place has bread meat and 13152 07:08:31,378 --> 07:08:33,660 obviously some nice cheese slices 13153 07:08:33,660 --> 07:08:35,760 so there you go okay we have a 13154 07:08:35,760 --> 07:08:38,160 cheeseburger now let's also make a mega 13155 07:08:38,160 --> 07:08:39,900 Burger so something with everything 13156 07:08:39,900 --> 07:08:41,878 so let's call this one the mega burger 13157 07:08:41,878 --> 07:08:44,160 and over here for the string name for 13158 07:08:44,160 --> 07:08:46,558 the Mega burger and for that we have 13159 07:08:46,558 --> 07:08:50,160 meat bread cheese let's also have some 13160 07:08:50,160 --> 07:08:52,558 nice cabbage slices and also some tomato 13161 07:08:52,558 --> 07:08:54,780 slices alright that's our Mega burger 13162 07:08:54,780 --> 07:08:56,820 with everything and finally let's also 13163 07:08:56,820 --> 07:08:58,500 make just a nice simple salad so let's 13164 07:08:58,500 --> 07:09:00,958 duplicate this for a salad 13165 07:09:00,958 --> 07:09:03,058 let's name it salad 13166 07:09:03,058 --> 07:09:05,520 and for the salad we don't have any meat 13167 07:09:05,520 --> 07:09:07,440 we don't have any bread and also no 13168 07:09:07,440 --> 07:09:09,660 cheese so just cabbage slice and tomato 13169 07:09:09,660 --> 07:09:12,478 slice that's a simple salad okay so here 13170 07:09:12,478 --> 07:09:14,760 we have all of our recipes so back here 13171 07:09:14,760 --> 07:09:16,978 on the delivery manager script instead 13172 07:09:16,978 --> 07:09:18,360 of making a list of lists of game 13173 07:09:18,360 --> 07:09:20,218 objects let's just make a list of recipe 13174 07:09:20,218 --> 07:09:23,340 recipe so and name it the recipe so list 13175 07:09:23,340 --> 07:09:24,660 this is where we're going to probably 13176 07:09:24,660 --> 07:09:26,160 see recipes that the customers are 13177 07:09:26,160 --> 07:09:28,138 waiting for so it's actually rename this 13178 07:09:28,138 --> 07:09:31,080 let's put it waiting recipe on list okay 13179 07:09:31,080 --> 07:09:32,638 so the customers are waiting for 13180 07:09:32,638 --> 07:09:35,040 whatever is inside this list and now we 13181 07:09:35,040 --> 07:09:36,540 could make this a serialized field then 13182 07:09:36,540 --> 07:09:38,580 set it in the editor but we don't want 13183 07:09:38,580 --> 07:09:40,260 to have a fixed list we want to 13184 07:09:40,260 --> 07:09:42,780 periodically spawn new recipes in order 13185 07:09:42,780 --> 07:09:44,520 to spawn new recipes we also need to 13186 07:09:44,520 --> 07:09:46,680 know which ones we can spawn so for that 13187 07:09:46,680 --> 07:09:48,240 we could add a list of all of the 13188 07:09:48,240 --> 07:09:50,520 recipes then we could pick a random one 13189 07:09:50,520 --> 07:09:52,080 from the list and add it over here to 13190 07:09:52,080 --> 07:09:53,820 the waiting list that would work that's 13191 07:09:53,820 --> 07:09:55,620 one good approach but since we already 13192 07:09:55,620 --> 07:09:57,360 did something similar to that various 13193 07:09:57,360 --> 07:09:58,860 times in this course here don't let me 13194 07:09:58,860 --> 07:10:00,180 teach you a different approach that 13195 07:10:00,180 --> 07:10:02,160 sometimes might make more sense for that 13196 07:10:02,160 --> 07:10:03,780 second approach we just need one thing 13197 07:10:03,780 --> 07:10:05,700 we need a script more object to hold all 13198 07:10:05,700 --> 07:10:08,100 of our recipes so let's do that let's do 13199 07:10:08,100 --> 07:10:10,798 a brand new c-sharp script this is the 13200 07:10:10,798 --> 07:10:13,500 recipe list scriptable object and then 13201 07:10:13,500 --> 07:10:15,600 inside this one is going to be a 13202 07:10:15,600 --> 07:10:18,058 scriptable object let's add the create 13203 07:10:18,058 --> 07:10:19,378 asset menu 13204 07:10:19,378 --> 07:10:21,298 and inside we're just going to have a 13205 07:10:21,298 --> 07:10:23,400 list of recipe so 13206 07:10:23,400 --> 07:10:26,580 for the recipe SLS so that's it super 13207 07:10:26,580 --> 07:10:28,860 simple now let's just create one object 13208 07:10:28,860 --> 07:10:30,900 of this type we can put it inside the 13209 07:10:30,900 --> 07:10:32,580 recipe as soon as since we're only going 13210 07:10:32,580 --> 07:10:34,138 to have one so let's make a recipe on 13211 07:10:34,138 --> 07:10:36,718 Lister so namely the recipient list SL 13212 07:10:36,718 --> 07:10:38,760 and then over here let's just drag our 13213 07:10:38,760 --> 07:10:40,680 recipe so we've got a burger a 13214 07:10:40,680 --> 07:10:43,260 cheeseburger we have a mega burger and 13215 07:10:43,260 --> 07:10:45,478 finally a salad okay so basically we 13216 07:10:45,478 --> 07:10:47,040 have a script ball object with all of 13217 07:10:47,040 --> 07:10:49,080 our recipes and now just for safety 13218 07:10:49,080 --> 07:10:51,360 since we only want to ever have a single 13219 07:10:51,360 --> 07:10:54,058 one of these objects a recipe on SSO for 13220 07:10:54,058 --> 07:10:55,440 this one we can go back here in the 13221 07:10:55,440 --> 07:10:56,940 script and simply comment out the create 13222 07:10:56,940 --> 07:10:59,340 asset menu so now back in the game over 13223 07:10:59,340 --> 07:11:01,080 here we can no longer create another 13224 07:11:01,080 --> 07:11:03,540 type of recipient list so so just say 13225 07:11:03,540 --> 07:11:05,218 nice safety thing since we probably only 13226 07:11:05,218 --> 07:11:07,500 need just one and let's also add an 13227 07:11:07,500 --> 07:11:09,120 underscore just so it shows up at the 13228 07:11:09,120 --> 07:11:11,638 top-down list okay great so we have this 13229 07:11:11,638 --> 07:11:14,458 and over here on the recipe manager we 13230 07:11:14,458 --> 07:11:15,900 can basically expose that in a 13231 07:11:15,900 --> 07:11:17,638 serialization so let's make a serialized 13232 07:11:17,638 --> 07:11:18,958 field 13233 07:11:18,958 --> 07:11:22,020 make it private of type recipe so list 13234 07:11:22,020 --> 07:11:24,840 recipe enlisted so for the recipient 13235 07:11:24,840 --> 07:11:27,420 list so and now here in the editor we 13236 07:11:27,420 --> 07:11:29,040 just drag that reference alright that's 13237 07:11:29,040 --> 07:11:31,080 it so basically the difference that we 13238 07:11:31,080 --> 07:11:33,000 did with this method is over here on 13239 07:11:33,000 --> 07:11:34,440 delivery manager instead of having a 13240 07:11:34,440 --> 07:11:36,058 list of all of our recipes we just have 13241 07:11:36,058 --> 07:11:37,860 a reference to one object and then that 13242 07:11:37,860 --> 07:11:39,360 object holds a list of all the recipes 13243 07:11:39,360 --> 07:11:41,520 in this specific use case like I said 13244 07:11:41,520 --> 07:11:42,958 this approach doesn't really have many 13245 07:11:42,958 --> 07:11:44,580 benefits compared to just starting the 13246 07:11:44,580 --> 07:11:46,860 last year but let's say we had another 13247 07:11:46,860 --> 07:11:48,780 script that also needs a list of all of 13248 07:11:48,780 --> 07:11:50,820 our recipes if we did that we would 13249 07:11:50,820 --> 07:11:53,160 basically have duplicate references so 13250 07:11:53,160 --> 07:11:54,600 this script would have a list of all the 13251 07:11:54,600 --> 07:11:56,160 recipes then some other script would 13252 07:11:56,160 --> 07:11:57,900 also have a list of all the recipes and 13253 07:11:57,900 --> 07:11:59,458 then if you wanted to add a brand new 13254 07:11:59,458 --> 07:12:01,260 recipe you'd need to add it to all the 13255 07:12:01,260 --> 07:12:03,180 lists on all the scripts whereas like 13256 07:12:03,180 --> 07:12:05,280 this any script that needs to know about 13257 07:12:05,280 --> 07:12:07,138 all of the recipes just needs a 13258 07:12:07,138 --> 07:12:09,240 reference to the recipe on SSO and 13259 07:12:09,240 --> 07:12:10,740 whenever we want to add or remove a 13260 07:12:10,740 --> 07:12:12,420 recipe we just need to update this one 13261 07:12:12,420 --> 07:12:14,340 object and everything works perfectly 13262 07:12:14,340 --> 07:12:16,080 that's one of the benefits of this 13263 07:12:16,080 --> 07:12:17,400 approach where you have a script mode 13264 07:12:17,400 --> 07:12:19,378 object to hold a list of all the objects 13265 07:12:19,378 --> 07:12:21,180 of some type personally I find this 13266 07:12:21,180 --> 07:12:23,340 pattern to be quite useful okay so on 13267 07:12:23,340 --> 07:12:25,260 delivery manager we have a list of all 13268 07:12:25,260 --> 07:12:27,298 of our recipes now let's just make a 13269 07:12:27,298 --> 07:12:29,040 simple timer to spawn them like I 13270 07:12:29,040 --> 07:12:30,540 mentioned previously in the spawn point 13271 07:12:30,540 --> 07:12:32,520 logic you could just use Echo routine if 13272 07:12:32,520 --> 07:12:33,600 you like that 13273 07:12:33,600 --> 07:12:35,280 core routines can be useful for running 13274 07:12:35,280 --> 07:12:37,378 timers but personally like I mentioned I 13275 07:12:37,378 --> 07:12:39,180 do not like Co routines I don't like the 13276 07:12:39,180 --> 07:12:41,160 pattern they force it to use so over 13277 07:12:41,160 --> 07:12:42,540 here I'm just going to make a simple 13278 07:12:42,540 --> 07:12:43,798 flow timer 13279 07:12:43,798 --> 07:12:46,378 so a private fluid for the spawn recipe 13280 07:12:46,378 --> 07:12:49,200 timer another one for the recipe timer 13281 07:12:49,200 --> 07:12:51,840 Max and let's say 4 seconds 13282 07:12:51,840 --> 07:12:53,878 then we just do a simple and private 13283 07:12:53,878 --> 07:12:55,020 weight update 13284 07:12:55,020 --> 07:12:57,420 on update let's count down the timer so 13285 07:12:57,420 --> 07:12:59,580 time dot down for time 13286 07:12:59,580 --> 07:13:03,000 and if the spawn timer is under 0f let's 13287 07:13:03,000 --> 07:13:04,500 reset the timer 13288 07:13:04,500 --> 07:13:06,180 and now let's basically spawn a recipe 13289 07:13:06,180 --> 07:13:08,458 so for that let's grab a random one from 13290 07:13:08,458 --> 07:13:10,920 the list so we go into the recipe list 13291 07:13:10,920 --> 07:13:13,978 so and grab the recipe as a list then 13292 07:13:13,978 --> 07:13:15,660 we're going to grab a random one so 13293 07:13:15,660 --> 07:13:18,058 let's get a random index so random.range 13294 07:13:18,058 --> 07:13:21,360 between 0 and the recipient list so dot 13295 07:13:21,360 --> 07:13:24,240 recipes dot count so you get a random 13296 07:13:24,240 --> 07:13:26,580 one this is going to be a recipe so for 13297 07:13:26,580 --> 07:13:28,500 the waiting recipe so 13298 07:13:28,500 --> 07:13:30,360 and then we simply go into the waiting 13299 07:13:30,360 --> 07:13:33,120 rest PSL list and we add a brand new 13300 07:13:33,120 --> 07:13:35,340 recipe okay that's it super simple let's 13301 07:13:35,340 --> 07:13:37,260 just make sure to initialize the list so 13302 07:13:37,260 --> 07:13:39,660 let's do here a simple awake for the 13303 07:13:39,660 --> 07:13:42,660 waiting recipes and just initialize it 13304 07:13:42,660 --> 07:13:44,280 okay so like this it should be working 13305 07:13:44,280 --> 07:13:46,138 however we're also going to generate 13306 07:13:46,138 --> 07:13:48,298 recipes non-stop we don't want that so 13307 07:13:48,298 --> 07:13:50,400 let's define some kind of maximum 13308 07:13:50,400 --> 07:13:53,160 so let's Define a simple end for the 13309 07:13:53,160 --> 07:13:56,700 waiting recipes Max 13310 07:13:56,700 --> 07:13:58,558 let's say we kind of have a maximum of 13311 07:13:58,558 --> 07:14:00,420 four recipes waiting 13312 07:14:00,420 --> 07:14:02,760 and then down here when camera lapses so 13313 07:14:02,760 --> 07:14:04,920 if the waiting recipes only stock count 13314 07:14:04,920 --> 07:14:07,138 if it is under the maximum then we 13315 07:14:07,138 --> 07:14:09,240 generate and add it okay that's it 13316 07:14:09,240 --> 07:14:10,320 pretty simple 13317 07:14:10,320 --> 07:14:12,000 now for testing let's just set allow 13318 07:14:12,000 --> 07:14:14,760 here to print the name so debug.log on 13319 07:14:14,760 --> 07:14:16,860 the waiting recipe so that we generate 13320 07:14:16,860 --> 07:14:19,860 so let's print out the recipe name okay 13321 07:14:19,860 --> 07:14:22,320 so let's test so here we are in yep one 13322 07:14:22,320 --> 07:14:24,058 will spawn right away so we have a solid 13323 07:14:24,058 --> 07:14:25,740 and after four seconds Yep they're going 13324 07:14:25,740 --> 07:14:27,840 out of salad and if we wait for four 13325 07:14:27,840 --> 07:14:29,280 seconds we should have another one there 13326 07:14:29,280 --> 07:14:31,798 you go a mega butter recipe and finally 13327 07:14:31,798 --> 07:14:33,900 after four seconds we have yep we have 13328 07:14:33,900 --> 07:14:35,940 another burger and now no matter how 13329 07:14:35,940 --> 07:14:38,100 much time passes there should be no more 13330 07:14:38,100 --> 07:14:40,320 since we're at the limit any uptime pass 13331 07:14:40,320 --> 07:14:42,840 then no more okay all right awesome so 13332 07:14:42,840 --> 07:14:44,820 we are correctly generating recipes that 13333 07:14:44,820 --> 07:14:47,040 the customers are waiting for now it's a 13334 07:14:47,040 --> 07:14:49,378 logic to try to fulfill these orders so 13335 07:14:49,378 --> 07:14:51,058 over here on delivery manager let's make 13336 07:14:51,058 --> 07:14:53,520 a function to deliver a recipe 13337 07:14:53,520 --> 07:14:55,558 so let's make a public Point make it 13338 07:14:55,558 --> 07:14:57,000 public since we're going to access this 13339 07:14:57,000 --> 07:14:59,340 from the delivery counter currently 13340 07:14:59,340 --> 07:15:01,020 deliver recipe 13341 07:15:01,020 --> 07:15:02,878 and the recipes are going to be 13342 07:15:02,878 --> 07:15:04,920 delivered whilst on a point so let's 13343 07:15:04,920 --> 07:15:06,540 receive a parameter of type Plate 13344 07:15:06,540 --> 07:15:07,798 Kitchen object 13345 07:15:07,798 --> 07:15:09,240 and over here the logic is actually 13346 07:15:09,240 --> 07:15:11,400 going to be pretty simple we just need 13347 07:15:11,400 --> 07:15:13,440 to cycle through all of the recipes that 13348 07:15:13,440 --> 07:15:15,420 the customers are waiting for and see if 13349 07:15:15,420 --> 07:15:17,280 the ingredients on this plate matches 13350 07:15:17,280 --> 07:15:19,378 the ones on any waiting recipe 13351 07:15:19,378 --> 07:15:21,360 so over here let's cycle through all of 13352 07:15:21,360 --> 07:15:23,760 our recipes so let's do before 13353 07:15:23,760 --> 07:15:26,760 entire zero going through the entire 13354 07:15:26,760 --> 07:15:29,700 recipe only star count I plus plus okay 13355 07:15:29,700 --> 07:15:32,458 let's grab the recipe so for the waiting 13356 07:15:32,458 --> 07:15:34,138 recipe so 13357 07:15:34,138 --> 07:15:36,120 and we grab from The Waiting recipes on 13358 07:15:36,120 --> 07:15:38,218 list on this index okay so we have that 13359 07:15:38,218 --> 07:15:40,558 then first let's do a quick test just to 13360 07:15:40,558 --> 07:15:42,780 check if the waiting recipe has the same 13361 07:15:42,780 --> 07:15:44,400 number of ingredients as they are on the 13362 07:15:44,400 --> 07:15:46,440 plate if not then we already know that 13363 07:15:46,440 --> 07:15:48,900 it's not valid so over here let's do a 13364 07:15:48,900 --> 07:15:51,840 quick test SO waiting recipe so let's 13365 07:15:51,840 --> 07:15:53,160 check the kitchen object that's only 13366 07:15:53,160 --> 07:15:55,500 it's not count if this one matches the 13367 07:15:55,500 --> 07:15:57,180 play kitchen object let's get the 13368 07:15:57,180 --> 07:15:59,040 kitchen object that's on the list and 13369 07:15:59,040 --> 07:16:01,200 also check the count so over here we 13370 07:16:01,200 --> 07:16:03,180 know that has the same number of 13371 07:16:03,180 --> 07:16:04,558 ingredients 13372 07:16:04,558 --> 07:16:07,080 so this is the first check then we need 13373 07:16:07,080 --> 07:16:08,760 to cycle through all the ingredients on 13374 07:16:08,760 --> 07:16:10,260 this recipe and all of the ingredients 13375 07:16:10,260 --> 07:16:12,600 on the plate and basically see if both 13376 07:16:12,600 --> 07:16:14,580 of them match so let's first cycle 13377 07:16:14,580 --> 07:16:16,860 through the ingredients on the recipe so 13378 07:16:16,860 --> 07:16:18,240 for each 13379 07:16:18,240 --> 07:16:20,878 kitchen object as so let's call it the 13380 07:16:20,878 --> 07:16:25,020 recipe kitchen object so in the waiting 13381 07:16:25,020 --> 07:16:26,700 recipe so let's go into the waiting 13382 07:16:26,700 --> 07:16:29,160 recipe and get the kitchen object list 13383 07:16:29,160 --> 07:16:33,000 okay so here we are cycling through all 13384 07:16:33,000 --> 07:16:35,160 ingredients in the recipe 13385 07:16:35,160 --> 07:16:37,200 then we need to cycle through all the 13386 07:16:37,200 --> 07:16:39,660 ingredients on the plate so let's do 13387 07:16:39,660 --> 07:16:41,580 another cycle for the Plate Kitchen 13388 07:16:41,580 --> 07:16:43,978 object SL and we're going to go inside 13389 07:16:43,978 --> 07:16:45,900 the Plate Kitchen object get the kitchen 13390 07:16:45,900 --> 07:16:47,820 object that's on the list like this 13391 07:16:47,820 --> 07:16:49,500 so here we are cycling through all the 13392 07:16:49,500 --> 07:16:52,378 ingredients on the plate 13393 07:16:52,378 --> 07:16:54,180 okay so now here basically we need to 13394 07:16:54,180 --> 07:16:55,680 see if this ingredient that we're 13395 07:16:55,680 --> 07:16:57,900 cycling through if this one matches the 13396 07:16:57,900 --> 07:17:01,020 ingredient on the recipe so here we 13397 07:17:01,020 --> 07:17:02,820 check if the Plate Kitchen object does 13398 07:17:02,820 --> 07:17:05,100 so if this one matches the recipe 13399 07:17:05,100 --> 07:17:07,320 kitchen outlet 13400 07:17:07,320 --> 07:17:10,138 if so then the ingredient does match 13401 07:17:10,138 --> 07:17:12,240 so in order to keep track if it does 13402 07:17:12,240 --> 07:17:13,080 match 13403 07:17:13,080 --> 07:17:15,240 over here before we cycle through all 13404 07:17:15,240 --> 07:17:16,680 the ones on the plane let's define a 13405 07:17:16,680 --> 07:17:20,638 bone for found or ingredient found 13406 07:17:20,638 --> 07:17:23,580 let's default it too false and over here 13407 07:17:23,580 --> 07:17:25,378 if we have match then this one becomes 13408 07:17:25,378 --> 07:17:27,298 true and by the way over here we can 13409 07:17:27,298 --> 07:17:28,860 also break out of the cycle 13410 07:17:28,860 --> 07:17:30,360 now if you're not familiar with break 13411 07:17:30,360 --> 07:17:32,100 basically this is going to break out at 13412 07:17:32,100 --> 07:17:34,978 the for each so let's say the plate has 13413 07:17:34,978 --> 07:17:36,660 10 ingredients and the second one 13414 07:17:36,660 --> 07:17:38,760 matches when this cycle gets to the 13415 07:17:38,760 --> 07:17:40,320 second one it triggers a break so it no 13416 07:17:40,320 --> 07:17:41,520 longer goes through the remaining eight 13417 07:17:41,520 --> 07:17:43,260 so basically it breaks out of the cycle 13418 07:17:43,260 --> 07:17:44,940 so keeps writing some code right down 13419 07:17:44,940 --> 07:17:46,978 here okay so we cycle through all of the 13420 07:17:46,978 --> 07:17:48,900 ones on the aggressively then recycle 13421 07:17:48,900 --> 07:17:50,940 through the plate and if we do find that 13422 07:17:50,940 --> 07:17:53,458 ingredient on that plate then we have an 13423 07:17:53,458 --> 07:17:55,680 ingredient found so over here 13424 07:17:55,680 --> 07:17:59,878 if we have a not ingredient found 13425 07:17:59,878 --> 07:18:03,540 then over here that means this recipe 13426 07:18:03,540 --> 07:18:07,320 ingredient was not found on the plate 13427 07:18:07,320 --> 07:18:08,878 so if that happens then essentially over 13428 07:18:08,878 --> 07:18:10,558 here we have a phenocate so the 13429 07:18:10,558 --> 07:18:12,058 ingredient that this recipe requires is 13430 07:18:12,058 --> 07:18:14,458 not on the plate so let's go up here 13431 07:18:14,458 --> 07:18:16,020 when we have the same number of 13432 07:18:16,020 --> 07:18:17,638 ingredients let's define a Boolean 13433 07:18:17,638 --> 07:18:20,638 called the plate contents matches recipe 13434 07:18:20,638 --> 07:18:23,160 let's see found it to true and over here 13435 07:18:23,160 --> 07:18:24,900 if we don't find at least one of them 13436 07:18:24,900 --> 07:18:27,058 then the plate contents do not match the 13437 07:18:27,058 --> 07:18:29,520 recipe and afterwards we can check this 13438 07:18:29,520 --> 07:18:31,260 bowl again 13439 07:18:31,260 --> 07:18:33,180 so if this one is true that means they 13440 07:18:33,180 --> 07:18:35,340 all match if just one of them does not 13441 07:18:35,340 --> 07:18:37,260 matches then this one won't be false 13442 07:18:37,260 --> 07:18:39,840 so over here we know player delivered 13443 07:18:39,840 --> 07:18:42,478 the correct recipe 13444 07:18:42,478 --> 07:18:44,340 so over here on let's do a quick debug 13445 07:18:44,340 --> 07:18:47,340 down log and print out a message 13446 07:18:47,340 --> 07:18:49,080 and after we do let's also do a return 13447 07:18:49,080 --> 07:18:51,000 so we stop the rest of the execution so 13448 07:18:51,000 --> 07:18:52,978 basically if we find a waiting recipe 13449 07:18:52,978 --> 07:18:55,320 that matches we don't want to keep going 13450 07:18:55,320 --> 07:18:57,120 and also here if we do find it let's 13451 07:18:57,120 --> 07:18:59,218 also remove it from the list 13452 07:18:59,218 --> 07:19:01,680 so let's go into waiting queue remove at 13453 07:19:01,680 --> 07:19:04,138 and remove at this index okay so we're 13454 07:19:04,138 --> 07:19:06,360 going to remove this recipe but if this 13455 07:19:06,360 --> 07:19:07,500 doesn't happen then it's going to be 13456 07:19:07,500 --> 07:19:09,000 keep cycling and it's going to cycle 13457 07:19:09,000 --> 07:19:10,978 through all the recipes so basically if 13458 07:19:10,978 --> 07:19:12,958 it reaches the end this far 13459 07:19:12,958 --> 07:19:16,760 then basically no match is found 13460 07:19:16,978 --> 07:19:19,500 so the player did not 13461 07:19:19,500 --> 07:19:23,660 deliver a correct recipe 13462 07:19:23,700 --> 07:19:28,400 so let's do another debug in here 13463 07:19:29,040 --> 07:19:31,798 okay so this is done for logic it looks 13464 07:19:31,798 --> 07:19:33,360 a bit complex but I hope this was easy 13465 07:19:33,360 --> 07:19:35,700 to follow when we see it in action It 13466 07:19:35,700 --> 07:19:37,798 all becomes a bit more clear so all 13467 07:19:37,798 --> 07:19:39,120 that's left is just calling this 13468 07:19:39,120 --> 07:19:40,860 function from the delivery counter so 13469 07:19:40,860 --> 07:19:43,260 let's do that over here on the delivery 13470 07:19:43,260 --> 07:19:45,478 counter it accepts plates and destroys 13471 07:19:45,478 --> 07:19:47,580 plates but before we destroy 13472 07:19:47,580 --> 07:19:49,500 let's go into the delivery manager which 13473 07:19:49,500 --> 07:19:51,718 means we need to access a reference so 13474 07:19:51,718 --> 07:19:53,520 again we could add a serialized field or 13475 07:19:53,520 --> 07:19:55,138 in this case it makes perfect sense to 13476 07:19:55,138 --> 07:19:57,240 make this a Singleton so let's make it 13477 07:19:57,240 --> 07:19:59,400 here public static of type delivering 13478 07:19:59,400 --> 07:20:01,920 manager call it instance with a public 13479 07:20:01,920 --> 07:20:05,360 get and a private set 13480 07:20:05,820 --> 07:20:08,520 okay then over here on awake let's set 13481 07:20:08,520 --> 07:20:10,920 instance equals this 13482 07:20:10,920 --> 07:20:13,020 all right so now over here on the 13483 07:20:13,020 --> 07:20:14,820 delivery counter we can go into the 13484 07:20:14,820 --> 07:20:17,580 delivery manager access the instance and 13485 07:20:17,580 --> 07:20:19,740 deliver our recipe and pass in the Plate 13486 07:20:19,740 --> 07:20:21,780 Kitchen object 13487 07:20:21,780 --> 07:20:24,420 okay that should do it let's test all 13488 07:20:24,420 --> 07:20:25,978 right so let's look in the log to see 13489 07:20:25,978 --> 07:20:27,958 what they are waiting for so there are 13490 07:20:27,958 --> 07:20:30,058 two cheeseburgers waiting another Mega 13491 07:20:30,058 --> 07:20:32,458 burger and a cheeseburger so let's make 13492 07:20:32,458 --> 07:20:34,740 a cheeseburger to deliver so first of 13493 07:20:34,740 --> 07:20:36,600 all let's cook some meat let's slice 13494 07:20:36,600 --> 07:20:38,940 some cheese let's pick up the meat 13495 07:20:38,940 --> 07:20:40,740 before it burns pick up the cheese and 13496 07:20:40,740 --> 07:20:42,840 we just need the bread okay this is a 13497 07:20:42,840 --> 07:20:45,718 valley cheeseburger so let's deliver it 13498 07:20:45,718 --> 07:20:47,280 and if there go the players delivered 13499 07:20:47,280 --> 07:20:49,500 the correct recipe okay great 13500 07:20:49,500 --> 07:20:51,180 now let's deliver something that nobody 13501 07:20:51,180 --> 07:20:52,920 asked for let's say just some meat 13502 07:20:52,920 --> 07:20:55,680 actually let's burn it just for fun all 13503 07:20:55,680 --> 07:20:57,120 right so there we have a bunch of 13504 07:20:57,120 --> 07:20:58,978 charred meat so nobody really wants this 13505 07:20:58,978 --> 07:21:01,200 but if we deliver if their yield player 13506 07:21:01,200 --> 07:21:03,600 did not deliver a correct recipe alright 13507 07:21:03,600 --> 07:21:05,400 awesome so over here everything worked 13508 07:21:05,400 --> 07:21:07,620 we have a bunch of recipes being 13509 07:21:07,620 --> 07:21:10,500 generated and then we have the logic so 13510 07:21:10,500 --> 07:21:11,760 that when the player delivers something 13511 07:21:11,760 --> 07:21:13,260 it checks if the players delivered 13512 07:21:13,260 --> 07:21:15,360 something correct or incorrect so 13513 07:21:15,360 --> 07:21:17,040 everything is great all that's missing 13514 07:21:17,040 --> 07:21:19,320 is obviously some nice UI so let's do 13515 07:21:19,320 --> 07:21:21,360 that in the next lecture 13516 07:21:21,360 --> 07:21:23,340 hello and welcome I'm your code monkey 13517 07:21:23,340 --> 07:21:25,558 in this lecture we're going to create a 13518 07:21:25,558 --> 07:21:27,540 nice UI visual to display our waiting 13519 07:21:27,540 --> 07:21:29,878 recipes okay so our delivery manager is 13520 07:21:29,878 --> 07:21:31,680 already working we are randomly spawning 13521 07:21:31,680 --> 07:21:33,298 some random recipes every once in a 13522 07:21:33,298 --> 07:21:34,978 while now instead of looking at the 13523 07:21:34,978 --> 07:21:37,260 console let's add a proper UI so for 13524 07:21:37,260 --> 07:21:38,940 that over here in the editor let's go 13525 07:21:38,940 --> 07:21:40,500 inside the canvas and by the way let's 13526 07:21:40,500 --> 07:21:42,240 click on the button to unlock the canvas 13527 07:21:42,240 --> 07:21:44,100 and this is actually the first time 13528 07:21:44,100 --> 07:21:46,020 we're using the Ragnar canvas quite a 13529 07:21:46,020 --> 07:21:47,638 while ago we just created it we didn't 13530 07:21:47,638 --> 07:21:49,260 really set it up so let's quickly do 13531 07:21:49,260 --> 07:21:51,420 that for the render mode this one is 13532 07:21:51,420 --> 07:21:53,340 meant to be a regular UI so let's leave 13533 07:21:53,340 --> 07:21:55,620 it on the screen space overlay then over 13534 07:21:55,620 --> 07:21:57,840 here on the canvas scaler instead of 13535 07:21:57,840 --> 07:21:59,700 constant pixel size let's go with scale 13536 07:21:59,700 --> 07:22:01,740 with screen size then for the reference 13537 07:22:01,740 --> 07:22:05,100 resolution I like to use 1920x1080 13538 07:22:05,100 --> 07:22:07,080 and finally unlike to fully match with 13539 07:22:07,080 --> 07:22:08,940 the height basically this means that 13540 07:22:08,940 --> 07:22:11,100 objects in the canvas will be scaled if 13541 07:22:11,100 --> 07:22:13,500 the height changes for example let's add 13542 07:22:13,500 --> 07:22:15,718 inside just a quick UI image just a test 13543 07:22:15,718 --> 07:22:17,400 let's look in the game View 13544 07:22:17,400 --> 07:22:18,660 so there you go there's the image let's 13545 07:22:18,660 --> 07:22:20,760 just put on a different color okay so 13546 07:22:20,760 --> 07:22:23,100 there's the image and note how if I 13547 07:22:23,100 --> 07:22:25,138 modify the aspect ratio here so let's 13548 07:22:25,138 --> 07:22:27,180 say I put it on 5x4 there go the 13549 07:22:27,180 --> 07:22:28,680 horizontal side of the window change but 13550 07:22:28,680 --> 07:22:31,440 note how the element was not scaled so I 13551 07:22:31,440 --> 07:22:33,240 can put it even on free aspects so 13552 07:22:33,240 --> 07:22:35,058 really wide and does not change the size 13553 07:22:35,058 --> 07:22:37,860 whereas if I modify this if I modify the 13554 07:22:37,860 --> 07:22:40,500 vertical size the image does indeed get 13555 07:22:40,500 --> 07:22:42,660 Scaled up or down personally I like the 13556 07:22:42,660 --> 07:22:44,160 setup because means that I only have to 13557 07:22:44,160 --> 07:22:45,298 worry about positioning things 13558 07:22:45,298 --> 07:22:47,638 horizontally if the vericon part gets 13559 07:22:47,638 --> 07:22:48,900 changed everything gets automatically 13560 07:22:48,900 --> 07:22:51,180 scaled okay so great so over here let's 13561 07:22:51,180 --> 07:22:53,638 go back into 4G all right and let's get 13562 07:22:53,638 --> 07:22:55,740 rid of the image all right back in the 13563 07:22:55,740 --> 07:22:57,540 scene view let's quickly look at the 13564 07:22:57,540 --> 07:22:59,340 canvas so we can select the canvas press 13565 07:22:59,340 --> 07:23:01,920 the F in order to zoom out and also we 13566 07:23:01,920 --> 07:23:03,780 can press the 2D button up here to go 13567 07:23:03,780 --> 07:23:06,240 into 3D mode okay so here's our nice UI 13568 07:23:06,240 --> 07:23:08,040 now inside the canvas let's create them 13569 07:23:08,040 --> 07:23:10,260 to game object call it the delivery 13570 07:23:10,260 --> 07:23:13,080 manager UI then in the inspector let's 13571 07:23:13,080 --> 07:23:14,520 make it stretch to occupy the whole 13572 07:23:14,520 --> 07:23:17,040 thing so let's put zero on everything 13573 07:23:17,040 --> 07:23:19,200 okay so this window now occupies the 13574 07:23:19,200 --> 07:23:20,400 entire screen 13575 07:23:20,400 --> 07:23:22,500 now inside let's do just like we did a 13576 07:23:22,500 --> 07:23:24,420 while ago for the plate icons meaning 13577 07:23:24,420 --> 07:23:26,218 let's make a template that we can then 13578 07:23:26,218 --> 07:23:28,558 clone but let's also put those templates 13579 07:23:28,558 --> 07:23:30,120 inside of a container so first of all 13580 07:23:30,120 --> 07:23:31,680 let's make the containers so a new empty 13581 07:23:31,680 --> 07:23:32,820 game object 13582 07:23:32,820 --> 07:23:34,920 of currently just the container the 13583 07:23:34,920 --> 07:23:36,298 reason why I'm going with this approach 13584 07:23:36,298 --> 07:23:38,520 is because I also want to have other 13585 07:23:38,520 --> 07:23:40,500 objects outside of here if you remember 13586 07:23:40,500 --> 07:23:42,958 how we did with the templates we can 13587 07:23:42,958 --> 07:23:45,180 actually go there and see so let's go 13588 07:23:45,180 --> 07:23:46,978 inside the prefabs inside the counters 13589 07:23:46,978 --> 07:23:48,958 actually it's on the kitchen objects 13590 07:23:48,958 --> 07:23:51,298 let's go inside the plate over here for 13591 07:23:51,298 --> 07:23:53,160 the template basically we use the play 13592 07:23:53,160 --> 07:23:55,260 tokens UI this main canvas as the 13593 07:23:55,260 --> 07:23:57,360 container but if you remember how we did 13594 07:23:57,360 --> 07:23:58,558 that in order to make sure we didn't end 13595 07:23:58,558 --> 07:24:00,120 up with duplicate icons we always 13596 07:24:00,120 --> 07:24:01,740 destroyed the previous one when we 13597 07:24:01,740 --> 07:24:04,080 spawned a brand new one so every time we 13598 07:24:04,080 --> 07:24:05,820 were cycling through the children of 13599 07:24:05,820 --> 07:24:07,500 this object in order to destroy all of 13600 07:24:07,500 --> 07:24:09,540 them except the template so over here 13601 07:24:09,540 --> 07:24:10,860 we're going to use a container so that 13602 07:24:10,860 --> 07:24:12,540 we can apply the logic only to the 13603 07:24:12,540 --> 07:24:14,218 children of the container and that way 13604 07:24:14,218 --> 07:24:16,320 we can have other objects outside of the 13605 07:24:16,320 --> 07:24:18,180 container for example outside of here 13606 07:24:18,180 --> 07:24:19,860 let's say we want some nice text just 13607 07:24:19,860 --> 07:24:22,378 saying recipes and waiting so on 13608 07:24:22,378 --> 07:24:23,820 delivery mansion let's make it a 13609 07:24:23,820 --> 07:24:25,860 challenge down let's go into UI and 13610 07:24:25,860 --> 07:24:28,320 let's make a text text mesh Pro and this 13611 07:24:28,320 --> 07:24:29,820 is the first time that we're using text 13612 07:24:29,820 --> 07:24:32,100 mesh Pro so this window pops out it's 13613 07:24:32,100 --> 07:24:34,440 actually import mesh Pro Essentials okay 13614 07:24:34,440 --> 07:24:36,780 just let it import okay that's it we 13615 07:24:36,780 --> 07:24:38,218 don't need the examples are extras so 13616 07:24:38,218 --> 07:24:40,080 let's just close this window and over 13617 07:24:40,080 --> 07:24:41,638 here on this window let's name this the 13618 07:24:41,638 --> 07:24:43,860 title text let's set the text to 13619 07:24:43,860 --> 07:24:46,500 something like recipes waiting 13620 07:24:46,500 --> 07:24:48,360 let's put it up there on the corner so 13621 07:24:48,360 --> 07:24:50,340 let's anchor it on the top left corner 13622 07:24:50,340 --> 07:24:52,680 also for the text I like to put it on a 13623 07:24:52,680 --> 07:24:54,120 width and height of zero but of course 13624 07:24:54,120 --> 07:24:56,040 that makes the text really vertical so 13625 07:24:56,040 --> 07:24:57,420 then down here on the wrapping let's 13626 07:24:57,420 --> 07:24:59,160 just disable it so there you go looks 13627 07:24:59,160 --> 07:25:01,320 like that and let's put it over there on 13628 07:25:01,320 --> 07:25:03,298 that corner now in scene view we are 13629 07:25:03,298 --> 07:25:05,218 seeing things different so if you want 13630 07:25:05,218 --> 07:25:06,660 to see what this looks like just go into 13631 07:25:06,660 --> 07:25:08,160 the game View and over there yep we do 13632 07:25:08,160 --> 07:25:09,360 see the recipes and let's just make it 13633 07:25:09,360 --> 07:25:10,860 in bond so there you go just some nice 13634 07:25:10,860 --> 07:25:13,320 text okay so that's our text and then 13635 07:25:13,320 --> 07:25:15,900 for the container let's make inside the 13636 07:25:15,900 --> 07:25:18,058 delivery template so let's create an 13637 07:25:18,058 --> 07:25:20,340 empty game object let's go with the 13638 07:25:20,340 --> 07:25:22,680 recipe template and for this one we're 13639 07:25:22,680 --> 07:25:24,058 going to want to Anchor it to the top 13640 07:25:24,058 --> 07:25:26,100 left corner so with the template 13641 07:25:26,100 --> 07:25:27,660 selected over here in the inspector 13642 07:25:27,660 --> 07:25:29,940 let's click and we want to click up here 13643 07:25:29,940 --> 07:25:33,120 however we also want to set the pivot so 13644 07:25:33,120 --> 07:25:34,798 let's make sure to hold down shift in 13645 07:25:34,798 --> 07:25:37,138 order to set the pivot over there okay 13646 07:25:37,138 --> 07:25:38,878 great that's exactly what we want so we 13647 07:25:38,878 --> 07:25:40,378 want the template right on the corner 13648 07:25:40,378 --> 07:25:43,320 then let's give it a size of say 250 by 13649 07:25:43,320 --> 07:25:45,958 100 okay now inside template we just 13650 07:25:45,958 --> 07:25:48,000 need two things we want to name the 13651 07:25:48,000 --> 07:25:49,680 recipe as well as the list of all the 13652 07:25:49,680 --> 07:25:51,360 ingredients although before that let's 13653 07:25:51,360 --> 07:25:52,740 actually make a nice visual for the 13654 07:25:52,740 --> 07:25:55,020 background so a new UI image for the 13655 07:25:55,020 --> 07:25:55,920 background 13656 07:25:55,920 --> 07:25:57,900 let's make this one stretch to occupy 13657 07:25:57,900 --> 07:25:59,700 the whole thing let's put everything on 13658 07:25:59,700 --> 07:26:01,558 zero okay that's the background let's 13659 07:26:01,558 --> 07:26:03,900 put it on a black we're just a little 13660 07:26:03,900 --> 07:26:06,180 bit lower Alpha okay that's good then 13661 07:26:06,180 --> 07:26:08,580 for name let's make a text field so 13662 07:26:08,580 --> 07:26:10,378 inside the template let's create another 13663 07:26:10,378 --> 07:26:13,978 text call it the recipe name text then 13664 07:26:13,978 --> 07:26:15,540 over here let's put it a bit small so on 13665 07:26:15,540 --> 07:26:17,400 the font size of maybe just 20 let's put 13666 07:26:17,400 --> 07:26:18,540 it in bold 13667 07:26:18,540 --> 07:26:20,760 and let's also again put the width and 13668 07:26:20,760 --> 07:26:22,860 height of 0 and over here make sure to 13669 07:26:22,860 --> 07:26:25,378 disable wrapping okay so that's the text 13670 07:26:25,378 --> 07:26:27,000 so we've got it up there let's just 13671 07:26:27,000 --> 07:26:28,680 anchor it to the top left corner okay 13672 07:26:28,680 --> 07:26:29,580 great 13673 07:26:29,580 --> 07:26:31,500 over here we can change the name to 13674 07:26:31,500 --> 07:26:33,718 recipe and then what we need is the 13675 07:26:33,718 --> 07:26:35,760 icons on here and for that we're going 13676 07:26:35,760 --> 07:26:37,260 to do pretty much the exact same thing 13677 07:26:37,260 --> 07:26:39,478 that we done on plate but before we do 13678 07:26:39,478 --> 07:26:40,978 that logic let's just get this basic 13679 07:26:40,978 --> 07:26:42,840 setup working so let's just position 13680 07:26:42,840 --> 07:26:45,058 everything so first of all the container 13681 07:26:45,058 --> 07:26:47,340 for all the templates let's anchor it on 13682 07:26:47,340 --> 07:26:49,978 the top left corner and let's push it 13683 07:26:49,978 --> 07:26:51,600 all the way over there and for 13684 07:26:51,600 --> 07:26:53,940 positioning them let's use this time the 13685 07:26:53,940 --> 07:26:56,340 vertical layout group so inside let's 13686 07:26:56,340 --> 07:26:57,780 duplicate the template just to be able 13687 07:26:57,780 --> 07:26:59,940 to see them okay so that's pretty much 13688 07:26:59,940 --> 07:27:01,440 we want we can actually set the width 13689 07:27:01,440 --> 07:27:03,298 and height both to zero and let's set 13690 07:27:03,298 --> 07:27:05,520 the spacing to something like 30. okay 13691 07:27:05,520 --> 07:27:07,860 so that's our basic UI now let's make 13692 07:27:07,860 --> 07:27:09,298 the script to run this 13693 07:27:09,298 --> 07:27:11,340 so over here in our scripts let's create 13694 07:27:11,340 --> 07:27:13,320 a brand new C sharp script for the 13695 07:27:13,320 --> 07:27:15,900 delivery manager UI let's go into the 13696 07:27:15,900 --> 07:27:18,058 parent game object and let's attach your 13697 07:27:18,058 --> 07:27:20,340 script let's open okay so now here first 13698 07:27:20,340 --> 07:27:21,900 we need a field for the container 13699 07:27:21,900 --> 07:27:24,540 another one for the template 13700 07:27:24,540 --> 07:27:27,180 so let's do a serialized film private 13701 07:27:27,180 --> 07:27:29,400 transform for the container 13702 07:27:29,400 --> 07:27:31,860 and another one for the transform and 13703 07:27:31,860 --> 07:27:34,200 this is going to be the recipe template 13704 07:27:34,200 --> 07:27:35,940 then let's do pretty much same thing we 13705 07:27:35,940 --> 07:27:37,440 did previously so first of all let's 13706 07:27:37,440 --> 07:27:39,420 actually go on a way in order to hide 13707 07:27:39,420 --> 07:27:41,638 the template so game objects set active 13708 07:27:41,638 --> 07:27:43,920 into false okay so first we hide the 13709 07:27:43,920 --> 07:27:45,900 template then let's make an update 13710 07:27:45,900 --> 07:27:47,820 visual function so private void update 13711 07:27:47,820 --> 07:27:48,958 visual 13712 07:27:48,958 --> 07:27:50,878 and for updating we're going to do the 13713 07:27:50,878 --> 07:27:52,860 exact same thing that we did so first 13714 07:27:52,860 --> 07:27:54,478 let's cycle through the container and 13715 07:27:54,478 --> 07:27:55,860 destroy everything except for the 13716 07:27:55,860 --> 07:27:58,920 template so do a 40 inch transform child 13717 07:27:58,920 --> 07:28:02,100 in the container 13718 07:28:02,100 --> 07:28:05,340 and if the child is the template 13719 07:28:05,340 --> 07:28:07,740 if so then we're going to continue and 13720 07:28:07,740 --> 07:28:09,420 if not we're going to destroy the child 13721 07:28:09,420 --> 07:28:12,120 game object okay so we have the cleanup 13722 07:28:12,120 --> 07:28:14,458 now we need is the second through all of 13723 07:28:14,458 --> 07:28:16,620 the waiting recipes so that means that 13724 07:28:16,620 --> 07:28:18,540 over here on delivery manager we need to 13725 07:28:18,540 --> 07:28:20,760 expose our waiting recipes on list so 13726 07:28:20,760 --> 07:28:22,260 let's go down here make a function to do 13727 07:28:22,260 --> 07:28:24,420 that probably going to return a list of 13728 07:28:24,420 --> 07:28:28,440 recipes so get waiting recipe so list 13729 07:28:28,440 --> 07:28:31,680 and we just return the waiting recipes 13730 07:28:31,680 --> 07:28:33,298 on list 13731 07:28:33,298 --> 07:28:35,218 okay great 13732 07:28:35,218 --> 07:28:37,860 so now here on the UI we can now go into 13733 07:28:37,860 --> 07:28:40,080 the delivery manager xsc static instance 13734 07:28:40,080 --> 07:28:42,478 in order to get the waiting recipes on 13735 07:28:42,478 --> 07:28:45,360 list so let's cycle through this so do a 13736 07:28:45,360 --> 07:28:48,718 40 inch for each recipe so recipe so in 13737 07:28:48,718 --> 07:28:51,180 the waiting rest vsl list 13738 07:28:51,180 --> 07:28:54,240 for each of them let's instantiate 13739 07:28:54,240 --> 07:28:56,700 and let's spawn our recipe template 13740 07:28:56,700 --> 07:28:59,458 spawn it inside the container and then 13741 07:28:59,458 --> 07:29:01,740 we just need to set this to enabled so 13742 07:29:01,740 --> 07:29:03,240 let's read the transform for the recipe 13743 07:29:03,240 --> 07:29:05,940 transform we grab this one grab the game 13744 07:29:05,940 --> 07:29:09,180 object and set active into true okay so 13745 07:29:09,180 --> 07:29:10,740 like this the only thing missing is the 13746 07:29:10,740 --> 07:29:12,478 text but that's okay for now 13747 07:29:12,478 --> 07:29:13,978 let you see where we're going to call 13748 07:29:13,978 --> 07:29:16,260 this function to update the visuals and 13749 07:29:16,260 --> 07:29:18,000 as usual we want to be smart and write 13750 07:29:18,000 --> 07:29:20,580 some good clean code so let's not do the 13751 07:29:20,580 --> 07:29:22,620 dirty approach of just updating this on 13752 07:29:22,620 --> 07:29:24,660 every single update instead let's only 13753 07:29:24,660 --> 07:29:25,740 call this function when something 13754 07:29:25,740 --> 07:29:27,840 actually changes so over here on the 13755 07:29:27,840 --> 07:29:29,400 delivery manager let's just make some 13756 07:29:29,400 --> 07:29:30,718 simple events 13757 07:29:30,718 --> 07:29:33,478 so if I'm like event event handler 13758 07:29:33,478 --> 07:29:37,200 let's go on recipes fund and another one 13759 07:29:37,200 --> 07:29:41,280 call it on recipe completed 13760 07:29:41,280 --> 07:29:43,020 and actually as soon as I add the event 13761 07:29:43,020 --> 07:29:44,638 handler which also add the using system 13762 07:29:44,638 --> 07:29:46,320 now here we have an interesting thing 13763 07:29:46,320 --> 07:29:48,120 we've got a nice namespace Collision 13764 07:29:48,120 --> 07:29:50,280 it's telling us that random is an 13765 07:29:50,280 --> 07:29:51,900 ambiguous reference between Unity engine 13766 07:29:51,900 --> 07:29:54,180 now random and system.r random that is 13767 07:29:54,180 --> 07:29:55,978 because both these namespaces Unity 13768 07:29:55,978 --> 07:29:57,718 engine and system both of them have a 13769 07:29:57,718 --> 07:30:00,120 class named exactly random so the code 13770 07:30:00,120 --> 07:30:01,680 here does not know which class we're 13771 07:30:01,680 --> 07:30:03,958 trying to use to solve this component we 13772 07:30:03,958 --> 07:30:06,058 really just need to be more specific in 13773 07:30:06,058 --> 07:30:07,320 this case here we want to use the UNT 13774 07:30:07,320 --> 07:30:09,120 engine version so let's just write the 13775 07:30:09,120 --> 07:30:12,120 full name Unity engine.renom and yep 13776 07:30:12,120 --> 07:30:14,100 that works okay so now let's fire off 13777 07:30:14,100 --> 07:30:16,138 the events so first of all the own 13778 07:30:16,138 --> 07:30:18,478 recipe spawns over here when we spawn a 13779 07:30:18,478 --> 07:30:21,360 recipe let's invoke this event so this 13780 07:30:21,360 --> 07:30:23,700 is ventar is not empty and let's also 13781 07:30:23,700 --> 07:30:25,138 get rid of the log we know we need that 13782 07:30:25,138 --> 07:30:27,420 okay now we could also add the wedding 13783 07:30:27,420 --> 07:30:28,920 recipe on the event artist but in this 13784 07:30:28,920 --> 07:30:30,240 case we don't need it just firing the 13785 07:30:30,240 --> 07:30:32,218 event is enough and then down here when 13786 07:30:32,218 --> 07:30:33,958 the players delivers something if the 13787 07:30:33,958 --> 07:30:35,700 player delivers the correct recipe we 13788 07:30:35,700 --> 07:30:37,860 remove it from the list and then let's 13789 07:30:37,860 --> 07:30:39,240 fire off the event so on recipe 13790 07:30:39,240 --> 07:30:42,240 completing let's invoke with this and 13791 07:30:42,240 --> 07:30:44,878 event rx.mt okay so we have the event 13792 07:30:44,878 --> 07:30:47,458 and down here we also don't need analog 13793 07:30:47,458 --> 07:30:49,978 okay so that works and finally over here 13794 07:30:49,978 --> 07:30:52,680 on the delivery man GUI let's just make 13795 07:30:52,680 --> 07:30:54,840 a private void start on start going to 13796 07:30:54,840 --> 07:30:57,058 the delivery manager access the static 13797 07:30:57,058 --> 07:30:58,978 instance and listen to both these events 13798 07:30:58,978 --> 07:31:01,440 so they spawned and let's also listen to 13799 07:31:01,440 --> 07:31:02,700 the other ones the library manager 13800 07:31:02,700 --> 07:31:05,280 instance on recipe completed 13801 07:31:05,280 --> 07:31:07,620 when either of these work let's just go 13802 07:31:07,620 --> 07:31:09,900 and update the visual so just like this 13803 07:31:09,900 --> 07:31:12,000 let's also rename this because again 13804 07:31:12,000 --> 07:31:14,040 instance doesn't sound like a very good 13805 07:31:14,040 --> 07:31:16,200 name let's actually rename this to only 13806 07:31:16,200 --> 07:31:18,958 remanager and same thing up here by the 13807 07:31:18,958 --> 07:31:20,878 way I'm using the visual studio shortcut 13808 07:31:20,878 --> 07:31:23,280 control RR in order to rename this to 13809 07:31:23,280 --> 07:31:25,440 delivering manager 13810 07:31:25,440 --> 07:31:27,600 and finally we also need to update the 13811 07:31:27,600 --> 07:31:29,280 visual OnStar just make sure the 13812 07:31:29,280 --> 07:31:31,920 previous ones do not show up okay that's 13813 07:31:31,920 --> 07:31:34,080 it so like this it should be working we 13814 07:31:34,080 --> 07:31:36,058 should be able to see no Visual and then 13815 07:31:36,058 --> 07:31:37,798 as more our spawned we should be able to 13816 07:31:37,798 --> 07:31:39,298 see each one being spawned until the 13817 07:31:39,298 --> 07:31:41,400 maximum so let's see just over here in 13818 07:31:41,400 --> 07:31:42,718 the UI let's make sure to drag the 13819 07:31:42,718 --> 07:31:44,520 references so the container and the 13820 07:31:44,520 --> 07:31:46,920 template and let's hit on play and okay 13821 07:31:46,920 --> 07:31:48,298 right away actually it spawned one 13822 07:31:48,298 --> 07:31:50,458 recipe it spawned instantly then after 13823 07:31:50,458 --> 07:31:52,080 four seconds there you go a second one 13824 07:31:52,080 --> 07:31:54,360 and after four seconds we should be able 13825 07:31:54,360 --> 07:31:56,700 to see yep another one now four more 13826 07:31:56,700 --> 07:31:58,558 seconds and we should see the final one 13827 07:31:58,558 --> 07:32:00,840 and now no matter how long we wait it 13828 07:32:00,840 --> 07:32:03,058 should no longer spawn anymore and yep 13829 07:32:03,058 --> 07:32:05,638 that works alright awesome so the basic 13830 07:32:05,638 --> 07:32:07,860 logic is working now let's handle the 13831 07:32:07,860 --> 07:32:10,200 proper Logic on the template for that 13832 07:32:10,200 --> 07:32:12,420 like I mentioned previously one approach 13833 07:32:12,420 --> 07:32:15,180 would be over here you could go and do a 13834 07:32:15,180 --> 07:32:16,978 transform.find 13835 07:32:16,978 --> 07:32:20,040 the actual recipe name text then get the 13836 07:32:20,040 --> 07:32:21,900 text mesh component and set it that 13837 07:32:21,900 --> 07:32:23,040 would work but like I mentioned 13838 07:32:23,040 --> 07:32:25,020 previously that would be very dirty not 13839 07:32:25,020 --> 07:32:27,478 good at all we should avoid using find 13840 07:32:27,478 --> 07:32:30,120 at any time and we should also avoid the 13841 07:32:30,120 --> 07:32:32,878 individual logic from the total logic so 13842 07:32:32,878 --> 07:32:34,740 let's do it properly and make a proper 13843 07:32:34,740 --> 07:32:37,200 script to handle each spawn template so 13844 07:32:37,200 --> 07:32:39,000 let's create a brand new c-sharp script 13845 07:32:39,000 --> 07:32:42,240 call this delivery manager single UI 13846 07:32:42,240 --> 07:32:44,218 single just because it refers to a 13847 07:32:44,218 --> 07:32:46,500 single recipe and also right now we 13848 07:32:46,500 --> 07:32:48,718 already have quite a few UI scripts so 13849 07:32:48,718 --> 07:32:50,878 let's organize our project again so 13850 07:32:50,878 --> 07:32:54,058 let's organize new folder for the UI and 13851 07:32:54,058 --> 07:32:55,798 inside let's put all of our UI scripts 13852 07:32:55,798 --> 07:32:57,680 so if we manage is single this one 13853 07:32:57,680 --> 07:33:00,298 deployed icons white icons and the 13854 07:33:00,298 --> 07:33:02,340 progress bar so let's put all of these 13855 07:33:02,340 --> 07:33:04,200 nicely organized in the UI folder okay 13856 07:33:04,200 --> 07:33:05,760 so with the script let's go into the 13857 07:33:05,760 --> 07:33:07,500 recipe template and attach the script 13858 07:33:07,500 --> 07:33:09,958 now let's open and over here let's begin 13859 07:33:09,958 --> 07:33:12,478 by adding a film for our text so a 13860 07:33:12,478 --> 07:33:13,860 serialized field 13861 07:33:13,860 --> 07:33:16,378 and over here it's also very important 13862 07:33:16,378 --> 07:33:19,138 for the text we are not using the text 13863 07:33:19,138 --> 07:33:21,780 inside DNT engine.ui this is the in 13864 07:33:21,780 --> 07:33:24,058 Legacy text it is not text mesh Pro so 13865 07:33:24,058 --> 07:33:26,340 this is not what we were using instead 13866 07:33:26,340 --> 07:33:28,920 we want to use text mesh Pro U going 13867 07:33:28,920 --> 07:33:31,558 which is inside TM Pro 13868 07:33:31,558 --> 07:33:33,420 so we need to go up here and add using 13869 07:33:33,420 --> 07:33:36,058 TM Pro and now we can use this type and 13870 07:33:36,058 --> 07:33:37,500 also make sure you're using text mesh 13871 07:33:37,500 --> 07:33:40,138 Pro ugui and not text mesh Pro this one 13872 07:33:40,138 --> 07:33:41,940 also exists but don't mix these two 13873 07:33:41,940 --> 07:33:44,700 these are two very different types if we 13874 07:33:44,700 --> 07:33:47,040 go over here in the editor and if 13875 07:33:47,040 --> 07:33:49,320 outside the canvas if I just create and 13876 07:33:49,320 --> 07:33:51,600 create new 3D object a new text object 13877 07:33:51,600 --> 07:33:54,058 if I do that then if we look over here 13878 07:33:54,058 --> 07:33:55,620 in the inspector we see this one as a 13879 07:33:55,620 --> 07:33:58,020 type text mesh Pro whereas for the ones 13880 07:33:58,020 --> 07:33:59,638 that we're using inside the canvas if we 13881 07:33:59,638 --> 07:34:01,860 unlock this is text mesh Pro it's a UI 13882 07:34:01,860 --> 07:34:03,780 text so these are the two different 13883 07:34:03,780 --> 07:34:06,298 classes within text mesh Pro you have 13884 07:34:06,298 --> 07:34:08,400 text mesh Pro and text mesh Pro ugly 13885 07:34:08,400 --> 07:34:10,620 we're working on the UI so we want this 13886 07:34:10,620 --> 07:34:12,958 one okay so we named this the recipe 13887 07:34:12,958 --> 07:34:14,638 name text 13888 07:34:14,638 --> 07:34:17,458 okay that's it over here in the editor 13889 07:34:17,458 --> 07:34:19,620 let's drag our reference all right so 13890 07:34:19,620 --> 07:34:21,058 now this group let's make a function to 13891 07:34:21,058 --> 07:34:24,058 set the recipe so a public void and 13892 07:34:24,058 --> 07:34:27,680 let's call it set recipe SL 13893 07:34:29,280 --> 07:34:31,020 they're going to receive a recipe so 13894 07:34:31,020 --> 07:34:33,120 recipe so 13895 07:34:33,120 --> 07:34:35,040 then we just go into the recipe name 13896 07:34:35,040 --> 07:34:37,020 text and we set the text to recipe so 13897 07:34:37,020 --> 07:34:38,940 dot recipe name 13898 07:34:38,940 --> 07:34:41,280 okay so that's pretty much it now over 13899 07:34:41,280 --> 07:34:43,680 here on the Y script when we instantiate 13900 07:34:43,680 --> 07:34:46,860 our recipe transform let's get component 13901 07:34:46,860 --> 07:34:49,280 of type of our 13902 07:34:49,280 --> 07:34:52,680 delivery manager single UI and call set 13903 07:34:52,680 --> 07:34:55,200 recipe so and pass in the recipe so okay 13904 07:34:55,200 --> 07:34:57,298 so let's see if the name shows up any 13905 07:34:57,298 --> 07:34:59,218 operator wait does show up so we can see 13906 07:34:59,218 --> 07:35:00,958 that we generate a cheeseburger recipe 13907 07:35:00,958 --> 07:35:03,180 and right now a mega burger recipe okay 13908 07:35:03,180 --> 07:35:05,580 great so all that's left are the icons 13909 07:35:05,580 --> 07:35:07,740 on here so like I said that is going to 13910 07:35:07,740 --> 07:35:10,320 be yet another usage of our template 13911 07:35:10,320 --> 07:35:11,520 pattern 13912 07:35:11,520 --> 07:35:13,920 so inside the recipe template let's 13913 07:35:13,920 --> 07:35:15,780 create an empty game object currently 13914 07:35:15,780 --> 07:35:18,360 the icon container and then inside that 13915 07:35:18,360 --> 07:35:20,340 let's make the template and template is 13916 07:35:20,340 --> 07:35:21,660 just going to be an image so we can just 13917 07:35:21,660 --> 07:35:23,580 create an image to our way 13918 07:35:23,580 --> 07:35:26,940 called the ingredient image let's scale 13919 07:35:26,940 --> 07:35:30,240 it with a size of 40 and 40. let's put a 13920 07:35:30,240 --> 07:35:32,700 image by default just like that and on 13921 07:35:32,700 --> 07:35:34,500 the icon container let's put the width 13922 07:35:34,500 --> 07:35:36,780 of zero height of zero and let's put a 13923 07:35:36,780 --> 07:35:39,058 horizontal layout group put it over 13924 07:35:39,058 --> 07:35:41,400 there on the left side and we can create 13925 07:35:41,400 --> 07:35:43,020 a bunch more just to see how it looks 13926 07:35:43,020 --> 07:35:45,540 okay so that's pretty much it now over 13927 07:35:45,540 --> 07:35:48,298 here on the single script let's add a 13928 07:35:48,298 --> 07:35:51,298 serialized field private transform for 13929 07:35:51,298 --> 07:35:54,240 the icon container another one for the 13930 07:35:54,240 --> 07:35:56,218 icon template 13931 07:35:56,218 --> 07:35:58,260 then we do the same thing as usual so 13932 07:35:58,260 --> 07:36:00,780 when we set the recipe so let's first of 13933 07:36:00,780 --> 07:36:02,520 all clean up the container so let's do a 13934 07:36:02,520 --> 07:36:05,638 40 inch transform child in the icon 13935 07:36:05,638 --> 07:36:07,020 container 13936 07:36:07,020 --> 07:36:10,138 and if the channel is the template 13937 07:36:10,138 --> 07:36:12,120 then we want to continue and ignore it 13938 07:36:12,120 --> 07:36:14,700 if not we want to destroy the child.game 13939 07:36:14,700 --> 07:36:17,638 object okay so that's the cleanup 13940 07:36:17,638 --> 07:36:19,740 and then let's do a four inch kitchen 13941 07:36:19,740 --> 07:36:21,298 object as so 13942 07:36:21,298 --> 07:36:25,080 in the recipe so dot kitchen object.zone 13943 07:36:25,080 --> 07:36:26,458 list 13944 07:36:26,458 --> 07:36:28,200 second through all of this let's 13945 07:36:28,200 --> 07:36:31,200 instantiate our icon template 13946 07:36:31,200 --> 07:36:34,138 instantiate it inside the icon container 13947 07:36:34,138 --> 07:36:36,180 so this is going to be the transform for 13948 07:36:36,180 --> 07:36:38,458 the icon transform 13949 07:36:38,458 --> 07:36:40,138 then as usual we need to go into the 13950 07:36:40,138 --> 07:36:41,940 game object set active in order to 13951 07:36:41,940 --> 07:36:43,378 enable it 13952 07:36:43,378 --> 07:36:45,900 and also let's go up here make a private 13953 07:36:45,900 --> 07:36:47,580 way to wake and on awake the icon 13954 07:36:47,580 --> 07:36:50,400 template game object let's disable it 13955 07:36:50,400 --> 07:36:52,620 okay we don't want the template to be 13956 07:36:52,620 --> 07:36:53,580 visible 13957 07:36:53,580 --> 07:36:56,520 okay so we instantiate the template we 13958 07:36:56,520 --> 07:36:59,040 set it as active then since this one 13959 07:36:59,040 --> 07:37:01,020 just has an image we can just do a get 13960 07:37:01,020 --> 07:37:03,298 component of Type image 13961 07:37:03,298 --> 07:37:06,058 that's image not image conversion 13962 07:37:06,058 --> 07:37:08,940 so image so it's this one the one inside 13963 07:37:08,940 --> 07:37:11,940 Unity engine.ui so let's get this image 13964 07:37:11,940 --> 07:37:14,458 and let's modify the Sprites and set it 13965 07:37:14,458 --> 07:37:16,138 to this kitchen object so that's right 13966 07:37:16,138 --> 07:37:18,360 okay so that's it that should do it 13967 07:37:18,360 --> 07:37:20,760 let's test over here in the editor let's 13968 07:37:20,760 --> 07:37:22,798 just go into the template let's drag the 13969 07:37:22,798 --> 07:37:24,780 container reference and the template 13970 07:37:24,780 --> 07:37:26,760 reference and let's also rename this 13971 07:37:26,760 --> 07:37:28,620 instead of ingredient image put icon 13972 07:37:28,620 --> 07:37:30,840 template just to be a bit more clear and 13973 07:37:30,840 --> 07:37:31,920 we can get rid of the other ones or 13974 07:37:31,920 --> 07:37:33,180 leave them doesn't really matter okay 13975 07:37:33,180 --> 07:37:36,180 great so let's hit on play and see and 13976 07:37:36,180 --> 07:37:37,978 yep right away does work so we can see a 13977 07:37:37,978 --> 07:37:40,138 burger is composed of a burger and a bun 13978 07:37:40,138 --> 07:37:42,600 a satellite yep there you go some sliced 13979 07:37:42,600 --> 07:37:44,638 cabbage and sliced tomatoes then 13980 07:37:44,638 --> 07:37:45,900 cheeseburger same thing as the burger 13981 07:37:45,900 --> 07:37:47,878 with some cheese and then another Burger 13982 07:37:47,878 --> 07:37:49,620 let's just deliver until we see the mega 13983 07:37:49,620 --> 07:37:52,138 Burger so let's deliver a cheeseburger 13984 07:37:52,138 --> 07:37:54,240 let's cut it 13985 07:37:54,240 --> 07:37:57,058 get this get some bread place it in 13986 07:37:57,058 --> 07:37:58,920 there pick it up before it burns that's 13987 07:37:58,920 --> 07:38:00,420 a cheeseburger so that one should vanish 13988 07:38:00,420 --> 07:38:02,520 and if they're good does vanish let's 13989 07:38:02,520 --> 07:38:04,260 see something else not cheeseburgers so 13990 07:38:04,260 --> 07:38:06,478 let's keep doing until we get a Mega 13991 07:38:06,478 --> 07:38:08,520 burger just see that everything works 13992 07:38:08,520 --> 07:38:11,218 so let's deliver a regular burger okay 13993 07:38:11,218 --> 07:38:15,020 now let's deliver a regular salad 13994 07:38:17,638 --> 07:38:19,680 okay just pick up like that like that 13995 07:38:19,680 --> 07:38:21,120 and drop it 13996 07:38:21,120 --> 07:38:23,218 okay let's see 13997 07:38:23,218 --> 07:38:25,860 any up there it is the Mega butter all 13998 07:38:25,860 --> 07:38:28,138 right great so the visual logic is fully 13999 07:38:28,138 --> 07:38:30,120 working and the delivery logic all of it 14000 07:38:30,120 --> 07:38:31,200 is working 14001 07:38:31,200 --> 07:38:33,240 so I can deliver the right recipes and 14002 07:38:33,240 --> 07:38:35,100 get rid of them from the recipe waiting 14003 07:38:35,100 --> 07:38:36,780 list and more are spawned every time 14004 07:38:36,780 --> 07:38:38,520 here we can see the name of the recipe 14005 07:38:38,520 --> 07:38:41,280 as well as all of the nice icons okay so 14006 07:38:41,280 --> 07:38:42,718 with all this our game is really taking 14007 07:38:42,718 --> 07:38:44,760 shape everything is very close to being 14008 07:38:44,760 --> 07:38:45,540 done 14009 07:38:45,540 --> 07:38:47,280 one massive thing we're still missing is 14010 07:38:47,280 --> 07:38:49,378 an obvious one which is sound so let's 14011 07:38:49,378 --> 07:38:52,020 do that in the next lecture 14012 07:38:52,020 --> 07:38:54,000 hey again quick intermission you're 14013 07:38:54,000 --> 07:38:56,040 almost at the end so once again congrats 14014 07:38:56,040 --> 07:38:58,138 for making it this far this is the 14015 07:38:58,138 --> 07:39:00,180 second secret call out go ahead Post in 14016 07:39:00,180 --> 07:39:02,100 the comments a timestamp and a nice monk 14017 07:39:02,100 --> 07:39:04,020 Emoji it won't be fun to see how many 14018 07:39:04,020 --> 07:39:06,120 people make it to this point by now you 14019 07:39:06,120 --> 07:39:07,860 already know about the website I hope 14020 07:39:07,860 --> 07:39:09,780 it's been very useful to you and you 14021 07:39:09,780 --> 07:39:11,280 already know to ask any questions in the 14022 07:39:11,280 --> 07:39:12,540 comments if you need help with anything 14023 07:39:12,540 --> 07:39:14,820 so that's life for me to say right now 14024 07:39:14,820 --> 07:39:16,500 is thanks for watching the course so far 14025 07:39:16,500 --> 07:39:18,120 and I really hope you've already learned 14026 07:39:18,120 --> 07:39:20,760 a ton there's only a bunch more lectures 14027 07:39:20,760 --> 07:39:22,680 until we get to the final polish game so 14028 07:39:22,680 --> 07:39:25,080 let's continue on the next lecture 14029 07:39:25,080 --> 07:39:27,000 hello and welcome I'm your code monkey 14030 07:39:27,000 --> 07:39:29,280 in this lecture we're going to add some 14031 07:39:29,280 --> 07:39:31,320 audio to our game starting with a really 14032 07:39:31,320 --> 07:39:33,478 nice music track okay so our game is 14033 07:39:33,478 --> 07:39:35,040 already looking pretty good but 14034 07:39:35,040 --> 07:39:37,260 everything is still way too silent so 14035 07:39:37,260 --> 07:39:39,478 let's begin by adding some music adding 14036 07:39:39,478 --> 07:39:42,420 this is actually extremely new in the 14037 07:39:42,420 --> 07:39:44,218 included assets over here inside the 14038 07:39:44,218 --> 07:39:46,020 sounds we've got a really nice music 14039 07:39:46,020 --> 07:39:48,360 track I hired a musician to make this it 14040 07:39:48,360 --> 07:39:50,760 sounds really good it's a seamless Loop 14041 07:39:50,760 --> 07:39:52,080 so to add to our game it's going to be 14042 07:39:52,080 --> 07:39:54,718 super simple we just want a constant 14043 07:39:54,718 --> 07:39:56,760 never-ending Loop so let's begin by 14044 07:39:56,760 --> 07:39:58,740 creating an empty game object call it 14045 07:39:58,740 --> 07:40:00,298 the Music Manager 14046 07:40:00,298 --> 07:40:02,400 let's reset transform keep things 14047 07:40:02,400 --> 07:40:04,440 organized and let's add a component and 14048 07:40:04,440 --> 07:40:06,660 we want the component an audio Source 14049 07:40:06,660 --> 07:40:09,420 here it is this one like name implies 14050 07:40:09,420 --> 07:40:11,580 this one acts like a source of audio 14051 07:40:11,580 --> 07:40:13,680 you will note how by default on the main 14052 07:40:13,680 --> 07:40:16,138 camera down here it already has an audio 14053 07:40:16,138 --> 07:40:18,360 listener so the source plays some sound 14054 07:40:18,360 --> 07:40:20,218 and The Listener listens to it now for 14055 07:40:20,218 --> 07:40:22,440 here we just need to set these fields so 14056 07:40:22,440 --> 07:40:24,058 for example on the autoclave let's make 14057 07:40:24,058 --> 07:40:26,218 sure to drag the music audio okay great 14058 07:40:26,218 --> 07:40:28,500 next over here and let's enable and play 14059 07:40:28,500 --> 07:40:30,478 on a wink we wanted to start playing 14060 07:40:30,478 --> 07:40:32,878 right wing and for this track we do want 14061 07:40:32,878 --> 07:40:35,218 to enable looping okay great then for 14062 07:40:35,218 --> 07:40:37,978 priority basically UNT has limited to 14063 07:40:37,978 --> 07:40:40,138 how many sounds can be played at once if 14064 07:40:40,138 --> 07:40:42,120 you play too many then some sounds won't 14065 07:40:42,120 --> 07:40:44,280 play and which ones do you play is all 14066 07:40:44,280 --> 07:40:46,320 based on priority we always want the 14067 07:40:46,320 --> 07:40:47,940 music to play so let's put this one on 14068 07:40:47,940 --> 07:40:49,138 Max priority 14069 07:40:49,138 --> 07:40:51,840 then for the volume later on we're going 14070 07:40:51,840 --> 07:40:53,580 to make a proper option screen to handle 14071 07:40:53,580 --> 07:40:54,298 this 14072 07:40:54,298 --> 07:40:55,860 but for now let's put it on something 14073 07:40:55,860 --> 07:40:58,860 like 0.4 or 0.5 just make a nice 14074 07:40:58,860 --> 07:41:01,260 background track then we have here the 14075 07:41:01,260 --> 07:41:03,540 spatial blend for this music track we 14076 07:41:03,540 --> 07:41:05,160 wanted to play the same regardless of 14077 07:41:05,160 --> 07:41:07,440 where the camera is so let's make this 14078 07:41:07,440 --> 07:41:09,780 all the way if only a 2d sound okay 14079 07:41:09,780 --> 07:41:11,400 that's it we don't need to play around 14080 07:41:11,400 --> 07:41:13,320 with any of the other settings and just 14081 07:41:13,320 --> 07:41:15,660 like this if we are on play any up 14082 07:41:15,660 --> 07:41:17,400 there's the music now if you're not 14083 07:41:17,400 --> 07:41:19,138 hearing anything make sure that on the 14084 07:41:19,138 --> 07:41:20,580 game view first of all that the game is 14085 07:41:20,580 --> 07:41:22,620 actually selected make sure the scene is 14086 07:41:22,620 --> 07:41:24,478 in Focus so over here I can move around 14087 07:41:24,478 --> 07:41:26,820 so the game's in Focus then on game view 14088 07:41:26,820 --> 07:41:28,920 we are on the top right corner make sure 14089 07:41:28,920 --> 07:41:31,260 this sound icon is toggled if not then 14090 07:41:31,260 --> 07:41:33,780 everything is muted and also again make 14091 07:41:33,780 --> 07:41:35,280 sure like I mentioned on the main camera 14092 07:41:35,280 --> 07:41:36,840 that it has the audio and listener 14093 07:41:36,840 --> 07:41:38,700 component with all that yep you should 14094 07:41:38,700 --> 07:41:40,080 be able to hear the music 14095 07:41:40,080 --> 07:41:42,000 now this song is playing and it won't 14096 07:41:42,000 --> 07:41:43,440 Loop forever just like we wanted 14097 07:41:43,440 --> 07:41:45,360 personally I really like how it sounds 14098 07:41:45,360 --> 07:41:47,280 I'm really happy with what the composer 14099 07:41:47,280 --> 07:41:49,138 made it perfectly matches the E5 of the 14100 07:41:49,138 --> 07:41:51,298 game so it really is this simple to add 14101 07:41:51,298 --> 07:41:53,520 some music to the game let me just point 14102 07:41:53,520 --> 07:41:56,160 out one thing also related to sound one 14103 07:41:56,160 --> 07:41:57,718 of the things you can make is an audio 14104 07:41:57,718 --> 07:41:59,400 mixer so for example on the project 14105 07:41:59,400 --> 07:42:02,580 files let's create a brand new and let's 14106 07:42:02,580 --> 07:42:05,160 find over here the audio mixer so there 14107 07:42:05,160 --> 07:42:06,660 you go here is an audio mixer then you 14108 07:42:06,660 --> 07:42:08,040 can double click to open up the audio 14109 07:42:08,040 --> 07:42:10,378 mixer window and then over here you have 14110 07:42:10,378 --> 07:42:11,878 the masternode 14111 07:42:11,878 --> 07:42:13,740 and then you can create multiple groups 14112 07:42:13,740 --> 07:42:15,660 so let's create a brand new groove for 14113 07:42:15,660 --> 07:42:16,920 something else 14114 07:42:16,920 --> 07:42:18,540 and then you can play around over here 14115 07:42:18,540 --> 07:42:20,638 with the effects with the volume all 14116 07:42:20,638 --> 07:42:22,020 kinds of things all kinds of effects 14117 07:42:22,020 --> 07:42:24,298 everything then for each sound where you 14118 07:42:24,298 --> 07:42:25,978 have the audio Source over here note how 14119 07:42:25,978 --> 07:42:28,260 you have an output and for this output 14120 07:42:28,260 --> 07:42:29,700 you can set it to play on the message so 14121 07:42:29,700 --> 07:42:31,680 it plays on everything or set it on just 14122 07:42:31,680 --> 07:42:33,900 one individual group so with this you 14123 07:42:33,900 --> 07:42:35,820 could assign a group to one individual 14124 07:42:35,820 --> 07:42:38,040 type of sound effect or the music or so 14125 07:42:38,040 --> 07:42:40,138 on maybe you could even have your music 14126 07:42:40,138 --> 07:42:42,780 split into multiple stems so there's a 14127 07:42:42,780 --> 07:42:44,638 lot you can do but for me I'm not an 14128 07:42:44,638 --> 07:42:46,378 audio engineer audio is probably the 14129 07:42:46,378 --> 07:42:47,820 part of game development that I know 14130 07:42:47,820 --> 07:42:49,440 least about I just stick with the 14131 07:42:49,440 --> 07:42:51,360 absolute Basics but if you want to learn 14132 07:42:51,360 --> 07:42:52,920 more definitely look into the audio 14133 07:42:52,920 --> 07:42:55,020 mixer this is an extremely powerful tool 14134 07:42:55,020 --> 07:42:57,058 but like I said for me I don't know how 14135 07:42:57,058 --> 07:42:58,378 to work with it so I'm just going to 14136 07:42:58,378 --> 07:43:00,780 stick with the basics so on the output 14137 07:43:00,780 --> 07:43:02,878 let's revert back into none close the 14138 07:43:02,878 --> 07:43:05,340 audio mixer and get rid of this and 14139 07:43:05,340 --> 07:43:06,840 there it is music is playing and the 14140 07:43:06,840 --> 07:43:09,058 wrong sounds really nice alright so here 14141 07:43:09,058 --> 07:43:11,040 we very easily added some music to our 14142 07:43:11,040 --> 07:43:12,718 game this lecture is actually super 14143 07:43:12,718 --> 07:43:14,340 short because it is generally that 14144 07:43:14,340 --> 07:43:16,200 simple now the next thing that we need 14145 07:43:16,200 --> 07:43:17,820 is not going to be a little bit more 14146 07:43:17,820 --> 07:43:19,798 complex and that is adding sound effects 14147 07:43:19,798 --> 07:43:22,920 so let's do that in the next lecture 14148 07:43:22,920 --> 07:43:24,840 hello and welcome I'm your code monkey 14149 07:43:24,840 --> 07:43:27,058 in this lecture we're going to add some 14150 07:43:27,058 --> 07:43:29,218 sound effects for our game okay so 14151 07:43:29,218 --> 07:43:31,020 previously we already added some really 14152 07:43:31,020 --> 07:43:33,000 nice music now let's add a whole bunch 14153 07:43:33,000 --> 07:43:35,458 of sound effects in the project files if 14154 07:43:35,458 --> 07:43:37,080 we go inside the assets over here we've 14155 07:43:37,080 --> 07:43:39,298 got all kinds of sound effects recently 14156 07:43:39,298 --> 07:43:40,860 I heard the really nice sound designer 14157 07:43:40,860 --> 07:43:42,240 to make all of these and I think they 14158 07:43:42,240 --> 07:43:44,280 all sound really great so let's add them 14159 07:43:44,280 --> 07:43:46,378 to our game now when it comes to sound 14160 07:43:46,378 --> 07:43:47,940 effects there are two main ways to play 14161 07:43:47,940 --> 07:43:50,218 a sound one is just like we did for the 14162 07:43:50,218 --> 07:43:52,260 music so we can create a game object at 14163 07:43:52,260 --> 07:43:53,820 the audio Source component and play it 14164 07:43:53,820 --> 07:43:55,860 that's one approach but that basically 14165 07:43:55,860 --> 07:43:58,080 requires pre-preparing the sound objects 14166 07:43:58,080 --> 07:44:00,240 so there is another simpler way that 14167 07:44:00,240 --> 07:44:02,160 just requires one line of code so let's 14168 07:44:02,160 --> 07:44:03,780 begin by making a Sound Manager game 14169 07:44:03,780 --> 07:44:05,820 object so a new empty game object for 14170 07:44:05,820 --> 07:44:08,340 The Sound Manager let's reset the 14171 07:44:08,340 --> 07:44:10,680 transform now let's make our script so 14172 07:44:10,680 --> 07:44:13,020 let's go in the scripts folder create a 14173 07:44:13,020 --> 07:44:14,760 brand new c-sharp script for The Sound 14174 07:44:14,760 --> 07:44:17,700 Manager let's attach the script and open 14175 07:44:17,700 --> 07:44:19,920 okay so now here let's make a function 14176 07:44:19,920 --> 07:44:22,500 to play Simple sound so let's do a 14177 07:44:22,500 --> 07:44:25,798 private void just call it play sound and 14178 07:44:25,798 --> 07:44:27,240 over here the way we play sound through 14179 07:44:27,240 --> 07:44:29,520 code is actually super simple we just go 14180 07:44:29,520 --> 07:44:31,680 inside the audio Source class 14181 07:44:31,680 --> 07:44:33,600 and in here there's a static function 14182 07:44:33,600 --> 07:44:35,878 play clip at point this as you can see 14183 07:44:35,878 --> 07:44:37,978 it takes an audio clip a vector 3 for 14184 07:44:37,978 --> 07:44:40,138 the position and finally a volume so 14185 07:44:40,138 --> 07:44:41,700 basically it won't play that sound on 14186 07:44:41,700 --> 07:44:44,218 that position by default TNT already has 14187 07:44:44,218 --> 07:44:46,440 3D sound so if you play the sound on the 14188 07:44:46,440 --> 07:44:47,878 left or the right side of the camera it 14189 07:44:47,878 --> 07:44:49,920 won't play in the correct place also for 14190 07:44:49,920 --> 07:44:51,478 the volume the further away it is from 14191 07:44:51,478 --> 07:44:53,458 the camera the lower it will be and if 14192 07:44:53,458 --> 07:44:55,020 we don't want the 3D sound we can just 14193 07:44:55,020 --> 07:44:56,280 play it directly on top of the camera 14194 07:44:56,280 --> 07:44:58,500 position okay so in this function let's 14195 07:44:58,500 --> 07:45:01,080 receive our arguments so for the audio 14196 07:45:01,080 --> 07:45:02,218 clip 14197 07:45:02,218 --> 07:45:04,620 it's going to be our audio clip 14198 07:45:04,620 --> 07:45:06,478 then let's receive the vector 340 14199 07:45:06,478 --> 07:45:08,820 position and let's also receive an 14200 07:45:08,820 --> 07:45:11,040 optional one for the volume 14201 07:45:11,040 --> 07:45:13,740 let's just default this to 1f okay so 14202 07:45:13,740 --> 07:45:15,540 here we just pass this in into our 14203 07:45:15,540 --> 07:45:17,160 function so the position and the volume 14204 07:45:17,160 --> 07:45:19,978 okay great so now let's call this nice 14205 07:45:19,978 --> 07:45:22,138 function and for example let's start 14206 07:45:22,138 --> 07:45:23,638 with a simple one so let's start with 14207 07:45:23,638 --> 07:45:25,860 the delivery sounds so over here on the 14208 07:45:25,860 --> 07:45:28,320 delivery manager script down here we 14209 07:45:28,320 --> 07:45:30,120 have the logic for delivering a recipe 14210 07:45:30,120 --> 07:45:32,760 and over here we know when we completed 14211 07:45:32,760 --> 07:45:34,860 a successful recipe or when we failed 14212 07:45:34,860 --> 07:45:36,360 and the player delivered a wrong recipe 14213 07:45:36,360 --> 07:45:38,400 so this is where we want to play some 14214 07:45:38,400 --> 07:45:40,558 sounds and again here we have yet 14215 07:45:40,558 --> 07:45:42,000 another very important clean code 14216 07:45:42,000 --> 07:45:42,958 question 14217 07:45:42,958 --> 07:45:45,000 we could definitely call the play sound 14218 07:45:45,000 --> 07:45:47,160 function directly from here that would 14219 07:45:47,160 --> 07:45:48,958 work but of course that would make this 14220 07:45:48,958 --> 07:45:50,340 class tightly coupled with The Sound 14221 07:45:50,340 --> 07:45:53,040 Manager for a simple game on this scale 14222 07:45:53,040 --> 07:45:55,080 that approach can work just play sounds 14223 07:45:55,080 --> 07:45:57,180 directly from the logic code however 14224 07:45:57,180 --> 07:45:59,218 again to make things properly we should 14225 07:45:59,218 --> 07:46:00,900 really separate the logic from the sound 14226 07:46:00,900 --> 07:46:02,760 just like we separated in logic from the 14227 07:46:02,760 --> 07:46:05,340 visuals so instead let's not call the 14228 07:46:05,340 --> 07:46:07,378 sound directly from here instead let's 14229 07:46:07,378 --> 07:46:09,058 make two more events 14230 07:46:09,058 --> 07:46:12,058 so let's make one on recipe success 14231 07:46:12,058 --> 07:46:15,360 another one on recipe failed 14232 07:46:15,360 --> 07:46:18,420 okay so now let's fire off these events 14233 07:46:18,420 --> 07:46:20,458 so over here we have the success so on 14234 07:46:20,458 --> 07:46:23,040 recipe success and if we get down here 14235 07:46:23,040 --> 07:46:25,558 then we have a fail so on recipe fail 14236 07:46:25,558 --> 07:46:28,740 okay great we have two events now back 14237 07:46:28,740 --> 07:46:30,298 here on The Sound Manager we can just 14238 07:46:30,298 --> 07:46:32,218 listen to those so let's do a start go 14239 07:46:32,218 --> 07:46:34,020 into the delivering manager access the 14240 07:46:34,020 --> 07:46:36,600 instance and listen to the on success 14241 07:46:36,600 --> 07:46:39,180 and on failed events let's listen to 14242 07:46:39,180 --> 07:46:41,760 that one delivery manager instance on 14243 07:46:41,760 --> 07:46:43,920 recipe film listen to both of these 14244 07:46:43,920 --> 07:46:46,320 again let's write some good clean codes 14245 07:46:46,320 --> 07:46:48,000 so let's rename this one instead of 14246 07:46:48,000 --> 07:46:50,218 instance let's put it delivery manager 14247 07:46:50,218 --> 07:46:54,000 and same thing on this one also name it 14248 07:46:54,000 --> 07:46:56,700 correctly delivery menu 14249 07:46:56,700 --> 07:47:00,600 okay great so now when you have this we 14250 07:47:00,600 --> 07:47:02,340 want to call and play sound 14251 07:47:02,340 --> 07:47:04,500 and now I want to pass in a reference to 14252 07:47:04,500 --> 07:47:07,320 the recipe film sound so technically one 14253 07:47:07,320 --> 07:47:08,760 approach would be appear to add a 14254 07:47:08,760 --> 07:47:10,558 serialized film for an audio clip that 14255 07:47:10,558 --> 07:47:12,540 would work but since we've already done 14256 07:47:12,540 --> 07:47:14,160 that so many times in this course here 14257 07:47:14,160 --> 07:47:15,840 let's use a different approach that I 14258 07:47:15,840 --> 07:47:17,100 also like to use 14259 07:47:17,100 --> 07:47:19,020 let's create a scriptable object to home 14260 07:47:19,020 --> 07:47:21,058 the reference to all of our sounds so 14261 07:47:21,058 --> 07:47:22,620 similar to how we Define the script 14262 07:47:22,620 --> 07:47:25,260 object on all of our recipes let's just 14263 07:47:25,260 --> 07:47:26,638 comment this out just make sure the code 14264 07:47:26,638 --> 07:47:28,920 compounds okay great so back here in the 14265 07:47:28,920 --> 07:47:30,478 editor let's make a new script more 14266 07:47:30,478 --> 07:47:32,040 object type so let's create a brand new 14267 07:47:32,040 --> 07:47:33,420 c-sharp script 14268 07:47:33,420 --> 07:47:36,298 for the audio clip refs script long 14269 07:47:36,298 --> 07:47:39,080 object now here let's make this a simple 14270 07:47:39,080 --> 07:47:42,360 scriptable object with a create asset 14271 07:47:42,360 --> 07:47:43,620 menu 14272 07:47:43,620 --> 07:47:46,138 okay so now for the fields if we 14273 07:47:46,138 --> 07:47:47,940 unlocking the S over here the audio 14274 07:47:47,940 --> 07:47:49,680 design that I hired actually made 14275 07:47:49,680 --> 07:47:51,958 several variations for each sound so 14276 07:47:51,958 --> 07:47:53,520 we've got multiple chops multiple 14277 07:47:53,520 --> 07:47:55,200 delivery fails and so on 14278 07:47:55,200 --> 07:47:56,820 so back in the code here instead of 14279 07:47:56,820 --> 07:47:58,558 storing a reference for a single audio 14280 07:47:58,558 --> 07:48:01,320 clip let's store an array for all of 14281 07:48:01,320 --> 07:48:03,840 them so we have the chop then we have on 14282 07:48:03,840 --> 07:48:06,000 the other Solutions and all of the 14283 07:48:06,000 --> 07:48:07,200 references 14284 07:48:07,200 --> 07:48:09,298 so there's a job there's the delivery 14285 07:48:09,298 --> 07:48:10,740 fail 14286 07:48:10,740 --> 07:48:14,100 then we have delivery success then we 14287 07:48:14,100 --> 07:48:17,058 have footsteps 14288 07:48:17,280 --> 07:48:20,280 then the object drop then the object 14289 07:48:20,280 --> 07:48:21,780 pickup 14290 07:48:21,780 --> 07:48:24,058 then we have the stove Sizzle although 14291 07:48:24,058 --> 07:48:26,820 this one is just one then we have the 14292 07:48:26,820 --> 07:48:30,840 trash and finally we have the warning 14293 07:48:30,840 --> 07:48:32,700 alright so these are all of the sound 14294 07:48:32,700 --> 07:48:34,920 references we're going to use back in 14295 07:48:34,920 --> 07:48:36,420 the editor let's just create the object 14296 07:48:36,420 --> 07:48:38,400 so on the script mode objects let's 14297 07:48:38,400 --> 07:48:40,740 create a brand new one let's make it of 14298 07:48:40,740 --> 07:48:42,420 audio clip per episode 14299 07:48:42,420 --> 07:48:46,138 just name it audio clip refs so 14300 07:48:46,138 --> 07:48:47,638 and over here let's just write the 14301 07:48:47,638 --> 07:48:49,680 references so let's use that quick ENT 14302 07:48:49,680 --> 07:48:51,780 tip in order to unlock the inspector now 14303 07:48:51,780 --> 07:48:53,878 I can select all the chops and drag them 14304 07:48:53,878 --> 07:48:56,458 all the delivery fails drag them it's 14305 07:48:56,458 --> 07:48:59,760 only re-success drag it then for all of 14306 07:48:59,760 --> 07:49:02,638 the footsteps after that are all of the 14307 07:49:02,638 --> 07:49:06,298 object drops then the pickups then we 14308 07:49:06,298 --> 07:49:08,520 have the sizzle which is just one 14309 07:49:08,520 --> 07:49:11,100 finally we have the trash and the 14310 07:49:11,100 --> 07:49:13,080 warning okay those are all the 14311 07:49:13,080 --> 07:49:15,478 references so our script on object now 14312 07:49:15,478 --> 07:49:18,120 has all of the data we need let's unlock 14313 07:49:18,120 --> 07:49:20,100 the inspector okay and back in the code 14314 07:49:20,100 --> 07:49:22,200 here on The Sound Manager let's make 14315 07:49:22,200 --> 07:49:24,058 another version of this function so 14316 07:49:24,058 --> 07:49:25,920 let's make one play sound except instead 14317 07:49:25,920 --> 07:49:27,780 of receiving an audio clip it receives 14318 07:49:27,780 --> 07:49:29,580 an array of audio clips 14319 07:49:29,580 --> 07:49:31,200 then basically we just call the other 14320 07:49:31,200 --> 07:49:33,000 function so we call the other place on 14321 07:49:33,000 --> 07:49:35,218 function and pass in an audio clip from 14322 07:49:35,218 --> 07:49:36,898 this array so let's actually rename this 14323 07:49:36,898 --> 07:49:38,940 so audio clip array 14324 07:49:38,940 --> 07:49:41,100 and let's pass in an audio clip from 14325 07:49:41,100 --> 07:49:44,520 here so do a simple random.range 14326 07:49:44,520 --> 07:49:47,820 between 0 and the array down length 14327 07:49:47,820 --> 07:49:50,878 pressing the position and the volume 14328 07:49:50,878 --> 07:49:53,520 okay so just like this now we need is a 14329 07:49:53,520 --> 07:49:55,020 reference to our suitable object so it's 14330 07:49:55,020 --> 07:49:57,540 generalized film private of the audio 14331 07:49:57,540 --> 07:50:00,478 clip refs SL 14332 07:50:00,478 --> 07:50:02,700 okay we have this then here in the 14333 07:50:02,700 --> 07:50:04,200 editor and let's just assign the 14334 07:50:04,200 --> 07:50:05,820 reference so the audio clip refs okay 14335 07:50:05,820 --> 07:50:07,978 great and over here when we have the 14336 07:50:07,978 --> 07:50:10,020 recipe failed let's go into the audio 14337 07:50:10,020 --> 07:50:11,580 clip refs 14338 07:50:11,580 --> 07:50:13,200 and let's pick up this one instant 14339 07:50:13,200 --> 07:50:14,580 delivery fail 14340 07:50:14,580 --> 07:50:16,020 and then the other one is going to be 14341 07:50:16,020 --> 07:50:17,878 delivery success 14342 07:50:17,878 --> 07:50:19,860 for the position let's just default to 14343 07:50:19,860 --> 07:50:22,020 the camera dot main transform that 14344 07:50:22,020 --> 07:50:24,260 position 14345 07:50:24,840 --> 07:50:26,940 so like this it sounds like exactly on 14346 07:50:26,940 --> 07:50:29,100 top of the camera okay so let's test and 14347 07:50:29,100 --> 07:50:31,620 see if it all works okay so here we are 14348 07:50:31,620 --> 07:50:33,840 and let's do a wrong delivery now quick 14349 07:50:33,840 --> 07:50:35,638 warning if you're following along or if 14350 07:50:35,638 --> 07:50:37,138 you're just watching the video this 14351 07:50:37,138 --> 07:50:38,878 sound will probably be way too loud but 14352 07:50:38,878 --> 07:50:40,260 let's test 14353 07:50:40,260 --> 07:50:42,120 so if I just pick up the plate and I 14354 07:50:42,120 --> 07:50:44,820 just deliver an empty plate yep there 14355 07:50:44,820 --> 07:50:46,138 you go there's the sound 14356 07:50:46,138 --> 07:50:47,940 and now if I deliver a correct one so 14357 07:50:47,940 --> 07:50:50,040 someone wants a salad so let's cut a 14358 07:50:50,040 --> 07:50:51,240 nice salad 14359 07:50:51,240 --> 07:50:54,180 chop that chop this pick up the plate 14360 07:50:54,180 --> 07:50:56,218 pick up that one and that one don't be 14361 07:50:56,218 --> 07:50:57,420 the correct salad 14362 07:50:57,420 --> 07:50:59,160 any of that I go with those were all 14363 07:50:59,160 --> 07:51:01,320 right great so the sound effects work 14364 07:51:01,320 --> 07:51:03,478 they played perfectly but they're a bit 14365 07:51:03,478 --> 07:51:05,280 too loud basically that's because these 14366 07:51:05,280 --> 07:51:06,958 sounds were designed to be played in the 14367 07:51:06,958 --> 07:51:09,120 world rather than on top of the camera 14368 07:51:09,120 --> 07:51:10,920 so when we play the sound let's actually 14369 07:51:10,920 --> 07:51:12,718 play it on the position of the delivery 14370 07:51:12,718 --> 07:51:13,680 counter 14371 07:51:13,680 --> 07:51:16,378 here is the delivery counter script and 14372 07:51:16,378 --> 07:51:18,000 based on our design we're only going to 14373 07:51:18,000 --> 07:51:19,860 have a single military counter so we can 14374 07:51:19,860 --> 07:51:21,780 just make this a Singleton 14375 07:51:21,780 --> 07:51:24,298 so as usual public static of type on 14376 07:51:24,298 --> 07:51:26,940 Livery counter call it instance where 14377 07:51:26,940 --> 07:51:29,398 they probably get and a private set 14378 07:51:29,398 --> 07:51:32,040 then on privatoid awake 14379 07:51:32,040 --> 07:51:35,458 let's just set the instance equals this 14380 07:51:35,458 --> 07:51:38,100 okay so over here on The Sound Manager 14381 07:51:38,100 --> 07:51:40,160 we can just grab delivery counter 14382 07:51:40,160 --> 07:51:42,600 delivery counter and we just go into 14383 07:51:42,600 --> 07:51:44,280 Library counter and grab the static 14384 07:51:44,280 --> 07:51:45,240 instance 14385 07:51:45,240 --> 07:51:47,458 and then for the sound position we can 14386 07:51:47,458 --> 07:51:49,558 just go into delivery counter access the 14387 07:51:49,558 --> 07:51:51,718 transform that position 14388 07:51:51,718 --> 07:51:53,878 okay so just like this on that one and 14389 07:51:53,878 --> 07:51:56,660 on this one 14390 07:51:58,740 --> 07:52:00,780 okay so it says now it shouldn't be as 14391 07:52:00,780 --> 07:52:01,680 loud 14392 07:52:01,680 --> 07:52:03,718 okay so here we are and let's do a wrong 14393 07:52:03,718 --> 07:52:06,600 delivery any hope it does work 14394 07:52:06,600 --> 07:52:08,458 now let's be successful delivery so 14395 07:52:08,458 --> 07:52:10,440 let's make a nice cheeseburger so grab 14396 07:52:10,440 --> 07:52:14,040 some cheese slice it grab plate just 14397 07:52:14,040 --> 07:52:16,138 need some bread 14398 07:52:16,138 --> 07:52:18,660 and delivered any of there you go it 14399 07:52:18,660 --> 07:52:20,820 worked all right awesome 14400 07:52:20,820 --> 07:52:22,620 okay so this is really it this is how 14401 07:52:22,620 --> 07:52:24,898 we're going to play our simple sounds 14402 07:52:24,898 --> 07:52:26,340 now there are some that are going to 14403 07:52:26,340 --> 07:52:27,958 require more logic like the footstep 14404 07:52:27,958 --> 07:52:30,180 sounds and the stove Sizzle but first 14405 07:52:30,180 --> 07:52:32,878 let's begin by adding the simple ones 14406 07:52:32,878 --> 07:52:35,340 so let's begin with the chop sounds this 14407 07:52:35,340 --> 07:52:37,558 is super simple we just need to go over 14408 07:52:37,558 --> 07:52:39,180 here onto the cutting counter and 14409 07:52:39,180 --> 07:52:41,218 actually we already have the uncut event 14410 07:52:41,218 --> 07:52:43,378 that we made previously this was used to 14411 07:52:43,378 --> 07:52:45,058 spawn the visual so we can also use it 14412 07:52:45,058 --> 07:52:46,440 to spawn these sounds 14413 07:52:46,440 --> 07:52:48,378 however there's actually one difference 14414 07:52:48,378 --> 07:52:50,760 we're going to have multiple cutting 14415 07:52:50,760 --> 07:52:53,100 counters and this one as you can see 14416 07:52:53,100 --> 07:52:55,558 this one is not a static event meaning 14417 07:52:55,558 --> 07:52:57,120 each different counter is going to have 14418 07:52:57,120 --> 07:52:59,458 each list of listeners and we really 14419 07:52:59,458 --> 07:53:01,260 don't want to have to subscribe to every 14420 07:53:01,260 --> 07:53:02,700 single one of the counters individually 14421 07:53:02,700 --> 07:53:04,920 so what we can do is instead of making 14422 07:53:04,920 --> 07:53:06,898 it a regular event that belongs to each 14423 07:53:06,898 --> 07:53:09,240 instance of a cut encounter we can make 14424 07:53:09,240 --> 07:53:11,040 a static event which won't belong to the 14425 07:53:11,040 --> 07:53:12,958 entire class but we still want to leave 14426 07:53:12,958 --> 07:53:14,700 this one just for the visual so let's do 14427 07:53:14,700 --> 07:53:17,398 another one a public static event event 14428 07:53:17,398 --> 07:53:18,660 handler 14429 07:53:18,660 --> 07:53:21,840 and let's call it on any cut basically 14430 07:53:21,840 --> 07:53:24,180 for any static events that belong to any 14431 07:53:24,180 --> 07:53:25,620 object type I like to add the keyword 14432 07:53:25,620 --> 07:53:28,440 any we're going to fire this event when 14433 07:53:28,440 --> 07:53:30,360 any cutting counter is going to trigger 14434 07:53:30,360 --> 07:53:33,058 a cut action so where we fire this event 14435 07:53:33,058 --> 07:53:34,440 is exactly the same thing so over here 14436 07:53:34,440 --> 07:53:35,940 we've got the uncut and let's do the 14437 07:53:35,940 --> 07:53:38,040 exact same thing so on any cut with this 14438 07:53:38,040 --> 07:53:40,500 an event R is not empty okay so we have 14439 07:53:40,500 --> 07:53:42,718 our nice static event and over here on 14440 07:53:42,718 --> 07:53:44,280 The Sound Manager let's listen to it so 14441 07:53:44,280 --> 07:53:46,080 let's go into the cutting counter again 14442 07:53:46,080 --> 07:53:47,458 we're going to access through the class 14443 07:53:47,458 --> 07:53:50,100 name and let's listen to the on any cut 14444 07:53:50,100 --> 07:53:52,500 event and over here let's just play the 14445 07:53:52,500 --> 07:53:55,080 sound so let's play the sound let's go 14446 07:53:55,080 --> 07:53:57,780 inside the audio play prefsl and let's 14447 07:53:57,780 --> 07:54:00,240 grab the chop sound then for the 14448 07:54:00,240 --> 07:54:01,138 position 14449 07:54:01,138 --> 07:54:03,298 we want to know who fired this event and 14450 07:54:03,298 --> 07:54:04,920 by following the c-sharp standard over 14451 07:54:04,920 --> 07:54:07,320 here we already have the object sender 14452 07:54:07,320 --> 07:54:08,878 so we know this was the object that 14453 07:54:08,878 --> 07:54:10,378 fired this event and we know this is 14454 07:54:10,378 --> 07:54:11,878 going to be of type cutting counter so 14455 07:54:11,878 --> 07:54:14,160 we can just get cutting counter cutting 14456 07:54:14,160 --> 07:54:16,920 counter and we just grab the sender as a 14457 07:54:16,920 --> 07:54:18,180 cutting counter 14458 07:54:18,180 --> 07:54:19,798 okay so we have this and then over here 14459 07:54:19,798 --> 07:54:21,478 very simple access transform that 14460 07:54:21,478 --> 07:54:22,798 position 14461 07:54:22,798 --> 07:54:24,660 okay that's it great 14462 07:54:24,660 --> 07:54:26,878 that won't play The Cutting sound on 14463 07:54:26,878 --> 07:54:28,558 that position on that cutting counter 14464 07:54:28,558 --> 07:54:31,020 okay great now let's handle the player 14465 07:54:31,020 --> 07:54:32,940 picking up something and for that let's 14466 07:54:32,940 --> 07:54:35,218 go over here onto the player class and 14467 07:54:35,218 --> 07:54:36,600 the way we set up the kitchen object 14468 07:54:36,600 --> 07:54:37,860 parent system is actually already 14469 07:54:37,860 --> 07:54:39,240 perfect for this 14470 07:54:39,240 --> 07:54:42,000 down here we have a function so if we 14471 07:54:42,000 --> 07:54:43,680 scroll down Yep this function set 14472 07:54:43,680 --> 07:54:45,780 kitchen object this one is called 14473 07:54:45,780 --> 07:54:47,580 whenever the player receives a kitchen 14474 07:54:47,580 --> 07:54:49,320 object which means really when the 14475 07:54:49,320 --> 07:54:51,540 player picks up something so if this 14476 07:54:51,540 --> 07:54:53,100 kitchen object is not known then that 14477 07:54:53,100 --> 07:54:54,540 means the player picked up something so 14478 07:54:54,540 --> 07:54:55,680 let's do that 14479 07:54:55,680 --> 07:54:57,840 so up here and let's make the event 14480 07:54:57,840 --> 07:55:01,080 so a public event event handler 14481 07:55:01,080 --> 07:55:04,378 call it on pick something 14482 07:55:04,378 --> 07:55:06,600 and then down here just to be test so if 14483 07:55:06,600 --> 07:55:08,760 the kitchen object is not known so if 14484 07:55:08,760 --> 07:55:10,378 the player did pick up something then 14485 07:55:10,378 --> 07:55:12,478 let's just fire off this event so just 14486 07:55:12,478 --> 07:55:15,478 view our usual invoke with this an event 14487 07:55:15,478 --> 07:55:18,378 RX rmt 14488 07:55:18,660 --> 07:55:20,760 okay so that's great 14489 07:55:20,760 --> 07:55:22,558 then on the sound management let's just 14490 07:55:22,558 --> 07:55:24,840 listen to it so let's go into the player 14491 07:55:24,840 --> 07:55:26,820 Quest let's access these static instance 14492 07:55:26,820 --> 07:55:28,860 and let's listen to the on picked up 14493 07:55:28,860 --> 07:55:31,080 something event and again let's rename 14494 07:55:31,080 --> 07:55:33,240 this to a proper name so player on pick 14495 07:55:33,240 --> 07:55:34,260 something 14496 07:55:34,260 --> 07:55:36,298 and over here let's just play the sound 14497 07:55:36,298 --> 07:55:39,058 and for the sound go into the refs and 14498 07:55:39,058 --> 07:55:42,000 grab in this case the object pickup 14499 07:55:42,000 --> 07:55:43,740 and for the position let's just go 14500 07:55:43,740 --> 07:55:44,878 player 14501 07:55:44,878 --> 07:55:47,458 dot instance and gravity transform that 14502 07:55:47,458 --> 07:55:48,360 position 14503 07:55:48,360 --> 07:55:51,240 okay that's it next for item dropping 14504 07:55:51,240 --> 07:55:53,638 now we can only drop items on a counter 14505 07:55:53,638 --> 07:55:55,798 so over here we have the base counter 14506 07:55:55,798 --> 07:55:57,600 class and again we have the same thing 14507 07:55:57,600 --> 07:55:59,878 so we have the set kitchen object and 14508 07:55:59,878 --> 07:56:01,500 again the same thing as with the cutting 14509 07:56:01,500 --> 07:56:03,420 counter we don't want to be required to 14510 07:56:03,420 --> 07:56:05,520 listen to every single counter we just 14511 07:56:05,520 --> 07:56:07,080 want to listen to one event so let's 14512 07:56:07,080 --> 07:56:09,420 make it up here so if I'm like static 14513 07:56:09,420 --> 07:56:11,580 event of type event handler 14514 07:56:11,580 --> 07:56:15,000 and let's name it on any object placed 14515 07:56:15,000 --> 07:56:17,298 here 14516 07:56:17,340 --> 07:56:19,138 and then down here when we have the set 14517 07:56:19,138 --> 07:56:21,000 kitchen object we do the usual if 14518 07:56:21,000 --> 07:56:23,940 kitchen object is not known if so then 14519 07:56:23,940 --> 07:56:26,958 let's fire off this event 14520 07:56:28,620 --> 07:56:30,240 okay great 14521 07:56:30,240 --> 07:56:32,218 and on the song Imagine let's listen so 14522 07:56:32,218 --> 07:56:34,620 go into the base counter on any object 14523 07:56:34,620 --> 07:56:37,200 placed here when that happens play the 14524 07:56:37,200 --> 07:56:39,600 sound then let's go into the other top 14525 07:56:39,600 --> 07:56:42,660 prefs and this one is the object drop so 14526 07:56:42,660 --> 07:56:44,940 that one and for the position let's do 14527 07:56:44,940 --> 07:56:46,798 the same thing we did so we cast the 14528 07:56:46,798 --> 07:56:49,680 base counter equals the sender as a base 14529 07:56:49,680 --> 07:56:52,020 counter and then we go into the base 14530 07:56:52,020 --> 07:56:54,478 counter and let's grab the transformed 14531 07:56:54,478 --> 07:56:56,638 up position okay so we just need one 14532 07:56:56,638 --> 07:56:58,378 more special counter type 14533 07:56:58,378 --> 07:57:01,080 here we have the trash counter and this 14534 07:57:01,080 --> 07:57:02,580 one it never really changes the parent 14535 07:57:02,580 --> 07:57:04,558 it just destroys the object it's over 14536 07:57:04,558 --> 07:57:06,058 here on the trash counter itself let's 14537 07:57:06,058 --> 07:57:08,520 fire off an event but again let's make 14538 07:57:08,520 --> 07:57:09,840 it static even though we're only going 14539 07:57:09,840 --> 07:57:11,218 to have one trash but make it Saturday 14540 07:57:11,218 --> 07:57:13,440 just to be able to support multiple so 14541 07:57:13,440 --> 07:57:15,440 public static event 14542 07:57:15,440 --> 07:57:17,100 Handler 14543 07:57:17,100 --> 07:57:21,260 on any object trashed 14544 07:57:22,440 --> 07:57:24,420 and then over here just fire off this 14545 07:57:24,420 --> 07:57:25,558 event 14546 07:57:25,558 --> 07:57:29,218 so invoke with this and eventar is not 14547 07:57:29,218 --> 07:57:30,360 empty okay 14548 07:57:30,360 --> 07:57:33,180 so now if we go into The Sound Manager 14549 07:57:33,180 --> 07:57:35,580 and over here once again the trash 14550 07:57:35,580 --> 07:57:38,820 counter on any not the on any object 14551 07:57:38,820 --> 07:57:41,218 place but on any object trashed 14552 07:57:41,218 --> 07:57:43,080 and on this one let's do pretty much 14553 07:57:43,080 --> 07:57:44,940 exactly the same thing so let's copy 14554 07:57:44,940 --> 07:57:47,040 this the sound is going to be the trash 14555 07:57:47,040 --> 07:57:49,558 sound instead of a bass counter 14556 07:57:49,558 --> 07:57:51,360 we could just cast it to a base counter 14557 07:57:51,360 --> 07:57:53,218 but let's make it proper so let's make a 14558 07:57:53,218 --> 07:57:55,680 trash counter as a trash counter and 14559 07:57:55,680 --> 07:57:58,020 this is a trash counter okay great 14560 07:57:58,020 --> 07:58:00,180 that's it so these are all of our basic 14561 07:58:00,180 --> 07:58:01,740 simple sounds as you can see all the 14562 07:58:01,740 --> 07:58:03,840 logic is super simple so let's test and 14563 07:58:03,840 --> 07:58:05,160 see if it all works 14564 07:58:05,160 --> 07:58:07,260 okay so first of all let's pick up an 14565 07:58:07,260 --> 07:58:09,180 object so if I go into a container and I 14566 07:58:09,180 --> 07:58:10,920 pick it up and if there you go there's 14567 07:58:10,920 --> 07:58:13,200 the sound now if I drop it somewhere and 14568 07:58:13,200 --> 07:58:14,878 if there's a sound now for the trash 14569 07:58:14,878 --> 07:58:17,458 pick it up drop it on the trash anyhow 14570 07:58:17,458 --> 07:58:19,920 there's the trash down okay great 14571 07:58:19,920 --> 07:58:22,320 then also let's check out the cutting so 14572 07:58:22,320 --> 07:58:23,940 if I pick up some cheese drop it there 14573 07:58:23,940 --> 07:58:26,458 and cut and if there go got a really 14574 07:58:26,458 --> 07:58:29,458 nice cutting sound okay so far so good 14575 07:58:29,458 --> 07:58:31,440 now let's handle the more complex ones 14576 07:58:31,440 --> 07:58:33,898 starting off with the stove for this one 14577 07:58:33,898 --> 07:58:35,878 the sound is meant to be on looping but 14578 07:58:35,878 --> 07:58:37,978 only when the sub is on so we don't want 14579 07:58:37,978 --> 07:58:40,138 to just play once but play and stop 14580 07:58:40,138 --> 07:58:41,700 playing depending on the state of the 14581 07:58:41,700 --> 07:58:42,660 stove 14582 07:58:42,660 --> 07:58:44,878 so for this one instead of spawning the 14583 07:58:44,878 --> 07:58:46,500 sound through code let's actually spawn 14584 07:58:46,500 --> 07:58:48,780 it on the object itself so let's go 14585 07:58:48,780 --> 07:58:51,478 inside the stove object let's go on the 14586 07:58:51,478 --> 07:58:54,240 stove counter and open up the prefab and 14587 07:58:54,240 --> 07:58:56,760 inside this prefab let's create a brand 14588 07:58:56,760 --> 07:58:59,520 new empty game object name it sound 14589 07:58:59,520 --> 07:59:01,320 let's reset transform make sure it's on 14590 07:59:01,320 --> 07:59:04,138 zero zero zero okay great now let's add 14591 07:59:04,138 --> 07:59:06,360 an audio Source component 14592 07:59:06,360 --> 07:59:08,580 and for the auto clip let's use the pan 14593 07:59:08,580 --> 07:59:11,398 sizzle let's make sure to not talk on 14594 07:59:11,398 --> 07:59:13,740 play on awake but we do want it to Loop 14595 07:59:13,740 --> 07:59:17,398 and let's also make it a 3D sound 14596 07:59:17,398 --> 07:59:20,280 okay so that's the basic setup Now to 14597 07:59:20,280 --> 07:59:22,440 control this let's make a script so 14598 07:59:22,440 --> 07:59:24,180 let's go into our scripts folder and 14599 07:59:24,180 --> 07:59:26,520 let's create a brand new c-sharp script 14600 07:59:26,520 --> 07:59:29,760 come with the stove counter sound 14601 07:59:29,760 --> 07:59:32,280 let's attach the script over here and 14602 07:59:32,280 --> 07:59:33,478 let's open it 14603 07:59:33,478 --> 07:59:35,398 so now here first let's grab the audio 14604 07:59:35,398 --> 07:59:37,620 Source component so we've got a private 14605 07:59:37,620 --> 07:59:40,920 audio source for the audio source and 14606 07:59:40,920 --> 07:59:43,680 just go on awake and audio Source 14607 07:59:43,680 --> 07:59:45,360 sequence get component of type audio 14608 07:59:45,360 --> 07:59:46,920 Source okay 14609 07:59:46,920 --> 07:59:48,478 then we're also going to need a 14610 07:59:48,478 --> 07:59:50,340 reference to the stove counter so let's 14611 07:59:50,340 --> 07:59:53,760 uh appear a centralized film private 14612 07:59:53,760 --> 07:59:56,218 of type stove counter for the stove 14613 07:59:56,218 --> 07:59:57,298 counter 14614 07:59:57,298 --> 07:59:59,340 then back in the editor let's drag that 14615 07:59:59,340 --> 08:00:00,898 reference all right 14616 08:00:00,898 --> 08:00:02,638 now on the stove counter over here we 14617 08:00:02,638 --> 08:00:04,378 already have the states and we have the 14618 08:00:04,378 --> 08:00:06,298 on-site change event again the same one 14619 08:00:06,298 --> 08:00:08,520 that we use to modify the visual so on 14620 08:00:08,520 --> 08:00:10,200 the sound lets you pretty much examine 14621 08:00:10,200 --> 08:00:11,218 the same thing 14622 08:00:11,218 --> 08:00:14,160 over here let's do a private void start 14623 08:00:14,160 --> 08:00:15,958 and on certain let's go into the stove 14624 08:00:15,958 --> 08:00:17,760 counter and listen to the on stay 14625 08:00:17,760 --> 08:00:19,500 changed event 14626 08:00:19,500 --> 08:00:22,138 and basically when this changes we want 14627 08:00:22,138 --> 08:00:24,360 to check if it's frying or fried if so 14628 08:00:24,360 --> 08:00:25,920 then we want to play the sound if no 14629 08:00:25,920 --> 08:00:27,600 then we don't want to play it so let's 14630 08:00:27,600 --> 08:00:29,878 define a ball call it play sound and 14631 08:00:29,878 --> 08:00:32,218 we're going to play if the state equals 14632 08:00:32,218 --> 08:00:36,898 we are frying or the state equals that 14633 08:00:36,898 --> 08:00:39,420 it is currently fried and about to burn 14634 08:00:39,420 --> 08:00:42,120 Okay then if we have a play sound 14635 08:00:42,120 --> 08:00:44,398 then let's go into the audio source and 14636 08:00:44,398 --> 08:00:46,878 comp play 14637 08:00:47,160 --> 08:00:49,500 and if not then let's go into audio 14638 08:00:49,500 --> 08:00:51,840 source and call pause 14639 08:00:51,840 --> 08:00:53,638 all right so that's it pretty simple 14640 08:00:53,638 --> 08:00:55,920 let's just make sure to save our prefab 14641 08:00:55,920 --> 08:00:57,780 go back outside and let's start on play 14642 08:00:57,780 --> 08:01:00,058 and okay four stars there's no sound 14643 08:01:00,058 --> 08:01:01,978 playing now if I pick up some meat and I 14644 08:01:01,978 --> 08:01:03,240 drop it on there 14645 08:01:03,240 --> 08:01:05,100 and if there go there's a sizzling sound 14646 08:01:05,100 --> 08:01:07,080 and continues going and now it is still 14647 08:01:07,080 --> 08:01:09,600 sizzling but if it burns it should stop 14648 08:01:09,600 --> 08:01:11,100 so if I go 14649 08:01:11,100 --> 08:01:12,958 and if there go the sizzling soundstomp 14650 08:01:12,958 --> 08:01:14,878 all right awesome so let's take this one 14651 08:01:14,878 --> 08:01:17,040 out let's actually trash it now let's 14652 08:01:17,040 --> 08:01:19,260 pick up another one let it cook 14653 08:01:19,260 --> 08:01:21,120 and once let's go pick it up and there 14654 08:01:21,120 --> 08:01:22,978 you go the sound of the Stomp all right 14655 08:01:22,978 --> 08:01:24,360 awesome 14656 08:01:24,360 --> 08:01:26,280 so we just have one more final sound 14657 08:01:26,280 --> 08:01:28,620 remaining that's the footsteps 14658 08:01:28,620 --> 08:01:30,478 by the way the warning sound is going to 14659 08:01:30,478 --> 08:01:32,820 be added during the Polish lecture 14660 08:01:32,820 --> 08:01:34,920 for the footsteps we want very much the 14661 08:01:34,920 --> 08:01:37,080 same thing that we did on the stove so 14662 08:01:37,080 --> 08:01:38,398 we're going to want a script to handle 14663 08:01:38,398 --> 08:01:39,780 that logic 14664 08:01:39,780 --> 08:01:41,280 but this time we don't need an audio 14665 08:01:41,280 --> 08:01:42,840 Source on the player we're going to use 14666 08:01:42,840 --> 08:01:45,298 the same play Method as the other ones 14667 08:01:45,298 --> 08:01:47,160 let's just make a script to run the 14668 08:01:47,160 --> 08:01:48,660 sounds so let's make a new c-sharp 14669 08:01:48,660 --> 08:01:51,298 script for the player sounds 14670 08:01:51,298 --> 08:01:54,058 let's go into the player game object and 14671 08:01:54,058 --> 08:01:56,340 attach the sound okay so here let's 14672 08:01:56,340 --> 08:01:58,680 first grab the player reference 14673 08:01:58,680 --> 08:02:02,160 so private player player and on private 14674 08:02:02,160 --> 08:02:03,898 way the way let's get the component of 14675 08:02:03,898 --> 08:02:06,898 type player and assign it to the player 14676 08:02:06,898 --> 08:02:08,100 okay 14677 08:02:08,100 --> 08:02:10,080 then for the footsteps basically we want 14678 08:02:10,080 --> 08:02:11,580 to play them every certain amount of 14679 08:02:11,580 --> 08:02:13,978 time so let's do appear a private Cloud 14680 08:02:13,978 --> 08:02:16,740 for the footstep timer another one for 14681 08:02:16,740 --> 08:02:18,718 the footstep tower Max and let's say you 14682 08:02:18,718 --> 08:02:21,058 want to play say 10 times per second 14683 08:02:21,058 --> 08:02:23,820 then we do a basic update and on update 14684 08:02:23,820 --> 08:02:26,820 footstep timer countdown by time.com 14685 08:02:26,820 --> 08:02:29,580 time and if the footstep timer is under 14686 08:02:29,580 --> 08:02:31,138 zero 14687 08:02:31,138 --> 08:02:33,360 then let's reset it so set it to the 14688 08:02:33,360 --> 08:02:34,558 maximum 14689 08:02:34,558 --> 08:02:36,000 and it's in here that we're going to 14690 08:02:36,000 --> 08:02:38,280 play the sound so now here we have two 14691 08:02:38,280 --> 08:02:41,218 options we can fire an event here and we 14692 08:02:41,218 --> 08:02:42,958 can listen to it on The Sound Manager so 14693 08:02:42,958 --> 08:02:44,340 exactly the same thing that we've been 14694 08:02:44,340 --> 08:02:46,978 doing previously or we can just trigger 14695 08:02:46,978 --> 08:02:49,378 the sound directly from here doing that 14696 08:02:49,378 --> 08:02:51,360 will mean that this class is tightly 14697 08:02:51,360 --> 08:02:53,340 coupled with The Sound Manager usually 14698 08:02:53,340 --> 08:02:55,740 we want to avoid tight couplings however 14699 08:02:55,740 --> 08:02:57,180 in this case the player sounds class 14700 08:02:57,180 --> 08:02:58,860 this one is really only meant to exist 14701 08:02:58,860 --> 08:03:01,200 alongside the sound manager so in this 14702 08:03:01,200 --> 08:03:02,700 case it's perfectly fine to totally 14703 08:03:02,700 --> 08:03:04,440 coupon them so let's play the sound 14704 08:03:04,440 --> 08:03:06,240 directly from here which means we need a 14705 08:03:06,240 --> 08:03:08,458 reference to The Sound Manager we can 14706 08:03:08,458 --> 08:03:09,958 make a serialized field or just make 14707 08:03:09,958 --> 08:03:12,240 this a Singleton so let's do that 14708 08:03:12,240 --> 08:03:16,620 so a public static type Sound Manager 14709 08:03:16,620 --> 08:03:18,898 name it instance where they probably get 14710 08:03:18,898 --> 08:03:21,360 any private set 14711 08:03:21,360 --> 08:03:25,138 then on private void awake 14712 08:03:25,138 --> 08:03:27,000 we just set the instance equals this 14713 08:03:27,000 --> 08:03:28,200 okay 14714 08:03:28,200 --> 08:03:30,540 so then over here we can just access it 14715 08:03:30,540 --> 08:03:32,700 so just go into the sound manager access 14716 08:03:32,700 --> 08:03:35,820 the instance and we call play sound 14717 08:03:35,820 --> 08:03:37,340 which we actually need to make public 14718 08:03:37,340 --> 08:03:39,718 however this function also takes a 14719 08:03:39,718 --> 08:03:42,000 reference to the audio clip array 14720 08:03:42,000 --> 08:03:43,740 so that means we need a reference to the 14721 08:03:43,740 --> 08:03:46,020 audio clips so again we have multiple 14722 08:03:46,020 --> 08:03:48,240 options we could add over here on the 14723 08:03:48,240 --> 08:03:50,340 player sounds at a serialized film for 14724 08:03:50,340 --> 08:03:52,978 the footstep sounds or we can just make 14725 08:03:52,978 --> 08:03:54,660 a specialized function over here on The 14726 08:03:54,660 --> 08:03:56,760 Sound Manager both options can work just 14727 08:03:56,760 --> 08:03:58,440 fine let's go with the second one just 14728 08:03:58,440 --> 08:04:00,600 to be different so just make here a 14729 08:04:00,600 --> 08:04:02,820 public void play 14730 08:04:02,820 --> 08:04:05,398 footstep sound 14731 08:04:05,398 --> 08:04:07,378 we're just going to receive a vector 3 14732 08:04:07,378 --> 08:04:09,240 for the position 14733 08:04:09,240 --> 08:04:11,878 and then we just call play sound let's 14734 08:04:11,878 --> 08:04:15,120 go into the audio clip refs ASL and 14735 08:04:15,120 --> 08:04:17,700 let's pick up the footsteps and play it 14736 08:04:17,700 --> 08:04:19,080 on this position 14737 08:04:19,080 --> 08:04:21,240 and let's also receive the volume 14738 08:04:21,240 --> 08:04:23,760 just appear a fault for the volume 14739 08:04:23,760 --> 08:04:25,260 okay so that's right now we just need to 14740 08:04:25,260 --> 08:04:26,638 call this function 14741 08:04:26,638 --> 08:04:28,020 it's over here on the player instead of 14742 08:04:28,020 --> 08:04:29,940 calling play sound let's go on the other 14743 08:04:29,940 --> 08:04:31,860 one play the footstep sound 14744 08:04:31,860 --> 08:04:33,660 then for the position that's the player 14745 08:04:33,660 --> 08:04:36,000 transformed that position and for the 14746 08:04:36,000 --> 08:04:37,620 volume I just exposed the volume just in 14747 08:04:37,620 --> 08:04:39,360 case you want to make the footsteps a 14748 08:04:39,360 --> 08:04:40,740 bit more sound or not 14749 08:04:40,740 --> 08:04:42,540 but for now let's begin with one F and 14750 08:04:42,540 --> 08:04:44,580 then see if that's waiting around as 14751 08:04:44,580 --> 08:04:46,260 usual instead of using magic numbers 14752 08:04:46,260 --> 08:04:48,360 let's define a fluid for the volume put 14753 08:04:48,360 --> 08:04:51,058 it at 1f and over here use the volume 14754 08:04:51,058 --> 08:04:53,638 okay great however you might be noticing 14755 08:04:53,638 --> 08:04:55,798 an obvious issue here right now this is 14756 08:04:55,798 --> 08:04:57,898 going to play non-stop obviously we 14757 08:04:57,898 --> 08:04:59,340 don't want to do that we only want to 14758 08:04:59,340 --> 08:05:00,898 play footstep sounds if the player is 14759 08:05:00,898 --> 08:05:03,180 actually moving so this pre-semble we 14760 08:05:03,180 --> 08:05:04,440 just need to ask the player if it is 14761 08:05:04,440 --> 08:05:05,458 moving 14762 08:05:05,458 --> 08:05:08,280 and we already did that so player is 14763 08:05:08,280 --> 08:05:10,558 walking so if the player is walking then 14764 08:05:10,558 --> 08:05:12,660 you play The Sounds if not we don't okay 14765 08:05:12,660 --> 08:05:15,240 that's it so let's test so here we are 14766 08:05:15,240 --> 08:05:16,620 and if I'm standing still there's no 14767 08:05:16,620 --> 08:05:18,420 footsteps okay that's great and as soon 14768 08:05:18,420 --> 08:05:20,398 as I move yep there you go we got some 14769 08:05:20,398 --> 08:05:21,898 nice WhatsApp sounds 14770 08:05:21,898 --> 08:05:24,420 all right great so with all that we 14771 08:05:24,420 --> 08:05:26,160 added all of our sounds 14772 08:05:26,160 --> 08:05:28,320 now here note how we mostly use this 14773 08:05:28,320 --> 08:05:30,120 method of going into the audio source 14774 08:05:30,120 --> 08:05:31,500 and using the play clip at Point 14775 08:05:31,500 --> 08:05:33,478 function this one is great because it is 14776 08:05:33,478 --> 08:05:35,478 so simple but it does have limitations 14777 08:05:35,478 --> 08:05:37,620 specifically with regards to all of the 14778 08:05:37,620 --> 08:05:39,780 options if we look on the audio Source 14779 08:05:39,780 --> 08:05:42,180 component here we have all these options 14780 08:05:42,180 --> 08:05:44,340 so you can use an output use an audio 14781 08:05:44,340 --> 08:05:45,780 mixer like we saw in the previous 14782 08:05:45,780 --> 08:05:48,180 lecture we can play around priority play 14783 08:05:48,180 --> 08:05:50,398 around the pitch make it 2D or 3D play 14784 08:05:50,398 --> 08:05:51,958 around over here with how the sound 14785 08:05:51,958 --> 08:05:54,120 falls off so tons and tons of options 14786 08:05:54,120 --> 08:05:55,680 that you can't really access if you use 14787 08:05:55,680 --> 08:05:58,260 that simple function so one approach if 14788 08:05:58,260 --> 08:06:00,298 you need these options you could make 14789 08:06:00,298 --> 08:06:02,638 each sound a prefab so make a prefab for 14790 08:06:02,638 --> 08:06:04,440 each different audio clip and then 14791 08:06:04,440 --> 08:06:05,700 instead of calling that function you 14792 08:06:05,700 --> 08:06:07,260 would simply instantiate that prefab to 14793 08:06:07,260 --> 08:06:09,478 spawn that audio so if you have lots of 14794 08:06:09,478 --> 08:06:11,218 options depending on how complex you 14795 08:06:11,218 --> 08:06:12,540 want your sound to be 14796 08:06:12,540 --> 08:06:14,638 but for a simple game and for simple 14797 08:06:14,638 --> 08:06:16,740 sounds this one line of code is super 14798 08:06:16,740 --> 08:06:17,520 simple 14799 08:06:17,520 --> 08:06:19,500 alright so here we have added sound 14800 08:06:19,500 --> 08:06:21,600 effects to our game that component with 14801 08:06:21,600 --> 08:06:23,340 the music that we had previously already 14802 08:06:23,340 --> 08:06:25,020 makes everything sound so much more 14803 08:06:25,020 --> 08:06:26,638 alive it's really starting to look like 14804 08:06:26,638 --> 08:06:28,200 a proper game 14805 08:06:28,200 --> 08:06:30,298 the one thing we still don't have is 14806 08:06:30,298 --> 08:06:32,040 some kind of game start and game and 14807 08:06:32,040 --> 08:06:34,320 scenario so let's have that in the next 14808 08:06:34,320 --> 08:06:36,798 lecture 14809 08:06:37,020 --> 08:06:39,718 hello and welcome I'm your code Maki in 14810 08:06:39,718 --> 08:06:41,340 this lecture let's add a simple and 14811 08:06:41,340 --> 08:06:43,440 beginning state to our game so right now 14812 08:06:43,440 --> 08:06:45,958 we can play the game of the mechanics 14813 08:06:45,958 --> 08:06:47,638 everything works perfectly and it's all 14814 08:06:47,638 --> 08:06:49,440 been implemented however in the 14815 08:06:49,440 --> 08:06:50,760 beginning of the game it just starts 14816 08:06:50,760 --> 08:06:52,680 right away as it loads there's no start 14817 08:06:52,680 --> 08:06:54,600 no countdown no time for the player to 14818 08:06:54,600 --> 08:06:55,440 get ready 14819 08:06:55,440 --> 08:06:57,058 someone sort that out with a simple 14820 08:06:57,058 --> 08:06:59,340 countdown let's begin by making a 14821 08:06:59,340 --> 08:07:01,020 general game manager script to handle 14822 08:07:01,020 --> 08:07:03,298 all of our general game States so let's 14823 08:07:03,298 --> 08:07:05,700 create a brand new c-sharp script 14824 08:07:05,700 --> 08:07:07,978 and now here you could use the name game 14825 08:07:07,978 --> 08:07:10,218 manager so you could use this name 14826 08:07:10,218 --> 08:07:13,080 however for some reason yantian likes uh 14827 08:07:13,080 --> 08:07:15,000 this custom icon when a script is named 14828 08:07:15,000 --> 08:07:17,398 exactly game manager personally I don't 14829 08:07:17,398 --> 08:07:19,080 like this I don't want it to be a 14830 08:07:19,080 --> 08:07:20,940 different icon I want this script to 14831 08:07:20,940 --> 08:07:22,620 look and behave just like any other one 14832 08:07:22,620 --> 08:07:24,660 of my scripts so personally I don't like 14833 08:07:24,660 --> 08:07:26,100 this but if it doesn't bother you then 14834 08:07:26,100 --> 08:07:27,718 go ahead use it doesn't really change 14835 08:07:27,718 --> 08:07:30,058 anything just a visual but in my case I 14836 08:07:30,058 --> 08:07:31,620 prefer to give it a different name so 14837 08:07:31,620 --> 08:07:33,840 sometimes I call it game Handler or 14838 08:07:33,840 --> 08:07:35,280 other times just something related to 14839 08:07:35,280 --> 08:07:36,718 this game like for example the kitchen 14840 08:07:36,718 --> 08:07:39,240 game manager and just like that it won't 14841 08:07:39,240 --> 08:07:41,520 have that custom icon just need to go 14842 08:07:41,520 --> 08:07:43,500 inside and rename this to Kitchen game 14843 08:07:43,500 --> 08:07:46,080 manager okay save the script and all 14844 08:07:46,080 --> 08:07:47,700 right now let's make a game object to 14845 08:07:47,700 --> 08:07:49,260 run it so a new game object with the 14846 08:07:49,260 --> 08:07:51,120 same name let's attach the kitchen game 14847 08:07:51,120 --> 08:07:53,040 manager and reset transform okay let's 14848 08:07:53,040 --> 08:07:55,500 go now here we're going to Define all of 14849 08:07:55,500 --> 08:07:57,058 the various game states that our game 14850 08:07:57,058 --> 08:07:59,100 can be in so for that let's define an 14851 08:07:59,100 --> 08:08:02,580 enum so a simple enum call it state 14852 08:08:02,580 --> 08:08:05,398 and for the various States let's say we 14853 08:08:05,398 --> 08:08:08,100 are first of all waiting to start then 14854 08:08:08,100 --> 08:08:11,280 we are on countdown to start then the 14855 08:08:11,280 --> 08:08:13,378 game is playing and then we have a game 14856 08:08:13,378 --> 08:08:16,378 over okay so these are our states let's 14857 08:08:16,378 --> 08:08:19,020 do a private void awake and on the 14858 08:08:19,020 --> 08:08:20,340 waiting list of the state so we need to 14859 08:08:20,340 --> 08:08:22,798 store a state for our state 14860 08:08:22,798 --> 08:08:25,440 and on a week we set the state equals 14861 08:08:25,440 --> 08:08:27,600 and let's begin on waiting to start by 14862 08:08:27,600 --> 08:08:29,040 the way the point with this waiting to 14863 08:08:29,040 --> 08:08:30,660 start say it will also be very important 14864 08:08:30,660 --> 08:08:32,398 in the next video covering multiplayer 14865 08:08:32,398 --> 08:08:33,958 basically we're going to wait until 14866 08:08:33,958 --> 08:08:35,638 everyone is connected before we start 14867 08:08:35,638 --> 08:08:37,740 the actual countdown but over here for 14868 08:08:37,740 --> 08:08:39,298 now we're just going to wait a little 14869 08:08:39,298 --> 08:08:41,100 bit on the waiting to start then we're 14870 08:08:41,100 --> 08:08:42,600 going to trigger the countdown and then 14871 08:08:42,600 --> 08:08:44,040 after some time trigger the game playing 14872 08:08:44,040 --> 08:08:45,780 state so pretty much all of these states 14873 08:08:45,780 --> 08:08:47,940 are going to be time based so let's make 14874 08:08:47,940 --> 08:08:51,180 a simple timer so a private float for 14875 08:08:51,180 --> 08:08:54,478 the waiting to start timer let's begin 14876 08:08:54,478 --> 08:08:57,000 on something like 1f so we just wait for 14877 08:08:57,000 --> 08:08:58,920 one second then let's make a private 14878 08:08:58,920 --> 08:09:00,898 void update and let's make a state 14879 08:09:00,898 --> 08:09:02,398 machine just like we've done previously 14880 08:09:02,398 --> 08:09:06,320 so do a switch on our state 14881 08:09:06,420 --> 08:09:09,058 in case we are on state DOT waiting to 14882 08:09:09,058 --> 08:09:09,840 start 14883 08:09:09,840 --> 08:09:11,940 if so then let's go into the waiting to 14884 08:09:11,940 --> 08:09:14,100 start timer count it down by time dot 14885 08:09:14,100 --> 08:09:15,420 Delta time 14886 08:09:15,420 --> 08:09:17,580 then if the waiting to start timer if it 14887 08:09:17,580 --> 08:09:20,100 is under zero if so then let's move into 14888 08:09:20,100 --> 08:09:22,860 the state equal state DOT let's go into 14889 08:09:22,860 --> 08:09:25,320 the countdown to start okay so that's it 14890 08:09:25,320 --> 08:09:26,580 and the other states are going to be 14891 08:09:26,580 --> 08:09:27,898 pretty much exactly the same so let's 14892 08:09:27,898 --> 08:09:29,340 just copy this so we have the winning 14893 08:09:29,340 --> 08:09:31,978 start and the countdown to start then we 14894 08:09:31,978 --> 08:09:34,138 have the game playing and finally we 14895 08:09:34,138 --> 08:09:35,580 have the game over and that one doesn't 14896 08:09:35,580 --> 08:09:38,280 have anything so just like this like I 14897 08:09:38,280 --> 08:09:40,260 said we could reuse the same timer but 14898 08:09:40,260 --> 08:09:42,298 let's write our code nice and proper so 14899 08:09:42,298 --> 08:09:44,340 let's make different timers for each so 14900 08:09:44,340 --> 08:09:46,558 let's make three timers so we're going 14901 08:09:46,558 --> 08:09:49,138 to have the countdown to start timer 14902 08:09:49,138 --> 08:09:50,940 so countdown 14903 08:09:50,940 --> 08:09:52,798 for this one let's see Fallen two three 14904 08:09:52,798 --> 08:09:53,820 so we're going to wait three seconds 14905 08:09:53,820 --> 08:09:55,860 before we start and then the game 14906 08:09:55,860 --> 08:09:57,478 playing timer 14907 08:09:57,478 --> 08:09:58,860 and for this one let's put it something 14908 08:09:58,860 --> 08:10:00,478 short just for testing so let's put it 14909 08:10:00,478 --> 08:10:02,940 just test and then down here let's just 14910 08:10:02,940 --> 08:10:04,680 use them so on the countdown let's count 14911 08:10:04,680 --> 08:10:06,420 down this timer on the game playing 14912 08:10:06,420 --> 08:10:08,280 count down this timer when the countdown 14913 08:10:08,280 --> 08:10:10,798 ends we go into game playing and when 14914 08:10:10,798 --> 08:10:12,478 the game playing ends we go into game 14915 08:10:12,478 --> 08:10:15,000 over alright so that's our super basic 14916 08:10:15,000 --> 08:10:16,740 state machine just a bunch of timers 14917 08:10:16,740 --> 08:10:17,820 super simple 14918 08:10:17,820 --> 08:10:19,860 let's do a quick look just to see so 14919 08:10:19,860 --> 08:10:22,200 over here just say debug.log and let's 14920 08:10:22,200 --> 08:10:24,180 just print out the current state 14921 08:10:24,180 --> 08:10:26,940 okay so just like this let's test and 14922 08:10:26,940 --> 08:10:28,378 yep right away we are waiting to start 14923 08:10:28,378 --> 08:10:30,298 after one second going to countdown then 14924 08:10:30,298 --> 08:10:31,978 after three seconds go into game playing 14925 08:10:31,978 --> 08:10:34,860 and now if we wait for 10 seconds 14926 08:10:34,860 --> 08:10:37,080 after 10 seconds we should be able to 14927 08:10:37,080 --> 08:10:39,240 see just a little bit and yep there you 14928 08:10:39,240 --> 08:10:41,280 go we've got our game over okay great 14929 08:10:41,280 --> 08:10:43,500 all the logic is working although we 14930 08:10:43,500 --> 08:10:44,458 actually didn't change anything 14931 08:10:44,458 --> 08:10:46,138 technically the game right now is on a 14932 08:10:46,138 --> 08:10:47,458 game over but everything still works the 14933 08:10:47,458 --> 08:10:48,840 same experience only so I can still play 14934 08:10:48,840 --> 08:10:50,940 I can still do everything 14935 08:10:50,940 --> 08:10:53,700 so let's sort them when we are in any 14936 08:10:53,700 --> 08:10:55,440 state other than the game playing State 14937 08:10:55,440 --> 08:10:57,058 we don't want the player to be able to 14938 08:10:57,058 --> 08:10:59,040 interact with anything we want to leave 14939 08:10:59,040 --> 08:11:00,958 it movement because that's usually nice 14940 08:11:00,958 --> 08:11:02,580 and fun but we don't want it to be able 14941 08:11:02,580 --> 08:11:04,320 to interact pickup objects or do 14942 08:11:04,320 --> 08:11:06,540 anything so let's do that basically over 14943 08:11:06,540 --> 08:11:08,218 here on the game manager let's just 14944 08:11:08,218 --> 08:11:10,378 expose the function so public pool let's 14945 08:11:10,378 --> 08:11:12,600 call this is game playing 14946 08:11:12,600 --> 08:11:14,580 then over here pretty simple just return 14947 08:11:14,580 --> 08:11:17,040 if the state equals state DOT gameplay 14948 08:11:17,040 --> 08:11:18,540 that's it 14949 08:11:18,540 --> 08:11:20,638 so now we can go into the player script 14950 08:11:20,638 --> 08:11:23,520 so over here on the player script let's 14951 08:11:23,520 --> 08:11:25,740 go down into the interaction function so 14952 08:11:25,740 --> 08:11:26,940 over here we've got the interact 14953 08:11:26,940 --> 08:11:29,340 alternate and the interact and on both 14954 08:11:29,340 --> 08:11:31,978 of these basically let's just ask if the 14955 08:11:31,978 --> 08:11:33,898 game is in the game playing state if so 14956 08:11:33,898 --> 08:11:35,520 we want to interact but if not then we 14957 08:11:35,520 --> 08:11:37,378 don't want to do anything so to access 14958 08:11:37,378 --> 08:11:39,000 the game manager we could add a pure 14959 08:11:39,000 --> 08:11:40,620 serialized field or as usual let's just 14960 08:11:40,620 --> 08:11:42,840 make a nice Singleton so pure public 14961 08:11:42,840 --> 08:11:45,120 static of type kitchen game manager the 14962 08:11:45,120 --> 08:11:48,120 instance make a public get and a private 14963 08:11:48,120 --> 08:11:49,378 set 14964 08:11:49,378 --> 08:11:51,780 then down here on awake let's set the 14965 08:11:51,780 --> 08:11:54,240 instance equals this okay so now over 14966 08:11:54,240 --> 08:11:55,680 here on the player let's just go into 14967 08:11:55,680 --> 08:11:57,240 the kitchen game manager access the 14968 08:11:57,240 --> 08:11:59,820 instance and test is game playing 14969 08:11:59,820 --> 08:12:01,558 and we're going to do an if if the game 14970 08:12:01,558 --> 08:12:03,840 is not playing so if we are not playing 14971 08:12:03,840 --> 08:12:05,100 we want to stop this so let's just 14972 08:12:05,100 --> 08:12:07,020 return so if the game is not playing the 14973 08:12:07,020 --> 08:12:09,000 code is going to stop executing here and 14974 08:12:09,000 --> 08:12:10,860 same thing on the interaction so just 14975 08:12:10,860 --> 08:12:12,600 like that we won't be able to interact 14976 08:12:12,600 --> 08:12:14,280 with anything once we are not in the 14977 08:12:14,280 --> 08:12:16,558 game playing State okay so here we are 14978 08:12:16,558 --> 08:12:18,298 waiting to start nope I cannot pick up 14979 08:12:18,298 --> 08:12:19,860 anything count down to start nope I 14980 08:12:19,860 --> 08:12:21,000 can't and as soon as we go into game 14981 08:12:21,000 --> 08:12:22,860 playing yep now I can't interact so I 14982 08:12:22,860 --> 08:12:24,360 can cut a bunch of things 14983 08:12:24,360 --> 08:12:26,638 and as soon as it goes into game 14984 08:12:26,638 --> 08:12:28,378 overstate 14985 08:12:28,378 --> 08:12:29,700 there you go currently in game over 14986 08:12:29,700 --> 08:12:31,440 state so now if I try and interact nope 14987 08:12:31,440 --> 08:12:33,360 can't do it okay awesome everything 14988 08:12:33,360 --> 08:12:35,160 works perfectly 14989 08:12:35,160 --> 08:12:37,138 so in terms of logic this is really it 14990 08:12:37,138 --> 08:12:39,360 there's nothing else we need to do 14991 08:12:39,360 --> 08:12:40,860 but of course right now the player would 14992 08:12:40,860 --> 08:12:42,780 have no clue as to why sometimes they 14993 08:12:42,780 --> 08:12:44,280 can grab and sometimes they can't so 14994 08:12:44,280 --> 08:12:46,378 let's add a proper visual 14995 08:12:46,378 --> 08:12:48,058 first let's add a visual to the starting 14996 08:12:48,058 --> 08:12:49,200 countdown 14997 08:12:49,200 --> 08:12:51,360 so let's do that as a canvas element so 14998 08:12:51,360 --> 08:12:52,978 let's go inside our canvas create an 14999 08:12:52,978 --> 08:12:55,320 empty game object name this the game 15000 08:12:55,320 --> 08:12:59,160 start countdown UI let's press F to 15001 08:12:59,160 --> 08:13:01,378 focus on the object press 2 to turn this 15002 08:13:01,378 --> 08:13:03,840 into 2D okay so let's see and over here 15003 08:13:03,840 --> 08:13:05,638 we really just need a text object so 15004 08:13:05,638 --> 08:13:06,958 let's leave this one anchored on the 15005 08:13:06,958 --> 08:13:08,218 center let's put the width and height 15006 08:13:08,218 --> 08:13:10,320 both on zero we don't need that and then 15007 08:13:10,320 --> 08:13:12,600 let's go inside create a new text object 15008 08:13:12,600 --> 08:13:15,600 call this the countdown text and then 15009 08:13:15,600 --> 08:13:17,280 inside let's just put a number so just a 15010 08:13:17,280 --> 08:13:18,000 three 15011 08:13:18,000 --> 08:13:20,218 let's put the width and height both on 15012 08:13:20,218 --> 08:13:22,500 zero then down here let's put it in bond 15013 08:13:22,500 --> 08:13:24,478 on a really big font size so let's say 15014 08:13:24,478 --> 08:13:26,700 something like 250 okay really nice big 15015 08:13:26,700 --> 08:13:28,920 number then let's also put it centered 15016 08:13:28,920 --> 08:13:30,780 and down the middle okay that's right 15017 08:13:30,780 --> 08:13:32,520 we've got our nice big countdown number 15018 08:13:32,520 --> 08:13:34,920 also by the way when using text mesh Pro 15019 08:13:34,920 --> 08:13:36,478 we can easily add a whole bunch of 15020 08:13:36,478 --> 08:13:38,820 effects if we'll look down here we have 15021 08:13:38,820 --> 08:13:40,920 the default text mesh Pro material and 15022 08:13:40,920 --> 08:13:42,420 over here we can add an outline another 15023 08:13:42,420 --> 08:13:44,218 line and so on so that's really great 15024 08:13:44,218 --> 08:13:46,920 however there's one very very crucial 15025 08:13:46,920 --> 08:13:49,138 thing when you want to add some effects 15026 08:13:49,138 --> 08:13:50,820 always remember that the effects are 15027 08:13:50,820 --> 08:13:52,740 being applied to the material meaning 15028 08:13:52,740 --> 08:13:54,600 any text objects that are sharing this 15029 08:13:54,600 --> 08:13:57,058 material all of them won't modify so for 15030 08:13:57,058 --> 08:13:58,798 the most part usually you don't want to 15031 08:13:58,798 --> 08:14:01,080 modify the default material if you do 15032 08:14:01,080 --> 08:14:02,580 then everything using this default 15033 08:14:02,580 --> 08:14:04,920 material will change like for example I 15034 08:14:04,920 --> 08:14:06,780 want to add a nice thick outline to this 15035 08:14:06,780 --> 08:14:08,878 one but over here I've got some regular 15036 08:14:08,878 --> 08:14:10,558 text that is also using the default 15037 08:14:10,558 --> 08:14:13,320 material so if I now add an upline and I 15038 08:14:13,320 --> 08:14:14,700 increase the thickness and if there you 15039 08:14:14,700 --> 08:14:16,680 go those also got an upline as well as 15040 08:14:16,680 --> 08:14:18,958 this and if I wanted download make it 15041 08:14:18,958 --> 08:14:20,878 quite a lot bigger there you go all of 15042 08:14:20,878 --> 08:14:22,558 them modify because all of them are 15043 08:14:22,558 --> 08:14:25,080 sharing the same material so usually you 15044 08:14:25,080 --> 08:14:26,580 don't want to modify the default 15045 08:14:26,580 --> 08:14:28,978 material if you want to add some kind of 15046 08:14:28,978 --> 08:14:30,420 special effects always make sure to 15047 08:14:30,420 --> 08:14:31,798 create a brand new material beforehand 15048 08:14:31,798 --> 08:14:34,080 so over here let's remove the outline 15049 08:14:34,080 --> 08:14:37,080 put it back on the dilation and let's go 15050 08:14:37,080 --> 08:14:38,398 up here to create the brand new material 15051 08:14:38,398 --> 08:14:40,020 first we need to find our phones over 15052 08:14:40,020 --> 08:14:41,580 here on the font asset we can just click 15053 08:14:41,580 --> 08:14:42,780 on it and we can see it over here 15054 08:14:42,780 --> 08:14:45,058 highlighted on the project window so 15055 08:14:45,058 --> 08:14:46,798 it's inside the text mesh profiler the 15056 08:14:46,798 --> 08:14:48,420 resources phones and so on so here is 15057 08:14:48,420 --> 08:14:50,760 the default font and inside this one is 15058 08:14:50,760 --> 08:14:52,558 the font that we're using now in this 15059 08:14:52,558 --> 08:14:54,180 font there's a nice little error icon 15060 08:14:54,180 --> 08:14:55,740 and inside we can see the default 15061 08:14:55,740 --> 08:14:57,898 material so let's duplicate this 15062 08:14:57,898 --> 08:14:59,520 material although it's important make 15063 08:14:59,520 --> 08:15:00,958 sure you duplicate the material and not 15064 08:15:00,958 --> 08:15:02,760 the font so with this material selected 15065 08:15:02,760 --> 08:15:04,798 I'm going to press Ctrl D and there you 15066 08:15:04,798 --> 08:15:06,718 go it duplicates the material and over 15067 08:15:06,718 --> 08:15:09,180 here let's give it some name so let's 15068 08:15:09,180 --> 08:15:10,500 say this is material that I want to use 15069 08:15:10,500 --> 08:15:12,240 for the start countdown 15070 08:15:12,240 --> 08:15:14,760 so there you go just like this also one 15071 08:15:14,760 --> 08:15:16,978 very very important thing the name of 15072 08:15:16,978 --> 08:15:18,540 the material needs to include the font 15073 08:15:18,540 --> 08:15:20,638 name otherwise it won't show up for 15074 08:15:20,638 --> 08:15:22,200 example if I get rid of this the only 15075 08:15:22,200 --> 08:15:24,240 version Sans SDF if I name the material 15076 08:15:24,240 --> 08:15:26,458 just like this and now I'll look over 15077 08:15:26,458 --> 08:15:28,020 here on the countdown text look on text 15078 08:15:28,020 --> 08:15:30,478 mesh Pro here is the drop down menu for 15079 08:15:30,478 --> 08:15:32,700 selecting material and over here note 15080 08:15:32,700 --> 08:15:34,978 how that one does not show up so it is 15081 08:15:34,978 --> 08:15:36,540 extremely important in order for it to 15082 08:15:36,540 --> 08:15:38,160 show up in here it needs to have the 15083 08:15:38,160 --> 08:15:40,020 same starting name so over here if I 15084 08:15:40,020 --> 08:15:41,940 rename this material put Liberation 15085 08:15:41,940 --> 08:15:44,398 sends SDF and then the name and now back 15086 08:15:44,398 --> 08:15:46,620 in here now look and yep now I do see my 15087 08:15:46,620 --> 08:15:48,840 material okay so that's great and over 15088 08:15:48,840 --> 08:15:51,000 here we can add what kind of effects we 15089 08:15:51,000 --> 08:15:52,798 want and it will only affect this one 15090 08:15:52,798 --> 08:15:55,138 and not any others okay so for this one 15091 08:15:55,138 --> 08:15:57,240 let's add a nice outline and let's make 15092 08:15:57,240 --> 08:15:59,040 some nice thick numbers so over here on 15093 08:15:59,040 --> 08:16:00,898 donation let's handle it by quite a 15094 08:16:00,898 --> 08:16:01,740 little bit 15095 08:16:01,740 --> 08:16:03,780 then for the outline color let's put it 15096 08:16:03,780 --> 08:16:06,298 maybe on a blue something a bit like 15097 08:16:06,298 --> 08:16:08,760 this okay let's push it back just a 15098 08:16:08,760 --> 08:16:10,620 little bit okay I think that looks 15099 08:16:10,620 --> 08:16:12,958 pretty good now if you want you could 15100 08:16:12,958 --> 08:16:15,240 add even more effect to this I made 15101 08:16:15,240 --> 08:16:16,978 another video covering how to use custom 15102 08:16:16,978 --> 08:16:19,558 Textures in your font doing that you can 15103 08:16:19,558 --> 08:16:21,000 just import the font directly into 15104 08:16:21,000 --> 08:16:23,160 Photoshop and edit it with all kinds of 15105 08:16:23,160 --> 08:16:25,020 effects for example in that method is 15106 08:16:25,020 --> 08:16:26,820 example what I used in my game hypernite 15107 08:16:26,820 --> 08:16:28,920 make the head counter look really nice I 15108 08:16:28,920 --> 08:16:30,360 also have a tutorial specifically on 15109 08:16:30,360 --> 08:16:32,160 that so if you want even more custom 15110 08:16:32,160 --> 08:16:33,840 text definitely go ahead and watch those 15111 08:16:33,840 --> 08:16:35,700 videos but anyways here we have our 15112 08:16:35,700 --> 08:16:37,740 countdown text looking pretty nice now 15113 08:16:37,740 --> 08:16:39,180 the number itself will be written 15114 08:16:39,180 --> 08:16:41,218 through code so let's do that let's go 15115 08:16:41,218 --> 08:16:42,780 into our scripts into our UI folder 15116 08:16:42,780 --> 08:16:45,000 create a brand new c-sharp script for 15117 08:16:45,000 --> 08:16:48,298 the game start countdown UI okay and 15118 08:16:48,298 --> 08:16:50,218 let's select the parent object and 15119 08:16:50,218 --> 08:16:52,320 attach the script now here first thing 15120 08:16:52,320 --> 08:16:53,940 we need is a reference to that text 15121 08:16:53,940 --> 08:16:56,280 object so let's add a serialized film 15122 08:16:56,280 --> 08:16:58,500 private and again remember what I 15123 08:16:58,500 --> 08:16:59,940 mentioned a couple of night years ago 15124 08:16:59,940 --> 08:17:02,160 with regards to the types so we want 15125 08:17:02,160 --> 08:17:05,340 xmesh Pro U GUI we want this one so it's 15126 08:17:05,340 --> 08:17:07,860 going to be our countdown text and now 15127 08:17:07,860 --> 08:17:10,020 for updating this text basically we just 15128 08:17:10,020 --> 08:17:11,580 need to know the game state so we need 15129 08:17:11,580 --> 08:17:13,138 to know when the countdown should show 15130 08:17:13,138 --> 08:17:15,360 up and as usual let's use some nice 15131 08:17:15,360 --> 08:17:17,580 events so over here on the kitchen game 15132 08:17:17,580 --> 08:17:19,740 manager let's fire an event whenever the 15133 08:17:19,740 --> 08:17:20,940 state changes 15134 08:17:20,940 --> 08:17:25,260 so a public event event handler 15135 08:17:25,260 --> 08:17:28,080 let's call it on stay changed 15136 08:17:28,080 --> 08:17:30,298 okay just like this no need for the 15137 08:17:30,298 --> 08:17:32,820 arguments so let's go down here whenever 15138 08:17:32,820 --> 08:17:34,320 the state changes and let's just invoke 15139 08:17:34,320 --> 08:17:36,898 this event so invoke this eventar is 15140 08:17:36,898 --> 08:17:38,280 that empty 15141 08:17:38,280 --> 08:17:40,320 so we change in there change in there 15142 08:17:40,320 --> 08:17:42,718 and change down there okay that's it so 15143 08:17:42,718 --> 08:17:43,860 now over here on the game start 15144 08:17:43,860 --> 08:17:45,660 countdown let's see we've probably start 15145 08:17:45,660 --> 08:17:47,340 and on start let's go into the kitchen 15146 08:17:47,340 --> 08:17:49,558 game manager access the instance listen 15147 08:17:49,558 --> 08:17:52,020 to the on say changed event as usual 15148 08:17:52,020 --> 08:17:53,638 write some nice clean codes so let's 15149 08:17:53,638 --> 08:17:56,458 rename this the kitchen game manager 15150 08:17:56,458 --> 08:17:58,440 so when they say changes we basically 15151 08:17:58,440 --> 08:18:00,600 want to show this if we are on the 15152 08:18:00,600 --> 08:18:02,700 countdown to start so let's go here to 15153 08:18:02,700 --> 08:18:04,200 the kitchen game manager and let's make 15154 08:18:04,200 --> 08:18:07,100 another function so public boom is 15155 08:18:07,100 --> 08:18:11,780 countdown to start active 15156 08:18:12,360 --> 08:18:15,958 and we just return if the state 15157 08:18:15,958 --> 08:18:18,660 equals the state DOT countdown to start 15158 08:18:18,660 --> 08:18:20,580 okay so that's a nice simple function 15159 08:18:20,580 --> 08:18:23,340 and on the UI script if the kitchen game 15160 08:18:23,340 --> 08:18:25,260 manager 15161 08:18:25,260 --> 08:18:27,540 if this one dot is countdown to start 15162 08:18:27,540 --> 08:18:29,458 active 15163 08:18:29,458 --> 08:18:31,798 if so then let's show if not then let's 15164 08:18:31,798 --> 08:18:33,360 hide so else 15165 08:18:33,360 --> 08:18:35,760 let's do a hide 15166 08:18:35,760 --> 08:18:37,440 so let's make these functions so proud 15167 08:18:37,440 --> 08:18:39,000 void show 15168 08:18:39,000 --> 08:18:41,700 and a private void hide and on this 15169 08:18:41,700 --> 08:18:43,200 let's just do the usual thing so game 15170 08:18:43,200 --> 08:18:45,840 objects and active into true or over 15171 08:18:45,840 --> 08:18:48,360 here set it into false and on start 15172 08:18:48,360 --> 08:18:49,860 right after we subscribe to the event 15173 08:18:49,860 --> 08:18:52,440 let's also hide it by default okay so 15174 08:18:52,440 --> 08:18:54,120 that's the basic logic for showing or 15175 08:18:54,120 --> 08:18:56,600 hiding it and now for the timer text 15176 08:18:56,600 --> 08:18:59,040 technically over here once inside the 15177 08:18:59,040 --> 08:19:00,718 countdown to start we could fire an 15178 08:19:00,718 --> 08:19:02,878 event on every single update that would 15179 08:19:02,878 --> 08:19:04,620 work but it would have some unnecessary 15180 08:19:04,620 --> 08:19:05,760 overhead 15181 08:19:05,760 --> 08:19:07,920 so instead another option is just make a 15182 08:19:07,920 --> 08:19:10,200 function to expose it so let's go here 15183 08:19:10,200 --> 08:19:12,540 make a public returning float get the 15184 08:19:12,540 --> 08:19:15,718 countdown to start timer 15185 08:19:15,718 --> 08:19:17,580 and we just return the countdown to 15186 08:19:17,580 --> 08:19:19,680 start timer very simple so then over 15187 08:19:19,680 --> 08:19:22,260 here on the UI script we can just make a 15188 08:19:22,260 --> 08:19:25,080 regular proud void update and on update 15189 08:19:25,080 --> 08:19:27,058 go into the countdown text in order to 15190 08:19:27,058 --> 08:19:28,440 set the text 15191 08:19:28,440 --> 08:19:30,000 and let's go into the kitchen game 15192 08:19:30,000 --> 08:19:32,760 manager and let's get the countdown to 15193 08:19:32,760 --> 08:19:35,878 start timer and just do A2 string okay 15194 08:19:35,878 --> 08:19:37,620 so that's it super simple so on update 15195 08:19:37,620 --> 08:19:39,000 we're going to constantly update the 15196 08:19:39,000 --> 08:19:41,160 timer so let's see if this works 15197 08:19:41,160 --> 08:19:42,958 back here in the editor let's just make 15198 08:19:42,958 --> 08:19:44,160 sure to drag the countdown text 15199 08:19:44,160 --> 08:19:46,558 reference and let's hit on play and okay 15200 08:19:46,558 --> 08:19:48,180 waiting to start and after a bit yep 15201 08:19:48,180 --> 08:19:49,620 there you go there's the number it's 15202 08:19:49,620 --> 08:19:51,058 currently on countdown and now the game 15203 08:19:51,058 --> 08:19:52,860 is playing so the show and high did work 15204 08:19:52,860 --> 08:19:54,478 on the number seem quite a bit odd 15205 08:19:54,478 --> 08:19:56,820 that's because over here on the settings 15206 08:19:56,820 --> 08:19:58,680 we have wrapping enamel so now I just 15207 08:19:58,680 --> 08:20:00,180 quickly disable this and let's test 15208 08:20:00,180 --> 08:20:01,138 again 15209 08:20:01,138 --> 08:20:02,878 sir we are waiting to start and there 15210 08:20:02,878 --> 08:20:04,680 you go there's our countdown three two 15211 08:20:04,680 --> 08:20:07,020 one zero and there you go gameplay 15212 08:20:07,020 --> 08:20:10,080 okay so it did work now of course as it 15213 08:20:10,080 --> 08:20:11,700 comes to the visuals it depends on what 15214 08:20:11,700 --> 08:20:12,540 you want 15215 08:20:12,540 --> 08:20:14,458 for example if you want to limit the 15216 08:20:14,458 --> 08:20:16,200 decimals you can use over here the two 15217 08:20:16,200 --> 08:20:18,600 string this one can include all kinds of 15218 08:20:18,600 --> 08:20:20,760 string formats for example for 15219 08:20:20,760 --> 08:20:22,860 displaying just two decimal places you 15220 08:20:22,860 --> 08:20:25,440 can add the string format F2 15221 08:20:25,440 --> 08:20:27,660 let's see what this looks like waiting 15222 08:20:27,660 --> 08:20:29,160 for the countdown and there you go now 15223 08:20:29,160 --> 08:20:31,320 it does Show with two decimals okay so 15224 08:20:31,320 --> 08:20:33,540 this is one approach alternatively 15225 08:20:33,540 --> 08:20:35,820 another format you can use is 15226 08:20:35,820 --> 08:20:38,700 number sign Point number number and 15227 08:20:38,700 --> 08:20:40,500 let's see this one 15228 08:20:40,500 --> 08:20:42,780 and yep there you go now it looks like 15229 08:20:42,780 --> 08:20:43,500 this 15230 08:20:43,500 --> 08:20:45,120 so as you can see there's lots of things 15231 08:20:45,120 --> 08:20:46,920 you can play around with when it comes 15232 08:20:46,920 --> 08:20:49,138 to the two string formats but in our 15233 08:20:49,138 --> 08:20:51,058 case I don't really want any decimals I 15234 08:20:51,058 --> 08:20:53,160 really just want to see whole numbers so 15235 08:20:53,160 --> 08:20:54,718 for that let's just seal out this number 15236 08:20:54,718 --> 08:20:57,000 so in mathf.cl 15237 08:20:57,000 --> 08:20:59,638 let's see on this one out and then just 15238 08:20:59,638 --> 08:21:02,760 do a two string okay let's see 15239 08:21:02,760 --> 08:21:05,760 so wait a bit and we got three two and 15240 08:21:05,760 --> 08:21:07,798 one and there you go the game is winning 15241 08:21:07,798 --> 08:21:10,440 alright awesome so here we have our 15242 08:21:10,440 --> 08:21:12,478 waiting to start and the countdown to 15243 08:21:12,478 --> 08:21:13,978 start all of that logic is working 15244 08:21:13,978 --> 08:21:16,320 perfectly now the next thing we need is 15245 08:21:16,320 --> 08:21:18,298 to handle the game end so let's do that 15246 08:21:18,298 --> 08:21:21,120 in the next lecture 15247 08:21:21,120 --> 08:21:22,978 hello and welcome I'm your code monkey 15248 08:21:22,978 --> 08:21:24,898 in this lecture we're going to handle 15249 08:21:24,898 --> 08:21:27,000 the game over State now for the game 15250 08:21:27,000 --> 08:21:28,500 over State this is obviously a game 15251 08:21:28,500 --> 08:21:30,360 design question for example you can make 15252 08:21:30,360 --> 08:21:32,160 it so that each recipe had a timer 15253 08:21:32,160 --> 08:21:33,840 attached to it and the player had to 15254 08:21:33,840 --> 08:21:35,340 create that recipe within time limit 15255 08:21:35,340 --> 08:21:37,978 then if they failed enough recipes you 15256 08:21:37,978 --> 08:21:40,080 could trigger some kind of game over or 15257 08:21:40,080 --> 08:21:41,520 for something more simple let's just do 15258 08:21:41,520 --> 08:21:43,798 exactly what we did for the game start 15259 08:21:43,798 --> 08:21:46,798 let's just do a basic countdown timer 15260 08:21:46,798 --> 08:21:48,780 after the game is over let's pop up a 15261 08:21:48,780 --> 08:21:50,458 game over window and show how many 15262 08:21:50,458 --> 08:21:51,958 recipes the players delivered so let's 15263 08:21:51,958 --> 08:21:54,478 do that let's go into our canvas and 15264 08:21:54,478 --> 08:21:56,638 inside make an empty game object call it 15265 08:21:56,638 --> 08:21:59,580 the game over UI then over here let's 15266 08:21:59,580 --> 08:22:01,378 stretch it to occupy the entire parent 15267 08:22:01,378 --> 08:22:04,500 like this now inside let's begin by 15268 08:22:04,500 --> 08:22:06,780 making a UI image this is going to be 15269 08:22:06,780 --> 08:22:09,298 the background let's put it in black 15270 08:22:09,298 --> 08:22:11,040 with just a little bit of transparency 15271 08:22:11,040 --> 08:22:13,620 and let's also stretches to occupy the 15272 08:22:13,620 --> 08:22:14,700 entire thing 15273 08:22:14,700 --> 08:22:17,700 so just like this then let's make some 15274 08:22:17,700 --> 08:22:20,638 text so let's make a new UI text click 15275 08:22:20,638 --> 08:22:22,260 the game over text 15276 08:22:22,260 --> 08:22:24,898 and let's say just game over 15277 08:22:24,898 --> 08:22:27,000 let's set the width and height both at 15278 08:22:27,000 --> 08:22:29,940 zero then down here disable wrapping put 15279 08:22:29,940 --> 08:22:32,458 it centered let's put it pretty big so 15280 08:22:32,458 --> 08:22:35,638 maybe 135 put it a little bit higher 15281 08:22:35,638 --> 08:22:38,820 then for some more text let's duplicate 15282 08:22:38,820 --> 08:22:41,040 this let's call this the enlay bone 15283 08:22:41,040 --> 08:22:44,340 recipes delivered text and over here we 15284 08:22:44,340 --> 08:22:46,558 just say recipes 15285 08:22:46,558 --> 08:22:48,298 delivered 15286 08:22:48,298 --> 08:22:50,458 let's put this one a bit lower and quite 15287 08:22:50,458 --> 08:22:51,660 a bit smaller 15288 08:22:51,660 --> 08:22:54,780 say on 50 okay and also on this one 15289 08:22:54,780 --> 08:22:56,458 let's put it in bold then change the 15290 08:22:56,458 --> 08:22:59,458 color a little bit okay next let's make 15291 08:22:59,458 --> 08:23:01,500 yet another text this one is going to be 15292 08:23:01,500 --> 08:23:03,360 for the final number so let's call this 15293 08:23:03,360 --> 08:23:06,000 recipes don't deliver text 15294 08:23:06,000 --> 08:23:07,740 and this one is just going to have 15295 08:23:07,740 --> 08:23:09,000 whatever number of recipes we've 15296 08:23:09,000 --> 08:23:10,680 delivered and let's put it over here and 15297 08:23:10,680 --> 08:23:12,840 quite a bit bigger okay so this is the 15298 08:23:12,840 --> 08:23:15,120 game over window that we want also a 15299 08:23:15,120 --> 08:23:16,620 quick note like I mentioned previously 15300 08:23:16,620 --> 08:23:18,780 the Sorting order over here on the UI is 15301 08:23:18,780 --> 08:23:21,058 based on the ordering the hierarchy so 15302 08:23:21,058 --> 08:23:23,160 for the game over we want this one to 15303 08:23:23,160 --> 08:23:24,958 show up on top of everything else so 15304 08:23:24,958 --> 08:23:26,398 make sure the game over it is the last 15305 08:23:26,398 --> 08:23:28,500 one over here on the UI make sure it is 15306 08:23:28,500 --> 08:23:31,320 the bottom most child on the canvas okay 15307 08:23:31,320 --> 08:23:33,360 now let's make a game object to run this 15308 08:23:33,360 --> 08:23:36,360 so let's create a brand new script game 15309 08:23:36,360 --> 08:23:39,120 over UI let's go into the object wait 15310 08:23:39,120 --> 08:23:41,280 for the compilation and let's drag the 15311 08:23:41,280 --> 08:23:43,378 script okay now here the only reference 15312 08:23:43,378 --> 08:23:45,120 that we need is just for the text so 15313 08:23:45,120 --> 08:23:47,700 let's just make a serialized film of 15314 08:23:47,700 --> 08:23:50,940 type text mesh Pro ugly for the recipes 15315 08:23:50,940 --> 08:23:53,580 delivered text here in the editor let's 15316 08:23:53,580 --> 08:23:56,040 just drag the reference okay now let's 15317 08:23:56,040 --> 08:23:58,740 make some show and height functions and 15318 08:23:58,740 --> 08:24:00,478 also show it just on the game over so 15319 08:24:00,478 --> 08:24:01,860 really we're going to do the exact same 15320 08:24:01,860 --> 08:24:03,478 thing that we did over here on the game 15321 08:24:03,478 --> 08:24:05,760 start countdown so let's actually copy 15322 08:24:05,760 --> 08:24:07,860 exactly this let's go into game over UI 15323 08:24:07,860 --> 08:24:10,440 pass the exact same thing Okay so we've 15324 08:24:10,440 --> 08:24:12,298 got the show and hide functions we test 15325 08:24:12,298 --> 08:24:14,160 and then over here on the state change 15326 08:24:14,160 --> 08:24:15,898 instead of showing this one on the 15327 08:24:15,898 --> 08:24:17,280 countdown we want to show it on the game 15328 08:24:17,280 --> 08:24:18,120 over 15329 08:24:18,120 --> 08:24:19,620 so let's go over here and just make 15330 08:24:19,620 --> 08:24:22,680 another function so public goal is game 15331 08:24:22,680 --> 08:24:26,340 over and we just return if the state 15332 08:24:26,340 --> 08:24:28,500 equals the state that game over okay 15333 08:24:28,500 --> 08:24:30,000 that's a function 15334 08:24:30,000 --> 08:24:32,580 so over here if we are is State game 15335 08:24:32,580 --> 08:24:33,898 over 15336 08:24:33,898 --> 08:24:36,540 if so then we show if not we hide okay 15337 08:24:36,540 --> 08:24:38,280 the last thing we need is just for the 15338 08:24:38,280 --> 08:24:39,840 text so this is going to be the recipes 15339 08:24:39,840 --> 08:24:42,540 only vertex so we're going to set this 15340 08:24:42,540 --> 08:24:43,798 to something 15341 08:24:43,798 --> 08:24:45,360 which really means that we just need to 15342 08:24:45,360 --> 08:24:46,920 keep track of all of the recipes that 15343 08:24:46,920 --> 08:24:49,138 have been delivered so until here onto 15344 08:24:49,138 --> 08:24:51,360 the delivery manager script and let's 15345 08:24:51,360 --> 08:24:53,458 just keep track so just a simple end so 15346 08:24:53,458 --> 08:24:56,340 a private end for the successful recipes 15347 08:24:56,340 --> 08:24:58,620 amount 15348 08:24:58,620 --> 08:25:00,478 and then whenever we have a recipe 15349 08:25:00,478 --> 08:25:01,978 success so let's go here into our 15350 08:25:01,978 --> 08:25:04,260 delivery recipe function whenever we 15351 08:25:04,260 --> 08:25:06,058 have a success let's just increase this 15352 08:25:06,058 --> 08:25:08,520 by one okay so that's it now we just 15353 08:25:08,520 --> 08:25:10,500 need a function to expose this so we 15354 08:25:10,500 --> 08:25:12,298 probably can't for the get the 15355 08:25:12,298 --> 08:25:14,580 successful recipes amount and just 15356 08:25:14,580 --> 08:25:16,440 return the successful recipes amount 15357 08:25:16,440 --> 08:25:18,958 okay so finally back here on the game 15358 08:25:18,958 --> 08:25:21,420 over UI let's just print it so go into 15359 08:25:21,420 --> 08:25:23,820 the delivery manager xsc static instance 15360 08:25:23,820 --> 08:25:26,100 and get the successful recipes amount 15361 08:25:26,100 --> 08:25:27,898 and of course we need the string so to 15362 08:25:27,898 --> 08:25:30,058 string except for this one this is never 15363 08:25:30,058 --> 08:25:31,440 going to change after the game is 15364 08:25:31,440 --> 08:25:33,180 already over so let's not do this on 15365 08:25:33,180 --> 08:25:34,920 update that would be quite wasteful so 15366 08:25:34,920 --> 08:25:37,080 let's just do it up here so as soon as 15367 08:25:37,080 --> 08:25:38,878 we have the game over we show we print 15368 08:25:38,878 --> 08:25:41,820 the recipes and that's it okay so let's 15369 08:25:41,820 --> 08:25:43,978 test so here we are waiting for the 15370 08:25:43,978 --> 08:25:47,580 timer and let's wait and just wait five 15371 08:25:47,580 --> 08:25:49,320 seconds for it to finish and we should 15372 08:25:49,320 --> 08:25:51,540 see a zero so let's just make sure that 15373 08:25:51,540 --> 08:25:54,540 works so after a little bit of time yep 15374 08:25:54,540 --> 08:25:55,860 there you go we've got recipes all over 15375 08:25:55,860 --> 08:25:57,478 zero okay 15376 08:25:57,478 --> 08:25:59,100 now back here again let's try and 15377 08:25:59,100 --> 08:26:00,540 deliver some recipes now so let's try 15378 08:26:00,540 --> 08:26:02,700 and make a cheeseburger try it only for 15379 08:26:02,700 --> 08:26:03,660 that 15380 08:26:03,660 --> 08:26:06,000 cut this one pick up this one 15381 08:26:06,000 --> 08:26:08,340 pick it up put it in there 15382 08:26:08,340 --> 08:26:11,638 and okay quickly all right good and 15383 08:26:11,638 --> 08:26:13,080 there you go we've got a one all right 15384 08:26:13,080 --> 08:26:15,540 Awesome everything worked perfectly 15385 08:26:15,540 --> 08:26:17,520 let's just add one more final element 15386 08:26:17,520 --> 08:26:19,620 right now we cannot see what is the time 15387 08:26:19,620 --> 08:26:21,600 left in the game so let's add a nice 15388 08:26:21,600 --> 08:26:23,218 lock element 15389 08:26:23,218 --> 08:26:24,958 so over here on the canvas let's make 15390 08:26:24,958 --> 08:26:26,820 another empty game object 15391 08:26:26,820 --> 08:26:29,820 let's name this the game playing clock 15392 08:26:29,820 --> 08:26:31,320 UI 15393 08:26:31,320 --> 08:26:33,360 and let's also put it behind the game 15394 08:26:33,360 --> 08:26:34,978 over UI so let's put it above on the 15395 08:26:34,978 --> 08:26:37,138 hierarchy so that it shows up behind in 15396 08:26:37,138 --> 08:26:38,340 order to be able to see what we're doing 15397 08:26:38,340 --> 08:26:40,200 let's also just hide the game over UI 15398 08:26:40,200 --> 08:26:41,520 but only here on scene view so let's 15399 08:26:41,520 --> 08:26:44,218 click on the I icon okay so here we have 15400 08:26:44,218 --> 08:26:46,440 our window let's just anchor it on the 15401 08:26:46,440 --> 08:26:49,020 upper right corner so let's put it 15402 08:26:49,020 --> 08:26:51,718 somewhere in there then inside let's 15403 08:26:51,718 --> 08:26:54,360 create a new UI image come with the 15404 08:26:54,360 --> 08:26:56,940 background for the Sprite 15405 08:26:56,940 --> 08:26:58,740 let's go with these circles right so 15406 08:26:58,740 --> 08:27:00,540 let's click on the eye icon to show all 15407 08:27:00,540 --> 08:27:02,280 the default Sprites and let's use the 15408 08:27:02,280 --> 08:27:04,200 one included with the circle 15409 08:27:04,200 --> 08:27:06,298 so you have this one let's also add a 15410 08:27:06,298 --> 08:27:09,000 nice little outline so let's put it on 2 15411 08:27:09,000 --> 08:27:12,840 2 with phone Alpha and let's also add a 15412 08:27:12,840 --> 08:27:15,360 nice shadow just nice visual so on five 15413 08:27:15,360 --> 08:27:17,520 minus five like that and for the color 15414 08:27:17,520 --> 08:27:19,558 let's also put it some kind of dark gray 15415 08:27:19,558 --> 08:27:22,320 okay so this is our background now let's 15416 08:27:22,320 --> 08:27:24,360 duplicate this so Ctrl d 15417 08:27:24,360 --> 08:27:26,340 and let's rename this one the timer 15418 08:27:26,340 --> 08:27:28,860 image and for this one let's give it a 15419 08:27:28,860 --> 08:27:30,420 different color so maybe something like 15420 08:27:30,420 --> 08:27:33,360 a blue so something like this okay and 15421 08:27:33,360 --> 08:27:34,978 now over here on the image type instead 15422 08:27:34,978 --> 08:27:37,260 of simple let's go with filmed let's 15423 08:27:37,260 --> 08:27:39,898 choose Radeon 360. okay great and now 15424 08:27:39,898 --> 08:27:41,458 over here we can play around the film 15425 08:27:41,458 --> 08:27:43,620 Mount and this will be our timer then 15426 08:27:43,620 --> 08:27:45,478 you can set it up however you want for 15427 08:27:45,478 --> 08:27:47,100 me I'm going to choose to start from the 15428 08:27:47,100 --> 08:27:49,320 top so as it starts the time we're going 15429 08:27:49,320 --> 08:27:51,600 to countdown Until the End okay so 15430 08:27:51,600 --> 08:27:53,700 that's great now let's make the script 15431 08:27:53,700 --> 08:27:55,680 to run this so let's create the brand 15432 08:27:55,680 --> 08:27:57,660 new c-sharp script same thing the game 15433 08:27:57,660 --> 08:28:00,660 playing clock UI and over here let's 15434 08:28:00,660 --> 08:28:02,940 just attach a script so now all we need 15435 08:28:02,940 --> 08:28:04,860 is reference to our image 15436 08:28:04,860 --> 08:28:08,218 so let's make a serialized field 15437 08:28:08,218 --> 08:28:10,200 private image let's make sure to use 15438 08:28:10,200 --> 08:28:11,760 this one the image inside Unity 15439 08:28:11,760 --> 08:28:14,638 engine.ui this is going to be our timer 15440 08:28:14,638 --> 08:28:17,760 image okay like this back here in the 15441 08:28:17,760 --> 08:28:19,440 editor let's drag the reference all 15442 08:28:19,440 --> 08:28:21,840 right now that we have this we need to 15443 08:28:21,840 --> 08:28:23,580 ask the game manager to get the timer 15444 08:28:23,580 --> 08:28:25,798 normalized so let's go over here onto 15445 08:28:25,798 --> 08:28:27,540 the kitchen game manager and let's make 15446 08:28:27,540 --> 08:28:29,580 a function to return just that so a 15447 08:28:29,580 --> 08:28:32,580 public float let's call it get plane 15448 08:28:32,580 --> 08:28:35,700 timer normalized or game point timer 15449 08:28:35,700 --> 08:28:38,218 actually just to match the state 15450 08:28:38,218 --> 08:28:41,398 so get this one and up here we have the 15451 08:28:41,398 --> 08:28:42,958 playing timer we just need to define a 15452 08:28:42,958 --> 08:28:44,638 maximum in order to be able to calculate 15453 08:28:44,638 --> 08:28:46,920 the normalized value so let's duplicate 15454 08:28:46,920 --> 08:28:49,558 this call it the game timer Max and set 15455 08:28:49,558 --> 08:28:51,600 this one to 10 and this one leave it 15456 08:28:51,600 --> 08:28:52,620 like this 15457 08:28:52,620 --> 08:28:54,540 and down here when we change the timer 15458 08:28:54,540 --> 08:28:56,638 when we go into game pointing let's set 15459 08:28:56,638 --> 08:28:59,218 this one equals this.mex that way we 15460 08:28:59,218 --> 08:29:01,378 only Define the timer just up here okay 15461 08:29:01,378 --> 08:29:03,240 so with that now down here we can do the 15462 08:29:03,240 --> 08:29:05,820 compilation so we can return the game 15463 08:29:05,820 --> 08:29:07,440 playing timer divided by the game 15464 08:29:07,440 --> 08:29:09,000 playing timer Max 15465 08:29:09,000 --> 08:29:10,680 except just like this going to be 15466 08:29:10,680 --> 08:29:12,660 inverted because for the game playing 15467 08:29:12,660 --> 08:29:14,700 timer we're counting down instead of 15468 08:29:14,700 --> 08:29:16,920 counting up so all we need to do is our 15469 08:29:16,920 --> 08:29:19,260 simple just reverses so just one minus 15470 08:29:19,260 --> 08:29:21,600 just like this okay great so we have 15471 08:29:21,600 --> 08:29:23,700 this function and then over here on the 15472 08:29:23,700 --> 08:29:26,160 clock just go private void update and on 15473 08:29:26,160 --> 08:29:27,780 update let's go into the kitchen game 15474 08:29:27,780 --> 08:29:29,940 manager the instance let's get that and 15475 08:29:29,940 --> 08:29:31,458 we're going to use that on the timer 15476 08:29:31,458 --> 08:29:34,080 image.fillment okay that's it super 15477 08:29:34,080 --> 08:29:36,718 simple let's see okay here we are on the 15478 08:29:36,718 --> 08:29:38,520 waiting to start all right waiting and 15479 08:29:38,520 --> 08:29:40,020 as soon as we start if there you go 15480 08:29:40,020 --> 08:29:42,180 there's the timer going and we can see 15481 08:29:42,180 --> 08:29:43,920 it constantly increasing 15482 08:29:43,920 --> 08:29:46,798 so it's at the halfway point 15483 08:29:46,798 --> 08:29:49,440 and just a little bit more 15484 08:29:49,440 --> 08:29:51,298 and there you go yep we've got the time 15485 08:29:51,298 --> 08:29:53,520 over and we have our game over 15486 08:29:53,520 --> 08:29:56,218 all right awesome so over here we 15487 08:29:56,218 --> 08:29:57,840 implemented a really nice game over 15488 08:29:57,840 --> 08:30:00,240 Saint we have a playing timer with an 15489 08:30:00,240 --> 08:30:02,458 icui element and when it ends we get a 15490 08:30:02,458 --> 08:30:03,958 game over window showing you a bunch of 15491 08:30:03,958 --> 08:30:06,298 stats now with this working the next 15492 08:30:06,298 --> 08:30:08,100 task is to have some kind of main menu 15493 08:30:08,100 --> 08:30:10,020 so we can play again after the game is 15494 08:30:10,020 --> 08:30:11,820 done so let's do that in the next 15495 08:30:11,820 --> 08:30:13,860 lecture 15496 08:30:13,860 --> 08:30:15,840 hello and welcome I'm your code monkey 15497 08:30:15,840 --> 08:30:18,120 in this lecture we're going to make a 15498 08:30:18,120 --> 08:30:20,160 super simple main menu and downloading 15499 08:30:20,160 --> 08:30:22,740 system okay so every game needs a main 15500 08:30:22,740 --> 08:30:25,260 menu so let's build one let's begin by 15501 08:30:25,260 --> 08:30:26,638 making the scene so let's go into our 15502 08:30:26,638 --> 08:30:29,280 scenes and create a brand new scene call 15503 08:30:29,280 --> 08:30:31,378 this the main menu scene 15504 08:30:31,378 --> 08:30:33,840 and okay here's our default scene now 15505 08:30:33,840 --> 08:30:35,218 over here for the most part you really 15506 08:30:35,218 --> 08:30:36,718 just want some basic buttons so nothing 15507 08:30:36,718 --> 08:30:39,058 too special so let's create a brand new 15508 08:30:39,058 --> 08:30:41,760 UI canvas and let's set up as usual so 15509 08:30:41,760 --> 08:30:43,860 screen space overlay yep then let's go 15510 08:30:43,860 --> 08:30:47,360 with scale with screen size 1920 by 1080 15511 08:30:47,360 --> 08:30:50,340 and let's match with the height okay so 15512 08:30:50,340 --> 08:30:53,040 there's our canvas now inside let's make 15513 08:30:53,040 --> 08:30:55,020 an empty game object name this the main 15514 08:30:55,020 --> 08:30:58,080 menu UI let's stretch it to occupy the 15515 08:30:58,080 --> 08:30:59,940 entire thing so zero zero on everything 15516 08:30:59,940 --> 08:31:00,958 okay 15517 08:31:00,958 --> 08:31:03,780 now inside let's create a brand new UI 15518 08:31:03,780 --> 08:31:06,740 button let's name this the play button 15519 08:31:06,740 --> 08:31:09,860 then inside for the text let's say play 15520 08:31:09,860 --> 08:31:12,420 Let's size the button to be quite a bit 15521 08:31:12,420 --> 08:31:15,478 bigger so let's say 450 by 150 and on 15522 08:31:15,478 --> 08:31:17,760 the text itself let's put it in bold 15523 08:31:17,760 --> 08:31:19,920 only font size quite a bit bigger let's 15524 08:31:19,920 --> 08:31:22,320 say 70 then let's also change the color 15525 08:31:22,320 --> 08:31:24,240 let's put the text in White and the play 15526 08:31:24,240 --> 08:31:26,218 button over here the normal color for 15527 08:31:26,218 --> 08:31:27,898 the image let's put it on a dark gray 15528 08:31:27,898 --> 08:31:29,940 then also over here on the button 15529 08:31:29,940 --> 08:31:32,100 background let's add a nice outline 15530 08:31:32,100 --> 08:31:34,680 let's put it on foam black say something 15531 08:31:34,680 --> 08:31:37,260 like three three then let's make a 15532 08:31:37,260 --> 08:31:39,420 Shadow and for this one five minus five 15533 08:31:39,420 --> 08:31:42,180 okay so that's our basic button let's 15534 08:31:42,180 --> 08:31:43,978 just anchor the button so choose the 15535 08:31:43,978 --> 08:31:45,840 play button let's anchor it on the lower 15536 08:31:45,840 --> 08:31:48,958 left corner and let's push it just a bit 15537 08:31:48,958 --> 08:31:51,540 like this okay pre-symbal now let's 15538 08:31:51,540 --> 08:31:53,340 duplicate this one push it a bit lower 15539 08:31:53,340 --> 08:31:55,440 let's also make it just a tiny bit 15540 08:31:55,440 --> 08:31:58,320 smaller so just 120 this is going to be 15541 08:31:58,320 --> 08:32:00,058 our quit button so let's rename this to 15542 08:32:00,058 --> 08:32:02,820 the quit button and inside for the text 15543 08:32:02,820 --> 08:32:05,580 just say quit and put a bit more on the 15544 08:32:05,580 --> 08:32:08,520 font size okay like this okay so we have 15545 08:32:08,520 --> 08:32:10,138 the two basic buttons that we need now 15546 08:32:10,138 --> 08:32:12,478 let's make this crypto random so let's 15547 08:32:12,478 --> 08:32:14,100 make script with the same name so main 15548 08:32:14,100 --> 08:32:16,680 menu UI so let's go into our script UI 15549 08:32:16,680 --> 08:32:18,718 folder create new script for the main 15550 08:32:18,718 --> 08:32:21,540 menu UI let's attach the script and open 15551 08:32:21,540 --> 08:32:23,878 okay so now here let's begin by making 15552 08:32:23,878 --> 08:32:26,218 serialized films for our buttons so it's 15553 08:32:26,218 --> 08:32:28,378 always film private of type button 15554 08:32:28,378 --> 08:32:31,260 inside Unity engine.ei this is the play 15555 08:32:31,260 --> 08:32:33,240 button and then we have another one for 15556 08:32:33,240 --> 08:32:35,700 the quit button okay back in the editor 15557 08:32:35,700 --> 08:32:37,320 let's drag the references so that's the 15558 08:32:37,320 --> 08:32:39,958 only button and the quit button okay now 15559 08:32:39,958 --> 08:32:41,340 here in the code let's add some 15560 08:32:41,340 --> 08:32:43,080 listeners to these buttons and let's do 15561 08:32:43,080 --> 08:32:44,580 a private way to wake and on the way 15562 08:32:44,580 --> 08:32:46,558 let's go into the play button and going 15563 08:32:46,558 --> 08:32:49,138 to the on click event so the event when 15564 08:32:49,138 --> 08:32:51,420 the player clicks on the button and 15565 08:32:51,420 --> 08:32:53,580 let's add in listener and now we pass in 15566 08:32:53,580 --> 08:32:55,798 The Listener now for here to do this we 15567 08:32:55,798 --> 08:32:57,660 can add a function so we can make a 15568 08:32:57,660 --> 08:33:00,600 private void Play Click we can define a 15569 08:33:00,600 --> 08:33:02,040 function kind of like this and over here 15570 08:33:02,040 --> 08:33:04,020 add it as The Listener so that's one 15571 08:33:04,020 --> 08:33:05,940 approach or another alternative that 15572 08:33:05,940 --> 08:33:07,920 personally I like to use is to use what 15573 08:33:07,920 --> 08:33:10,260 is called a Lambda expression so instead 15574 08:33:10,260 --> 08:33:11,700 of defining an external function down 15575 08:33:11,700 --> 08:33:13,740 here we just go up here and directly 15576 08:33:13,740 --> 08:33:15,600 with the finding Lambda so we open 15577 08:33:15,600 --> 08:33:18,420 parameters to display the parameters for 15578 08:33:18,420 --> 08:33:19,798 the function which in this case we have 15579 08:33:19,798 --> 08:33:22,320 none so just open and close then we do a 15580 08:33:22,320 --> 08:33:24,600 nice little arrow and then we have 15581 08:33:24,600 --> 08:33:27,298 whatever we want to be our clear code so 15582 08:33:27,298 --> 08:33:29,160 both the code that I have here and one 15583 08:33:29,160 --> 08:33:30,660 that I have here both of these are 15584 08:33:30,660 --> 08:33:32,398 exactly the same thing this one is 15585 08:33:32,398 --> 08:33:34,020 called the unlimited expression which is 15586 08:33:34,020 --> 08:33:36,240 also a type of delegate definitely go 15587 08:33:36,240 --> 08:33:37,860 ahead and watch my video on C sharp 15588 08:33:37,860 --> 08:33:39,840 delicates in detail it's yet another 15589 08:33:39,840 --> 08:33:42,478 extremely powerful c-sharp feature I 15590 08:33:42,478 --> 08:33:44,100 find them especially useful especially 15591 08:33:44,100 --> 08:33:46,080 over here to setting the click listeners 15592 08:33:46,080 --> 08:33:47,940 there's no need to make another function 15593 08:33:47,940 --> 08:33:49,860 just use a Lambda expression that's it 15594 08:33:49,860 --> 08:33:51,478 so over here I'm going to use that 15595 08:33:51,478 --> 08:33:53,458 instead of an external function Okay so 15596 08:33:53,458 --> 08:33:55,500 we've got the play and then let's also 15597 08:33:55,500 --> 08:33:57,298 listen to the equip so on the quit 15598 08:33:57,298 --> 08:33:59,638 button the exact same thing okay now 15599 08:33:59,638 --> 08:34:01,138 first on the equip button it's actually 15600 08:34:01,138 --> 08:34:03,240 very simple we just go into application 15601 08:34:03,240 --> 08:34:05,940 and we call the quit function this will 15602 08:34:05,940 --> 08:34:07,558 quit the game that's it very similar 15603 08:34:07,558 --> 08:34:09,718 although one note if we actually test it 15604 08:34:09,718 --> 08:34:11,580 like this so here is the game playing 15605 08:34:11,580 --> 08:34:13,920 and if I click on quit and nope nothing 15606 08:34:13,920 --> 08:34:15,780 happens now the logic is actually 15607 08:34:15,780 --> 08:34:17,580 working we can see visually that the 15608 08:34:17,580 --> 08:34:19,080 button is changing state so we are 15609 08:34:19,080 --> 08:34:21,478 indeed capturing clicks however when the 15610 08:34:21,478 --> 08:34:22,920 game is running inside the editor 15611 08:34:22,920 --> 08:34:24,058 calling that function the 15612 08:34:24,058 --> 08:34:26,520 application.quit doesn't do anything but 15613 08:34:26,520 --> 08:34:28,320 if this were a phone bill then clicking 15614 08:34:28,320 --> 08:34:29,820 on that would indeed close their game 15615 08:34:29,820 --> 08:34:32,760 okay so now for the play button for this 15616 08:34:32,760 --> 08:34:34,500 one it's also very simple we just need 15617 08:34:34,500 --> 08:34:37,080 to go inside the scene manager which is 15618 08:34:37,080 --> 08:34:38,940 inside the unity engine.scene management 15619 08:34:38,940 --> 08:34:41,040 we just need to go inside of this one 15620 08:34:41,040 --> 08:34:43,680 and we call load scene 15621 08:34:43,680 --> 08:34:45,420 this function will load with a certain 15622 08:34:45,420 --> 08:34:47,940 scene and for loading we can either use 15623 08:34:47,940 --> 08:34:49,798 the scene film index or we can use the 15624 08:34:49,798 --> 08:34:51,718 scene name like I've mentioned several 15625 08:34:51,718 --> 08:34:53,878 times string names are horrible although 15626 08:34:53,878 --> 08:34:55,440 in this case the alternative using an 15627 08:34:55,440 --> 08:34:57,958 INT is also not very good just a number 15628 08:34:57,958 --> 08:35:00,000 is very hard to read the code and being 15629 08:35:00,000 --> 08:35:02,040 able to know what scene this is loading 15630 08:35:02,040 --> 08:35:04,200 so there's one better approach that I 15631 08:35:04,200 --> 08:35:05,940 prefer to use but first over here let's 15632 08:35:05,940 --> 08:35:08,458 just use the index just for testing so 15633 08:35:08,458 --> 08:35:10,080 we're going to load the scene on index 15634 08:35:10,080 --> 08:35:13,320 one so just like this and then here in 15635 08:35:13,320 --> 08:35:15,000 the editor and let's go into file and 15636 08:35:15,000 --> 08:35:16,080 build settings 15637 08:35:16,080 --> 08:35:17,760 and over here we see the scenes in our 15638 08:35:17,760 --> 08:35:19,260 build right now we just have the game 15639 08:35:19,260 --> 08:35:21,478 scene so let's just add our scene so 15640 08:35:21,478 --> 08:35:23,160 let's drag the main medicine and drag it 15641 08:35:23,160 --> 08:35:24,780 on there and also let's make sure it's 15642 08:35:24,780 --> 08:35:26,340 on the top of the list basically the 15643 08:35:26,340 --> 08:35:27,478 first scene is the one that won't be 15644 08:35:27,478 --> 08:35:29,458 unloaded as soon as the game starts so 15645 08:35:29,458 --> 08:35:31,440 let's try it right up top just like that 15646 08:35:31,440 --> 08:35:33,240 then over here on the right we see the 15647 08:35:33,240 --> 08:35:35,580 index so by loading the scene on the 15648 08:35:35,580 --> 08:35:36,958 next one we're going to be unloading the 15649 08:35:36,958 --> 08:35:39,180 game scene okay so with the slits test 15650 08:35:39,180 --> 08:35:42,000 so here we are and if I click on playing 15651 08:35:42,000 --> 08:35:43,740 and if there you go it doesn't load the 15652 08:35:43,740 --> 08:35:46,080 main scene okay great everything is 15653 08:35:46,080 --> 08:35:48,360 working so this is the seamless way to 15654 08:35:48,360 --> 08:35:50,398 do scene loading however this method 15655 08:35:50,398 --> 08:35:52,378 does have one issue it's not super 15656 08:35:52,378 --> 08:35:53,820 noticeable when a game of this scale 15657 08:35:53,820 --> 08:35:55,558 because it loads pretty quickly 15658 08:35:55,558 --> 08:35:58,020 but like this note how when we click on 15659 08:35:58,020 --> 08:35:59,878 play there you go everything freezes for 15660 08:35:59,878 --> 08:36:01,260 a little bit while the game is loading 15661 08:36:01,260 --> 08:36:03,000 like I mentioned in this case the freeze 15662 08:36:03,000 --> 08:36:04,680 is so small so not necessarily an issue 15663 08:36:04,680 --> 08:36:06,478 but if the game was much more complex 15664 08:36:06,478 --> 08:36:08,040 then the player would be staring at a 15665 08:36:08,040 --> 08:36:09,780 frozen main menu for perhaps 30 seconds 15666 08:36:09,780 --> 08:36:12,180 that would not be good one way to avoid 15667 08:36:12,180 --> 08:36:13,798 that is actually very simple basically 15668 08:36:13,798 --> 08:36:15,420 it's what I already covered in detail in 15669 08:36:15,420 --> 08:36:17,398 the scene loading video that video was 15670 08:36:17,398 --> 08:36:18,780 made quite a while ago but it's still 15671 08:36:18,780 --> 08:36:20,638 very much up to date here we're going to 15672 08:36:20,638 --> 08:36:22,260 do pretty much the same thing so we 15673 08:36:22,260 --> 08:36:24,180 first create the scene just empty just 15674 08:36:24,180 --> 08:36:26,340 saying loading and then from that scene 15675 08:36:26,340 --> 08:36:28,320 we load the final scene that way the 15676 08:36:28,320 --> 08:36:29,820 game stays Frozen on a scene that says 15677 08:36:29,820 --> 08:36:31,378 loading which is much more clear to the 15678 08:36:31,378 --> 08:36:33,958 player so let's do that first let's make 15679 08:36:33,958 --> 08:36:35,638 our scene so inside our scenes folder 15680 08:36:35,638 --> 08:36:38,218 let's create a brand new scene call this 15681 08:36:38,218 --> 08:36:40,558 the unloading scene okay let's go inside 15682 08:36:40,558 --> 08:36:42,840 and on this one we want this one to be 15683 08:36:42,840 --> 08:36:44,398 fully black so let's go into the main 15684 08:36:44,398 --> 08:36:46,260 camera and scroll down over here under 15685 08:36:46,260 --> 08:36:48,058 environment and instead of rendering the 15686 08:36:48,058 --> 08:36:49,740 Skybox for the background let's go with 15687 08:36:49,740 --> 08:36:51,780 a solid color and let's go with phone 15688 08:36:51,780 --> 08:36:54,478 black okay there's our black main camera 15689 08:36:54,478 --> 08:36:57,660 now let's make a canvas so a new UI 15690 08:36:57,660 --> 08:37:00,540 canvas let's set up as usual so scale 15691 08:37:00,540 --> 08:37:04,200 with screen size 1920 by 1080 and match 15692 08:37:04,200 --> 08:37:06,360 with the height okay then inside let's 15693 08:37:06,360 --> 08:37:08,760 just make a simple text object so just 15694 08:37:08,760 --> 08:37:10,200 say text then over here on let's say 15695 08:37:10,200 --> 08:37:13,160 just loading 15696 08:37:13,440 --> 08:37:15,420 let's put the text width and height on 15697 08:37:15,420 --> 08:37:18,000 zero put it on Bold let's make sure to 15698 08:37:18,000 --> 08:37:19,920 disable wrapping 15699 08:37:19,920 --> 08:37:22,080 and push it over there on the side and 15700 08:37:22,080 --> 08:37:23,398 maybe increase the font size down a 15701 08:37:23,398 --> 08:37:25,440 little bit okay there you go we have our 15702 08:37:25,440 --> 08:37:27,600 very basic loading screen now we're 15703 08:37:27,600 --> 08:37:29,398 going to unload this scene and then once 15704 08:37:29,398 --> 08:37:30,780 on this scene we're going to load the 15705 08:37:30,780 --> 08:37:32,820 final scene although also one very 15706 08:37:32,820 --> 08:37:34,200 important thing related to loading 15707 08:37:34,200 --> 08:37:36,058 scenes is you need to remember the 15708 08:37:36,058 --> 08:37:38,398 lifetime of the objects regular game 15709 08:37:38,398 --> 08:37:39,718 objects only for example the ones that 15710 08:37:39,718 --> 08:37:41,398 we see here in the hierarchy these get 15711 08:37:41,398 --> 08:37:43,378 destroyed when you do a scene change 15712 08:37:43,378 --> 08:37:45,058 so for the goal that we're trying to 15713 08:37:45,058 --> 08:37:47,040 achieve we need to unload this loading 15714 08:37:47,040 --> 08:37:49,378 scene but then also somehow transfer 15715 08:37:49,378 --> 08:37:51,058 data so that the loading scene here 15716 08:37:51,058 --> 08:37:53,340 knows which one is the final scene now 15717 08:37:53,340 --> 08:37:54,420 you might think that over here on the 15718 08:37:54,420 --> 08:37:56,040 main menu we could create a game object 15719 08:37:56,040 --> 08:37:57,600 attach a script that would hone the 15720 08:37:57,600 --> 08:37:59,520 reference to the final scene but like I 15721 08:37:59,520 --> 08:38:01,200 said game objects get destroyed as soon 15722 08:38:01,200 --> 08:38:03,298 as we unload the unloading scene so for 15723 08:38:03,298 --> 08:38:04,920 transferring data between scenes we 15724 08:38:04,920 --> 08:38:06,840 can't really use a regular script on a 15725 08:38:06,840 --> 08:38:09,180 regular game object now one approach is 15726 08:38:09,180 --> 08:38:11,760 to use the don't destroy on loan this is 15727 08:38:11,760 --> 08:38:13,798 a Unity function that helps you stop a 15728 08:38:13,798 --> 08:38:15,420 particular script or a game object from 15729 08:38:15,420 --> 08:38:17,580 being destroyed that way the object 15730 08:38:17,580 --> 08:38:19,378 won't process through scene changes so 15731 08:38:19,378 --> 08:38:21,780 that's one option but another option 15732 08:38:21,780 --> 08:38:24,058 that I prefer is very simple let's just 15733 08:38:24,058 --> 08:38:26,280 make it another class so let's create a 15734 08:38:26,280 --> 08:38:29,218 new c-sharp script call this loader and 15735 08:38:29,218 --> 08:38:30,780 over here let's go ahead and make this 15736 08:38:30,780 --> 08:38:33,120 class a static class and we are not 15737 08:38:33,120 --> 08:38:35,340 going to extend Model Behavior so just 15738 08:38:35,340 --> 08:38:36,420 like this 15739 08:38:36,420 --> 08:38:38,700 basically by making it static it means 15740 08:38:38,700 --> 08:38:40,378 that this one is not attached to any 15741 08:38:40,378 --> 08:38:42,540 specific instance of an object this 15742 08:38:42,540 --> 08:38:44,280 class cannot be attached to any object 15743 08:38:44,280 --> 08:38:45,840 and cannot have any instances 15744 08:38:45,840 --> 08:38:47,700 constructed then inside we can add 15745 08:38:47,700 --> 08:38:49,500 static functions in fields like for 15746 08:38:49,500 --> 08:38:51,840 example a static and for the Target 15747 08:38:51,840 --> 08:38:53,638 scene index 15748 08:38:53,638 --> 08:38:55,620 so now this field we could set this 15749 08:38:55,620 --> 08:38:57,718 field from over here on the main menu UI 15750 08:38:57,718 --> 08:39:00,058 and when we would load we would not be 15751 08:39:00,058 --> 08:39:02,218 resetting this field also here I should 15752 08:39:02,218 --> 08:39:04,500 point out one quick thing you can make 15753 08:39:04,500 --> 08:39:06,360 field static without making the entire 15754 08:39:06,360 --> 08:39:08,638 class itself static making the class 15755 08:39:08,638 --> 08:39:10,740 static is just a good approach if the 15756 08:39:10,740 --> 08:39:12,360 entire thing if everything in this class 15757 08:39:12,360 --> 08:39:14,520 is also meant to be static if you don't 15758 08:39:14,520 --> 08:39:16,320 make it static then you can have regular 15759 08:39:16,320 --> 08:39:18,240 films here 15760 08:39:18,240 --> 08:39:20,398 you can have both static and non-sanic 15761 08:39:20,398 --> 08:39:23,458 whereas if you make this static 15762 08:39:23,458 --> 08:39:24,840 then you're going to have an error 15763 08:39:24,840 --> 08:39:26,340 because you cannot have non-static 15764 08:39:26,340 --> 08:39:28,620 feelings so this is another clean code 15765 08:39:28,620 --> 08:39:30,420 thing if it's only meant to contain 15766 08:39:30,420 --> 08:39:32,398 static logic then make the class itself 15767 08:39:32,398 --> 08:39:34,920 static okay so we have a static field 15768 08:39:34,920 --> 08:39:37,378 for our Target scene but as usual we 15769 08:39:37,378 --> 08:39:39,600 don't want this to be a public field we 15770 08:39:39,600 --> 08:39:41,040 don't want the main menu to directly 15771 08:39:41,040 --> 08:39:43,378 write to this field so let's make this 15772 08:39:43,378 --> 08:39:45,000 class the only one responsible for 15773 08:39:45,000 --> 08:39:46,620 anything related with scene loading 15774 08:39:46,620 --> 08:39:48,958 since then let's make a function so a 15775 08:39:48,958 --> 08:39:51,600 public static void call it load 15776 08:39:51,600 --> 08:39:54,000 and for a printer let's receive a string 15777 08:39:54,000 --> 08:39:56,638 for the Target scene name then over here 15778 08:39:56,638 --> 08:39:57,958 we will load the actual scene so let's 15779 08:39:57,958 --> 08:40:00,240 go into the scene manager and load the 15780 08:40:00,240 --> 08:40:01,680 scene 15781 08:40:01,680 --> 08:40:03,898 analyst best in the Target scene name 15782 08:40:03,898 --> 08:40:05,820 okay that's it 15783 08:40:05,820 --> 08:40:07,440 and then over here on the main menu UI 15784 08:40:07,440 --> 08:40:08,760 instead of directly unloading a scene 15785 08:40:08,760 --> 08:40:11,280 let's go into the loader and con load 15786 08:40:11,280 --> 08:40:13,080 and pass in the scene name so that's the 15787 08:40:13,080 --> 08:40:14,638 game scene 15788 08:40:14,638 --> 08:40:16,138 okay so this is what we're going to do 15789 08:40:16,138 --> 08:40:18,360 that's good except it's obviously not 15790 08:40:18,360 --> 08:40:20,458 good over here we're using string names 15791 08:40:20,458 --> 08:40:22,440 that's horrible we should never use this 15792 08:40:22,440 --> 08:40:24,780 so let's avoid using strings as much as 15793 08:40:24,780 --> 08:40:26,638 possible in one simple way is to just 15794 08:40:26,638 --> 08:40:29,040 Define an enum for all of our scenes so 15795 08:40:29,040 --> 08:40:30,718 let's go here on the other and let's 15796 08:40:30,718 --> 08:40:33,600 define that so a public enum let's call 15797 08:40:33,600 --> 08:40:34,860 it scene 15798 08:40:34,860 --> 08:40:37,020 and for all of our scenes so we have the 15799 08:40:37,020 --> 08:40:39,718 main menu scene then we have the game 15800 08:40:39,718 --> 08:40:42,478 scene and the unloading scene 15801 08:40:42,478 --> 08:40:44,820 okay so then down here on this function 15802 08:40:44,820 --> 08:40:46,978 inside receiving a string we just 15803 08:40:46,978 --> 08:40:49,558 receive a scene for the Target scene and 15804 08:40:49,558 --> 08:40:51,540 we use the target scene although of 15805 08:40:51,540 --> 08:40:53,100 course the NT API does not support 15806 08:40:53,100 --> 08:40:55,378 unloading our custom enum it has to be 15807 08:40:55,378 --> 08:40:57,298 an index or string so the simple 15808 08:40:57,298 --> 08:40:58,920 approach is just to convert this one 15809 08:40:58,920 --> 08:41:00,898 into a string that's it so the only 15810 08:41:00,898 --> 08:41:02,280 thing you need to make sure is that the 15811 08:41:02,280 --> 08:41:04,860 enum values over here match the actual 15812 08:41:04,860 --> 08:41:07,260 name on the actual scenes perfectly so 15813 08:41:07,260 --> 08:41:09,540 don't make any mistakes keep it case 15814 08:41:09,540 --> 08:41:11,040 sensitive so don't do this make sure 15815 08:41:11,040 --> 08:41:13,260 everything matches perfectly okay so 15816 08:41:13,260 --> 08:41:14,580 just like this everything should already 15817 08:41:14,580 --> 08:41:17,100 be working the same as previously so the 15818 08:41:17,100 --> 08:41:19,020 main menu calls that let's actually just 15819 08:41:19,020 --> 08:41:21,240 use that so let's use scene Dot Game 15820 08:41:21,240 --> 08:41:22,138 scene 15821 08:41:22,138 --> 08:41:24,058 so on the main menu we do this and 15822 08:41:24,058 --> 08:41:25,860 unloader we load the scene okay let's 15823 08:41:25,860 --> 08:41:28,080 test here is the main menu and if we 15824 08:41:28,080 --> 08:41:30,240 click and wait a bit and after you go it 15825 08:41:30,240 --> 08:41:32,160 didn't load the game scene okay great so 15826 08:41:32,160 --> 08:41:33,298 everything still works the same as 15827 08:41:33,298 --> 08:41:34,558 presently except now all of the 15828 08:41:34,558 --> 08:41:37,138 unloading logic is inside of this class 15829 08:41:37,138 --> 08:41:39,180 and over here let's open a loading scene 15830 08:41:39,180 --> 08:41:41,040 in the middle basically when we have 15831 08:41:41,040 --> 08:41:42,360 this function to load a final scene 15832 08:41:42,360 --> 08:41:44,940 let's first off set this field so this 15833 08:41:44,940 --> 08:41:46,558 one instead of being type in let's make 15834 08:41:46,558 --> 08:41:48,600 it a type scene and this is going to be 15835 08:41:48,600 --> 08:41:50,638 the target scene and let's make it 15836 08:41:50,638 --> 08:41:52,500 private okay 15837 08:41:52,500 --> 08:41:54,420 so when we have this function let's set 15838 08:41:54,420 --> 08:41:56,638 that field although here remember how 15839 08:41:56,638 --> 08:41:58,320 this is a static class so in order to 15840 08:41:58,320 --> 08:41:59,700 access this field we need to exit 15841 08:41:59,700 --> 08:42:01,558 through the class name because over here 15842 08:42:01,558 --> 08:42:03,240 we also have a local variable with the 15843 08:42:03,240 --> 08:42:05,458 exact same name so what sex is the 15844 08:42:05,458 --> 08:42:07,620 unloader.target scene and set it to the 15845 08:42:07,620 --> 08:42:08,820 Target scene 15846 08:42:08,820 --> 08:42:11,340 so again don't be confused here you can 15847 08:42:11,340 --> 08:42:12,660 even use visual studio and put the 15848 08:42:12,660 --> 08:42:14,218 cursor on top to see what object 15849 08:42:14,218 --> 08:42:15,898 represents what so you can see the 15850 08:42:15,898 --> 08:42:17,520 unloader.target scene is referencing 15851 08:42:17,520 --> 08:42:19,320 this field whereas this one over here is 15852 08:42:19,320 --> 08:42:21,360 referencing the local field so we want 15853 08:42:21,360 --> 08:42:23,040 to assign the member field to the one 15854 08:42:23,040 --> 08:42:25,440 that we received as a parameter okay so 15855 08:42:25,440 --> 08:42:27,180 we store that and then let's immediately 15856 08:42:27,180 --> 08:42:28,920 unload the unloading scene so scene 15857 08:42:28,920 --> 08:42:31,740 manager let's load the scene and we're 15858 08:42:31,740 --> 08:42:33,898 going to load 15859 08:42:33,898 --> 08:42:36,540 the scene dot loading scene dot to 15860 08:42:36,540 --> 08:42:37,860 string okay so we're going to download 15861 08:42:37,860 --> 08:42:40,138 that and now here comes the tricky part 15862 08:42:40,138 --> 08:42:42,540 if we do this so if we load the 15863 08:42:42,540 --> 08:42:43,798 unloading scene and then immediately 15864 08:42:43,798 --> 08:42:45,780 unload the target scene if we didn't 15865 08:42:45,780 --> 08:42:47,638 like this it won't actually show the 15866 08:42:47,638 --> 08:42:48,898 loading scene 15867 08:42:48,898 --> 08:42:50,820 we're calling these functions one right 15868 08:42:50,820 --> 08:42:53,280 after the other so to unload the one and 15869 08:42:53,280 --> 08:42:55,200 immediately the other basically we need 15870 08:42:55,200 --> 08:42:57,120 to wait at least one frame to render so 15871 08:42:57,120 --> 08:42:59,100 that the unloading scene is visible and 15872 08:42:59,100 --> 08:43:01,020 then we can alert the final scene so 15873 08:43:01,020 --> 08:43:02,580 let's make a script to do a very simple 15874 08:43:02,580 --> 08:43:05,100 jump let's create a brand new c-sharp 15875 08:43:05,100 --> 08:43:08,040 script for the unloader comeback and now 15876 08:43:08,040 --> 08:43:10,320 let's go inside the unloading scene so 15877 08:43:10,320 --> 08:43:11,700 this is important let's make this on the 15878 08:43:11,700 --> 08:43:13,260 loading scene not the main menu or the 15879 08:43:13,260 --> 08:43:15,120 game scene so over here let's create an 15880 08:43:15,120 --> 08:43:16,740 empty game object for the unloader 15881 08:43:16,740 --> 08:43:19,320 comeback let's reset transform just keep 15882 08:43:19,320 --> 08:43:21,058 things nice and clean and let's attach a 15883 08:43:21,058 --> 08:43:22,558 script so the only other comeback okay 15884 08:43:22,558 --> 08:43:25,080 and on this script we want to basically 15885 08:43:25,080 --> 08:43:27,360 just wait for the very first update 15886 08:43:27,360 --> 08:43:29,940 so let's see private ball is first 15887 08:43:29,940 --> 08:43:32,580 update and we started off as true 15888 08:43:32,580 --> 08:43:33,660 actually 15889 08:43:33,660 --> 08:43:36,120 so is the first update is true then we 15890 08:43:36,120 --> 08:43:39,058 do a product void update so if it is the 15891 08:43:39,058 --> 08:43:41,520 first update if so then let's set is 15892 08:43:41,520 --> 08:43:43,978 first update to false 15893 08:43:43,978 --> 08:43:46,020 we have the first update although 15894 08:43:46,020 --> 08:43:47,340 technology I should point out that we 15895 08:43:47,340 --> 08:43:49,020 don't really need this we're going to 15896 08:43:49,020 --> 08:43:50,878 load right away so either way it will 15897 08:43:50,878 --> 08:43:53,100 only run One update but still I like to 15898 08:43:53,100 --> 08:43:54,478 add this just to make the logic 15899 08:43:54,478 --> 08:43:56,638 perfectly clear basically if it is the 15900 08:43:56,638 --> 08:43:58,200 first update then let's call a function 15901 08:43:58,200 --> 08:44:00,058 on the unloader so on the loader over 15902 08:44:00,058 --> 08:44:02,100 here let's make a function public static 15903 08:44:02,100 --> 08:44:05,760 void call it below their comeback 15904 08:44:05,760 --> 08:44:07,798 okay we have this function it's over 15905 08:44:07,798 --> 08:44:09,478 here on the other convex let's just go 15906 08:44:09,478 --> 08:44:11,340 into the unloader and call the unloader 15907 08:44:11,340 --> 08:44:13,558 convex function all right so basically 15908 08:44:13,558 --> 08:44:15,058 now here we have this function that is 15909 08:44:15,058 --> 08:44:16,500 going to be triggered on the first 15910 08:44:16,500 --> 08:44:18,240 update so we know for certain the 15911 08:44:18,240 --> 08:44:20,160 unloading scene has been rendered so 15912 08:44:20,160 --> 08:44:21,840 it's over here that we want to load the 15913 08:44:21,840 --> 08:44:24,478 actual final scene okay that's it here 15914 08:44:24,478 --> 08:44:26,160 we have a super simple loading system 15915 08:44:26,160 --> 08:44:28,138 just make perfectly sure that the 15916 08:44:28,138 --> 08:44:29,760 unloader come back with the script this 15917 08:44:29,760 --> 08:44:31,680 one only exists on the loading scene it 15918 08:44:31,680 --> 08:44:33,240 should not be on any of the other ones 15919 08:44:33,240 --> 08:44:35,520 so let's test and for that let's go 15920 08:44:35,520 --> 08:44:37,440 inside the main menu scene okay and now 15921 08:44:37,440 --> 08:44:39,420 let's hit on play okay so here we are on 15922 08:44:39,420 --> 08:44:41,700 main menu now if I click on play and 15923 08:44:41,700 --> 08:44:43,138 actually here's the thing that I forgot 15924 08:44:43,138 --> 08:44:45,180 so make sure you don't forget this we 15925 08:44:45,180 --> 08:44:46,500 need to add the unloading scene to the 15926 08:44:46,500 --> 08:44:48,420 builds in order to be able to load 15927 08:44:48,420 --> 08:44:50,218 so let's go up here into the build 15928 08:44:50,218 --> 08:44:52,080 settings let's go into the project drag 15929 08:44:52,080 --> 08:44:53,940 the unloading scene like that okay so 15930 08:44:53,940 --> 08:44:56,218 now let's test so here we are on the 15931 08:44:56,218 --> 08:44:58,080 main menu let's hit on play and there's 15932 08:44:58,080 --> 08:44:59,820 the loading scene after a bit yep here 15933 08:44:59,820 --> 08:45:01,920 we have our game scene all right awesome 15934 08:45:01,920 --> 08:45:03,958 so with that everything is working 15935 08:45:03,958 --> 08:45:05,878 perfectly all of the logic is working 15936 08:45:05,878 --> 08:45:08,160 great now the wrong words great let's 15937 08:45:08,160 --> 08:45:09,898 just make a nice proper visual for our 15938 08:45:09,898 --> 08:45:12,180 main menu so for that let's go inside 15939 08:45:12,180 --> 08:45:14,580 the game scene and over here let's copy 15940 08:45:14,580 --> 08:45:16,920 a few things so let's pick up the four 15941 08:45:16,920 --> 08:45:19,320 object and let's also pick up the global 15942 08:45:19,320 --> 08:45:21,660 volume with the post pressing so let's 15943 08:45:21,660 --> 08:45:23,700 copy both of these let's go into the 15944 08:45:23,700 --> 08:45:25,558 main menu scene and over here on let's 15945 08:45:25,558 --> 08:45:28,378 paste both objects okay now let's also 15946 08:45:28,378 --> 08:45:30,298 drag some player visuals so let's put 15947 08:45:30,298 --> 08:45:32,280 this in 3D go back down into the floor 15948 08:45:32,280 --> 08:45:34,860 and let's pick up some visuals so let's 15949 08:45:34,860 --> 08:45:36,840 go inside our assets on the prefabs 15950 08:45:36,840 --> 08:45:39,540 visuals let's find over here the player 15951 08:45:39,540 --> 08:45:41,398 visual again make sure you drag the 15952 08:45:41,398 --> 08:45:43,440 visual only we don't want any logic 15953 08:45:43,440 --> 08:45:45,660 components and by the way this is yet 15954 08:45:45,660 --> 08:45:47,280 another great benefit of separating the 15955 08:45:47,280 --> 08:45:49,558 logic from the visuals right now it's 15956 08:45:49,558 --> 08:45:51,240 super simple for us to play some players 15957 08:45:51,240 --> 08:45:53,100 here because we have just the visuals 15958 08:45:53,100 --> 08:45:54,898 commonly separated from the logic okay 15959 08:45:54,898 --> 08:45:56,820 so on the visual let's just make it look 15960 08:45:56,820 --> 08:45:59,218 at the camera let's position a bunch 15961 08:45:59,218 --> 08:46:01,440 more players so let's duplicate this 15962 08:46:01,440 --> 08:46:04,138 and put one to the side we're going to 15963 08:46:04,138 --> 08:46:05,580 move the camera in a bit but now let's 15964 08:46:05,580 --> 08:46:08,160 just place them and included assets 15965 08:46:08,160 --> 08:46:09,958 there are a bunch of materials so over 15966 08:46:09,958 --> 08:46:11,520 here we see the employer body then we've 15967 08:46:11,520 --> 08:46:13,798 got a blue a green and a red like I said 15968 08:46:13,798 --> 08:46:15,420 this first course is on making this game 15969 08:46:15,420 --> 08:46:17,218 in single player but the goal is to then 15970 08:46:17,218 --> 08:46:19,080 make a second course after this one on 15971 08:46:19,080 --> 08:46:21,000 converting this game into multiplier so 15972 08:46:21,000 --> 08:46:23,100 that's why I included multiple colors so 15973 08:46:23,100 --> 08:46:25,620 let's just drag these let's go into this 15974 08:46:25,620 --> 08:46:27,958 player Visual and on this one make it 15975 08:46:27,958 --> 08:46:31,740 blue so on the head and on the body then 15976 08:46:31,740 --> 08:46:33,660 on this one on the side here let's make 15977 08:46:33,660 --> 08:46:36,240 this one green so green there and green 15978 08:46:36,240 --> 08:46:39,058 on the head and for the one behind let's 15979 08:46:39,058 --> 08:46:40,920 make this one the red one so put it in 15980 08:46:40,920 --> 08:46:43,740 red and in red Okay so we've got our 15981 08:46:43,740 --> 08:46:46,020 nice four players now let's also add a 15982 08:46:46,020 --> 08:46:47,340 camera so we're going to have the camera 15983 08:46:47,340 --> 08:46:49,920 kind of like this kind of from below and 15984 08:46:49,920 --> 08:46:51,180 looking upwards I think that looks 15985 08:46:51,180 --> 08:46:52,978 pretty good for that let's use cine 15986 08:46:52,978 --> 08:46:54,420 machines and let's go into game object 15987 08:46:54,420 --> 08:46:57,240 go into cinemachine and let's create a 15988 08:46:57,240 --> 08:46:59,218 brand new version on camera okay unlike 15989 08:46:59,218 --> 08:47:01,378 this let's just push it up a little bit 15990 08:47:01,378 --> 08:47:03,780 okay so this is our nice composition 15991 08:47:03,780 --> 08:47:05,820 now on the virtual camera let's just go 15992 08:47:05,820 --> 08:47:07,680 ahead and add some noise so let's add 15993 08:47:07,680 --> 08:47:10,080 basic multi-channel purlin so let's do 15994 08:47:10,080 --> 08:47:11,398 it just like we did when we first had 15995 08:47:11,398 --> 08:47:13,080 the thin machine so let's use the 15996 08:47:13,080 --> 08:47:15,180 handheld normal mild and now let's just 15997 08:47:15,180 --> 08:47:16,978 play around these films which by the way 15998 08:47:16,978 --> 08:47:18,058 you can do that while the game is 15999 08:47:18,058 --> 08:47:19,978 playing so let's hit on play and over 16000 08:47:19,978 --> 08:47:21,660 here you can play around down the fields 16001 08:47:21,660 --> 08:47:23,638 although actually defaults already look 16002 08:47:23,638 --> 08:47:25,200 pretty good but let's put the frequency 16003 08:47:25,200 --> 08:47:27,120 maybe a little bit less and the 16004 08:47:27,120 --> 08:47:29,580 amplitude maybe a little bit bigger so 16005 08:47:29,580 --> 08:47:31,920 just some nice little Sway and by the 16006 08:47:31,920 --> 08:47:33,420 way if you make any changes to the send 16007 08:47:33,420 --> 08:47:35,398 machine virtual camera and now you stop 16008 08:47:35,398 --> 08:47:36,898 playing it will actually lose those 16009 08:47:36,898 --> 08:47:38,820 changes but over here on the virtual 16010 08:47:38,820 --> 08:47:40,320 camera there's this nice toggle save 16011 08:47:40,320 --> 08:47:42,898 during play so if you tick this and now 16012 08:47:42,898 --> 08:47:45,120 you exit play mode and there you go 16013 08:47:45,120 --> 08:47:47,040 those changes were saved okay great now 16014 08:47:47,040 --> 08:47:48,478 let's just make sure to untick this so 16015 08:47:48,478 --> 08:47:50,580 we don't accidentally modify okay so 16016 08:47:50,580 --> 08:47:52,260 here we have the basic Vision that we 16017 08:47:52,260 --> 08:47:54,718 want finally there's also a game logo in 16018 08:47:54,718 --> 08:47:56,100 the included assets 16019 08:47:56,100 --> 08:47:57,840 so let's just go into our canvas into 16020 08:47:57,840 --> 08:47:59,700 our main menu let's create a brand new 16021 08:47:59,700 --> 08:48:03,478 UI image let's assign the logo Sprite 16022 08:48:03,478 --> 08:48:05,878 then let's just position it on that 16023 08:48:05,878 --> 08:48:08,218 corner so let's move it all the way up 16024 08:48:08,218 --> 08:48:09,660 there we can anchor it to the top left 16025 08:48:09,660 --> 08:48:11,760 corner and let's make it a bit bigger 16026 08:48:11,760 --> 08:48:13,440 and by the way I want something like 16027 08:48:13,440 --> 08:48:15,000 this if you play around this it might 16028 08:48:15,000 --> 08:48:17,280 get a bit scratched so if so over here 16029 08:48:17,280 --> 08:48:18,718 on the options on the image you can 16030 08:48:18,718 --> 08:48:20,280 download this one to preserve the aspect 16031 08:48:20,280 --> 08:48:22,320 ratio so that way even if you stretch it 16032 08:48:22,320 --> 08:48:23,760 won't actually be stretch it will always 16033 08:48:23,760 --> 08:48:26,638 be perfect okay just like this okay so 16034 08:48:26,638 --> 08:48:28,620 here we have our basic main menu it's a 16035 08:48:28,620 --> 08:48:30,600 basic setup but it looks pretty good and 16036 08:48:30,600 --> 08:48:32,520 with that we have built a nice main menu 16037 08:48:32,520 --> 08:48:34,860 alongside with the unloading system so I 16038 08:48:34,860 --> 08:48:36,540 can click on play it goes into the 16039 08:48:36,540 --> 08:48:37,978 loading scene and then into the game 16040 08:48:37,978 --> 08:48:39,478 scene so that's great 16041 08:48:39,478 --> 08:48:41,160 the next thing that we need is some kind 16042 08:48:41,160 --> 08:48:43,020 of pause button so let's do that in the 16043 08:48:43,020 --> 08:48:44,580 next lecture 16044 08:48:44,580 --> 08:48:46,580 hello and welcome I'm your code monkey 16045 08:48:46,580 --> 08:48:48,780 in this lecture we're going to add a 16046 08:48:48,780 --> 08:48:50,580 pause button with a pulse window that 16047 08:48:50,580 --> 08:48:52,320 also has the ability to quit back to the 16048 08:48:52,320 --> 08:48:54,120 main menu and in doing so we're also 16049 08:48:54,120 --> 08:48:55,680 going to solve some sneaky issues with 16050 08:48:55,680 --> 08:48:57,958 loading okay so here in the main menu we 16051 08:48:57,958 --> 08:48:59,520 can click the play button in order to 16052 08:48:59,520 --> 08:49:01,260 unload the game and yep everything works 16053 08:49:01,260 --> 08:49:03,120 now I'm in the game but now let's say I 16054 08:49:03,120 --> 08:49:04,740 want to pause the game for a bit or quit 16055 08:49:04,740 --> 08:49:06,120 back to the main menu right now there's 16056 08:49:06,120 --> 08:49:08,340 no way so let's do that let's go here 16057 08:49:08,340 --> 08:49:10,378 onto the game scene and first let's send 16058 08:49:10,378 --> 08:49:12,120 on the pause and for that we're actually 16059 08:49:12,120 --> 08:49:14,700 going to need some input so let's first 16060 08:49:14,700 --> 08:49:16,740 go inside our player input actions let's 16061 08:49:16,740 --> 08:49:19,138 open this and then over here let's make 16062 08:49:19,138 --> 08:49:21,420 a brand new action let's name it the 16063 08:49:21,420 --> 08:49:22,260 pause 16064 08:49:22,260 --> 08:49:24,058 for the action type let's go with button 16065 08:49:24,058 --> 08:49:25,740 okay and for the bindings over here 16066 08:49:25,740 --> 08:49:28,020 let's go with escape and actually if we 16067 08:49:28,020 --> 08:49:29,280 use the same method that we've been 16068 08:49:29,280 --> 08:49:31,020 using if we listen and press on Escape 16069 08:49:31,020 --> 08:49:33,000 nope doesn't work because Escape just 16070 08:49:33,000 --> 08:49:35,280 cancels it so instead we need to use a 16071 08:49:35,280 --> 08:49:36,958 search bar here Search for escape 16072 08:49:36,958 --> 08:49:39,600 keyboard just like this okay great now 16073 08:49:39,600 --> 08:49:41,340 again as always let's make sure to save 16074 08:49:41,340 --> 08:49:43,260 the asset and wait for the compilation 16075 08:49:43,260 --> 08:49:46,320 to happen there it is so now here on the 16076 08:49:46,320 --> 08:49:48,600 game input list let's listen to it and 16077 08:49:48,600 --> 08:49:50,820 fire the event as usual so go into the 16078 08:49:50,820 --> 08:49:52,440 player input actions the player action 16079 08:49:52,440 --> 08:49:55,978 map let's go into the pause action and 16080 08:49:55,978 --> 08:49:58,080 listen to the performed event 16081 08:49:58,080 --> 08:50:00,058 and when this happens let's fire off an 16082 08:50:00,058 --> 08:50:04,080 event so a public event event handler 16083 08:50:04,080 --> 08:50:07,260 let's go on pause action 16084 08:50:07,260 --> 08:50:09,180 and then down here we're simply going to 16085 08:50:09,180 --> 08:50:11,958 invoke this event 16086 08:50:15,000 --> 08:50:17,520 okay just like this now from listening 16087 08:50:17,520 --> 08:50:19,440 to it here's the question where does 16088 08:50:19,440 --> 08:50:21,780 that make more sense should we do it 16089 08:50:21,780 --> 08:50:23,398 over here on the player script or 16090 08:50:23,398 --> 08:50:24,780 perhaps over here on the kitchen game 16091 08:50:24,780 --> 08:50:26,878 manager I think over here on the game 16092 08:50:26,878 --> 08:50:28,680 manager makes more sense since a pause 16093 08:50:28,680 --> 08:50:30,058 is more related to the game itself 16094 08:50:30,058 --> 08:50:31,740 rather than a specific action by the 16095 08:50:31,740 --> 08:50:34,378 player so let's add it over here let's 16096 08:50:34,378 --> 08:50:35,820 first of all listen to the event so 16097 08:50:35,820 --> 08:50:37,558 let's see what private void start and on 16098 08:50:37,558 --> 08:50:39,120 start let's listen to it so let's go 16099 08:50:39,120 --> 08:50:41,340 into the game input and we didn't 16100 08:50:41,340 --> 08:50:42,840 actually make it a Singleton yet so 16101 08:50:42,840 --> 08:50:44,760 let's do that over here let's make a 16102 08:50:44,760 --> 08:50:47,398 public static game input 16103 08:50:47,398 --> 08:50:50,760 for the instance with a public yet and a 16104 08:50:50,760 --> 08:50:52,500 private set 16105 08:50:52,500 --> 08:50:54,298 then down here on the Wake let's set 16106 08:50:54,298 --> 08:50:56,160 instance equals this okay there's our 16107 08:50:56,160 --> 08:50:57,958 Singleton so now back in the kitchen 16108 08:50:57,958 --> 08:50:59,760 game manager what's going to be instance 16109 08:50:59,760 --> 08:51:02,940 and listen to the on pause action event 16110 08:51:02,940 --> 08:51:05,638 and again let's rename this to give it a 16111 08:51:05,638 --> 08:51:07,080 proper name 16112 08:51:07,080 --> 08:51:09,958 so the C game input on pause action okay 16113 08:51:09,958 --> 08:51:12,298 so here we have it when we have this 16114 08:51:12,298 --> 08:51:14,280 let's call some kind of pause game 16115 08:51:14,280 --> 08:51:16,558 function so let's define this let's go 16116 08:51:16,558 --> 08:51:18,360 to the end of the file here and over 16117 08:51:18,360 --> 08:51:20,100 here let's make that function 16118 08:51:20,100 --> 08:51:22,318 so a private void pause game and over 16119 08:51:22,318 --> 08:51:24,660 here we're going to pause the game now 16120 08:51:24,660 --> 08:51:26,040 for pausing doing this is actually 16121 08:51:26,040 --> 08:51:27,420 surprisingly easy 16122 08:51:27,420 --> 08:51:29,398 basically all of our logic is using time 16123 08:51:29,398 --> 08:51:31,920 dot on time for example over here on the 16124 08:51:31,920 --> 08:51:33,780 player script we have our movement speed 16125 08:51:33,780 --> 08:51:36,600 yep then we get the inputs and over here 16126 08:51:36,600 --> 08:51:38,638 on the handle movement function yep for 16127 08:51:38,638 --> 08:51:40,318 the movement distance we have move speed 16128 08:51:40,318 --> 08:51:42,718 multiplied by time.10 is done or another 16129 08:51:42,718 --> 08:51:44,700 use case over here on the stove counter 16130 08:51:44,700 --> 08:51:46,500 we've got a frying timer and how we 16131 08:51:46,500 --> 08:51:48,000 count it down again is the same thing 16132 08:51:48,000 --> 08:51:50,100 time dot double time well it turns out 16133 08:51:50,100 --> 08:51:52,200 that behind the scenes time to time the 16134 08:51:52,200 --> 08:51:54,120 time actually already has a multiplier 16135 08:51:54,120 --> 08:51:56,218 when you access this it is after that 16136 08:51:56,218 --> 08:51:58,260 multiplier calculation so over here on 16137 08:51:58,260 --> 08:52:00,000 the pause game function we can just go 16138 08:52:00,000 --> 08:52:01,978 into time and we can modify the time 16139 08:52:01,978 --> 08:52:04,860 scale this one is the multiplier so if 16140 08:52:04,860 --> 08:52:06,898 we just put this at 0f then that's it 16141 08:52:06,898 --> 08:52:08,398 this is going to pause all of the other 16142 08:52:08,398 --> 08:52:11,398 Delta times so let's test so here we are 16143 08:52:11,398 --> 08:52:12,898 pay attention to that in the countdown 16144 08:52:12,898 --> 08:52:14,458 timer and I press on escape and there 16145 08:52:14,458 --> 08:52:16,558 you go everything pauses the countdown 16146 08:52:16,558 --> 08:52:18,540 timer pauses over here the script pauses 16147 08:52:18,540 --> 08:52:20,340 and I can no longer move nothing works 16148 08:52:20,340 --> 08:52:22,440 everything is perfectly paused alright 16149 08:52:22,440 --> 08:52:24,780 Awesome everything works except one 16150 08:52:24,780 --> 08:52:26,458 problem obviously right now we cannot 16151 08:52:26,458 --> 08:52:28,558 unpause if I press Escape it's not in 16152 08:52:28,558 --> 08:52:30,660 pausing so let's do that over here on 16153 08:52:30,660 --> 08:52:32,280 the kitchen game manager let's add a 16154 08:52:32,280 --> 08:52:34,740 simple bone so a private bone let's come 16155 08:52:34,740 --> 08:52:37,080 with is game paused and let's see found 16156 08:52:37,080 --> 08:52:39,840 it to phones okay so is game paused and 16157 08:52:39,840 --> 08:52:40,978 then down here on the pause game 16158 08:52:40,978 --> 08:52:42,840 function let's simply flip this one so 16159 08:52:42,840 --> 08:52:44,638 we set this one equals not this one so 16160 08:52:44,638 --> 08:52:46,680 that is going to flip that Boolean and 16161 08:52:46,680 --> 08:52:48,600 then we check if the game is paused if 16162 08:52:48,600 --> 08:52:51,478 so set it to zero f and if not then 16163 08:52:51,478 --> 08:52:53,398 we're going to set the time.time scale 16164 08:52:53,398 --> 08:52:56,580 back into one F okay so now this should 16165 08:52:56,580 --> 08:52:58,860 pause and unpause so essentially rename 16166 08:52:58,860 --> 08:53:00,360 this function since this is no longer 16167 08:53:00,360 --> 08:53:03,180 just going to pause let's rename this to 16168 08:53:03,180 --> 08:53:05,040 toggle and pause game this is going to 16169 08:53:05,040 --> 08:53:06,540 pause and unpause 16170 08:53:06,540 --> 08:53:08,580 okay so let's test 16171 08:53:08,580 --> 08:53:10,138 okay so here we are everything is 16172 08:53:10,138 --> 08:53:11,878 running now I pause and there you go 16173 08:53:11,878 --> 08:53:13,440 everything freeze I cannot move the 16174 08:53:13,440 --> 08:53:14,760 arrow will stop the countdown to stop 16175 08:53:14,760 --> 08:53:16,558 when I press again and there you go nice 16176 08:53:16,558 --> 08:53:19,378 and redeemed all right great so all of 16177 08:53:19,378 --> 08:53:21,180 the logic is working perfectly the only 16178 08:53:21,180 --> 08:53:22,318 thing we need is we don't just see 16179 08:53:22,318 --> 08:53:24,718 visual and as usual let's separate the 16180 08:53:24,718 --> 08:53:27,120 logic from the visuals so let's go 16181 08:53:27,120 --> 08:53:28,740 inside the canvas let's go into the 16182 08:53:28,740 --> 08:53:30,840 scene View and inside the canvas let's 16183 08:53:30,840 --> 08:53:33,240 create an empty game object call it the 16184 08:53:33,240 --> 08:53:36,660 game pause UI then let's stretch to 16185 08:53:36,660 --> 08:53:38,818 occupy the entire screen so zero on 16186 08:53:38,818 --> 08:53:41,340 everything okay great now inside let's 16187 08:53:41,340 --> 08:53:43,318 first of all add a background so a new 16188 08:53:43,318 --> 08:53:46,260 image name this the background let's 16189 08:53:46,260 --> 08:53:49,378 once again stretch to occupy everything 16190 08:53:49,378 --> 08:53:51,660 and on the color let's put it in black 16191 08:53:51,660 --> 08:53:53,458 with just a little bit of alpha okay 16192 08:53:53,458 --> 08:53:55,740 just like that then let's add some text 16193 08:53:55,740 --> 08:53:58,200 so let's create a brand new UI text 16194 08:53:58,200 --> 08:54:00,840 let's name it pause text 16195 08:54:00,840 --> 08:54:03,420 and in here let's just say paused let's 16196 08:54:03,420 --> 08:54:05,458 just make it big so the width and height 16197 08:54:05,458 --> 08:54:08,580 both on zero let's disable wrapping Put 16198 08:54:08,580 --> 08:54:10,558 It Center down the middle and let's 16199 08:54:10,558 --> 08:54:12,120 increase the font size by quite a bit 16200 08:54:12,120 --> 08:54:14,878 and put it in bold and let's also change 16201 08:54:14,878 --> 08:54:16,920 the color maybe a nice yellow something 16202 08:54:16,920 --> 08:54:19,740 like this okay that looks pretty good 16203 08:54:19,740 --> 08:54:21,840 let's just lift it up by a little bit 16204 08:54:21,840 --> 08:54:25,318 now let's make a script to show this so 16205 08:54:25,318 --> 08:54:27,000 on the UI folder let's create a brand 16206 08:54:27,000 --> 08:54:29,398 new c-sharp script call this the game 16207 08:54:29,398 --> 08:54:33,000 pause UI let's attach it then open now 16208 08:54:33,000 --> 08:54:34,620 here let's do the usual thing so let's 16209 08:54:34,620 --> 08:54:36,540 make two show and hide functions so 16210 08:54:36,540 --> 08:54:38,940 private void show and then a private 16211 08:54:38,940 --> 08:54:40,740 void hide 16212 08:54:40,740 --> 08:54:43,020 so on the show game object set active 16213 08:54:43,020 --> 08:54:45,898 into true and on the hides set it into 16214 08:54:45,898 --> 08:54:47,280 false 16215 08:54:47,280 --> 08:54:49,620 okay that's it pretty simple now we need 16216 08:54:49,620 --> 08:54:51,180 to know when to show our hide these 16217 08:54:51,180 --> 08:54:53,040 functions so we're here on the kitchen 16218 08:54:53,040 --> 08:54:55,080 game manager let's make two events to do 16219 08:54:55,080 --> 08:54:57,360 that so let's go up here make a public 16220 08:54:57,360 --> 08:54:59,940 event event handler 16221 08:54:59,940 --> 08:55:02,160 and let's name this on game pause 16222 08:55:02,160 --> 08:55:06,360 another one for on game unpaused okay we 16223 08:55:06,360 --> 08:55:08,760 have both events then down here on the 16224 08:55:08,760 --> 08:55:10,798 toggle pause game if we have this one 16225 08:55:10,798 --> 08:55:12,840 time scale 0 that means we have pause so 16226 08:55:12,840 --> 08:55:15,240 let's invoke the on game pause this 16227 08:55:15,240 --> 08:55:17,458 eventar is not empty okay and on this 16228 08:55:17,458 --> 08:55:19,440 one let's trigger the other one so on 16229 08:55:19,440 --> 08:55:21,120 game unpause 16230 08:55:21,120 --> 08:55:24,000 okay we've got the two basic events now 16231 08:55:24,000 --> 08:55:25,798 back here on the game pause UI let's 16232 08:55:25,798 --> 08:55:27,540 listen to it and as usual let's do it on 16233 08:55:27,540 --> 08:55:29,940 start so private start let's go into the 16234 08:55:29,940 --> 08:55:31,740 kitchen game manager access the static 16235 08:55:31,740 --> 08:55:34,138 instance and let's listen to the on game 16236 08:55:34,138 --> 08:55:35,040 pause 16237 08:55:35,040 --> 08:55:37,080 and I'm going to listen to the other one 16238 08:55:37,080 --> 08:55:39,540 so the instance on game unpaused so 16239 08:55:39,540 --> 08:55:41,458 listen to both of them and as usual 16240 08:55:41,458 --> 08:55:43,020 let's write the clean codes and let's 16241 08:55:43,020 --> 08:55:46,740 rename this so kitchen game manager and 16242 08:55:46,740 --> 08:55:48,540 on this one the same thing 16243 08:55:48,540 --> 08:55:51,540 so also the kitchen game manager 16244 08:55:51,540 --> 08:55:54,420 okay we have both and when the game is 16245 08:55:54,420 --> 08:55:56,218 unpaused then we want to hide the pause 16246 08:55:56,218 --> 08:55:58,260 window and when the game is paused then 16247 08:55:58,260 --> 08:56:00,180 we want to show the pause window and 16248 08:56:00,180 --> 08:56:01,860 finally of course we want to hide it by 16249 08:56:01,860 --> 08:56:03,898 defaults over here on sart after we add 16250 08:56:03,898 --> 08:56:06,360 listeners let's just hide it okay so 16251 08:56:06,360 --> 08:56:08,700 that's it that should work so let's test 16252 08:56:08,700 --> 08:56:10,680 so here we are everything is running now 16253 08:56:10,680 --> 08:56:12,298 press the pause and there you go got a 16254 08:56:12,298 --> 08:56:14,040 nice pause window press again and there 16255 08:56:14,040 --> 08:56:16,740 you go everything resumes okay great so 16256 08:56:16,740 --> 08:56:18,360 the last thing that we want is just a 16257 08:56:18,360 --> 08:56:19,920 button over here to go back to the main 16258 08:56:19,920 --> 08:56:22,020 menu and let's also add a button to 16259 08:56:22,020 --> 08:56:23,458 resume without having to press the 16260 08:56:23,458 --> 08:56:25,978 hotkey so over here let's create a new 16261 08:56:25,978 --> 08:56:28,620 UI let's make it a button this is going 16262 08:56:28,620 --> 08:56:31,138 to be the main menu button now let's 16263 08:56:31,138 --> 08:56:33,898 make it quite a bit bigger okay width 16264 08:56:33,898 --> 08:56:36,360 and height of 30 and 80. let's put this 16265 08:56:36,360 --> 08:56:38,580 one quite a bit down there and inside 16266 08:56:38,580 --> 08:56:41,398 for the text this one is the main menu 16267 08:56:41,398 --> 08:56:44,520 let's put the color in White and the 16268 08:56:44,520 --> 08:56:46,680 background for the button let's put this 16269 08:56:46,680 --> 08:56:49,200 one in a dark gray and let's also just 16270 08:56:49,200 --> 08:56:52,080 for fun add a nice upline and let's also 16271 08:56:52,080 --> 08:56:53,340 add a shadow 16272 08:56:53,340 --> 08:56:55,200 for the outline let's put it on for 16273 08:56:55,200 --> 08:56:58,440 Alpha and let's put it on about 3 3 and 16274 08:56:58,440 --> 08:57:00,298 for the effect on the shadow 5 minus 16275 08:57:00,298 --> 08:57:02,700 five okay so that's a nice outline and 16276 08:57:02,700 --> 08:57:03,718 nice shadow 16277 08:57:03,718 --> 08:57:06,000 and then for the text itself let's put 16278 08:57:06,000 --> 08:57:08,218 it in bold and raise it by just a little 16279 08:57:08,218 --> 08:57:10,020 bit okay just like that looks pretty 16280 08:57:10,020 --> 08:57:13,080 good so this is the main menu button and 16281 08:57:13,080 --> 08:57:14,940 then let's also make so duplicate this 16282 08:57:14,940 --> 08:57:16,978 let's make this one rename it this is 16283 08:57:16,978 --> 08:57:18,718 the resume button 16284 08:57:18,718 --> 08:57:21,058 and inside on the text let's say resume 16285 08:57:21,058 --> 08:57:24,240 okay we have our two basic buttons so 16286 08:57:24,240 --> 08:57:26,100 let's handle them in the script so over 16287 08:57:26,100 --> 08:57:28,020 here let's add as usual a serialized 16288 08:57:28,020 --> 08:57:30,298 field private of type button so that's 16289 08:57:30,298 --> 08:57:34,020 inside Unity engine.ui so it's for the 16290 08:57:34,020 --> 08:57:36,000 resume button and then we're going to 16291 08:57:36,000 --> 08:57:39,420 have the main menu button 16292 08:57:39,420 --> 08:57:41,700 okay let's save the script and back in 16293 08:57:41,700 --> 08:57:43,440 the editor let's drag those references 16294 08:57:43,440 --> 08:57:45,840 so that's the main menu button and the 16295 08:57:45,840 --> 08:57:48,058 resume button okay so now for these 16296 08:57:48,058 --> 08:57:50,218 let's add the click action so let's do a 16297 08:57:50,218 --> 08:57:52,020 private awake and on the way go into the 16298 08:57:52,020 --> 08:57:54,180 resume button the on click and let's add 16299 08:57:54,180 --> 08:57:55,920 a listener so this is going to be our 16300 08:57:55,920 --> 08:57:57,120 listener 16301 08:57:57,120 --> 08:57:59,878 and same thing for a main menu button so 16302 08:57:59,878 --> 08:58:02,160 main menu now for the main menu this one 16303 08:58:02,160 --> 08:58:03,660 is super simple let's just go into the 16304 08:58:03,660 --> 08:58:06,298 loader and call the unload function and 16305 08:58:06,298 --> 08:58:07,500 we're going to download the main menu 16306 08:58:07,500 --> 08:58:08,398 scene 16307 08:58:08,398 --> 08:58:10,558 okay that's the main menu very simple 16308 08:58:10,558 --> 08:58:12,840 and for the resume this one is only 16309 08:58:12,840 --> 08:58:14,580 going to be clickable when the game is 16310 08:58:14,580 --> 08:58:16,860 paused so we can just trigger the same 16311 08:58:16,860 --> 08:58:18,420 function on the kitchen game manager to 16312 08:58:18,420 --> 08:58:20,940 toggle the pause so kitchen can manager 16313 08:58:20,940 --> 08:58:23,540 the instance and toggle the pause game 16314 08:58:23,540 --> 08:58:26,100 this one is actually private so let's go 16315 08:58:26,100 --> 08:58:28,440 to it and let's make this public so we 16316 08:58:28,440 --> 08:58:30,360 can count from there okay that's it 16317 08:58:30,360 --> 08:58:32,878 super simple Let's test okay so here we 16318 08:58:32,878 --> 08:58:34,620 are and let's pause the game and now if 16319 08:58:34,620 --> 08:58:36,718 I click on resume if there go it does 16320 08:58:36,718 --> 08:58:38,280 work everything resumes and now pause 16321 08:58:38,280 --> 08:58:40,138 again and now let's go back to the main 16322 08:58:40,138 --> 08:58:42,600 menu loading any up there you go back in 16323 08:58:42,600 --> 08:58:44,520 the main menu alright awesome so 16324 08:58:44,520 --> 08:58:46,020 everything works perfectly 16325 08:58:46,020 --> 08:58:48,360 however there's one sneaky issue here 16326 08:58:48,360 --> 08:58:50,520 you can already see the issue by seeing 16327 08:58:50,520 --> 08:58:51,958 that all of these animations are still 16328 08:58:51,958 --> 08:58:54,478 but let's click on play and notebook 16329 08:58:54,478 --> 08:58:56,878 that issue everything is still frozen I 16330 08:58:56,878 --> 08:58:58,740 cannot move the character and over there 16331 08:58:58,740 --> 08:59:00,718 the Shader that one is completely Frozen 16332 08:59:00,718 --> 08:59:03,240 so the times can only still set to zero 16333 08:59:03,240 --> 08:59:05,340 basically we need to manually reset it 16334 08:59:05,340 --> 08:59:07,200 and the simplest way to do this is 16335 08:59:07,200 --> 08:59:08,940 really just in the main menu 16336 08:59:08,940 --> 08:59:11,100 so we can go here on the main menu UI 16337 08:59:11,100 --> 08:59:13,020 and we can just use this as our reset 16338 08:59:13,020 --> 08:59:16,020 function so let's just go into time.time 16339 08:59:16,020 --> 08:59:18,420 scale and let's set this one back into 16340 08:59:18,420 --> 08:59:20,340 one F that's it that's the only change 16341 08:59:20,340 --> 08:59:22,740 Let's test so here we are let's pause 16342 08:59:22,740 --> 08:59:24,718 let's go back into the main menu 16343 08:59:24,718 --> 08:59:26,760 and we can see the animations are indeed 16344 08:59:26,760 --> 08:59:28,860 playing and if we go back into play and 16345 08:59:28,860 --> 08:59:30,058 if there you go everything works 16346 08:59:30,058 --> 08:59:32,818 perfectly we can pause and yep here we 16347 08:59:32,818 --> 08:59:34,680 do see one of the other two sneaky 16348 08:59:34,680 --> 08:59:36,898 issues left basically it has to do with 16349 08:59:36,898 --> 08:59:39,180 scene loading and cleanup so the first 16350 08:59:39,180 --> 08:59:40,978 one is on input 16351 08:59:40,978 --> 08:59:43,378 over here on the game input class we are 16352 08:59:43,378 --> 08:59:45,298 constructing our player input actions 16353 08:59:45,298 --> 08:59:48,240 and we are listening to these events and 16354 08:59:48,240 --> 08:59:49,920 technically this object the one where 16355 08:59:49,920 --> 08:59:51,898 the game input is attached this object 16356 08:59:51,898 --> 08:59:53,340 is going to be destroyed when the scene 16357 08:59:53,340 --> 08:59:54,420 changes 16358 08:59:54,420 --> 08:59:56,520 however this object that we're creating 16359 08:59:56,520 --> 08:59:58,798 this instance of player input actions 16360 08:59:58,798 --> 09:00:00,600 this one does not get destroyed 16361 09:00:00,600 --> 09:00:02,580 automatically so that is why when I went 16362 09:00:02,580 --> 09:00:04,680 into the pause menu again for the second 16363 09:00:04,680 --> 09:00:06,840 time over here we've got a missing 16364 09:00:06,840 --> 09:00:09,180 reference exception basically the player 16365 09:00:09,180 --> 09:00:11,160 input actions of the previous game is 16366 09:00:11,160 --> 09:00:12,958 trying to show the pause window also of 16367 09:00:12,958 --> 09:00:14,700 the previous game which has since been 16368 09:00:14,700 --> 09:00:16,920 destroyed so obviously we have a missing 16369 09:00:16,920 --> 09:00:18,478 reference exception because that object 16370 09:00:18,478 --> 09:00:21,000 no longer exists so in this case we have 16371 09:00:21,000 --> 09:00:23,760 two options to solve this one option is 16372 09:00:23,760 --> 09:00:25,620 we can just unsubscribe to these events 16373 09:00:25,620 --> 09:00:28,020 Unity mono behaviors have a really nice 16374 09:00:28,020 --> 09:00:30,240 combat called on destroying so over here 16375 09:00:30,240 --> 09:00:32,398 private void on Destroy so this is the 16376 09:00:32,398 --> 09:00:34,020 default one this one is called when the 16377 09:00:34,020 --> 09:00:36,120 mono behavior is destroyed 16378 09:00:36,120 --> 09:00:38,280 so we can go into this one and we can 16379 09:00:38,280 --> 09:00:40,378 manually unsubscribe and the way that 16380 09:00:40,378 --> 09:00:42,360 you unsubscribe is you just do minus 16381 09:00:42,360 --> 09:00:44,780 equals 16382 09:00:45,478 --> 09:00:47,160 so this would solve that problem because 16383 09:00:47,160 --> 09:00:48,898 when this object is destroyed it's going 16384 09:00:48,898 --> 09:00:50,760 to unsubscribe from those events so the 16385 09:00:50,760 --> 09:00:52,798 next time it will no longer trigger so 16386 09:00:52,798 --> 09:00:54,958 that would fix it however on the game 16387 09:00:54,958 --> 09:00:57,240 input class we are still creating a new 16388 09:00:57,240 --> 09:01:00,540 object of this type I'm not 100 sure how 16389 09:01:00,540 --> 09:01:02,280 the input system works in the background 16390 09:01:02,280 --> 09:01:04,200 so perhaps this object might say in 16391 09:01:04,200 --> 09:01:06,478 memory which is not good so another 16392 09:01:06,478 --> 09:01:08,160 approach we can do or perhaps in 16393 09:01:08,160 --> 09:01:09,540 combination with this is we can 16394 09:01:09,540 --> 09:01:11,398 unsubscribe and then we can properly 16395 09:01:11,398 --> 09:01:14,040 dispose of this object how we do that is 16396 09:01:14,040 --> 09:01:16,260 very simple let's just go into the 16397 09:01:16,260 --> 09:01:18,360 player input actions and we just call 16398 09:01:18,360 --> 09:01:21,180 the dispose function that's it 16399 09:01:21,180 --> 09:01:23,160 this should clean up that object and 16400 09:01:23,160 --> 09:01:25,978 free up any memory so let's test so here 16401 09:01:25,978 --> 09:01:27,660 in the game view let's pause let's go 16402 09:01:27,660 --> 09:01:29,818 back into the main menu now let's go 16403 09:01:29,818 --> 09:01:31,920 back into the main game and now if I hit 16404 09:01:31,920 --> 09:01:33,660 pause and if there you go we no longer 16405 09:01:33,660 --> 09:01:35,940 have any errors okay so that's good 16406 09:01:35,940 --> 09:01:38,100 however now we still have one more 16407 09:01:38,100 --> 09:01:40,318 potential issue and this one has to do 16408 09:01:40,318 --> 09:01:42,420 with Statics like I mentioned before 16409 09:01:42,420 --> 09:01:44,638 Statics belong to the class and not any 16410 09:01:44,638 --> 09:01:46,860 instance of that class so that means 16411 09:01:46,860 --> 09:01:48,780 that static films will not be destroyed 16412 09:01:48,780 --> 09:01:51,058 or reset when the scene changes in the 16413 09:01:51,058 --> 09:01:52,798 case of our unloader here where we have 16414 09:01:52,798 --> 09:01:55,200 a private static field this one the fact 16415 09:01:55,200 --> 09:01:56,340 that this one doesn't reset 16416 09:01:56,340 --> 09:01:57,540 automatically that was a good thing 16417 09:01:57,540 --> 09:01:58,920 that's what allowed this to make the 16418 09:01:58,920 --> 09:02:01,080 unloading system but in the case of 16419 09:02:01,080 --> 09:02:02,940 maybe static events that might not be as 16420 09:02:02,940 --> 09:02:05,100 good it might mean that we might be 16421 09:02:05,100 --> 09:02:06,478 keeping some state from the previous 16422 09:02:06,478 --> 09:02:08,340 game which might cause everything to 16423 09:02:08,340 --> 09:02:10,500 break so basically we have a similar 16424 09:02:10,500 --> 09:02:12,000 problem to what we had in the input 16425 09:02:12,000 --> 09:02:14,160 where some logic from the previous game 16426 09:02:14,160 --> 09:02:16,558 might be affecting the next game in all 16427 09:02:16,558 --> 09:02:18,000 the code that we wrote the main place 16428 09:02:18,000 --> 09:02:19,680 where we use Statics were in The 16429 09:02:19,680 --> 09:02:21,840 Singletons and these are going to be 16430 09:02:21,840 --> 09:02:23,100 cleared automatically when the 16431 09:02:23,100 --> 09:02:24,840 underlying instance object when that one 16432 09:02:24,840 --> 09:02:27,180 is destroying so these do not cause any 16433 09:02:27,180 --> 09:02:29,638 problems however for example over here 16434 09:02:29,638 --> 09:02:31,620 on the cutting counter we've got a 16435 09:02:31,620 --> 09:02:34,200 static event when the scene changes this 16436 09:02:34,200 --> 09:02:36,360 will not be cleared so this will still 16437 09:02:36,360 --> 09:02:38,638 have the same number of listeners we can 16438 09:02:38,638 --> 09:02:40,080 actually see how many listeners there 16439 09:02:40,080 --> 09:02:41,940 are by printing it so let's go down here 16440 09:02:41,940 --> 09:02:44,458 before we're invoking the event let's do 16441 09:02:44,458 --> 09:02:46,740 a debug download let's go inside the on 16442 09:02:46,740 --> 09:02:49,440 any cut event and over here we can get 16443 09:02:49,440 --> 09:02:52,138 the invocation list this one is a list 16444 09:02:52,138 --> 09:02:53,398 of all of the functions that are 16445 09:02:53,398 --> 09:02:54,958 listening to this event 16446 09:02:54,958 --> 09:02:56,818 and we can just print out the link to 16447 09:02:56,818 --> 09:02:58,620 see how many listeners are listening to 16448 09:02:58,620 --> 09:03:00,420 this event so let's see what this 16449 09:03:00,420 --> 09:03:03,000 returns okay so over here let's pick up 16450 09:03:03,000 --> 09:03:04,740 some cheese and slice it and if I'm 16451 09:03:04,740 --> 09:03:06,360 working the log yep there you go one 16452 09:03:06,360 --> 09:03:08,040 there's only one listener okay that's 16453 09:03:08,040 --> 09:03:09,000 correct 16454 09:03:09,000 --> 09:03:11,280 however now if I go back into the main 16455 09:03:11,280 --> 09:03:14,160 menu and now I go back and I play again 16456 09:03:14,160 --> 09:03:16,860 okay so let's play let's just wait for 16457 09:03:16,860 --> 09:03:19,080 the countdown and once the countdown 16458 09:03:19,080 --> 09:03:20,760 ends pick up some cheese go there slice 16459 09:03:20,760 --> 09:03:21,898 it and there you go there's the problem 16460 09:03:21,898 --> 09:03:24,298 now we have two listeners in this case 16461 09:03:24,298 --> 09:03:25,740 doesn't really cause an error because 16462 09:03:25,740 --> 09:03:27,780 the tune listeners they're just over 16463 09:03:27,780 --> 09:03:29,580 here on The Sound Manager so we are 16464 09:03:29,580 --> 09:03:31,138 subscribing to this event and we're 16465 09:03:31,138 --> 09:03:32,878 doing the cut and playing the cut object 16466 09:03:32,878 --> 09:03:35,160 however if here we do something with 16467 09:03:35,160 --> 09:03:37,378 this transform like for example let's 16468 09:03:37,378 --> 09:03:39,240 just do a debug download on this 16469 09:03:39,240 --> 09:03:41,760 transform that position if we do this 16470 09:03:41,760 --> 09:03:44,040 here let's go ahead on the first one 16471 09:03:44,040 --> 09:03:46,138 let's slice and okay that works let's go 16472 09:03:46,138 --> 09:03:48,120 back into the main menu now play again 16473 09:03:48,120 --> 09:03:50,458 now wait for the timer 16474 09:03:50,458 --> 09:03:52,440 pick up some cheese go there slice any 16475 09:03:52,440 --> 09:03:54,540 of that I go there we have our air that 16476 09:03:54,540 --> 09:03:55,798 is because we are now accessing The 16477 09:03:55,798 --> 09:03:57,478 Sound Manager transform and that one has 16478 09:03:57,478 --> 09:03:59,638 since been destroyed so if you do use 16479 09:03:59,638 --> 09:04:02,040 static events like this one here if you 16480 09:04:02,040 --> 09:04:03,780 do that always remember you need to 16481 09:04:03,780 --> 09:04:05,878 manually reset that state it won't 16482 09:04:05,878 --> 09:04:07,680 happen automatically on the scene load 16483 09:04:07,680 --> 09:04:09,540 and one way that I normally do it is 16484 09:04:09,540 --> 09:04:11,458 just make a class responsible for doing 16485 09:04:11,458 --> 09:04:13,558 that so let's go ahead and let's create 16486 09:04:13,558 --> 09:04:15,898 a brand new c-sharp class let's call 16487 09:04:15,898 --> 09:04:19,200 this the reset static data manager and 16488 09:04:19,200 --> 09:04:20,878 for this one we want this one to run 16489 09:04:20,878 --> 09:04:22,860 only on the main menu That's only where 16490 09:04:22,860 --> 09:04:25,378 we're going to reset things so let's go 16491 09:04:25,378 --> 09:04:27,298 inside the main menu scene let's go 16492 09:04:27,298 --> 09:04:29,280 there let's create a brand new empty 16493 09:04:29,280 --> 09:04:32,700 game object for the reset static data 16494 09:04:32,700 --> 09:04:35,218 manager let's reset transform just keep 16495 09:04:35,218 --> 09:04:37,440 things clean and let's attach that 16496 09:04:37,440 --> 09:04:39,298 script again it's very important that 16497 09:04:39,298 --> 09:04:41,040 this object only exists on the main menu 16498 09:04:41,040 --> 09:04:42,898 then over here we're basically just 16499 09:04:42,898 --> 09:04:44,878 going to go into any script and reset 16500 09:04:44,878 --> 09:04:46,798 any data so for that on all those 16501 09:04:46,798 --> 09:04:48,718 scripts let's make a function 16502 09:04:48,718 --> 09:04:50,340 so over here on the cutting counter 16503 09:04:50,340 --> 09:04:52,378 let's make a public static function 16504 09:04:52,378 --> 09:04:56,040 let's call this reset static data in 16505 09:04:56,040 --> 09:04:57,898 order to reset any listeners let's just 16506 09:04:57,898 --> 09:04:59,700 go into the on any cut and set it to 16507 09:04:59,700 --> 09:05:01,680 null that will clear all the listeners 16508 09:05:01,680 --> 09:05:04,020 so we just do this and then on this 16509 09:05:04,020 --> 09:05:05,878 script Let's see we practically awake 16510 09:05:05,878 --> 09:05:08,040 and on awake let's go into the cutting 16511 09:05:08,040 --> 09:05:10,440 counter under the class so not any 16512 09:05:10,440 --> 09:05:11,878 instance so we're going to access the 16513 09:05:11,878 --> 09:05:13,740 static and we're going to reset the 16514 09:05:13,740 --> 09:05:15,898 static data that will clear all the 16515 09:05:15,898 --> 09:05:17,818 listeners on The Cutting counter all we 16516 09:05:17,818 --> 09:05:19,558 need to do is make sure to do this on 16517 09:05:19,558 --> 09:05:21,360 every single static event that we have 16518 09:05:21,360 --> 09:05:23,580 so on The Sound Manager and by the way 16519 09:05:23,580 --> 09:05:25,978 here we can get rid of the testing code 16520 09:05:25,978 --> 09:05:28,440 here we can see all the static events 16521 09:05:28,440 --> 09:05:29,638 that we're using so we've got the 16522 09:05:29,638 --> 09:05:30,840 cutting counter then we've got the base 16523 09:05:30,840 --> 09:05:32,940 counter and trash counter so let's go 16524 09:05:32,940 --> 09:05:34,500 here on the base counter and paste the 16525 09:05:34,500 --> 09:05:36,478 exact same thing and reset this event 16526 09:05:36,478 --> 09:05:38,760 okay and now let's go into the trash 16527 09:05:38,760 --> 09:05:39,780 counter 16528 09:05:39,780 --> 09:05:41,398 so here on trash counter same thing 16529 09:05:41,398 --> 09:05:44,218 reset this event set them all into null 16530 09:05:44,218 --> 09:05:46,318 and by the way here we have a warning 16531 09:05:46,318 --> 09:05:48,120 that's because trash counter extends 16532 09:05:48,120 --> 09:05:49,378 base counter so basically this is 16533 09:05:49,378 --> 09:05:50,638 telling us that we are hiding another 16534 09:05:50,638 --> 09:05:52,798 function with the exact same name in 16535 09:05:52,798 --> 09:05:54,478 this case we do want to hide it so 16536 09:05:54,478 --> 09:05:55,978 what's actually make this new to make 16537 09:05:55,978 --> 09:05:57,298 sure that this one is a different one 16538 09:05:57,298 --> 09:06:00,120 just to avoid that warning and same 16539 09:06:00,120 --> 09:06:01,620 thing over here on the cutting counter 16540 09:06:01,620 --> 09:06:03,780 we also need to make a new okay so 16541 09:06:03,780 --> 09:06:05,878 that's it and now we just need to go 16542 09:06:05,878 --> 09:06:07,558 over here onto the reset static data 16543 09:06:07,558 --> 09:06:09,598 manager let's go into the base counter 16544 09:06:09,598 --> 09:06:11,877 and reset the static data go into the 16545 09:06:11,877 --> 09:06:13,980 trash counter and reset the static data 16546 09:06:13,980 --> 09:06:16,377 okay that should do it let's see so here 16547 09:06:16,377 --> 09:06:18,057 we are in the game let's pick it up and 16548 09:06:18,057 --> 09:06:20,040 slice it and yep we've got just one 16549 09:06:20,040 --> 09:06:21,718 listener that's good let's go back 16550 09:06:21,718 --> 09:06:23,877 outside back into the main menu let's 16551 09:06:23,877 --> 09:06:26,398 play once more and over here let's pick 16552 09:06:26,398 --> 09:06:28,078 it up again go there drop it and there 16553 09:06:28,078 --> 09:06:29,578 you go still just one listener because 16554 09:06:29,578 --> 09:06:31,438 we are now correctly eliminating all of 16555 09:06:31,438 --> 09:06:32,820 the previous listeners 16556 09:06:32,820 --> 09:06:35,040 so this is the one sneaky issue that you 16557 09:06:35,040 --> 09:06:36,540 must be careful with when it comes to 16558 09:06:36,540 --> 09:06:39,180 object Lifetime and Statics for static 16559 09:06:39,180 --> 09:06:40,680 Fields you need to remember that they 16560 09:06:40,680 --> 09:06:42,480 don't manually get cleaned up that's up 16561 09:06:42,480 --> 09:06:44,398 to you so that's something you have to 16562 09:06:44,398 --> 09:06:45,960 keep in mind but you can also see how 16563 09:06:45,960 --> 09:06:47,699 easy it is to solve now that this is 16564 09:06:47,699 --> 09:06:49,258 solved let's just go into the cutting 16565 09:06:49,258 --> 09:06:50,877 counter and just get rid of our testing 16566 09:06:50,877 --> 09:06:52,980 log alright so with all of that all of 16567 09:06:52,980 --> 09:06:54,598 our scenes are working so we can start 16568 09:06:54,598 --> 09:06:56,640 from here from the main menu and go 16569 09:06:56,640 --> 09:06:58,557 straight into the game then here we are 16570 09:06:58,557 --> 09:07:00,300 in the game playing normally we can 16571 09:07:00,300 --> 09:07:02,218 pause the game at any point from the 16572 09:07:02,218 --> 09:07:04,438 pause screen we cannot resume or we can 16573 09:07:04,438 --> 09:07:06,718 go back into the main menu and from back 16574 09:07:06,718 --> 09:07:08,218 into the main menu we can once again 16575 09:07:08,218 --> 09:07:10,258 play the game from scratch and if there 16576 09:07:10,258 --> 09:07:13,320 you go everything works alright awesome 16577 09:07:13,320 --> 09:07:15,180 now the next thing that every game 16578 09:07:15,180 --> 09:07:17,160 requires is some options so let's do 16579 09:07:17,160 --> 09:07:19,500 that in the next lecture 16580 09:07:19,500 --> 09:07:21,438 hello and welcome I'm your code monkey 16581 09:07:21,438 --> 09:07:23,758 in this lecture we're going to create a 16582 09:07:23,758 --> 09:07:25,737 simple options menu where we can modify 16583 09:07:25,737 --> 09:07:28,140 the audio levels okay so here let's make 16584 09:07:28,140 --> 09:07:30,360 the options menu so on our game scene 16585 09:07:30,360 --> 09:07:32,160 let's go into the canvas and create a 16586 09:07:32,160 --> 09:07:34,438 new empty game object let's make this 16587 09:07:34,438 --> 09:07:37,140 the options UI let's stretch out this 16588 09:07:37,140 --> 09:07:39,180 one to occupy the entire screen 16589 09:07:39,180 --> 09:07:42,480 then inside let's make a UI image once 16590 09:07:42,480 --> 09:07:45,180 again let's stretch out everything 16591 09:07:45,180 --> 09:07:48,540 let's put this one in black in just 16592 09:07:48,540 --> 09:07:50,877 almost full Alpha okay now let's make 16593 09:07:50,877 --> 09:07:52,860 some texts so let's create a brand new 16594 09:07:52,860 --> 09:07:56,460 UI text call it the options text 16595 09:07:56,460 --> 09:07:58,820 then for text let's say just options 16596 09:07:58,820 --> 09:08:02,098 let's put the width and height at zero 16597 09:08:02,098 --> 09:08:04,800 let's disable wrapping Put It Center 16598 09:08:04,800 --> 09:08:07,140 down the middle and put it quite a lot 16599 09:08:07,140 --> 09:08:08,398 bigger 16600 09:08:08,398 --> 09:08:10,438 okay that's the options now just move it 16601 09:08:10,438 --> 09:08:12,540 slightly upwards all right now let's 16602 09:08:12,540 --> 09:08:14,398 make some simple buttons to handle our 16603 09:08:14,398 --> 09:08:16,258 audio controls we're going to make it 16604 09:08:16,258 --> 09:08:18,122 super simple literally just a button we 16605 09:08:18,122 --> 09:08:20,519 can click so inside the options UI let's 16606 09:08:20,519 --> 09:08:22,438 create a brand new button 16607 09:08:22,438 --> 09:08:26,282 call this the sound effects button then 16608 09:08:26,282 --> 09:08:27,898 let's make the button a bit bigger 16609 09:08:27,898 --> 09:08:31,578 something like this okay 16610 09:08:32,339 --> 09:08:35,218 and inside for the text let's say sound 16611 09:08:35,218 --> 09:08:36,960 effects and then we're going to have a 16612 09:08:36,960 --> 09:08:39,057 number for the sound effects let's just 16613 09:08:39,057 --> 09:08:41,098 quickly change the color so put the text 16614 09:08:41,098 --> 09:08:44,339 in White and the button over here the 16615 09:08:44,339 --> 09:08:46,860 button image let's put it in a dark ring 16616 09:08:46,860 --> 09:08:49,019 okay let's also make it just a tiny bit 16617 09:08:49,019 --> 09:08:51,057 thinner it's just like that okay so this 16618 09:08:51,057 --> 09:08:52,980 is the sound effects button now let's 16619 09:08:52,980 --> 09:08:54,417 duplicate this one this one is going to 16620 09:08:54,417 --> 09:08:56,040 be the music button so let's name this 16621 09:08:56,040 --> 09:08:58,140 the music button 16622 09:08:58,140 --> 09:09:00,782 then inside for the text music and then 16623 09:09:00,782 --> 09:09:01,917 a number 16624 09:09:01,917 --> 09:09:04,500 and that's pretty much it so by clicking 16625 09:09:04,500 --> 09:09:06,000 on either of these buttons we're going 16626 09:09:06,000 --> 09:09:08,282 to increase and then Loop the volume so 16627 09:09:08,282 --> 09:09:10,258 let's make a simple script to handle our 16628 09:09:10,258 --> 09:09:12,360 options window so in our scripts inside 16629 09:09:12,360 --> 09:09:14,398 the UI let's create a brand new c-sharp 16630 09:09:14,398 --> 09:09:17,699 script for the options UI let's go ahead 16631 09:09:17,699 --> 09:09:19,917 and attach a script and open 16632 09:09:19,917 --> 09:09:22,320 so here as usual let's get some films 16633 09:09:22,320 --> 09:09:24,360 for our buttons so a serialized film 16634 09:09:24,360 --> 09:09:27,782 private of type button for the sound 16635 09:09:27,782 --> 09:09:30,300 effects button and then there's another 16636 09:09:30,300 --> 09:09:33,680 one for the music button 16637 09:09:35,398 --> 09:09:37,500 okay both buttons now let's add the 16638 09:09:37,500 --> 09:09:39,540 click event so on private awake let's go 16639 09:09:39,540 --> 09:09:41,640 into the sound effects button and on the 16640 09:09:41,640 --> 09:09:45,057 on click let's add a listener 16641 09:09:45,057 --> 09:09:46,860 and we're going to do the same thing on 16642 09:09:46,860 --> 09:09:48,660 the music button 16643 09:09:48,660 --> 09:09:51,660 okay so now when we click we want to 16644 09:09:51,660 --> 09:09:54,057 change the volume so let's go here onto 16645 09:09:54,057 --> 09:09:55,860 The Sound Manager and make a function to 16646 09:09:55,860 --> 09:09:57,660 modify the volume 16647 09:09:57,660 --> 09:10:02,782 let's make a private void change volume 16648 09:10:03,000 --> 09:10:04,500 and here we're going to increase the 16649 09:10:04,500 --> 09:10:06,782 volume by 0.1 percent so constantly 16650 09:10:06,782 --> 09:10:09,300 increase in 10 increments so that means 16651 09:10:09,300 --> 09:10:10,860 we need to keep track of the volume so 16652 09:10:10,860 --> 09:10:12,480 up here in order to find a SIM phone 16653 09:10:12,480 --> 09:10:15,980 private float for the volume 16654 09:10:18,782 --> 09:10:22,019 well it's default it to one F okay so 16655 09:10:22,019 --> 09:10:24,417 now down here we take the volume and we 16656 09:10:24,417 --> 09:10:27,300 increase it by 0.1 F and now let's Loop 16657 09:10:27,300 --> 09:10:28,622 it back to zero 16658 09:10:28,622 --> 09:10:30,898 now for looping usually you do it using 16659 09:10:30,898 --> 09:10:33,000 the modular operator so here you could 16660 09:10:33,000 --> 09:10:37,258 do volume equals volume module of 1.1 f 16661 09:10:37,258 --> 09:10:39,718 that way when it gets to 1.1 f it would 16662 09:10:39,718 --> 09:10:42,180 reset back to zero but here since we're 16663 09:10:42,180 --> 09:10:44,160 working with floats which can have a bit 16664 09:10:44,160 --> 09:10:46,438 of odd Precision with this let's just do 16665 09:10:46,438 --> 09:10:48,057 a simple lift to make sure that always 16666 09:10:48,057 --> 09:10:49,078 works 16667 09:10:49,078 --> 09:10:52,622 so if the volume is above one f 16668 09:10:52,622 --> 09:10:55,019 if so then let's just reset it to zero 16669 09:10:55,019 --> 09:10:56,460 okay 16670 09:10:56,460 --> 09:10:58,258 so here we modified volume and let's 16671 09:10:58,258 --> 09:10:59,820 just make sure to use it over here when 16672 09:10:59,820 --> 09:11:01,160 we actually call the audio 16673 09:11:01,160 --> 09:11:03,598 source.playclip Point here we've got a 16674 09:11:03,598 --> 09:11:04,800 volume but this is the one that we 16675 09:11:04,800 --> 09:11:06,960 received as a parameter so let's 16676 09:11:06,960 --> 09:11:09,180 actually receive this one rename this to 16677 09:11:09,180 --> 09:11:11,398 volume multiplier 16678 09:11:11,398 --> 09:11:13,199 and we're going to basically multiply 16679 09:11:13,199 --> 09:11:15,057 the one that we receive in the parameter 16680 09:11:15,057 --> 09:11:17,460 by the one that we actually store 16681 09:11:17,460 --> 09:11:19,500 so this way on these functions when we 16682 09:11:19,500 --> 09:11:21,057 play a certain sound we can still give 16683 09:11:21,057 --> 09:11:23,398 an optional volume if we want to make it 16684 09:11:23,398 --> 09:11:25,438 louder or quieter then the regular sound 16685 09:11:25,438 --> 09:11:27,598 effects okay so we have our change 16686 09:11:27,598 --> 09:11:29,820 volume function now we just need to call 16687 09:11:29,820 --> 09:11:31,557 this from the options UI so that means 16688 09:11:31,557 --> 09:11:32,820 this one actually needs to be public 16689 09:11:32,820 --> 09:11:36,122 okay so now here on the options UI we go 16690 09:11:36,122 --> 09:11:37,737 into the sound manager access the 16691 09:11:37,737 --> 09:11:40,140 instance and call change volume okay so 16692 09:11:40,140 --> 09:11:41,820 that is going to change the volume then 16693 09:11:41,820 --> 09:11:43,737 we just need to update the values on the 16694 09:11:43,737 --> 09:11:46,377 options UI so let's make a proud void 16695 09:11:46,377 --> 09:11:48,898 update visual 16696 09:11:48,898 --> 09:11:51,000 and this one we need to update the text 16697 09:11:51,000 --> 09:11:53,098 so up here on let's add once again some 16698 09:11:53,098 --> 09:11:56,218 more serialized Fields so text mesh Pro 16699 09:11:56,218 --> 09:11:59,398 ugly one for the sound effects text and 16700 09:11:59,398 --> 09:12:02,098 another one for the music text 16701 09:12:02,098 --> 09:12:04,622 okay we have both these then here the 16702 09:12:04,622 --> 09:12:07,199 sound effects text not text 16703 09:12:07,199 --> 09:12:09,360 equals and we go into The Sound Manager 16704 09:12:09,360 --> 09:12:11,840 the instance 16705 09:12:13,078 --> 09:12:15,360 and then we need to get the volume 16706 09:12:15,360 --> 09:12:16,500 so over here on the sound management 16707 09:12:16,500 --> 09:12:18,180 let's make a function together so a 16708 09:12:18,180 --> 09:12:22,622 public float return get volume and we 16709 09:12:22,622 --> 09:12:25,377 just return the volume okay so then here 16710 09:12:25,377 --> 09:12:28,140 let's get volume except volume is going 16711 09:12:28,140 --> 09:12:30,057 to be a normalized value so rather than 16712 09:12:30,057 --> 09:12:34,258 showing 0.1.2.3 on the UI let's just 16713 09:12:34,258 --> 09:12:37,199 multiply the volume by 10f that way we 16714 09:12:37,199 --> 09:12:39,598 show between 1 and 10 okay then let's 16715 09:12:39,598 --> 09:12:42,360 just round out this number 16716 09:12:42,360 --> 09:12:45,360 and then add the text 16717 09:12:45,360 --> 09:12:48,237 so here's sound effects and then we have 16718 09:12:48,237 --> 09:12:50,578 the bone okay so that's pretty much it 16719 09:12:50,578 --> 09:12:52,377 and up here when we change the volume 16720 09:12:52,377 --> 09:12:55,258 let's just update the visual 16721 09:12:55,258 --> 09:12:57,360 and let's also make a private void start 16722 09:12:57,360 --> 09:12:59,578 and on start let's also update the video 16723 09:12:59,578 --> 09:13:01,557 okay that's it pretty simple now let's 16724 09:13:01,557 --> 09:13:03,258 do the exact same thing on the music 16725 09:13:03,258 --> 09:13:06,360 except on the Music Manager we named it 16726 09:13:06,360 --> 09:13:07,980 music manager but over here we just have 16727 09:13:07,980 --> 09:13:09,300 an audio Source there's no actual 16728 09:13:09,300 --> 09:13:11,640 manager so let's actually make one let's 16729 09:13:11,640 --> 09:13:14,040 create new c-sharp script for the Music 16730 09:13:14,040 --> 09:13:17,160 Manager let's go into the Music Manager 16731 09:13:17,160 --> 09:13:20,218 object let's attach a script and let's 16732 09:13:20,218 --> 09:13:22,800 open so here we really just need pretty 16733 09:13:22,800 --> 09:13:24,237 much exactly the same thing that we had 16734 09:13:24,237 --> 09:13:26,160 so let's just go here into The Sound 16735 09:13:26,160 --> 09:13:28,140 Manager and just copy these 16736 09:13:28,140 --> 09:13:29,820 so on the Music Manager let's paste them 16737 09:13:29,820 --> 09:13:32,699 we need a volume so a private mode for 16738 09:13:32,699 --> 09:13:34,800 the volume just like this okay so that 16739 09:13:34,800 --> 09:13:36,718 changes the volume except again the 16740 09:13:36,718 --> 09:13:38,519 Music Manager this one the music is 16741 09:13:38,519 --> 09:13:40,438 constantly going to be unlooping so 16742 09:13:40,438 --> 09:13:42,540 after we modify the volume we need to 16743 09:13:42,540 --> 09:13:44,460 update the actual audio source so let's 16744 09:13:44,460 --> 09:13:47,699 begin by grabbing the audio source audio 16745 09:13:47,699 --> 09:13:50,519 source and we just do a pro void awake 16746 09:13:50,519 --> 09:13:52,019 and on a week let's grab the audio 16747 09:13:52,019 --> 09:13:53,398 source 16748 09:13:53,398 --> 09:13:55,438 get the component of time Body Source 16749 09:13:55,438 --> 09:13:57,782 okay so we have this and when we change 16750 09:13:57,782 --> 09:13:59,820 the volume let's go here and update this 16751 09:13:59,820 --> 09:14:01,980 phone okay that's it and let's also 16752 09:14:01,980 --> 09:14:04,737 default it to some like 0.3f okay good 16753 09:14:04,737 --> 09:14:06,480 then in order to be able to call this 16754 09:14:06,480 --> 09:14:08,098 from the option Cy we just need to make 16755 09:14:08,098 --> 09:14:10,320 it a single turn so as usual public 16756 09:14:10,320 --> 09:14:12,300 static Music Manager for the instance 16757 09:14:12,300 --> 09:14:15,237 and we have a public get and a private 16758 09:14:15,237 --> 09:14:16,377 set 16759 09:14:16,377 --> 09:14:18,540 and then an awake just set instance 16760 09:14:18,540 --> 09:14:20,339 equals this okay 16761 09:14:20,339 --> 09:14:22,557 so then here on the options UI we can go 16762 09:14:22,557 --> 09:14:24,898 into the Music Manager the instance and 16763 09:14:24,898 --> 09:14:26,758 change the volume and afterwards let's 16764 09:14:26,758 --> 09:14:28,917 update the visual and down here on the 16765 09:14:28,917 --> 09:14:30,960 update visual lets you pretty much the 16766 09:14:30,960 --> 09:14:33,660 same thing so on the music text modify 16767 09:14:33,660 --> 09:14:36,660 the text to say music then we go into 16768 09:14:36,660 --> 09:14:39,540 the music manager and get the volume all 16769 09:14:39,540 --> 09:14:41,098 right that's it all this should be 16770 09:14:41,098 --> 09:14:42,718 working let's just drag our references 16771 09:14:42,718 --> 09:14:44,699 so back in the afternoon let's drag 16772 09:14:44,699 --> 09:14:46,500 firstly button so the sound effects 16773 09:14:46,500 --> 09:14:48,660 button that's this one then the music 16774 09:14:48,660 --> 09:14:50,938 button that's this one then we have the 16775 09:14:50,938 --> 09:14:53,040 music text that's this one and the sound 16776 09:14:53,040 --> 09:14:55,917 effects that's like that okay let's test 16777 09:14:55,917 --> 09:14:58,199 okay so here we are the music is playing 16778 09:14:58,199 --> 09:15:00,057 and as I click the music is currently 16779 09:15:00,057 --> 09:15:01,737 getting louder and louder 16780 09:15:01,737 --> 09:15:03,540 and their game I'm using is at max 16781 09:15:03,540 --> 09:15:05,578 volume and if I click again no the music 16782 09:15:05,578 --> 09:15:07,860 is completely muted alright awesome any 16783 09:15:07,860 --> 09:15:09,598 sound effects also work so like this 16784 09:15:09,598 --> 09:15:11,699 they should be less leather than usual 16785 09:15:11,699 --> 09:15:13,980 okay great so everything works perfectly 16786 09:15:13,980 --> 09:15:16,140 except obviously we have one big issue 16787 09:15:16,140 --> 09:15:18,122 the options window is on top of 16788 09:15:18,122 --> 09:15:19,019 everything 16789 09:15:19,019 --> 09:15:21,237 the goal is for the options window to be 16790 09:15:21,237 --> 09:15:23,578 kind of a sub menu of the pause window 16791 09:15:23,578 --> 09:15:25,622 we want to have an options button on the 16792 09:15:25,622 --> 09:15:27,180 pause window that won't bring up the 16793 09:15:27,180 --> 09:15:29,820 options window so let's do that let's 16794 09:15:29,820 --> 09:15:31,680 first hide the options window let's go 16795 09:15:31,680 --> 09:15:34,140 into the game pause UI and over here we 16796 09:15:34,140 --> 09:15:35,519 have these buttons let's just make one 16797 09:15:35,519 --> 09:15:37,737 more let's put it down the middle this 16798 09:15:37,737 --> 09:15:40,019 is going to be the options button 16799 09:15:40,019 --> 09:15:42,000 and inside let's modify the text to 16800 09:15:42,000 --> 09:15:43,800 options okay 16801 09:15:43,800 --> 09:15:46,078 now let's edit this script so we're 16802 09:15:46,078 --> 09:15:47,877 going to have another button so this is 16803 09:15:47,877 --> 09:15:50,398 the options button and down here we're 16804 09:15:50,398 --> 09:15:51,960 going to have another click so the 16805 09:15:51,960 --> 09:15:53,758 options button okay 16806 09:15:53,758 --> 09:15:56,339 and when this happens we want to just 16807 09:15:56,339 --> 09:15:58,737 show the options window so in order to 16808 09:15:58,737 --> 09:16:00,718 access it let's make this a Singleton so 16809 09:16:00,718 --> 09:16:04,377 public static for the options UI 16810 09:16:04,377 --> 09:16:07,819 a static instance 16811 09:16:08,877 --> 09:16:11,339 with a getting a private set 16812 09:16:11,339 --> 09:16:13,980 and on weak as usual instance equals 16813 09:16:13,980 --> 09:16:14,938 this 16814 09:16:14,938 --> 09:16:17,282 so over here on the game POS UI we go 16815 09:16:17,282 --> 09:16:19,377 into the options UI access the instance 16816 09:16:19,377 --> 09:16:21,300 and then call a show function so we need 16817 09:16:21,300 --> 09:16:23,758 to make this 16818 09:16:23,758 --> 09:16:25,737 so here on the options UI let's make 16819 09:16:25,737 --> 09:16:28,737 those so a public void show 16820 09:16:28,737 --> 09:16:31,140 and this one as usual just game objects 16821 09:16:31,140 --> 09:16:34,398 that active into true 16822 09:16:39,839 --> 09:16:42,660 and then we have a private hide 16823 09:16:42,660 --> 09:16:45,898 and this set active in two phones 16824 09:16:45,898 --> 09:16:47,820 okay we have both these on the other 16825 09:16:47,820 --> 09:16:50,398 side we show it and over here on start 16826 09:16:50,398 --> 09:16:53,218 let's also hide it okay 16827 09:16:53,218 --> 09:16:55,320 then let's also hide it manually so 16828 09:16:55,320 --> 09:16:57,000 let's add a button to close the options 16829 09:16:57,000 --> 09:16:59,578 UI so over here let's show the options 16830 09:16:59,578 --> 09:17:02,282 UI and let's make another button let's 16831 09:17:02,282 --> 09:17:04,680 put it on the bottom this one is the 16832 09:17:04,680 --> 09:17:05,938 close button 16833 09:17:05,938 --> 09:17:08,160 and over here let's just say close 16834 09:17:08,160 --> 09:17:10,320 so then here on the options UI just make 16835 09:17:10,320 --> 09:17:12,898 another button the close button and down 16836 09:17:12,898 --> 09:17:15,980 here for the click event 16837 09:17:16,199 --> 09:17:18,660 we go into the close button and we just 16838 09:17:18,660 --> 09:17:20,460 call height 16839 09:17:20,460 --> 09:17:22,218 okay so that won't hide the window 16840 09:17:22,218 --> 09:17:24,718 however remember that the pause window 16841 09:17:24,718 --> 09:17:26,398 can also be closed by just pressing 16842 09:17:26,398 --> 09:17:29,578 escape if we resume with the hotkey it 16843 09:17:29,578 --> 09:17:31,320 won't hide the pause window so let's 16844 09:17:31,320 --> 09:17:32,640 also make sure this one hides on the 16845 09:17:32,640 --> 09:17:34,557 same thing so we can do pretty much 16846 09:17:34,557 --> 09:17:36,057 going to the kitchen game manager the 16847 09:17:36,057 --> 09:17:37,980 instance and let's listen when the game 16848 09:17:37,980 --> 09:17:40,320 is unpaused so when that happens let's 16849 09:17:40,320 --> 09:17:41,820 hide this window 16850 09:17:41,820 --> 09:17:43,800 so once again let's do things nice and 16851 09:17:43,800 --> 09:17:46,557 clean let's rename this so the kitchen 16852 09:17:46,557 --> 09:17:48,540 game manager 16853 09:17:48,540 --> 09:17:50,640 and when this happens let's just hide 16854 09:17:50,640 --> 09:17:53,339 okay this should work let's just drag on 16855 09:17:53,339 --> 09:17:55,199 the references so first here on the 16856 09:17:55,199 --> 09:17:57,598 options UI let's drag the close button 16857 09:17:57,598 --> 09:18:00,898 and then on the game pause UI let's drag 16858 09:18:00,898 --> 09:18:03,480 the options button okay so let's test 16859 09:18:03,480 --> 09:18:05,758 and if right away the options window is 16860 09:18:05,758 --> 09:18:07,377 not showing the trade and if I press in 16861 09:18:07,377 --> 09:18:08,640 this game there you go there's the pause 16862 09:18:08,640 --> 09:18:10,557 window and if I can click on options if 16863 09:18:10,557 --> 09:18:12,237 there's the options window now if I can 16864 09:18:12,237 --> 09:18:13,980 go and close back here back into resume 16865 09:18:13,980 --> 09:18:17,218 okay works now if I pause options and 16866 09:18:17,218 --> 09:18:19,320 now press on the Escape key and you 16867 09:18:19,320 --> 09:18:21,122 better go closes everything all right 16868 09:18:21,122 --> 09:18:23,218 great so everything is working fine 16869 09:18:23,218 --> 09:18:27,540 however we have one slight issue 16870 09:18:27,540 --> 09:18:30,122 the option does work so I can modify 16871 09:18:30,122 --> 09:18:31,557 this to change the sound effects and 16872 09:18:31,557 --> 09:18:34,199 Music volume so for example let's mute 16873 09:18:34,199 --> 09:18:35,877 the music and put the sound effects on 16874 09:18:35,877 --> 09:18:39,057 five so I put it like this but now if I 16875 09:18:39,057 --> 09:18:42,180 stop playing and I hit play again 16876 09:18:42,180 --> 09:18:44,460 and working the options and oh there's 16877 09:18:44,460 --> 09:18:46,438 the issue basically that is back to the 16878 09:18:46,438 --> 09:18:48,782 default obviously that is resetting 16879 09:18:48,782 --> 09:18:50,160 since we didn't actually save anything 16880 09:18:50,160 --> 09:18:53,282 so let's save it now in unity the 16881 09:18:53,282 --> 09:18:55,078 easiest way to save some data is using 16882 09:18:55,078 --> 09:18:57,718 player prefs so let's go over here on 16883 09:18:57,718 --> 09:19:00,057 The Sound Manager and when we modify the 16884 09:19:00,057 --> 09:19:02,519 volume over here when we do that let's 16885 09:19:02,519 --> 09:19:05,160 access the Unity Player prefs and over 16886 09:19:05,160 --> 09:19:07,078 here we've got a bunch of set functions 16887 09:19:07,078 --> 09:19:09,417 so we can save a float an INT or a 16888 09:19:09,417 --> 09:19:11,398 string this one as you can see it takes 16889 09:19:11,398 --> 09:19:14,098 a string and a value so this is pretty 16890 09:19:14,098 --> 09:19:16,560 much essentially just a dictionary now 16891 09:19:16,560 --> 09:19:18,060 for the key as you can see it's a type 16892 09:19:18,060 --> 09:19:20,040 string but again we should not be using 16893 09:19:20,040 --> 09:19:21,300 strings directly 16894 09:19:21,300 --> 09:19:23,340 so let's go up here in order to make a 16895 09:19:23,340 --> 09:19:25,680 proper constant so a private con string 16896 09:19:25,680 --> 09:19:27,980 let's go with Pro layer 16897 09:19:27,980 --> 09:19:32,460 prefs sound effects volume 16898 09:19:32,460 --> 09:19:36,180 and let's go sound effects volume 16899 09:19:36,180 --> 09:19:38,820 okay we have our nice Center in content 16900 09:19:38,820 --> 09:19:40,740 and down here when we set the float 16901 09:19:40,740 --> 09:19:43,500 let's use this string and say the volume 16902 09:19:43,500 --> 09:19:45,960 okay so that is going to set the float 16903 09:19:45,960 --> 09:19:48,180 and now technically Unity is going to 16904 09:19:48,180 --> 09:19:49,800 automatically save the player perhaps 16905 09:19:49,800 --> 09:19:51,840 basically there are only problems if 16906 09:19:51,840 --> 09:19:54,240 Unity somehow crashes in between when 16907 09:19:54,240 --> 09:19:56,340 you can't set float and when it actually 16908 09:19:56,340 --> 09:19:59,040 saves but if you want to prevent that 16909 09:19:59,040 --> 09:20:00,900 from happening you can just go and tell 16910 09:20:00,900 --> 09:20:03,596 it to save manually just like that that 16911 09:20:03,596 --> 09:20:05,700 won't definitely save it and now we just 16912 09:20:05,700 --> 09:20:08,580 need to handle loading so here on awake 16913 09:20:08,580 --> 09:20:10,020 when we have this let's go into the play 16914 09:20:10,020 --> 09:20:13,020 prefs and let's use get float let's pass 16915 09:20:13,020 --> 09:20:15,480 in the same key so this one takes the 16916 09:20:15,480 --> 09:20:17,280 key and default value so let's default 16917 09:20:17,280 --> 09:20:19,256 it to one F basically the default value 16918 09:20:19,256 --> 09:20:22,080 is used if there's no save data on 16919 09:20:22,080 --> 09:20:24,360 display prefs on this key so the first 16920 09:20:24,360 --> 09:20:25,980 time we run it's actually going to use 16921 09:20:25,980 --> 09:20:28,020 this default and this one's going to 16922 09:20:28,020 --> 09:20:29,400 return these saved value so let's just 16923 09:20:29,400 --> 09:20:30,660 set it on the volume 16924 09:20:30,660 --> 09:20:32,936 okay so that's it that's only takes to 16925 09:20:32,936 --> 09:20:34,916 save some basic data now let's do the 16926 09:20:34,916 --> 09:20:37,080 exact same thing on music so over here 16927 09:20:37,080 --> 09:20:39,660 on the Music Manager let's first Define 16928 09:20:39,660 --> 09:20:43,916 our private con string for the player 16929 09:20:43,916 --> 09:20:46,560 pref's music volume 16930 09:20:46,560 --> 09:20:50,040 and this is going to be the music volume 16931 09:20:50,040 --> 09:20:52,560 okay we have our string and then down 16932 09:20:52,560 --> 09:20:54,540 here when you change the volume layer 16933 09:20:54,540 --> 09:20:56,660 press 16934 09:20:58,256 --> 09:21:01,560 and let's set the float on this key and 16935 09:21:01,560 --> 09:21:03,900 let's pass in the Music Volume okay and 16936 09:21:03,900 --> 09:21:05,820 then what's going to player prefs and 16937 09:21:05,820 --> 09:21:08,096 actually save it and now appear on the 16938 09:21:08,096 --> 09:21:08,880 wake 16939 09:21:08,880 --> 09:21:11,460 let's grab the volume 16940 09:21:11,460 --> 09:21:13,256 and it's going to be going to the player 16941 09:21:13,256 --> 09:21:15,596 prefs in order to get the float on this 16942 09:21:15,596 --> 09:21:17,340 key 16943 09:21:17,340 --> 09:21:20,460 and default value is 0.3f however over 16944 09:21:20,460 --> 09:21:21,840 here on the music again we are not 16945 09:21:21,840 --> 09:21:24,416 spawning the sound afterwards the sound 16946 09:21:24,416 --> 09:21:26,160 starts playing right away 16947 09:21:26,160 --> 09:21:28,020 so let's make sure to set the audio 16948 09:21:28,020 --> 09:21:29,880 Source volume to the one we grab from 16949 09:21:29,880 --> 09:21:32,400 there okay that's it so like this it 16950 09:21:32,400 --> 09:21:35,040 should be working so let's test so here 16951 09:21:35,040 --> 09:21:36,596 we are and the music is playing let's 16952 09:21:36,596 --> 09:21:39,180 pause go into the options let's bring 16953 09:21:39,180 --> 09:21:41,220 the music completely down so let's mute 16954 09:21:41,220 --> 09:21:43,020 the music okay the music is gone and 16955 09:21:43,020 --> 09:21:45,416 sound effects let's put a note 5. now 16956 09:21:45,416 --> 09:21:47,580 let's stop playing and now play again 16957 09:21:47,580 --> 09:21:50,640 and going to the menu options and if 16958 09:21:50,640 --> 09:21:52,380 there you go the data was indeed saved 16959 09:21:52,380 --> 09:21:54,596 and the music is indeed muted alright 16960 09:21:54,596 --> 09:21:57,660 awesome so here we have some basic data 16961 09:21:57,660 --> 09:21:59,580 being saved and also just quick note 16962 09:21:59,580 --> 09:22:01,740 related to saving for this simple game 16963 09:22:01,740 --> 09:22:03,480 decisions are pretty quick so I didn't 16964 09:22:03,480 --> 09:22:05,340 include any kind of save system for the 16965 09:22:05,340 --> 09:22:07,500 actual game data but if you want to know 16966 09:22:07,500 --> 09:22:08,820 how to do that I also have video 16967 09:22:08,820 --> 09:22:11,460 covering that topic okay so with that we 16968 09:22:11,460 --> 09:22:13,320 have our options window working the 16969 09:22:13,320 --> 09:22:15,780 volume sliders work perfectly the next 16970 09:22:15,780 --> 09:22:17,400 thing we need to add to our options is 16971 09:22:17,400 --> 09:22:19,800 some key rebinding so let's do that in 16972 09:22:19,800 --> 09:22:21,360 the next lecture 16973 09:22:21,360 --> 09:22:23,340 hello and welcome I'm your code monkey 16974 09:22:23,340 --> 09:22:25,560 in this lecture we're going to add key 16975 09:22:25,560 --> 09:22:28,320 rebinding to our options menu so here we 16976 09:22:28,320 --> 09:22:30,240 already have this nice options menu we 16977 09:22:30,240 --> 09:22:31,620 can modify the volume of the sound 16978 09:22:31,620 --> 09:22:33,900 effects or the music next let's handle 16979 09:22:33,900 --> 09:22:36,060 key rebinding okay so first let's build 16980 09:22:36,060 --> 09:22:38,276 the elements over here on the UI so 16981 09:22:38,276 --> 09:22:40,560 let's create a bunch more buttons but 16982 09:22:40,560 --> 09:22:41,756 before that let's actually make some 16983 09:22:41,756 --> 09:22:43,080 text on the side and buttons in the 16984 09:22:43,080 --> 09:22:45,720 middle so let's create a brand new UI 16985 09:22:45,720 --> 09:22:46,620 text 16986 09:22:46,620 --> 09:22:49,020 call this move of text 16987 09:22:49,020 --> 09:22:50,756 let's put it on the same size as the 16988 09:22:50,756 --> 09:22:52,740 other one so these got a font of 24 so 16989 09:22:52,740 --> 09:22:55,320 let's put it same thing font of 24 width 16990 09:22:55,320 --> 09:22:57,120 and height let's put both of these on 16991 09:22:57,120 --> 09:22:59,220 zero and down here anchor it to the left 16992 09:22:59,220 --> 09:23:00,900 okay down the middle and with no 16993 09:23:00,900 --> 09:23:03,416 wrapping okay so then over here this is 16994 09:23:03,416 --> 09:23:05,756 going to be the move up action 16995 09:23:05,756 --> 09:23:08,340 so we have move up then we have the move 16996 09:23:08,340 --> 09:23:11,276 down move left move right then we have 16997 09:23:11,276 --> 09:23:13,256 the interact the interact alternate and 16998 09:23:13,256 --> 09:23:15,480 finally the pause so these are all of 16999 09:23:15,480 --> 09:23:16,916 our actions so let's just make all of 17000 09:23:16,916 --> 09:23:17,700 these 17001 09:23:17,700 --> 09:23:19,800 so rename this so this one is the move 17002 09:23:19,800 --> 09:23:20,820 down 17003 09:23:20,820 --> 09:23:23,360 then this one over here is the move left 17004 09:23:23,360 --> 09:23:27,416 this one is the move right this one is 17005 09:23:27,416 --> 09:23:30,320 the interact text then the interact 17006 09:23:30,320 --> 09:23:33,596 alternate text and finally the pause 17007 09:23:33,596 --> 09:23:35,756 text now let's just modify the text on 17008 09:23:35,756 --> 09:23:37,620 these so that's the pause 17009 09:23:37,620 --> 09:23:40,680 that one is the indirect Alt 17010 09:23:40,680 --> 09:23:44,040 then this one is the interact then we've 17011 09:23:44,040 --> 09:23:46,140 got the move right 17012 09:23:46,140 --> 09:23:49,500 then over here the move left and finally 17013 09:23:49,500 --> 09:23:51,900 we have the move down 17014 09:23:51,900 --> 09:23:54,060 okay so those are our labels for our 17015 09:23:54,060 --> 09:23:56,040 controls now let's just make buttons 17016 09:23:56,040 --> 09:23:57,300 over here on the right side so let's 17017 09:23:57,300 --> 09:23:59,340 duplicate one of these buttons let's put 17018 09:23:59,340 --> 09:24:01,200 it over here and put it on something 17019 09:24:01,200 --> 09:24:04,200 like 50 by 50. so this is going to be 17020 09:24:04,200 --> 09:24:07,256 the move up button and inside on the 17021 09:24:07,256 --> 09:24:09,300 text this is going to be pretty much 17022 09:24:09,300 --> 09:24:12,960 just a w okay so we have the move up 17023 09:24:12,960 --> 09:24:14,700 then we're going to have the move down 17024 09:24:14,700 --> 09:24:19,380 move left move right the interact the 17025 09:24:19,380 --> 09:24:21,660 interact alternate and the pause 17026 09:24:21,660 --> 09:24:23,400 so we just need a bit more space so 17027 09:24:23,400 --> 09:24:25,500 let's move all of these up by quite a 17028 09:24:25,500 --> 09:24:28,320 bit let's also move the music and the 17029 09:24:28,320 --> 09:24:31,080 sound effects so move all of these like 17030 09:24:31,080 --> 09:24:33,720 that okay let's just name all these 17031 09:24:33,720 --> 09:24:35,756 buttons so this one 17032 09:24:35,756 --> 09:24:38,880 is the second one so this may move down 17033 09:24:38,880 --> 09:24:42,120 then over here the move left 17034 09:24:42,120 --> 09:24:45,900 then the move right then the interact 17035 09:24:45,900 --> 09:24:50,220 button the interact alternate button 17036 09:24:50,220 --> 09:24:53,756 and finally the pause button okay those 17037 09:24:53,756 --> 09:24:55,500 are on the buttons let's just position 17038 09:24:55,500 --> 09:24:57,660 all of the labels exactly where they 17039 09:24:57,660 --> 09:24:59,960 should be 17040 09:25:02,520 --> 09:25:04,680 okay so here we have all of the options 17041 09:25:04,680 --> 09:25:06,776 all of our bindings now in code let's 17042 09:25:06,776 --> 09:25:08,700 grab references to all the buttons and 17043 09:25:08,700 --> 09:25:11,040 all the text inside the buttons so here 17044 09:25:11,040 --> 09:25:12,660 inside the options URL let's add all of 17045 09:25:12,660 --> 09:25:15,060 those so first of all for the attacks 17046 09:25:15,060 --> 09:25:16,980 we're going to have the move of text 17047 09:25:16,980 --> 09:25:19,200 then the down left right and so on so 17048 09:25:19,200 --> 09:25:21,660 let you see all of these so down 17049 09:25:21,660 --> 09:25:24,120 then over here the left then the right 17050 09:25:24,120 --> 09:25:27,060 then the interact text the interact 17051 09:25:27,060 --> 09:25:30,360 alternate text and finally we have the 17052 09:25:30,360 --> 09:25:31,436 pause text 17053 09:25:31,436 --> 09:25:33,596 and for the buttons let's go up here 17054 09:25:33,596 --> 09:25:35,276 make all the buttons so they move up 17055 09:25:35,276 --> 09:25:40,140 button then they move down button 17056 09:25:40,140 --> 09:25:43,500 then we have the move left button then 17057 09:25:43,500 --> 09:25:46,200 the move right button then we have the 17058 09:25:46,200 --> 09:25:48,360 interact button the interact alternate 17059 09:25:48,360 --> 09:25:49,436 button 17060 09:25:49,436 --> 09:25:52,140 and finally the pause button 17061 09:25:52,140 --> 09:25:55,020 okay so we have all of these references 17062 09:25:55,020 --> 09:25:56,756 over here in the editor let's just drag 17063 09:25:56,756 --> 09:25:58,740 them so let's make sure we drag them on 17064 09:25:58,740 --> 09:26:01,200 correctly so let's do it one by one so 17065 09:26:01,200 --> 09:26:03,416 the move up this is the text and 17066 09:26:03,416 --> 09:26:04,620 actually it's not that one so that's 17067 09:26:04,620 --> 09:26:06,000 already a mistake right there we want 17068 09:26:06,000 --> 09:26:07,980 the text from inside buttons 17069 09:26:07,980 --> 09:26:09,660 so let's pick up all of these text 17070 09:26:09,660 --> 09:26:11,820 objects so let's go into the options so 17071 09:26:11,820 --> 09:26:13,740 text inside the move up let's grab that 17072 09:26:13,740 --> 09:26:15,960 one then inside the move down let's grab 17073 09:26:15,960 --> 09:26:18,480 that one and then left and so on so 17074 09:26:18,480 --> 09:26:20,040 definitely make sure you grab the right 17075 09:26:20,040 --> 09:26:22,436 ones okay that's on text now for the 17076 09:26:22,436 --> 09:26:25,140 button so let's move up button then you 17077 09:26:25,140 --> 09:26:26,160 move down 17078 09:26:26,160 --> 09:26:28,080 then they move left 17079 09:26:28,080 --> 09:26:32,040 the move right the interact interact 17080 09:26:32,040 --> 09:26:34,740 alternate and finally the pause button 17081 09:26:34,740 --> 09:26:36,660 okay great and just to verify that 17082 09:26:36,660 --> 09:26:37,980 everything is working let's give proper 17083 09:26:37,980 --> 09:26:39,840 names to these objects 17084 09:26:39,840 --> 09:26:44,000 so the move up button text 17085 09:26:48,540 --> 09:26:50,276 okay so I've renamed all the buttons so 17086 09:26:50,276 --> 09:26:52,080 now over here it's much easier to verify 17087 09:26:52,080 --> 09:26:54,000 that we have the correct references so 17088 09:26:54,000 --> 09:26:56,220 the sound sound music music and so on so 17089 09:26:56,220 --> 09:26:57,660 definitely make sure all of these are 17090 09:26:57,660 --> 09:26:59,096 correct otherwise you might go crazy 17091 09:26:59,096 --> 09:27:01,256 when things start to go a bit weird so 17092 09:27:01,256 --> 09:27:02,640 make sure these are all correct all 17093 09:27:02,640 --> 09:27:04,800 right now let's begin by updating the 17094 09:27:04,800 --> 09:27:07,140 text inside over here so let's go into 17095 09:27:07,140 --> 09:27:09,416 our update visual so we go into this set 17096 09:27:09,416 --> 09:27:10,980 the text and now we need to get the 17097 09:27:10,980 --> 09:27:13,080 binding text for this binding so for 17098 09:27:13,080 --> 09:27:14,520 that let's make that function on the 17099 09:27:14,520 --> 09:27:16,680 game input over here let's just comment 17100 09:27:16,680 --> 09:27:17,700 this out 17101 09:27:17,700 --> 09:27:19,740 then over here on the game input script 17102 09:27:19,740 --> 09:27:21,300 let's make a function to get the 17103 09:27:21,300 --> 09:27:23,276 bindings certainly we could make 17104 09:27:23,276 --> 09:27:24,900 something just to grab this player input 17105 09:27:24,900 --> 09:27:26,880 actions but again we don't want the 17106 09:27:26,880 --> 09:27:28,620 options UI to know what input system 17107 09:27:28,620 --> 09:27:31,140 we're using it should work regardless of 17108 09:27:31,140 --> 09:27:32,756 what input system 17109 09:27:32,756 --> 09:27:34,680 so we don't want the game input to 17110 09:27:34,680 --> 09:27:36,776 return anything of this type instead we 17111 09:27:36,776 --> 09:27:38,400 want to make a nice layer of abstraction 17112 09:27:38,400 --> 09:27:40,620 so for that let's make an enum to Define 17113 09:27:40,620 --> 09:27:43,200 all of our bindings so let's make a 17114 09:27:43,200 --> 09:27:44,640 public since we're going to access it 17115 09:27:44,640 --> 09:27:46,980 enum call it binding 17116 09:27:46,980 --> 09:27:48,776 and over here let's add all the bindings 17117 09:27:48,776 --> 09:27:51,480 so we've got the move up then we have 17118 09:27:51,480 --> 09:27:55,380 the move down the move left the move 17119 09:27:55,380 --> 09:27:58,560 right then we have the interact the 17120 09:27:58,560 --> 09:28:00,720 interact alternate 17121 09:28:00,720 --> 09:28:03,060 and finally the pause so these are all 17122 09:28:03,060 --> 09:28:04,980 of the bindings now let's make a 17123 09:28:04,980 --> 09:28:07,140 function to return the binding text 17124 09:28:07,140 --> 09:28:09,300 so over here let's make a public we're 17125 09:28:09,300 --> 09:28:11,040 going to return a string 17126 09:28:11,040 --> 09:28:13,620 let's just name it get binding text and 17127 09:28:13,620 --> 09:28:17,220 as a parameter let's receive a binding 17128 09:28:17,220 --> 09:28:19,500 okay so now here let's just do a switch 17129 09:28:19,500 --> 09:28:22,200 switch on this binding and basically 17130 09:28:22,200 --> 09:28:24,120 just match up the enum to whatever 17131 09:28:24,120 --> 09:28:25,680 action we have 17132 09:28:25,680 --> 09:28:27,480 so for example let's begin with the 17133 09:28:27,480 --> 09:28:29,040 interact since these are the simplest 17134 09:28:29,040 --> 09:28:30,180 ones 17135 09:28:30,180 --> 09:28:32,820 so for this one to get the bindings we 17136 09:28:32,820 --> 09:28:35,160 first go inside the player input actions 17137 09:28:35,160 --> 09:28:37,080 then let's go inside the player action 17138 09:28:37,080 --> 09:28:39,300 map then for the action so in this case 17139 09:28:39,300 --> 09:28:41,640 the interact and anything inside we've 17140 09:28:41,640 --> 09:28:44,340 got the bindings this is an array of all 17141 09:28:44,340 --> 09:28:46,740 of the bindings in our input map we 17142 09:28:46,740 --> 09:28:48,416 defined all of the keyboard bindings on 17143 09:28:48,416 --> 09:28:50,460 index 0. later on we're going to add 17144 09:28:50,460 --> 09:28:52,436 Gamepad bindings but for now we're going 17145 09:28:52,436 --> 09:28:55,020 to have the keyboard always on index 0. 17146 09:28:55,020 --> 09:28:57,180 so over here going to bindings axis on 17147 09:28:57,180 --> 09:28:59,880 zero and let's just do a two string 17148 09:28:59,880 --> 09:29:02,640 okay so let's just return this and let's 17149 09:29:02,640 --> 09:29:04,320 do a default to return always this one 17150 09:29:04,320 --> 09:29:06,596 just like this okay so let's do a quick 17151 09:29:06,596 --> 09:29:08,160 unlock to see what this returns so let's 17152 09:29:08,160 --> 09:29:10,436 do it over here on the game input just a 17153 09:29:10,436 --> 09:29:12,900 debug.log go into there get the binding 17154 09:29:12,900 --> 09:29:14,820 tags for the interact 17155 09:29:14,820 --> 09:29:17,580 okay so let's test and right away yep we 17156 09:29:17,580 --> 09:29:19,980 do see it working so the interact and 17157 09:29:19,980 --> 09:29:22,560 The Binding is on keyboard slash e but 17158 09:29:22,560 --> 09:29:24,180 we don't want all of this text we really 17159 09:29:24,180 --> 09:29:26,340 just want to see the E thankfully the 17160 09:29:26,340 --> 09:29:28,080 input system has a really great function 17161 09:29:28,080 --> 09:29:29,936 for just that so instead of calling the 17162 09:29:29,936 --> 09:29:32,276 general to string let's call to display 17163 09:29:32,276 --> 09:29:35,276 string let's see any of this one does 17164 09:29:35,276 --> 09:29:37,500 return just easy okay great so this is 17165 09:29:37,500 --> 09:29:39,300 the one that we want let's do the same 17166 09:29:39,300 --> 09:29:40,740 thing for all of the other simple 17167 09:29:40,740 --> 09:29:42,000 actions 17168 09:29:42,000 --> 09:29:44,220 so we've got the interact then we have 17169 09:29:44,220 --> 09:29:47,820 the interact alternate and we have the 17170 09:29:47,820 --> 09:29:49,380 pause so these are all the super simple 17171 09:29:49,380 --> 09:29:51,840 ones so just going to interact alternate 17172 09:29:51,840 --> 09:29:54,000 grab the binding on zero and for the 17173 09:29:54,000 --> 09:29:55,980 pause binding on zero okay so these are 17174 09:29:55,980 --> 09:29:58,256 all super simple now the more complex 17175 09:29:58,256 --> 09:30:00,540 one is the move it's more complex 17176 09:30:00,540 --> 09:30:02,096 because you can see all the others just 17177 09:30:02,096 --> 09:30:04,200 have one binding except for the move 17178 09:30:04,200 --> 09:30:06,960 over here we have a composite binding so 17179 09:30:06,960 --> 09:30:08,580 that's basically a binding which inside 17180 09:30:08,580 --> 09:30:10,980 has four separate bindings basically the 17181 09:30:10,980 --> 09:30:12,416 way that this works is that when you use 17182 09:30:12,416 --> 09:30:13,860 a composed binding all of these are 17183 09:30:13,860 --> 09:30:16,256 added to the array so this to the vector 17184 09:30:16,256 --> 09:30:18,180 is going to be on binding 0 then the up 17185 09:30:18,180 --> 09:30:19,980 is going to be on binding one two three 17186 09:30:19,980 --> 09:30:22,320 four and so on then the arrow keys this 17187 09:30:22,320 --> 09:30:25,256 one is going to be on five then we have 17188 09:30:25,256 --> 09:30:27,840 six seven eight nine and ten let's do a 17189 09:30:27,840 --> 09:30:29,520 log just to verify 17190 09:30:29,520 --> 09:30:32,820 so here if we do one for the move up 17191 09:30:32,820 --> 09:30:35,096 action for this one let's go into the 17192 09:30:35,096 --> 09:30:37,020 move and let's print out just the 17193 09:30:37,020 --> 09:30:38,880 binding zero let's do a regular two 17194 09:30:38,880 --> 09:30:41,520 string let's see what this returns so up 17195 09:30:41,520 --> 09:30:44,276 here let's just modify our log to say 17196 09:30:44,276 --> 09:30:46,680 the move up okay so let's see any up 17197 09:30:46,680 --> 09:30:48,776 index 0 does have the move to the vector 17198 09:30:48,776 --> 09:30:51,120 and now if we print the one on binding 17199 09:30:51,120 --> 09:30:53,400 of one yep now this one does have the 17200 09:30:53,400 --> 09:30:54,776 move on the w 17201 09:30:54,776 --> 09:30:56,820 so like I said we can see that all of 17202 09:30:56,820 --> 09:30:58,200 these Composites these are technically 17203 09:30:58,200 --> 09:31:00,300 inside that one but in terms of that 17204 09:31:00,300 --> 09:31:02,460 array it's just a flat array so this one 17205 09:31:02,460 --> 09:31:05,820 index 0 1 2 3 and 4. so that makes it 17206 09:31:05,820 --> 09:31:08,220 super simple to add over here so they 17207 09:31:08,220 --> 09:31:10,200 move up down left right 17208 09:31:10,200 --> 09:31:13,640 and let's just do all these 17209 09:31:13,800 --> 09:31:15,596 so we have all the bindings and over 17210 09:31:15,596 --> 09:31:19,680 here just one two three and four 17211 09:31:19,680 --> 09:31:21,416 and set a two string let's call the 17212 09:31:21,416 --> 09:31:24,416 display string okay so the binding text 17213 09:31:24,416 --> 09:31:26,400 this is all set up so let's go up here 17214 09:31:26,400 --> 09:31:28,740 and get rid of our testing code we can 17215 09:31:28,740 --> 09:31:30,776 now call this from the options UI so 17216 09:31:30,776 --> 09:31:32,220 over here let's do exam with that so 17217 09:31:32,220 --> 09:31:33,900 when we update the visual 17218 09:31:33,900 --> 09:31:36,180 let's go into the game and put let's 17219 09:31:36,180 --> 09:31:38,400 access the static instance let's get the 17220 09:31:38,400 --> 09:31:40,800 binding text and this one is going to do 17221 09:31:40,800 --> 09:31:42,060 the move up 17222 09:31:42,060 --> 09:31:43,680 so that's it this one is going to return 17223 09:31:43,680 --> 09:31:44,820 a string 17224 09:31:44,820 --> 09:31:48,020 let's write all of them 17225 09:31:52,740 --> 09:31:54,720 okay here are all of them so let's see 17226 09:31:54,720 --> 09:31:57,060 and if there they are all perfect don't 17227 09:31:57,060 --> 09:32:00,060 we SCD EF Escape okay great so the 17228 09:32:00,060 --> 09:32:01,800 visual is working now let's end on the 17229 09:32:01,800 --> 09:32:04,256 rebinding so let's add a click event 17230 09:32:04,256 --> 09:32:07,800 let's go into the move up button 17231 09:32:07,800 --> 09:32:10,140 let's go into the on click let's add in 17232 09:32:10,140 --> 09:32:12,660 listener and for the enlistener over 17233 09:32:12,660 --> 09:32:14,220 here let's make a function on the game 17234 09:32:14,220 --> 09:32:16,740 input to rebind this binding 17235 09:32:16,740 --> 09:32:19,020 so over here on the game input let's see 17236 09:32:19,020 --> 09:32:22,256 public void rebind binding and we 17237 09:32:22,256 --> 09:32:25,200 receive a binding 17238 09:32:25,200 --> 09:32:27,960 now for rebinding I cover this in detail 17239 09:32:27,960 --> 09:32:29,640 in the dedicated input system video 17240 09:32:29,640 --> 09:32:31,980 first basically we need to disable the 17241 09:32:31,980 --> 09:32:33,596 action map so let's go into the player 17242 09:32:33,596 --> 09:32:36,000 input actions let's access the player 17243 09:32:36,000 --> 09:32:37,620 and disable it so we need to do this 17244 09:32:37,620 --> 09:32:39,300 first then we're going to need to find 17245 09:32:39,300 --> 09:32:42,776 the action so player input actions and 17246 09:32:42,776 --> 09:32:44,520 for now let's go into the player and 17247 09:32:44,520 --> 09:32:47,220 let's just modify the move up action so 17248 09:32:47,220 --> 09:32:48,840 we're going to call the function perform 17249 09:32:48,840 --> 09:32:51,480 Interactive rebinding 17250 09:32:51,480 --> 09:32:53,520 this one as you can see takes a binding 17251 09:32:53,520 --> 09:32:55,620 index and if you remember up here we saw 17252 09:32:55,620 --> 09:32:58,080 that in order to modify the move up it's 17253 09:32:58,080 --> 09:32:59,820 on bindings index one so let's modify 17254 09:32:59,820 --> 09:33:01,436 the one on index one 17255 09:33:01,436 --> 09:33:04,200 okay so this is the function this 17256 09:33:04,200 --> 09:33:05,936 returns an object of this type a 17257 09:33:05,936 --> 09:33:08,756 rebinding operation this is a pretty 17258 09:33:08,756 --> 09:33:10,680 complex object where you can modify all 17259 09:33:10,680 --> 09:33:12,060 kinds of things add a bunch of 17260 09:33:12,060 --> 09:33:14,276 limitations and so on like for example 17261 09:33:14,276 --> 09:33:15,960 make a key not be able to be bound to 17262 09:33:15,960 --> 09:33:18,180 the mouse or something so there's tons 17263 09:33:18,180 --> 09:33:19,500 and tons of options you can play with 17264 09:33:19,500 --> 09:33:22,140 over here for the simple thing let's 17265 09:33:22,140 --> 09:33:24,720 just add an on complete listener so this 17266 09:33:24,720 --> 09:33:26,756 one takes in a convex and this will be 17267 09:33:26,756 --> 09:33:29,040 called whenever the interactive 17268 09:33:29,040 --> 09:33:30,840 rebinding completes 17269 09:33:30,840 --> 09:33:33,180 so over here on let's define and Lambda 17270 09:33:33,180 --> 09:33:35,640 so we come back and inside we have this 17271 09:33:35,640 --> 09:33:37,200 by the way over here this is the same 17272 09:33:37,200 --> 09:33:38,400 line of the expression that we saw 17273 09:33:38,400 --> 09:33:40,680 previously so exactly the same thing as 17274 09:33:40,680 --> 09:33:42,540 this except when we have just one 17275 09:33:42,540 --> 09:33:44,040 parenthesis we don't need to add them 17276 09:33:44,040 --> 09:33:46,740 okay so like this so then on this convex 17277 09:33:46,740 --> 09:33:48,480 we can see all kinds of things like for 17278 09:33:48,480 --> 09:33:50,040 example we can see the action that we 17279 09:33:50,040 --> 09:33:52,320 just rebound this is going to contain 17280 09:33:52,320 --> 09:33:54,960 all the data on the rebind operation so 17281 09:33:54,960 --> 09:33:56,756 for example let's print out the path so 17282 09:33:56,756 --> 09:33:58,560 let's go into the action 17283 09:33:58,560 --> 09:34:00,660 let's go into the bindings 17284 09:34:00,660 --> 09:34:03,720 on index 1 and let's print out the path 17285 09:34:03,720 --> 09:34:07,520 similar to a debug.log 17286 09:34:09,660 --> 09:34:11,756 and there's actually another one so 17287 09:34:11,756 --> 09:34:14,340 let's log the path and also the override 17288 09:34:14,340 --> 09:34:16,080 path these are two different things 17289 09:34:16,080 --> 09:34:18,180 let's see why in a bit we do this and 17290 09:34:18,180 --> 09:34:20,160 after we log we also need to rename on 17291 09:34:20,160 --> 09:34:21,596 the player action map so let's go into 17292 09:34:21,596 --> 09:34:24,360 the player input actions deep layer and 17293 09:34:24,360 --> 09:34:26,880 back enable this okay so we're only 17294 09:34:26,880 --> 09:34:28,436 going to need these settings on the 17295 09:34:28,436 --> 09:34:30,540 rewind action then we can just call 17296 09:34:30,540 --> 09:34:32,340 start in order to start the rebinding 17297 09:34:32,340 --> 09:34:34,916 process okay so this should work let's 17298 09:34:34,916 --> 09:34:36,776 just call this from the options UI so 17299 09:34:36,776 --> 09:34:38,756 over here we have the click let's go 17300 09:34:38,756 --> 09:34:41,756 into game input instance and let's 17301 09:34:41,756 --> 09:34:43,916 rebind The Binding and for this one is 17302 09:34:43,916 --> 09:34:46,256 the move up 17303 09:34:46,256 --> 09:34:49,380 okay with this let's test okay so here 17304 09:34:49,380 --> 09:34:51,360 if I click on the button and I click on 17305 09:34:51,360 --> 09:34:54,120 the T key and if there go it did work so 17306 09:34:54,120 --> 09:34:55,620 you can see that it print out the 17307 09:34:55,620 --> 09:34:57,960 regular path that is w and the override 17308 09:34:57,960 --> 09:35:01,256 path which is C so now if I exit out of 17309 09:35:01,256 --> 09:35:03,300 the options go back into the game if I 17310 09:35:03,300 --> 09:35:05,276 press W nope it does not move but if I 17311 09:35:05,276 --> 09:35:08,276 press T yep it does move upwards okay 17312 09:35:08,276 --> 09:35:10,860 great so we have successfully rebound 17313 09:35:10,860 --> 09:35:14,220 this one key now here just one thing in 17314 09:35:14,220 --> 09:35:15,720 previous versions of the input system 17315 09:35:15,720 --> 09:35:18,060 when doing a rebind operation you need 17316 09:35:18,060 --> 09:35:20,040 to manually dispose of this comeback 17317 09:35:20,040 --> 09:35:22,256 otherwise it would throw a memory error 17318 09:35:22,256 --> 09:35:23,936 in the recent version that I'm using 17319 09:35:23,936 --> 09:35:25,620 here there's no error so it seems 17320 09:35:25,620 --> 09:35:27,360 perhaps it's no longer needed to dispose 17321 09:35:27,360 --> 09:35:29,096 of the compact manually but still 17322 09:35:29,096 --> 09:35:30,660 there's no harm doing it just in case 17323 09:35:30,660 --> 09:35:33,180 over here combat dot dispose 17324 09:35:33,180 --> 09:35:35,340 okay so with that the key rebinding is 17325 09:35:35,340 --> 09:35:37,680 working except we have two issues the 17326 09:35:37,680 --> 09:35:38,820 first one is that it's not very clear 17327 09:35:38,820 --> 09:35:41,160 that it's listening for an input and the 17328 09:35:41,160 --> 09:35:43,200 second one is that the text options also 17329 09:35:43,200 --> 09:35:45,360 does not update so it's on both those 17330 09:35:45,360 --> 09:35:47,460 first let's add a visual when waiting 17331 09:35:47,460 --> 09:35:49,800 for a key press so inside the game 17332 09:35:49,800 --> 09:35:51,300 options UI let's create an empty game 17333 09:35:51,300 --> 09:35:54,900 object call this the press to rebind 17334 09:35:54,900 --> 09:35:56,096 team 17335 09:35:56,096 --> 09:35:58,560 let's stretch it out so put it on zero 17336 09:35:58,560 --> 09:36:01,980 on everything okay then inside let's add 17337 09:36:01,980 --> 09:36:03,416 a UI image 17338 09:36:03,416 --> 09:36:05,756 let's put it in black and once again 17339 09:36:05,756 --> 09:36:07,680 let's stretch it out 17340 09:36:07,680 --> 09:36:10,980 okay now let's also add a simple text 17341 09:36:10,980 --> 09:36:14,340 and for text let's say press a key 17342 09:36:14,340 --> 09:36:17,460 to rebind as usual let's put the width 17343 09:36:17,460 --> 09:36:20,096 and height on zero put it in bold Center 17344 09:36:20,096 --> 09:36:22,680 down the middle with no wrapping and 17345 09:36:22,680 --> 09:36:25,436 increase the size by quite a bit okay so 17346 09:36:25,436 --> 09:36:27,240 that's our super basic window now in the 17347 09:36:27,240 --> 09:36:28,740 code we just want to show and hide this 17348 09:36:28,740 --> 09:36:30,360 so let's do that and let's actually 17349 09:36:30,360 --> 09:36:32,040 begin with this hidden by default so 17350 09:36:32,040 --> 09:36:34,860 let's disable this object so here on the 17351 09:36:34,860 --> 09:36:36,960 options UI let's add another serialized 17352 09:36:36,960 --> 09:36:39,720 film it's going to be a transform for 17353 09:36:39,720 --> 09:36:44,540 the press to rebind key transform 17354 09:36:45,000 --> 09:36:47,040 so you have this let's make two show and 17355 09:36:47,040 --> 09:36:49,500 hide functions 17356 09:36:49,500 --> 09:36:53,520 so we show press to rebind key 17357 09:36:53,520 --> 09:36:55,860 we just go into that one game objects 17358 09:36:55,860 --> 09:36:58,140 and active this one into true 17359 09:36:58,140 --> 09:36:59,756 and another one where we set it to 17360 09:36:59,756 --> 09:37:01,380 phones so just 17361 09:37:01,380 --> 09:37:03,960 hide and set it to false okay pretty 17362 09:37:03,960 --> 09:37:06,540 simple let's make sure to hide this over 17363 09:37:06,540 --> 09:37:09,200 here on our start okay just like that 17364 09:37:09,200 --> 09:37:12,060 and for showing let's show it when we 17365 09:37:12,060 --> 09:37:13,980 actually rebind an action so right in 17366 09:37:13,980 --> 09:37:16,020 here but since we're going to have tons 17367 09:37:16,020 --> 09:37:17,520 of listeners to these events let's 17368 09:37:17,520 --> 09:37:19,080 actually make a nice separate function 17369 09:37:19,080 --> 09:37:21,720 to handle all of the rebinding logic so 17370 09:37:21,720 --> 09:37:24,660 down here let's make a function rebind 17371 09:37:24,660 --> 09:37:26,400 binding 17372 09:37:26,400 --> 09:37:30,720 we receive a game input.binding 17373 09:37:31,320 --> 09:37:33,660 then first we show the press rewind key 17374 09:37:33,660 --> 09:37:36,416 and then let's go into game input access 17375 09:37:36,416 --> 09:37:38,640 the instance and time to rebind binding 17376 09:37:38,640 --> 09:37:40,500 and pass in the same binding 17377 09:37:40,500 --> 09:37:42,900 okay so we have this and now up here on 17378 09:37:42,900 --> 09:37:44,820 the button event let's just call in this 17379 09:37:44,820 --> 09:37:47,936 function okay very simple so this will 17380 09:37:47,936 --> 09:37:50,520 work for actually showing the window but 17381 09:37:50,520 --> 09:37:52,620 now we need to know when to hide it and 17382 09:37:52,620 --> 09:37:54,060 for that let's use something that we've 17383 09:37:54,060 --> 09:37:55,500 used a few times in this course but 17384 09:37:55,500 --> 09:37:57,660 never directly let's use a c-sharp 17385 09:37:57,660 --> 09:37:59,936 donate as usual I have a dedicated video 17386 09:37:59,936 --> 09:38:01,916 on them this is basically how you can 17387 09:38:01,916 --> 09:38:04,080 define a field or a parameter of a type 17388 09:38:04,080 --> 09:38:06,540 which can hold a function it's another 17389 09:38:06,540 --> 09:38:08,880 Super useful CCR feature definitely 17390 09:38:08,880 --> 09:38:10,560 watch that video to learn all about it 17391 09:38:10,560 --> 09:38:13,860 let's go here on the game input and down 17392 09:38:13,860 --> 09:38:16,020 here when we have our rewind binding 17393 09:38:16,020 --> 09:38:17,936 over here let's receive a second 17394 09:38:17,936 --> 09:38:19,380 parameter this one is going to be of 17395 09:38:19,380 --> 09:38:21,776 type action this is one of the built-in 17396 09:38:21,776 --> 09:38:23,820 dongates it takes no parameters and 17397 09:38:23,820 --> 09:38:26,040 returns void so this one is perfect for 17398 09:38:26,040 --> 09:38:27,540 a simple comeback just like this one 17399 09:38:27,540 --> 09:38:30,480 let's go with on action rebound and 17400 09:38:30,480 --> 09:38:32,160 we're going to trigger this right here 17401 09:38:32,160 --> 09:38:34,200 after we achieve the convex so we get 17402 09:38:34,200 --> 09:38:36,180 the comeback let's trigger this just 17403 09:38:36,180 --> 09:38:38,040 like that and let's also get rid of 17404 09:38:38,040 --> 09:38:39,416 these testing logs we no longer need 17405 09:38:39,416 --> 09:38:40,980 them so just like this 17406 09:38:40,980 --> 09:38:43,436 now back here on the options UI so we've 17407 09:38:43,436 --> 09:38:45,300 got that and for the second parameter 17408 09:38:45,300 --> 09:38:47,820 let's just pass in the function to hide 17409 09:38:47,820 --> 09:38:50,220 that window so hi the press the rewind 17410 09:38:50,220 --> 09:38:52,980 key that's it again remember we're 17411 09:38:52,980 --> 09:38:54,900 passing in the function itself we're not 17412 09:38:54,900 --> 09:38:56,936 calling it so there's no parentheses 17413 09:38:56,936 --> 09:38:58,320 we're just passing in the function 17414 09:38:58,320 --> 09:39:01,500 itself okay so with this let's test so 17415 09:39:01,500 --> 09:39:03,120 here on the options let's rebind the 17416 09:39:03,120 --> 09:39:04,860 move W and there you go it does show up 17417 09:39:04,860 --> 09:39:06,480 to window and now if I press the key you 17418 09:39:06,480 --> 09:39:09,000 better go down hides okay great so this 17419 09:39:09,000 --> 09:39:10,560 is working but over here the text is 17420 09:39:10,560 --> 09:39:12,720 still not updating so over here on the 17421 09:39:12,720 --> 09:39:14,700 second comeback instead of just calling 17422 09:39:14,700 --> 09:39:16,740 this function we need to call this and 17423 09:39:16,740 --> 09:39:18,120 then also call the update visual 17424 09:39:18,120 --> 09:39:20,340 function so as usual let's use a simple 17425 09:39:20,340 --> 09:39:22,800 Lambda expression to do exactly both 17426 09:39:22,800 --> 09:39:25,500 so let's open and close the parentheses 17427 09:39:25,500 --> 09:39:28,620 and we do exactly this 17428 09:39:28,620 --> 09:39:30,480 so we hide the price of rebind and then 17429 09:39:30,480 --> 09:39:32,880 we update the visual okay that's it 17430 09:39:32,880 --> 09:39:34,916 let's test so here we are let's rewind 17431 09:39:34,916 --> 09:39:36,960 the move down we press on the T key and 17432 09:39:36,960 --> 09:39:38,460 there you go we did rebind and it did 17433 09:39:38,460 --> 09:39:41,220 update all right great now let's just 17434 09:39:41,220 --> 09:39:42,900 apply this to all of the other bindings 17435 09:39:42,900 --> 09:39:45,240 so first up here on the buttons let's 17436 09:39:45,240 --> 09:39:47,756 set listeners to all the buttons so 17437 09:39:47,756 --> 09:39:49,380 let's see move left 17438 09:39:49,380 --> 09:39:51,540 actually be moved down 17439 09:39:51,540 --> 09:39:55,200 then the move left move right the 17440 09:39:55,200 --> 09:39:56,936 interact button 17441 09:39:56,936 --> 09:39:59,580 the interact alternate button and 17442 09:39:59,580 --> 09:40:01,980 finally the pause button and for the 17443 09:40:01,980 --> 09:40:03,720 bindings this one is the fast binding 17444 09:40:03,720 --> 09:40:07,200 the interact alternate then the interact 17445 09:40:07,200 --> 09:40:10,436 then the move this one is the right 17446 09:40:10,436 --> 09:40:12,060 again make sure you don't make mistakes 17447 09:40:12,060 --> 09:40:14,276 here you call them the exact same one so 17448 09:40:14,276 --> 09:40:16,380 they move down okay so all of it is 17449 09:40:16,380 --> 09:40:17,276 correct here 17450 09:40:17,276 --> 09:40:19,860 and over here on the player input let's 17451 09:40:19,860 --> 09:40:23,596 do a switch on our binding 17452 09:40:30,540 --> 09:40:33,120 so Keys move up we do something and now 17453 09:40:33,120 --> 09:40:34,680 we could write this code directly up 17454 09:40:34,680 --> 09:40:37,256 here and then make a move down and write 17455 09:40:37,256 --> 09:40:38,936 a bunch more code that would work but 17456 09:40:38,936 --> 09:40:40,980 that would be way too worthy so let's 17457 09:40:40,980 --> 09:40:42,800 write our code in a nice clean way 17458 09:40:42,800 --> 09:40:44,640 basically the only thing we need down 17459 09:40:44,640 --> 09:40:46,436 here is we need to know the actual 17460 09:40:46,436 --> 09:40:48,540 action we're going to rebind and we need 17461 09:40:48,540 --> 09:40:50,756 to know the action index so let's just 17462 09:40:50,756 --> 09:40:52,860 find up here exactly that so an input 17463 09:40:52,860 --> 09:40:54,840 action for the input action 17464 09:40:54,840 --> 09:40:57,180 and then an end for the binding index 17465 09:40:57,180 --> 09:40:59,520 okay and then over here when we have the 17466 09:40:59,520 --> 09:41:00,960 switch for all of our bindings we just 17467 09:41:00,960 --> 09:41:03,416 set those so the input action in this 17468 09:41:03,416 --> 09:41:05,580 case it's going to be the player input 17469 09:41:05,580 --> 09:41:08,276 actions player and it's the move action 17470 09:41:08,276 --> 09:41:10,916 and for The Binding index 17471 09:41:10,916 --> 09:41:13,200 this one is on index one 17472 09:41:13,200 --> 09:41:14,936 then we're going to have the other moves 17473 09:41:14,936 --> 09:41:17,580 so they move down is going to be on 17474 09:41:17,580 --> 09:41:19,380 index 2. 17475 09:41:19,380 --> 09:41:22,756 then left and right 17476 09:41:25,256 --> 09:41:28,620 these are on index 3 and 4. okay so we 17477 09:41:28,620 --> 09:41:30,120 have all these and now for the other 17478 09:41:30,120 --> 09:41:31,020 ones 17479 09:41:31,020 --> 09:41:33,416 so for the interact this is the interact 17480 09:41:33,416 --> 09:41:36,000 action on binding zero then we've got 17481 09:41:36,000 --> 09:41:38,460 the interact alternate and the pause 17482 09:41:38,460 --> 09:41:42,120 so interact alternate and the pause 17483 09:41:42,120 --> 09:41:44,160 and this one is the pause action and the 17484 09:41:44,160 --> 09:41:45,960 interact alternate action and all of 17485 09:41:45,960 --> 09:41:48,000 them are on finding index of zero okay 17486 09:41:48,000 --> 09:41:49,320 so that's good so over here we are 17487 09:41:49,320 --> 09:41:50,756 assigning the input action and defining 17488 09:41:50,756 --> 09:41:52,860 index and also one thing we need to make 17489 09:41:52,860 --> 09:41:55,256 sure to always assign these values 17490 09:41:55,256 --> 09:41:57,300 so let's make sure to add a default here 17491 09:41:57,300 --> 09:41:58,860 just make sure it always works okay 17492 09:41:58,860 --> 09:42:01,256 great so now down here instead of always 17493 09:42:01,256 --> 09:42:03,000 accessing the move let's access whatever 17494 09:42:03,000 --> 09:42:05,400 is stored in the input action 17495 09:42:05,400 --> 09:42:07,320 and for The Binding whatever it is on 17496 09:42:07,320 --> 09:42:09,596 The Binding index okay so now this will 17497 09:42:09,596 --> 09:42:11,880 work with all of our bindings so here we 17498 09:42:11,880 --> 09:42:13,560 are and let's try rebinding all of them 17499 09:42:13,560 --> 09:42:15,060 so let's put them over here on the side 17500 09:42:15,060 --> 09:42:17,580 so before it move up let's put on T down 17501 09:42:17,580 --> 09:42:22,320 on G A on F then D on H for the interact 17502 09:42:22,320 --> 09:42:26,640 on y interact jumped on J and for the 17503 09:42:26,640 --> 09:42:28,980 Escape let's put it on E okay so all 17504 09:42:28,980 --> 09:42:30,540 these Keys have been rebound let's just 17505 09:42:30,540 --> 09:42:32,640 make sure they work so here I am moving 17506 09:42:32,640 --> 09:42:34,500 with these keys and yep it does work go 17507 09:42:34,500 --> 09:42:36,416 up here to interact and do the alt 17508 09:42:36,416 --> 09:42:38,520 interact and now the pause and if there 17509 09:42:38,520 --> 09:42:39,776 you go everything works perfectly 17510 09:42:39,776 --> 09:42:42,360 alright awesome so everything worked 17511 09:42:42,360 --> 09:42:44,220 perfectly although again we have the 17512 09:42:44,220 --> 09:42:46,680 same issue as previously so all the keys 17513 09:42:46,680 --> 09:42:48,180 have been rebound so it's not correct 17514 09:42:48,180 --> 09:42:51,120 right however now if I stop playing and 17515 09:42:51,120 --> 09:42:52,740 now if I play again 17516 09:42:52,740 --> 09:42:54,840 and nope there's the issue the rebinding 17517 09:42:54,840 --> 09:42:57,596 was lost so just like with the sound we 17518 09:42:57,596 --> 09:42:59,756 also need to save the new state now 17519 09:42:59,756 --> 09:43:01,560 thankfully the new input system has a 17520 09:43:01,560 --> 09:43:03,020 function that makes that super easy 17521 09:43:03,020 --> 09:43:05,820 let's go down to where we are rebinding 17522 09:43:05,820 --> 09:43:07,860 things and when we finish rebinding 17523 09:43:07,860 --> 09:43:09,300 let's just go into the player input 17524 09:43:09,300 --> 09:43:12,180 actions and let's call this function the 17525 09:43:12,180 --> 09:43:15,240 save bindings overrides as Json 17526 09:43:15,240 --> 09:43:17,340 this one is going to return a Json 17527 09:43:17,340 --> 09:43:19,380 string now if you don't know what is 17528 09:43:19,380 --> 09:43:21,180 Json go watch my quick video on it 17529 09:43:21,180 --> 09:43:22,980 basically it's a super easy to 17530 09:43:22,980 --> 09:43:25,020 understand and widely used file format 17531 09:43:25,020 --> 09:43:28,140 it's very easy to read and modify it's a 17532 09:43:28,140 --> 09:43:30,480 format where it's stored as just text so 17533 09:43:30,480 --> 09:43:32,580 let's look at what this says once we 17534 09:43:32,580 --> 09:43:34,916 debug down log over here after rebinding 17535 09:43:34,916 --> 09:43:37,680 something let's see so here if I rebind 17536 09:43:37,680 --> 09:43:39,776 one of these and if there you go there 17537 09:43:39,776 --> 09:43:41,880 we have our Json so the override 17538 09:43:41,880 --> 09:43:44,160 Bindings that overload the move on this 17539 09:43:44,160 --> 09:43:46,680 ID on this new path so basically we just 17540 09:43:46,680 --> 09:43:48,660 need to sort this string somewhere and 17541 09:43:48,660 --> 09:43:50,096 just like we did with the sound let's 17542 09:43:50,096 --> 09:43:52,320 just store it in the player prefs so 17543 09:43:52,320 --> 09:43:54,776 first let's define our constant so 17544 09:43:54,776 --> 09:43:58,320 private constring for the player prefs 17545 09:43:58,320 --> 09:43:59,936 bindings 17546 09:43:59,936 --> 09:44:04,140 and let's call this the input bindings 17547 09:44:04,140 --> 09:44:07,200 okay just like this 17548 09:44:07,200 --> 09:44:09,900 so then down here after we rebind the 17549 09:44:09,900 --> 09:44:10,620 king 17550 09:44:10,620 --> 09:44:13,436 let's go into player prefs and let's set 17551 09:44:13,436 --> 09:44:17,276 a string on the player prefs 17552 09:44:17,276 --> 09:44:18,776 bindings 17553 09:44:18,776 --> 09:44:20,640 and we're going to save the overrides as 17554 09:44:20,640 --> 09:44:22,936 Json 17555 09:44:23,096 --> 09:44:24,840 and after we do let's just make sure the 17556 09:44:24,840 --> 09:44:26,580 player perhaps is correctly saved okay 17557 09:44:26,580 --> 09:44:29,400 so that saves it then let's go on a way 17558 09:44:29,400 --> 09:44:31,860 to unload it so over here on awake let's 17559 09:44:31,860 --> 09:44:33,120 load that 17560 09:44:33,120 --> 09:44:34,740 let's first do a quick test to see if 17561 09:44:34,740 --> 09:44:38,460 there's a save so if the player prefs if 17562 09:44:38,460 --> 09:44:42,540 it has a king and if it has this key 17563 09:44:42,540 --> 09:44:45,060 if so then let's get it so the player 17564 09:44:45,060 --> 09:44:48,240 prefs let's get the string on this key 17565 09:44:48,240 --> 09:44:49,860 that returns this ring and we're going 17566 09:44:49,860 --> 09:44:51,416 to use the string let's just go into the 17567 09:44:51,416 --> 09:44:53,220 player input actions 17568 09:44:53,220 --> 09:44:55,500 and let's call the function load binding 17569 09:44:55,500 --> 09:44:58,080 overrides from Json just like this and 17570 09:44:58,080 --> 09:44:59,880 also let's make sure we do this right 17571 09:44:59,880 --> 09:45:01,800 after we construct the object and before 17572 09:45:01,800 --> 09:45:04,256 we enable the action map okay so that's 17573 09:45:04,256 --> 09:45:06,720 really it let's test so here we are 17574 09:45:06,720 --> 09:45:09,060 let's rebind the move up to T okay hit 17575 09:45:09,060 --> 09:45:11,400 rebound now stop playing now playing 17576 09:45:11,400 --> 09:45:13,740 again and you appeared is still rebound 17577 09:45:13,740 --> 09:45:16,980 to T alright awesome okay so here we 17578 09:45:16,980 --> 09:45:19,080 created a really nice options menu where 17579 09:45:19,080 --> 09:45:21,416 we can modify the volume and rebind keys 17580 09:45:21,416 --> 09:45:23,220 the only issue that we still have is 17581 09:45:23,220 --> 09:45:25,020 that we can only navigate the menus with 17582 09:45:25,020 --> 09:45:27,120 the mouse so let's add support for many 17583 09:45:27,120 --> 09:45:28,980 navigation with a controller in the next 17584 09:45:28,980 --> 09:45:30,416 lecture 17585 09:45:30,416 --> 09:45:32,400 hello and welcome I'm your code monkey 17586 09:45:32,400 --> 09:45:34,436 in this lecture we're going to set up 17587 09:45:34,436 --> 09:45:35,820 phone controller support for our game 17588 09:45:35,820 --> 09:45:38,040 including regular actions and menu 17589 09:45:38,040 --> 09:45:40,500 navigation okay so first let's just set 17590 09:45:40,500 --> 09:45:42,776 up the controller input I have an Xbox 17591 09:45:42,776 --> 09:45:45,360 impact controller connected so let's 17592 09:45:45,360 --> 09:45:47,520 open up our player input actions and 17593 09:45:47,520 --> 09:45:49,620 over here we have all of our actions and 17594 09:45:49,620 --> 09:45:51,300 we already made the move one a long time 17595 09:45:51,300 --> 09:45:53,460 ago so let's just add the bindings for 17596 09:45:53,460 --> 09:45:55,020 the other ones for example over here on 17597 09:45:55,020 --> 09:45:56,400 the interact let's add a brand new 17598 09:45:56,400 --> 09:45:58,256 binding let's go into the path and 17599 09:45:58,256 --> 09:46:00,660 listen and for interact I'm going to 17600 09:46:00,660 --> 09:46:03,360 press the A Button and again here you 17601 09:46:03,360 --> 09:46:05,160 can specify just the a button on Xbox 17602 09:46:05,160 --> 09:46:07,080 controller or you can use the generic 17603 09:46:07,080 --> 09:46:09,060 South button which will mean a on an 17604 09:46:09,060 --> 09:46:12,000 Xbox or cross on a PlayStation or B on a 17605 09:46:12,000 --> 09:46:14,276 switch or anything else so let's go with 17606 09:46:14,276 --> 09:46:16,320 the generic one for the internal 17607 09:46:16,320 --> 09:46:18,180 alternate let's add a binding and for 17608 09:46:18,180 --> 09:46:19,860 this one I'm going to put it on the X on 17609 09:46:19,860 --> 09:46:21,900 the Xbox so the button West 17610 09:46:21,900 --> 09:46:24,360 and for the pause let's add let's listen 17611 09:46:24,360 --> 09:46:26,340 and I'm going to press the menu which is 17612 09:46:26,340 --> 09:46:28,740 the start button okay so these are the 17613 09:46:28,740 --> 09:46:31,140 basic inputs let's make sure they work 17614 09:46:31,140 --> 09:46:33,480 and thanks to this new input system we 17615 09:46:33,480 --> 09:46:34,916 really don't need to modify any code 17616 09:46:34,916 --> 09:46:37,200 let's just save this asset 17617 09:46:37,200 --> 09:46:39,120 let's wait for the compilation and then 17618 09:46:39,120 --> 09:46:41,640 we can do a test so here we are and yep 17619 09:46:41,640 --> 09:46:43,500 I'm using my control to move now let's 17620 09:46:43,500 --> 09:46:45,000 just wait for the countdown 17621 09:46:45,000 --> 09:46:47,640 and go up there and pick up a cheese put 17622 09:46:47,640 --> 09:46:49,916 it and slice some cheese yep I can do 17623 09:46:49,916 --> 09:46:51,540 that pick up a plate and so on all right 17624 09:46:51,540 --> 09:46:53,520 so everything works let's also pause and 17625 09:46:53,520 --> 09:46:55,680 yep that also works okay great so 17626 09:46:55,680 --> 09:46:57,900 everything works except there are two 17627 09:46:57,900 --> 09:47:00,300 issues with the GamePad especially one 17628 09:47:00,300 --> 09:47:01,680 with the movement that I only noticed 17629 09:47:01,680 --> 09:47:04,080 just now the first issue that we have is 17630 09:47:04,080 --> 09:47:05,700 the dead zone right now we don't have 17631 09:47:05,700 --> 09:47:08,220 one so if I just lightly touch my 17632 09:47:08,220 --> 09:47:10,020 Gamepad joystick there you go it starts 17633 09:47:10,020 --> 09:47:12,000 moving automatically in Gamepad games 17634 09:47:12,000 --> 09:47:13,436 you should always have some kind of dead 17635 09:47:13,436 --> 09:47:15,120 zone to prevent any kind of joy-con 17636 09:47:15,120 --> 09:47:16,980 drift thankfully that is super easy to 17637 09:47:16,980 --> 09:47:18,540 Zone let's just go into the player input 17638 09:47:18,540 --> 09:47:20,096 action so let's go into the move find 17639 09:47:20,096 --> 09:47:21,840 the left stick binding 17640 09:47:21,840 --> 09:47:23,880 and over here for the processors let's 17641 09:47:23,880 --> 09:47:25,800 add one and let's add a stick dead zone 17642 09:47:25,800 --> 09:47:28,200 so that's it pretty simple this 17643 09:47:28,200 --> 09:47:30,000 basically considers that inputs under 17644 09:47:30,000 --> 09:47:32,400 this minimum to be zero and above this 17645 09:47:32,400 --> 09:47:34,500 maximum to be one so if you have 17646 09:47:34,500 --> 09:47:36,840 joystick drift where when the joystick 17647 09:47:36,840 --> 09:47:39,000 is Idle it's always moving by say 0.1 17648 09:47:39,000 --> 09:47:41,040 and direction this helps solve that 17649 09:47:41,040 --> 09:47:42,960 problem except in our case for a game 17650 09:47:42,960 --> 09:47:45,240 we're only using normalized inputs so 17651 09:47:45,240 --> 09:47:46,860 actually for our use case let's increase 17652 09:47:46,860 --> 09:47:49,080 the minimum by quite a bit I did some 17653 09:47:49,080 --> 09:47:51,660 testing in 0.5 Works quite great and the 17654 09:47:51,660 --> 09:47:54,000 max that default that is just fine okay 17655 09:47:54,000 --> 09:47:56,160 so that's it one problem solved let's 17656 09:47:56,160 --> 09:47:58,380 just go ahead save this Ascent now the 17657 09:47:58,380 --> 09:48:00,360 other bigger issue that we have is if I 17658 09:48:00,360 --> 09:48:01,980 approach a counter and I try and look at 17659 09:48:01,980 --> 09:48:04,380 it it's really difficult it tries moving 17660 09:48:04,380 --> 09:48:05,400 left and right instead of actually 17661 09:48:05,400 --> 09:48:07,560 facing the counter that's because the 17662 09:48:07,560 --> 09:48:09,360 logic that we added in a long time ago 17663 09:48:09,360 --> 09:48:10,800 that logic to help the character 17664 09:48:10,800 --> 09:48:12,416 controller feel better when moving on 17665 09:48:12,416 --> 09:48:14,400 diagonals against the counter 17666 09:48:14,400 --> 09:48:16,140 that works great for keyboard because 17667 09:48:16,140 --> 09:48:18,596 it's digital so it's either moving phone 17668 09:48:18,596 --> 09:48:19,980 and left probably right or on the 17669 09:48:19,980 --> 09:48:21,000 diagonals 17670 09:48:21,000 --> 09:48:22,860 but it messes up the control which is 17671 09:48:22,860 --> 09:48:25,020 analog on the player movement if we are 17672 09:48:25,020 --> 09:48:26,520 not moving perfectly up or perfectly 17673 09:48:26,520 --> 09:48:28,620 down then it's considered a diagonal and 17674 09:48:28,620 --> 09:48:30,120 on a Gamepad it's really difficult to 17675 09:48:30,120 --> 09:48:32,340 get a perfect just up or just down input 17676 09:48:32,340 --> 09:48:34,140 we're always going to have a tiny bit of 17677 09:48:34,140 --> 09:48:36,360 either left or right so that's the issue 17678 09:48:36,360 --> 09:48:38,040 that we have here and thankfully the 17679 09:48:38,040 --> 09:48:40,020 solution is actually pretty simple let's 17680 09:48:40,020 --> 09:48:42,180 go over here on to our player script and 17681 09:48:42,180 --> 09:48:43,800 let's scroll down into the handle 17682 09:48:43,800 --> 09:48:45,180 movement function okay 17683 09:48:45,180 --> 09:48:47,096 so we're doing a can move using the 17684 09:48:47,096 --> 09:48:48,540 regular move Direction and if it doesn't 17685 09:48:48,540 --> 09:48:50,096 work then it's over here that we are 17686 09:48:50,096 --> 09:48:51,840 attempting only the X movement or only 17687 09:48:51,840 --> 09:48:54,180 the Z movement and for doing that we 17688 09:48:54,180 --> 09:48:56,096 made it so we can move if there is 17689 09:48:56,096 --> 09:48:58,620 nothing only on the X and if we have any 17690 09:48:58,620 --> 09:49:00,776 movement at all on the X so if it is 17691 09:49:00,776 --> 09:49:02,580 different from zero basically the issue 17692 09:49:02,580 --> 09:49:05,060 here is if the move dear.x is let's say 17693 09:49:05,060 --> 09:49:07,560 0.001 that is still different from zero 17694 09:49:07,560 --> 09:49:08,880 so it is still going to trigger this 17695 09:49:08,880 --> 09:49:11,040 logic so basically let's just widen this 17696 09:49:11,040 --> 09:49:13,140 Gap instead of testing literally just 17697 09:49:13,140 --> 09:49:15,240 different from zero let's test if they 17698 09:49:15,240 --> 09:49:18,960 moved here.x if it is under say minus 17699 09:49:18,960 --> 09:49:22,800 0.5 F or if moved here dot X if it is 17700 09:49:22,800 --> 09:49:24,900 bigger than plus 0.5 f 17701 09:49:24,900 --> 09:49:27,180 so instead of being exactly just on zero 17702 09:49:27,180 --> 09:49:28,916 we're only going to consider diagonals 17703 09:49:28,916 --> 09:49:30,840 if we are at least moving 0.5 either 17704 09:49:30,840 --> 09:49:33,000 left or right so we just did this and 17705 09:49:33,000 --> 09:49:34,740 same thing over here except we just test 17706 09:49:34,740 --> 09:49:37,680 for this n so we moved here.z and they 17707 09:49:37,680 --> 09:49:40,020 move the other dot set okay so like this 17708 09:49:40,020 --> 09:49:41,340 it should feel much better on the 17709 09:49:41,340 --> 09:49:43,200 GamePad and still work exactly the same 17710 09:49:43,200 --> 09:49:45,120 on the keyboard so let's test 17711 09:49:45,120 --> 09:49:47,220 so here I am moving around and yep now 17712 09:49:47,220 --> 09:49:48,960 it is much easier to just stay around 17713 09:49:48,960 --> 09:49:51,720 and look straight at the counter okay so 17714 09:49:51,720 --> 09:49:53,400 that's great so I can pick up and this 17715 09:49:53,400 --> 09:49:55,020 is all much much easier and the 17716 09:49:55,020 --> 09:49:56,820 character is no longer just sliding left 17717 09:49:56,820 --> 09:50:00,060 and right Non-Stop okay that's great so 17718 09:50:00,060 --> 09:50:01,680 now that this is working let's set 17719 09:50:01,680 --> 09:50:03,300 support for rebinding our controller 17720 09:50:03,300 --> 09:50:05,640 bindings so over here on the game input 17721 09:50:05,640 --> 09:50:07,256 let's do it just like we did for the 17722 09:50:07,256 --> 09:50:08,756 keyboard so let's add a bunch more 17723 09:50:08,756 --> 09:50:10,860 bindings over here on the enum let's add 17724 09:50:10,860 --> 09:50:13,340 the GamePad interact then the GamePad 17725 09:50:13,340 --> 09:50:17,040 interact alternate and then the GamePad 17726 09:50:17,040 --> 09:50:18,360 pause 17727 09:50:18,360 --> 09:50:20,756 okay so we have our bindings then let's 17728 09:50:20,756 --> 09:50:22,140 go down and add them to both our 17729 09:50:22,140 --> 09:50:23,700 functions so of course the text and then 17730 09:50:23,700 --> 09:50:25,680 the bindings so we're here on the text 17731 09:50:25,680 --> 09:50:28,020 let's copy pretty much this we're going 17732 09:50:28,020 --> 09:50:30,900 to have the GamePad interact then we're 17733 09:50:30,900 --> 09:50:32,880 going to have the other two so the 17734 09:50:32,880 --> 09:50:34,860 GamePad tracked alternate and the 17735 09:50:34,860 --> 09:50:36,540 GamePad pause okay 17736 09:50:36,540 --> 09:50:38,460 now for these bindings we're going to 17737 09:50:38,460 --> 09:50:40,140 use the same actions so this one is the 17738 09:50:40,140 --> 09:50:42,060 interact alternate and over here we have 17739 09:50:42,060 --> 09:50:44,160 the interact and over here on the input 17740 09:50:44,160 --> 09:50:45,960 actions we saw that we added for all of 17741 09:50:45,960 --> 09:50:48,480 them on index 0 we have the keyboard and 17742 09:50:48,480 --> 09:50:50,580 on the next one we have all the gamepads 17743 09:50:50,580 --> 09:50:52,200 so over here that's literally don't 17744 09:50:52,200 --> 09:50:54,300 change for the GamePad let's go into 17745 09:50:54,300 --> 09:50:56,276 bindings and access the array on index 17746 09:50:56,276 --> 09:50:57,120 one 17747 09:50:57,120 --> 09:50:59,520 okay and then over here on the rebind 17748 09:50:59,520 --> 09:51:01,320 binding it's going to be pretty much the 17749 09:51:01,320 --> 09:51:03,000 exact same thing so let's copy all these 17750 09:51:03,000 --> 09:51:06,480 change this to the GamePad interact then 17751 09:51:06,480 --> 09:51:09,240 the GamePad interact alternate and then 17752 09:51:09,240 --> 09:51:12,416 the GamePad pause some of these all we 17753 09:51:12,416 --> 09:51:14,340 need to change is just by an index put 17754 09:51:14,340 --> 09:51:16,980 them all on one okay so with that all of 17755 09:51:16,980 --> 09:51:18,416 the code over here on the game input is 17756 09:51:18,416 --> 09:51:20,340 working perfectly now let's go over here 17757 09:51:20,340 --> 09:51:22,860 into our options UI so we've got all of 17758 09:51:22,860 --> 09:51:25,080 our buttons so let's duplicate our 17759 09:51:25,080 --> 09:51:26,276 buttons let's just go into the 17760 09:51:26,276 --> 09:51:27,596 interactive pause and so on let's 17761 09:51:27,596 --> 09:51:29,276 duplicate push them to the right side 17762 09:51:29,276 --> 09:51:30,596 okay 17763 09:51:30,596 --> 09:51:32,820 and just change the name so let's get 17764 09:51:32,820 --> 09:51:35,160 into all of them so this one's the game 17765 09:51:35,160 --> 09:51:38,936 pad interact button then the game pad 17766 09:51:38,936 --> 09:51:40,860 interact alternate and finally the 17767 09:51:40,860 --> 09:51:42,480 GamePad Parts okay 17768 09:51:42,480 --> 09:51:44,820 also inside let's also rename these 17769 09:51:44,820 --> 09:51:46,436 buttons just to make sure the text works 17770 09:51:46,436 --> 09:51:48,620 great 17771 09:51:49,256 --> 09:51:51,240 and let's also make sure that these show 17772 09:51:51,240 --> 09:51:53,580 up behind the press the rebound key so 17773 09:51:53,580 --> 09:51:56,160 let's drag them put them above okay so 17774 09:51:56,160 --> 09:51:57,776 that's our setup over here on the 17775 09:51:57,776 --> 09:51:59,820 options UI now let's go over here on the 17776 09:51:59,820 --> 09:52:01,620 options UI script and let's add 17777 09:52:01,620 --> 09:52:03,120 references to our buttons and to our 17778 09:52:03,120 --> 09:52:04,380 text objects 17779 09:52:04,380 --> 09:52:07,980 so let's copy all these the GamePad and 17780 09:52:07,980 --> 09:52:09,900 add all these this is the pause the 17781 09:52:09,900 --> 09:52:12,360 interact and the interact confident and 17782 09:52:12,360 --> 09:52:14,700 then down here the exact same thing 17783 09:52:14,700 --> 09:52:18,140 let's add all of these 17784 09:52:18,480 --> 09:52:21,000 okay like this now over here let's drag 17785 09:52:21,000 --> 09:52:22,800 all of our references so on the options 17786 09:52:22,800 --> 09:52:25,080 UI let's make sure to always write the 17787 09:52:25,080 --> 09:52:27,840 correct things so the GamePad interact 17788 09:52:27,840 --> 09:52:31,500 text the interact alternate text and the 17789 09:52:31,500 --> 09:52:33,720 pause button text and then the buttons 17790 09:52:33,720 --> 09:52:36,360 themselves so the pause button interact 17791 09:52:36,360 --> 09:52:38,820 alt and the interact button again make 17792 09:52:38,820 --> 09:52:40,140 sure you always drag the correct 17793 09:52:40,140 --> 09:52:41,700 references so check and double check 17794 09:52:41,700 --> 09:52:43,680 make sure everything is correct okay 17795 09:52:43,680 --> 09:52:46,080 then over here for our code let's first 17796 09:52:46,080 --> 09:52:48,840 handle the text over here 17797 09:52:48,840 --> 09:52:51,360 so the text for all these 17798 09:52:51,360 --> 09:52:54,480 so the GamePad interact text then the 17799 09:52:54,480 --> 09:52:56,220 GamePad interact alternate text and 17800 09:52:56,220 --> 09:52:58,740 finally the GamePad pause text and we 17801 09:52:58,740 --> 09:53:01,200 just go the game file pause the GamePad 17802 09:53:01,200 --> 09:53:03,180 interact alternate and the GamePad 17803 09:53:03,180 --> 09:53:05,580 interact finally over here on the 17804 09:53:05,580 --> 09:53:08,276 buttons let's do the exact same thing 17805 09:53:08,276 --> 09:53:10,680 so Gamepad interact interact alternate 17806 09:53:10,680 --> 09:53:13,880 and the pause 17807 09:53:14,880 --> 09:53:17,880 okay so we added everything let's do a 17808 09:53:17,880 --> 09:53:19,740 test and see if everything is working so 17809 09:53:19,740 --> 09:53:21,300 over here let's pause the game go into 17810 09:53:21,300 --> 09:53:23,640 the options and for the interact let's 17811 09:53:23,640 --> 09:53:25,200 modify this one instead of a and let's 17812 09:53:25,200 --> 09:53:27,000 put it on B and yeah there you go it did 17813 09:53:27,000 --> 09:53:29,400 go so let's close let's resume and now 17814 09:53:29,400 --> 09:53:31,256 let's see so if I approach and I press a 17815 09:53:31,256 --> 09:53:33,120 nothing happens Press B and there you go 17816 09:53:33,120 --> 09:53:36,416 it does interact okay awesome so the 17817 09:53:36,416 --> 09:53:37,980 rebinding is all working perfectly 17818 09:53:37,980 --> 09:53:40,916 except we have another obvious issue 17819 09:53:40,916 --> 09:53:43,436 I can pause with the GamePad however now 17820 09:53:43,436 --> 09:53:45,240 with this pause I cannot click on any of 17821 09:53:45,240 --> 09:53:47,460 those buttons and if I go back to the 17822 09:53:47,460 --> 09:53:48,416 main menu 17823 09:53:48,416 --> 09:53:50,400 over here I also cannot do anything with 17824 09:53:50,400 --> 09:53:52,560 a controller so at some of that the 17825 09:53:52,560 --> 09:53:54,596 first step is on the event system object 17826 09:53:54,596 --> 09:53:56,700 look at how it shows us this warning 17827 09:53:56,700 --> 09:53:58,620 basically if we're using the new input 17828 09:53:58,620 --> 09:54:00,060 system we should be using a different 17829 09:54:00,060 --> 09:54:02,276 input Handler here thankfully this is 17830 09:54:02,276 --> 09:54:04,020 super easy we just need to click on this 17831 09:54:04,020 --> 09:54:05,276 button and yep that's it it 17832 09:54:05,276 --> 09:54:07,200 automatically sets it up now the way 17833 09:54:07,200 --> 09:54:09,300 that this works is by pre-selecting 17834 09:54:09,300 --> 09:54:11,756 buttons in order to better see which 17835 09:54:11,756 --> 09:54:13,020 button is selected we should probably 17836 09:54:13,020 --> 09:54:15,540 add a more visible color let's go into 17837 09:54:15,540 --> 09:54:17,880 our pause window so for now let's hide 17838 09:54:17,880 --> 09:54:19,916 over here the options UI show the pause 17839 09:54:19,916 --> 09:54:21,776 window and we have these three buttons 17840 09:54:21,776 --> 09:54:23,580 let's select all of them 17841 09:54:23,580 --> 09:54:25,436 and over here on the right side on the 17842 09:54:25,436 --> 09:54:27,960 button we can see one option for the 17843 09:54:27,960 --> 09:54:29,220 selected color 17844 09:54:29,220 --> 09:54:30,900 so instead of being white which is going 17845 09:54:30,900 --> 09:54:32,460 to be really difficult to see let's put 17846 09:54:32,460 --> 09:54:33,900 something really visible so let's say 17847 09:54:33,900 --> 09:54:37,380 like a bright green okay like this 17848 09:54:37,380 --> 09:54:39,060 let's do the same thing for all of the 17849 09:54:39,060 --> 09:54:41,520 buttons on the options UI so let's show 17850 09:54:41,520 --> 09:54:44,220 this one and find all the buttons so 17851 09:54:44,220 --> 09:54:47,040 we've got all of these ones down here 17852 09:54:47,040 --> 09:54:49,256 and these three ones up here and let's 17853 09:54:49,256 --> 09:54:50,756 do the same thing so on the selected 17854 09:54:50,756 --> 09:54:53,400 let's put it all on my screen okay so 17855 09:54:53,400 --> 09:54:55,020 all the buttons have a nice selected 17856 09:54:55,020 --> 09:54:57,900 color and just like this if we test and 17857 09:54:57,900 --> 09:54:59,400 if I pause the game 17858 09:54:59,400 --> 09:55:01,560 and right now nothing is selected so 17859 09:55:01,560 --> 09:55:03,120 right now I cannot do anything with the 17860 09:55:03,120 --> 09:55:05,936 controller however if I press over here 17861 09:55:05,936 --> 09:55:07,740 with the mouse on this button and then 17862 09:55:07,740 --> 09:55:10,140 let go once outside the button yep look 17863 09:55:10,140 --> 09:55:12,416 at that now that button is selected so 17864 09:55:12,416 --> 09:55:13,916 now as long as that one is selected now 17865 09:55:13,916 --> 09:55:15,960 if I move with the mouse pad yep now I 17866 09:55:15,960 --> 09:55:17,936 can navigate through this menu and if I 17867 09:55:17,936 --> 09:55:19,916 press on a yep I can essentially click 17868 09:55:19,916 --> 09:55:22,020 that button so that's great basically 17869 09:55:22,020 --> 09:55:23,340 all we need is to make sure that we 17870 09:55:23,340 --> 09:55:24,840 select the button as soon as the pause 17871 09:55:24,840 --> 09:55:27,000 menu shows up so let's go over here on 17872 09:55:27,000 --> 09:55:29,160 the game pause UI script and then over 17873 09:55:29,160 --> 09:55:30,960 here let's go into the show function so 17874 09:55:30,960 --> 09:55:32,820 when we show this window when we do 17875 09:55:32,820 --> 09:55:34,500 let's go into the resume button and just 17876 09:55:34,500 --> 09:55:36,360 call the select function this will make 17877 09:55:36,360 --> 09:55:38,640 it selected so that's it and with this 17878 09:55:38,640 --> 09:55:40,500 if we test and now here with the game 17879 09:55:40,500 --> 09:55:42,960 playing if I pause whilst pressing the 17880 09:55:42,960 --> 09:55:45,000 button on the GamePad and if they go 17881 09:55:45,000 --> 09:55:46,560 down and selected and now I can select 17882 09:55:46,560 --> 09:55:49,380 any option okay that's great so now it 17883 09:55:49,380 --> 09:55:51,840 works fully with just the GamePad except 17884 09:55:51,840 --> 09:55:54,480 now if I go into options yep now you can 17885 09:55:54,480 --> 09:55:55,860 see that the button that is selected is 17886 09:55:55,860 --> 09:55:57,480 on the options one over there on the 17887 09:55:57,480 --> 09:55:59,040 background so let's also make sure to 17888 09:55:59,040 --> 09:56:00,720 select a button on the options as soon 17889 09:56:00,720 --> 09:56:02,580 as the options window shows up so over 17890 09:56:02,580 --> 09:56:05,040 here on the options UI let's go into our 17891 09:56:05,040 --> 09:56:06,360 show function 17892 09:56:06,360 --> 09:56:08,276 and let's just select the sound effects 17893 09:56:08,276 --> 09:56:10,680 button and just console it okay let's 17894 09:56:10,680 --> 09:56:13,500 test so here let's pause go into options 17895 09:56:13,500 --> 09:56:15,180 select any of the Lego that did work 17896 09:56:15,180 --> 09:56:18,240 okay great except we have another issue 17897 09:56:18,240 --> 09:56:21,060 as I move up or down over here on these 17898 09:56:21,060 --> 09:56:23,220 buttons you have a look at that some of 17899 09:56:23,220 --> 09:56:25,320 them are a bit strange like for example 17900 09:56:25,320 --> 09:56:28,080 over here on a I'm moving up and look at 17901 09:56:28,080 --> 09:56:29,820 that it actually selected the resume 17902 09:56:29,820 --> 09:56:32,640 button behind it so as we are moving up 17903 09:56:32,640 --> 09:56:34,256 or down we are actually selecting 17904 09:56:34,256 --> 09:56:36,720 buttons on both menus that's very 17905 09:56:36,720 --> 09:56:39,060 strange basically what is going on is 17906 09:56:39,060 --> 09:56:40,860 that since both windows are visible the 17907 09:56:40,860 --> 09:56:42,720 game is trying to guess which button we 17908 09:56:42,720 --> 09:56:44,580 want to select basically what is 17909 09:56:44,580 --> 09:56:46,256 happening is Unity is trying to use 17910 09:56:46,256 --> 09:56:48,776 automatic navigation if we select the 17911 09:56:48,776 --> 09:56:50,700 button so let's go for example let's 17912 09:56:50,700 --> 09:56:54,060 hide the options and show just the game 17913 09:56:54,060 --> 09:56:55,800 pause okay let's select one of these 17914 09:56:55,800 --> 09:56:57,660 buttons and over there on the button 17915 09:56:57,660 --> 09:56:59,400 component we can see navigation is set 17916 09:56:59,400 --> 09:57:01,320 to automatic and we have a button to 17917 09:57:01,320 --> 09:57:03,596 visualize and if we click on that yep 17918 09:57:03,596 --> 09:57:05,460 over here we can see all kinds of arrows 17919 09:57:05,460 --> 09:57:07,680 for example we we can see one over here 17920 09:57:07,680 --> 09:57:09,360 on the options that seems to be going to 17921 09:57:09,360 --> 09:57:11,520 some button in there that is going to be 17922 09:57:11,520 --> 09:57:14,040 the button that is showing over there so 17923 09:57:14,040 --> 09:57:15,596 if we move down from the options we're 17924 09:57:15,596 --> 09:57:16,860 going to end up over here on the 17925 09:57:16,860 --> 09:57:19,380 interact alt button now usually the 17926 09:57:19,380 --> 09:57:21,180 automatic navigation actually works very 17927 09:57:21,180 --> 09:57:22,980 well the only reason why we're having 17928 09:57:22,980 --> 09:57:25,200 problems is because we have both windows 17929 09:57:25,200 --> 09:57:27,480 active at once one solution to this is 17930 09:57:27,480 --> 09:57:29,880 to make the navigation explicit so let's 17931 09:57:29,880 --> 09:57:31,560 hide the options here and over here on 17932 09:57:31,560 --> 09:57:33,776 the resume on the navigation instead of 17933 09:57:33,776 --> 09:57:36,060 automatic let's put none and then let's 17934 09:57:36,060 --> 09:57:38,640 select explicit and if now we have our 17935 09:57:38,640 --> 09:57:40,980 own four Fields so we can decide which 17936 09:57:40,980 --> 09:57:42,596 object gets selected when we are here 17937 09:57:42,596 --> 09:57:45,060 and we move up down left or right so for 17938 09:57:45,060 --> 09:57:46,980 example here we would drag for the up 17939 09:57:46,980 --> 09:57:48,960 going up we could go into the main menu 17940 09:57:48,960 --> 09:57:51,060 so we will drag that button and going 17941 09:57:51,060 --> 09:57:53,276 down we could drag the options button so 17942 09:57:53,276 --> 09:57:55,200 that's one solution just add the 17943 09:57:55,200 --> 09:57:56,756 explicit navigation to every single 17944 09:57:56,756 --> 09:57:59,400 button or another simpler solution is 17945 09:57:59,400 --> 09:58:02,160 let's leave this one on automatic and it 17946 09:58:02,160 --> 09:58:03,776 said we're just going to hide the pause 17947 09:58:03,776 --> 09:58:05,640 window once we are in the options window 17948 09:58:05,640 --> 09:58:08,820 so over here on the game pause UI let's 17949 09:58:08,820 --> 09:58:10,436 see over here we are showing the options 17950 09:58:10,436 --> 09:58:12,480 you Ai and when we do let's just call 17951 09:58:12,480 --> 09:58:14,880 hide on this so we are going to hide 17952 09:58:14,880 --> 09:58:17,220 this window when we show the options and 17953 09:58:17,220 --> 09:58:19,560 then on the options we want to know when 17954 09:58:19,560 --> 09:58:21,180 the options closes so that we can show 17955 09:58:21,180 --> 09:58:23,276 this one again so over here on the show 17956 09:58:23,276 --> 09:58:26,400 function let's receive an action this is 17957 09:58:26,400 --> 09:58:28,020 what we're going to do when we close the 17958 09:58:28,020 --> 09:58:31,080 options let's call it on close button 17959 09:58:31,080 --> 09:58:32,340 action 17960 09:58:32,340 --> 09:58:34,916 and let's store it up here so let's 17961 09:58:34,916 --> 09:58:36,060 store 17962 09:58:36,060 --> 09:58:38,220 a simple and private action for this 17963 09:58:38,220 --> 09:58:40,800 okay so we have this and then down here 17964 09:58:40,800 --> 09:58:43,320 when we have our show function when we 17965 09:58:43,320 --> 09:58:45,060 have let's set this equals this we store 17966 09:58:45,060 --> 09:58:46,916 this and then we're just going to run 17967 09:58:46,916 --> 09:58:48,660 this action whenever we click on the 17968 09:58:48,660 --> 09:58:50,400 close button so let's go over here the 17969 09:58:50,400 --> 09:58:52,980 close button we've got that one let's 17970 09:58:52,980 --> 09:58:54,840 hide the options window and Trigger this 17971 09:58:54,840 --> 09:58:56,756 action so now we need is over here on 17972 09:58:56,756 --> 09:58:58,800 the game plus UI let's pass in and 17973 09:58:58,800 --> 09:59:01,020 basically when we close the options UI 17974 09:59:01,020 --> 09:59:04,256 we want to show the POS UI okay so let's 17975 09:59:04,256 --> 09:59:06,540 test so here we are let's pause the game 17976 09:59:06,540 --> 09:59:08,400 okay let's go into options and open it 17977 09:59:08,400 --> 09:59:10,020 and if there go it only shows the 17978 09:59:10,020 --> 09:59:11,820 options and over here moving up or down 17979 09:59:11,820 --> 09:59:13,740 works perfectly and moving left and 17980 09:59:13,740 --> 09:59:15,596 right also works perfectly 17981 09:59:15,596 --> 09:59:17,340 and now if I want to go back let's go 17982 09:59:17,340 --> 09:59:18,900 into close press it and there you go 17983 09:59:18,900 --> 09:59:20,580 back into the pause menu 17984 09:59:20,580 --> 09:59:22,680 all right awesome so everything is 17985 09:59:22,680 --> 09:59:24,480 working perfectly now the last thing we 17986 09:59:24,480 --> 09:59:26,276 need is over here on the main menu so 17987 09:59:26,276 --> 09:59:28,680 let's do the same thing first let's open 17988 09:59:28,680 --> 09:59:30,416 up the main menu scene 17989 09:59:30,416 --> 09:59:32,936 let's save the changes okay and over 17990 09:59:32,936 --> 09:59:34,436 here let's begin by doing the same thing 17991 09:59:34,436 --> 09:59:36,180 on the event system so let's replace it 17992 09:59:36,180 --> 09:59:37,560 okay great 17993 09:59:37,560 --> 09:59:39,540 then let's go inside our canvas inside 17994 09:59:39,540 --> 09:59:43,320 main menu y let's select our buttons and 17995 09:59:43,320 --> 09:59:45,000 once again let's modify the select color 17996 09:59:45,000 --> 09:59:47,756 put it on my screen all right and since 17997 09:59:47,756 --> 09:59:50,936 over here we only have one menu we could 17998 09:59:50,936 --> 09:59:52,740 set a test selected over here on the 17999 09:59:52,740 --> 09:59:54,360 main menu UI script 18000 09:59:54,360 --> 09:59:56,580 that's one option or we can just go into 18001 09:59:56,580 --> 09:59:58,320 the event system and over here on the 18002 09:59:58,320 --> 09:59:59,756 event system there's a film for the 18003 09:59:59,756 --> 10:00:02,040 first selected so you can just drag the 18004 10:00:02,040 --> 10:00:03,660 play button and that will automatically 18005 10:00:03,660 --> 10:00:06,720 make it the selected one so it says and 18006 10:00:06,720 --> 10:00:08,040 yep the play button starts off as 18007 10:00:08,040 --> 10:00:10,436 selected and I can move up or down 18008 10:00:10,436 --> 10:00:13,020 and if I press a button yep there you go 18009 10:00:13,020 --> 10:00:14,756 here I am playing the game I can pause I 18010 10:00:14,756 --> 10:00:16,320 can resume go back to the main menu and 18011 10:00:16,320 --> 10:00:18,960 so on all right awesome so here we have 18012 10:00:18,960 --> 10:00:20,460 the final thing we needed to make our 18013 10:00:20,460 --> 10:00:22,080 game fully playable with the GamePad 18014 10:00:22,080 --> 10:00:24,416 thanks to how the input system works and 18015 10:00:24,416 --> 10:00:26,460 the menu automatic navigation this was a 18016 10:00:26,460 --> 10:00:28,800 pretty simple task for this our game is 18017 10:00:28,800 --> 10:00:30,840 pretty much completely done however the 18018 10:00:30,840 --> 10:00:32,460 next lecture is also one of the most 18019 10:00:32,460 --> 10:00:34,020 important lectures it's all about 18020 10:00:34,020 --> 10:00:35,756 publish so let's do that in the next 18021 10:00:35,756 --> 10:00:37,320 lecture 18022 10:00:37,320 --> 10:00:39,300 hello and welcome I'm your code monkey 18023 10:00:39,300 --> 10:00:41,756 in this lecture we're going to add all 18024 10:00:41,756 --> 10:00:43,380 kinds of small things to polish our 18025 10:00:43,380 --> 10:00:45,300 power game if you are regular on this 18026 10:00:45,300 --> 10:00:46,560 channel then you've certainly heard me 18027 10:00:46,560 --> 10:00:48,300 say that polish is what separates good 18028 10:00:48,300 --> 10:00:50,460 games from great games so as you build 18029 10:00:50,460 --> 10:00:51,900 your own games make sure you don't 18030 10:00:51,900 --> 10:00:54,540 neglect polish here let's add a bunch of 18031 10:00:54,540 --> 10:00:56,580 small tiny things that will make a big 18032 10:00:56,580 --> 10:00:58,560 difference in the final game let's begin 18033 10:00:58,560 --> 10:01:01,080 with a very simple very visual one let's 18034 10:01:01,080 --> 10:01:03,540 just add some ones to our map and first 18035 10:01:03,540 --> 10:01:05,520 let's just hide our canvas so that it's 18036 10:01:05,520 --> 10:01:07,800 not blocking our view so again over here 18037 10:01:07,800 --> 10:01:09,300 we can use the buttons on the hierarchy 18038 10:01:09,300 --> 10:01:11,040 to hide it okay great 18039 10:01:11,040 --> 10:01:13,140 so let's add some walls and for that 18040 10:01:13,140 --> 10:01:16,380 let's create a brand new 3D cube let's 18041 10:01:16,380 --> 10:01:18,840 name this a wall let's put it quite a 18042 10:01:18,840 --> 10:01:20,700 bit thin so over here on the scale for 18043 10:01:20,700 --> 10:01:23,276 the X so let's put it 0.25 then on the 18044 10:01:23,276 --> 10:01:25,436 one let's put three so something like 18045 10:01:25,436 --> 10:01:27,480 this then we modified Z so let's put it 18046 10:01:27,480 --> 10:01:29,936 over here on the side right next to the 18047 10:01:29,936 --> 10:01:31,980 counters okay so that's the wall let's 18048 10:01:31,980 --> 10:01:34,560 just stretch it out One Direction and 18049 10:01:34,560 --> 10:01:37,140 the other one okay so that's our basic 18050 10:01:37,140 --> 10:01:37,916 one 18051 10:01:37,916 --> 10:01:40,020 now when you included project files 18052 10:01:40,020 --> 10:01:41,520 there's a nice one material so let's go 18053 10:01:41,520 --> 10:01:43,436 over here into assets under materials 18054 10:01:43,436 --> 10:01:45,416 and you appeared as you want material so 18055 10:01:45,416 --> 10:01:47,160 let's just drag it and use this one and 18056 10:01:47,160 --> 10:01:48,660 if there you go it's just a nice simple 18057 10:01:48,660 --> 10:01:51,240 gradient this is also an example of how 18058 10:01:51,240 --> 10:01:52,860 you can take something simple and make 18059 10:01:52,860 --> 10:01:54,900 it a bit more interesting if you look at 18060 10:01:54,900 --> 10:01:56,820 this material the base texture is really 18061 10:01:56,820 --> 10:01:59,520 just this it is literally just a simple 18062 10:01:59,520 --> 10:02:02,096 vertical gradient texture and then with 18063 10:02:02,096 --> 10:02:03,660 the color point to it and looks pretty 18064 10:02:03,660 --> 10:02:06,120 good okay so this dual let's put the 18065 10:02:06,120 --> 10:02:07,740 wall on on three sides so let's 18066 10:02:07,740 --> 10:02:09,480 supplicate this so just select and press 18067 10:02:09,480 --> 10:02:12,480 Ctrl D 2.8 let's put one on the other 18068 10:02:12,480 --> 10:02:15,180 side so right there right next to the 18069 10:02:15,180 --> 10:02:17,400 counters okay and finally the one there 18070 10:02:17,400 --> 10:02:19,680 so Ctrl D to duplicate it let's push it 18071 10:02:19,680 --> 10:02:21,960 over there on the side and rotate it 90 18072 10:02:21,960 --> 10:02:23,096 degrees 18073 10:02:23,096 --> 10:02:26,340 and let's put it just like that let's 18074 10:02:26,340 --> 10:02:29,040 just scale it to get to that end and to 18075 10:02:29,040 --> 10:02:31,620 get to that end okay so we have our nice 18076 10:02:31,620 --> 10:02:33,840 walls but over here if we're playing the 18077 10:02:33,840 --> 10:02:35,520 game we can still see the floor on the 18078 10:02:35,520 --> 10:02:37,380 outside that looks a bit ugly so let's 18079 10:02:37,380 --> 10:02:38,340 fix that 18080 10:02:38,340 --> 10:02:40,740 let's create another object and let's 18081 10:02:40,740 --> 10:02:43,500 create a 3D object another Cube and for 18082 10:02:43,500 --> 10:02:45,060 this Cube let's put it over here on the 18083 10:02:45,060 --> 10:02:46,620 side and this one let's use the black 18084 10:02:46,620 --> 10:02:48,960 material so again in the included assets 18085 10:02:48,960 --> 10:02:50,880 there's this nice black material there 18086 10:02:50,880 --> 10:02:52,560 you go it's completely black nothing to 18087 10:02:52,560 --> 10:02:53,340 it 18088 10:02:53,340 --> 10:02:55,256 so let's just use this as kind of a 18089 10:02:55,256 --> 10:02:58,560 Hider so let's just scale it quite a bit 18090 10:02:58,560 --> 10:03:01,700 and lift it up 18091 10:03:02,520 --> 10:03:04,500 okay so there it is a black material 18092 10:03:04,500 --> 10:03:06,480 right next to the wall and let's put 18093 10:03:06,480 --> 10:03:09,000 another one over here on the left side 18094 10:03:09,000 --> 10:03:10,860 and just like that 18095 10:03:10,860 --> 10:03:12,416 you can also put another one on the back 18096 10:03:12,416 --> 10:03:13,740 there even though I don't think the 18097 10:03:13,740 --> 10:03:15,776 camera can see that part but still let's 18098 10:03:15,776 --> 10:03:18,720 put it so just put it like that and 18099 10:03:18,720 --> 10:03:21,596 stretch it out okay that's good by the 18100 10:03:21,596 --> 10:03:23,040 way over here on the outside it doesn't 18101 10:03:23,040 --> 10:03:24,540 have to be perfect doesn't have to 18102 10:03:24,540 --> 10:03:26,276 perfectly match the camera is never 18103 10:03:26,276 --> 10:03:27,900 going to see that position so it doesn't 18104 10:03:27,900 --> 10:03:29,640 matter it only matters what the camera 18105 10:03:29,640 --> 10:03:32,580 can see and if we pull it like this and 18106 10:03:32,580 --> 10:03:34,200 if they're yellow now that looks quite 18107 10:03:34,200 --> 10:03:36,776 nice if we want over there we can get it 18108 10:03:36,776 --> 10:03:38,936 together just a little bit and we can 18109 10:03:38,936 --> 10:03:41,400 also move the camera forward a tiny bit 18110 10:03:41,400 --> 10:03:44,460 so over here on this one let's push it 18111 10:03:44,460 --> 10:03:46,500 just a little bit to the left okay and 18112 10:03:46,500 --> 10:03:48,000 now in the virtual camera 18113 10:03:48,000 --> 10:03:50,040 let's play the game 18114 10:03:50,040 --> 10:03:52,140 and now here if we want we can push it 18115 10:03:52,140 --> 10:03:54,240 up a little bit something like this so 18116 10:03:54,240 --> 10:03:56,160 let's put it on this set so let's copy 18117 10:03:56,160 --> 10:03:59,096 it stop playing the game and let's paste 18118 10:03:59,096 --> 10:04:00,240 it just like that 18119 10:04:00,240 --> 10:04:02,400 okay so here's our game and as you can 18120 10:04:02,400 --> 10:04:04,500 see with just this one tiny chain just 18121 10:04:04,500 --> 10:04:06,180 adding some walls and a nice black 18122 10:04:06,180 --> 10:04:08,460 outside just with that it already looks 18123 10:04:08,460 --> 10:04:10,140 so much better than having some counters 18124 10:04:10,140 --> 10:04:12,360 in wide open space now for another 18125 10:04:12,360 --> 10:04:14,340 simple one let's add some nice particles 18126 10:04:14,340 --> 10:04:16,020 while the player is moving 18127 10:04:16,020 --> 10:04:18,300 so in the included assets if we go 18128 10:04:18,300 --> 10:04:20,220 inside the prefab visuals over here is a 18129 10:04:20,220 --> 10:04:21,776 nice one for player moving particles 18130 10:04:21,776 --> 10:04:24,060 this one as you can see is a particle 18131 10:04:24,060 --> 10:04:26,220 system so let's drag it over here into 18132 10:04:26,220 --> 10:04:28,256 the world see what it looks like and as 18133 10:04:28,256 --> 10:04:29,700 you can see by default it's actually not 18134 10:04:29,700 --> 10:04:31,620 spawning anything so I can make sure 18135 10:04:31,620 --> 10:04:32,936 that this one is running and nope 18136 10:04:32,936 --> 10:04:34,916 nothing is spawning so this is actually 18137 10:04:34,916 --> 10:04:36,840 set up in a really interesting way is 18138 10:04:36,840 --> 10:04:38,520 that instead of spawning particles all 18139 10:04:38,520 --> 10:04:40,800 the time it only emits while moving so 18140 10:04:40,800 --> 10:04:42,900 if I click to move this object there you 18141 10:04:42,900 --> 10:04:44,700 go the particles start emitting and if I 18142 10:04:44,700 --> 10:04:46,916 stop they stop so this one is definitely 18143 10:04:46,916 --> 10:04:49,740 perfect for a player particle system the 18144 10:04:49,740 --> 10:04:51,540 way this setup is over here on the 18145 10:04:51,540 --> 10:04:54,120 emission on rate over time it is set to 18146 10:04:54,120 --> 10:04:55,436 zero so it doesn't spawn anything 18147 10:04:55,436 --> 10:04:57,480 automatically and it only has over here 18148 10:04:57,480 --> 10:04:59,756 the rate over distance so as it moves 18149 10:04:59,756 --> 10:05:01,140 it's going to spawn that number of 18150 10:05:01,140 --> 10:05:02,880 particles then the other settings 18151 10:05:02,880 --> 10:05:05,460 they're all pretty basic so there's some 18152 10:05:05,460 --> 10:05:07,380 gravity so they fall down just like the 18153 10:05:07,380 --> 10:05:10,256 stove counter particles simulation is 18154 10:05:10,256 --> 10:05:12,180 over here on space so that as I move the 18155 10:05:12,180 --> 10:05:14,340 particle stay behind this is important 18156 10:05:14,340 --> 10:05:16,320 if I were to put that in local and I 18157 10:05:16,320 --> 10:05:17,756 move it around look at that this is not 18158 10:05:17,756 --> 10:05:19,800 what we want we want the particles to 18159 10:05:19,800 --> 10:05:21,480 essentially stay behind instead of 18160 10:05:21,480 --> 10:05:23,400 following this transform so that is why 18161 10:05:23,400 --> 10:05:25,860 this change is super important if that 18162 10:05:25,860 --> 10:05:27,416 one is set to whirl and as I move yep 18163 10:05:27,416 --> 10:05:29,936 the particles stay behind okay great and 18164 10:05:29,936 --> 10:05:31,256 the other property is around pretty 18165 10:05:31,256 --> 10:05:33,720 basic for the shape it's a cone pointing 18166 10:05:33,720 --> 10:05:35,820 upwards then for the size of our 18167 10:05:35,820 --> 10:05:37,500 lifetime again just a basic curve 18168 10:05:37,500 --> 10:05:39,416 constantly becoming smaller and smaller 18169 10:05:39,416 --> 10:05:42,120 and down here on the renderer instead of 18170 10:05:42,120 --> 10:05:43,680 rendering your quads actually rendering 18171 10:05:43,680 --> 10:05:45,840 a mesh and it's rendering a sphere mesh 18172 10:05:45,840 --> 10:05:47,520 so that's just so that it looks a little 18173 10:05:47,520 --> 10:05:49,380 bit better I think than just having a 18174 10:05:49,380 --> 10:05:51,720 Sprite particle okay so that's it so in 18175 10:05:51,720 --> 10:05:53,160 order to make this work really all we 18176 10:05:53,160 --> 10:05:55,436 need is just attach it to the player 18177 10:05:55,436 --> 10:05:57,240 so let's find the player make this 18178 10:05:57,240 --> 10:05:59,276 object a child of the player game object 18179 10:05:59,276 --> 10:06:01,916 and again let's also make sure to set 18180 10:06:01,916 --> 10:06:03,660 all of this to zero so the position on 18181 10:06:03,660 --> 10:06:06,000 zero zero and zero 18182 10:06:06,000 --> 10:06:07,436 and there you go just with this that's 18183 10:06:07,436 --> 10:06:09,720 all we need if we test here we are 18184 10:06:09,720 --> 10:06:11,520 stopping there are no particles and as I 18185 10:06:11,520 --> 10:06:13,256 start moving if there you go some nice 18186 10:06:13,256 --> 10:06:16,080 particles around the player okay great 18187 10:06:16,080 --> 10:06:18,660 next let's add a pretty obvious one some 18188 10:06:18,660 --> 10:06:21,240 kind of mini tutorial we want a window 18189 10:06:21,240 --> 10:06:23,040 to show the controls and the goal of the 18190 10:06:23,040 --> 10:06:24,660 game and wait for the player input 18191 10:06:24,660 --> 10:06:26,580 before we start the countdown 18192 10:06:26,580 --> 10:06:28,800 so for that let's go into our canvas so 18193 10:06:28,800 --> 10:06:31,916 let's show our canvas and inside let's 18194 10:06:31,916 --> 10:06:34,080 create an empty game object called the 18195 10:06:34,080 --> 10:06:35,640 tutorial UI 18196 10:06:35,640 --> 10:06:37,860 let's drag this one above the game pause 18197 10:06:37,860 --> 10:06:39,416 window so that it shows up behind it 18198 10:06:39,416 --> 10:06:41,700 let's double click to center it and 18199 10:06:41,700 --> 10:06:43,680 let's press on the 2D button to go into 18200 10:06:43,680 --> 10:06:46,436 2D mode okay let's also hide those two 18201 10:06:46,436 --> 10:06:47,880 windows so you can actually see what 18202 10:06:47,880 --> 10:06:49,620 we're doing so outside all of these okay 18203 10:06:49,620 --> 10:06:50,640 great 18204 10:06:50,640 --> 10:06:52,500 now this one first of all let's stretch 18205 10:06:52,500 --> 10:06:54,300 it to occupy everything so put zero on 18206 10:06:54,300 --> 10:06:57,960 everything okay then inside let's make a 18207 10:06:57,960 --> 10:07:01,320 UI image for our background once again 18208 10:07:01,320 --> 10:07:04,320 let's stretch it put it like this 18209 10:07:04,320 --> 10:07:06,060 and for this one instead of black like 18210 10:07:06,060 --> 10:07:07,680 we've used for all of our Windows let's 18211 10:07:07,680 --> 10:07:09,776 actually leave it on white put it on an 18212 10:07:09,776 --> 10:07:11,340 alpha something like half so something 18213 10:07:11,340 --> 10:07:12,540 like this just to be a bit different 18214 10:07:12,540 --> 10:07:14,700 then on top of this let's make another 18215 10:07:14,700 --> 10:07:17,276 image so let's make another UI image and 18216 10:07:17,276 --> 10:07:18,660 for this one instead of stretching let's 18217 10:07:18,660 --> 10:07:20,756 give it a size so let's put it on 1280 18218 10:07:20,756 --> 10:07:24,240 by 800 and for the image I created a 18219 10:07:24,240 --> 10:07:26,936 nice image for the tutorial if we go 18220 10:07:26,936 --> 10:07:28,500 inside the assets and then inside 18221 10:07:28,500 --> 10:07:30,540 textures yup here is a really nice 18222 10:07:30,540 --> 10:07:32,040 tutorial image 18223 10:07:32,040 --> 10:07:34,320 so let's just go ahead and use it so on 18224 10:07:34,320 --> 10:07:36,416 the image let's drag it all right 18225 10:07:36,416 --> 10:07:38,700 there's our nice internal image so this 18226 10:07:38,700 --> 10:07:40,436 has a pre-based tutorial so the recipe 18227 10:07:40,436 --> 10:07:42,060 is coming from the customers then the 18228 10:07:42,060 --> 10:07:43,140 player has to prepare the correct 18229 10:07:43,140 --> 10:07:45,120 recipes and deliver them on a plate on 18230 10:07:45,120 --> 10:07:47,580 the delivery counter so just a very base 18231 10:07:47,580 --> 10:07:50,160 tutorial and also over here it's very 18232 10:07:50,160 --> 10:07:51,840 important for the player to know how to 18233 10:07:51,840 --> 10:07:53,936 actually play the game so there are some 18234 10:07:53,936 --> 10:07:55,680 labels for the controls and now we're 18235 10:07:55,680 --> 10:07:57,300 going to dynamically add some keys on 18236 10:07:57,300 --> 10:07:59,756 top so let's do that let's create an 18237 10:07:59,756 --> 10:08:02,640 empty game object call this the king 18238 10:08:02,640 --> 10:08:06,000 let's put it on a size of 40 by 40 okay 18239 10:08:06,000 --> 10:08:09,180 now let's go inside and inside let's 18240 10:08:09,180 --> 10:08:11,700 make an image let's name this the 18241 10:08:11,700 --> 10:08:12,840 background 18242 10:08:12,840 --> 10:08:15,960 and for the Sprite let's go with the 18243 10:08:15,960 --> 10:08:18,360 included Circle so default Circle 18244 10:08:18,360 --> 10:08:20,700 and for the size let's stretch it occupy 18245 10:08:20,700 --> 10:08:23,340 everything put it on zero zero zero okay 18246 10:08:23,340 --> 10:08:25,200 there's our nice key 18247 10:08:25,200 --> 10:08:27,900 so we have the background and for the 18248 10:08:27,900 --> 10:08:29,460 background let's actually make it just a 18249 10:08:29,460 --> 10:08:30,960 little bit darker 18250 10:08:30,960 --> 10:08:34,080 and let's also add just a nice shadow so 18251 10:08:34,080 --> 10:08:36,776 maybe three minus three and let's also 18252 10:08:36,776 --> 10:08:38,400 make a nice upline 18253 10:08:38,400 --> 10:08:41,220 let's put it on two by two 18254 10:08:41,220 --> 10:08:43,140 full Alpha so something like this just 18255 10:08:43,140 --> 10:08:45,480 to be a nice one maybe one by one okay 18256 10:08:45,480 --> 10:08:47,460 so that's just the visual and then on 18257 10:08:47,460 --> 10:08:49,800 top of it let's add a text 18258 10:08:49,800 --> 10:08:51,180 and this one's essentially going to be 18259 10:08:51,180 --> 10:08:53,460 the king so let's put a key for the 18260 10:08:53,460 --> 10:08:56,160 width and height let's stretch it to 18261 10:08:56,160 --> 10:08:58,800 match the parent size okay then for the 18262 10:08:58,800 --> 10:09:00,480 phone here let's go with maybe just say 18263 10:09:00,480 --> 10:09:02,660 20 let's put it Center down the middle 18264 10:09:02,660 --> 10:09:05,520 and also let's put it on bond okay so 18265 10:09:05,520 --> 10:09:07,500 that's our nice key indicator 18266 10:09:07,500 --> 10:09:10,436 so this is our key and we're going to 18267 10:09:10,436 --> 10:09:11,880 have the movement so the movement on the 18268 10:09:11,880 --> 10:09:13,980 keyboard is going to have four keys so 18269 10:09:13,980 --> 10:09:16,740 let's just implicate so one two three 18270 10:09:16,740 --> 10:09:20,040 and four Keys okay then on the GamePad 18271 10:09:20,040 --> 10:09:22,020 that one is actually not rebindable so 18272 10:09:22,020 --> 10:09:24,840 let's put this one as static 18273 10:09:24,840 --> 10:09:27,720 so let's just go inside inside the text 18274 10:09:27,720 --> 10:09:31,080 and just say left stick and let's lower 18275 10:09:31,080 --> 10:09:32,756 the font size so that it fits in there 18276 10:09:32,756 --> 10:09:33,960 okay great 18277 10:09:33,960 --> 10:09:36,240 then for some more keys 18278 10:09:36,240 --> 10:09:38,400 we're going to have the interact action 18279 10:09:38,400 --> 10:09:41,276 then the interact alternate 18280 10:09:41,276 --> 10:09:43,620 and finally the pause action 18281 10:09:43,620 --> 10:09:45,840 then let's just duplicate these to be on 18282 10:09:45,840 --> 10:09:48,320 the other side 18283 10:09:52,380 --> 10:09:55,140 okay so these are all of our keys now 18284 10:09:55,140 --> 10:09:57,060 instead of having key one two three this 18285 10:09:57,060 --> 10:09:58,560 is very difficult to understand so let's 18286 10:09:58,560 --> 10:10:00,900 give it some proper names so this is the 18287 10:10:00,900 --> 10:10:03,960 key move up then we have the key move 18288 10:10:03,960 --> 10:10:05,276 down 18289 10:10:05,276 --> 10:10:08,340 then the key moves left then the key 18290 10:10:08,340 --> 10:10:09,900 move right 18291 10:10:09,900 --> 10:10:12,436 then this one is going to be the key 18292 10:10:12,436 --> 10:10:14,700 Gamepad move 18293 10:10:14,700 --> 10:10:17,580 then we have the key interact 18294 10:10:17,580 --> 10:10:21,060 the key interact alternates 18295 10:10:21,060 --> 10:10:23,096 the key pause 18296 10:10:23,096 --> 10:10:26,520 this one is the key Gamepad interact 18297 10:10:26,520 --> 10:10:28,500 alternate 18298 10:10:28,500 --> 10:10:31,680 this one is the key Gamepad interact and 18299 10:10:31,680 --> 10:10:36,020 finally the key Gamepad pause 18300 10:10:36,360 --> 10:10:38,220 okay all of these and since we're going 18301 10:10:38,220 --> 10:10:40,020 to drag references to the text objects 18302 10:10:40,020 --> 10:10:41,936 let's also give those a name 18303 10:10:41,936 --> 10:10:45,540 so just copy drop it with text 18304 10:10:45,540 --> 10:10:48,500 just like this 18305 10:10:51,416 --> 10:10:53,220 okay so those are all the names so 18306 10:10:53,220 --> 10:10:54,840 everything is nice and organized okay 18307 10:10:54,840 --> 10:10:57,480 great now let's make the script to run 18308 10:10:57,480 --> 10:10:59,880 this so our tutorial UI let's go down 18309 10:10:59,880 --> 10:11:02,096 into our UI scripts create the brand new 18310 10:11:02,096 --> 10:11:05,220 c-sharp script for the tutorial UI and 18311 10:11:05,220 --> 10:11:07,436 let's attach the script okay 18312 10:11:07,436 --> 10:11:09,840 so first let's drag references to all of 18313 10:11:09,840 --> 10:11:12,300 our keys we only need the text so let's 18314 10:11:12,300 --> 10:11:15,416 do a serialize field of type text mesh 18315 10:11:15,416 --> 10:11:17,756 Pro U going again never make the mistake 18316 10:11:17,756 --> 10:11:19,740 always use the ugly one if we're working 18317 10:11:19,740 --> 10:11:23,400 the UI so the key move of text 18318 10:11:23,400 --> 10:11:26,840 so let's add all of these 18319 10:11:28,020 --> 10:11:30,596 okay these are all the references then 18320 10:11:30,596 --> 10:11:32,820 over here let's drag on and make sure to 18321 10:11:32,820 --> 10:11:36,020 drag the correct ones 18322 10:11:37,980 --> 10:11:40,020 okay let's double check to make sure all 18323 10:11:40,020 --> 10:11:41,700 the references are correct okay they 18324 10:11:41,700 --> 10:11:43,800 don't seem correct all right great and 18325 10:11:43,800 --> 10:11:45,300 then over here only to pretty much 18326 10:11:45,300 --> 10:11:46,680 exactly the same thing that we did over 18327 10:11:46,680 --> 10:11:49,436 here on the options so we need exactly 18328 10:11:49,436 --> 10:11:52,200 this so let's copy this and over here 18329 10:11:52,200 --> 10:11:54,180 and let's do just that 18330 10:11:54,180 --> 10:11:57,660 let's see a private void update visual 18331 10:11:57,660 --> 10:11:59,520 and on this one let's do pretty much 18332 10:11:59,520 --> 10:12:01,860 this so the key move up text 18333 10:12:01,860 --> 10:12:03,480 I know this one you get binding text to 18334 10:12:03,480 --> 10:12:07,756 move up yep let's just do all the others 18335 10:12:15,776 --> 10:12:17,580 okay so those are all the bindings 18336 10:12:17,580 --> 10:12:20,756 that's great now let's go over here on a 18337 10:12:20,756 --> 10:12:23,160 proud void start and on start let's 18338 10:12:23,160 --> 10:12:25,916 update our visual all right and also 18339 10:12:25,916 --> 10:12:27,776 let's make sure this updates just in 18340 10:12:27,776 --> 10:12:29,460 case the player rebinds something from 18341 10:12:29,460 --> 10:12:31,256 the pause menu once the tutorial is 18342 10:12:31,256 --> 10:12:32,340 still visible 18343 10:12:32,340 --> 10:12:34,080 so we just need to know when that 18344 10:12:34,080 --> 10:12:35,580 happens so let's go over here onto the 18345 10:12:35,580 --> 10:12:37,860 game input and make a nice event so 18346 10:12:37,860 --> 10:12:40,680 public event even Handler let's call it 18347 10:12:40,680 --> 10:12:43,020 on binding rebind 18348 10:12:43,020 --> 10:12:45,540 okay we have this event and down here 18349 10:12:45,540 --> 10:12:47,460 when we have our rebind binding function 18350 10:12:47,460 --> 10:12:50,220 we do this we rebind and over here let's 18351 10:12:50,220 --> 10:12:53,060 invoke this event 18352 10:12:57,000 --> 10:12:59,040 okay just like this 18353 10:12:59,040 --> 10:13:02,220 so then on TTR only y let's go into the 18354 10:13:02,220 --> 10:13:05,220 game input the instance on binding 18355 10:13:05,220 --> 10:13:08,460 rebind let's listen to this event and as 18356 10:13:08,460 --> 10:13:10,620 always let's rename this so let's put a 18357 10:13:10,620 --> 10:13:13,200 game input okay when this happens let's 18358 10:13:13,200 --> 10:13:15,300 simply update the visual 18359 10:13:15,300 --> 10:13:17,580 okay that's it pretty simple so let's 18360 10:13:17,580 --> 10:13:19,560 test and see if the inputs are correct 18361 10:13:19,560 --> 10:13:21,480 and if there it is we do see it correct 18362 10:13:21,480 --> 10:13:23,640 so we've got ones we've got e to 18363 10:13:23,640 --> 10:13:25,680 interact F and over there we've got the 18364 10:13:25,680 --> 10:13:28,800 GamePad okay great so all the buttons 18365 10:13:28,800 --> 10:13:30,360 are correct all that's left is the show 18366 10:13:30,360 --> 10:13:32,400 and hide so over here let's make the 18367 10:13:32,400 --> 10:13:35,096 usual two functions so product void show 18368 10:13:35,096 --> 10:13:38,520 and a proud boy in Hind and for these 18369 10:13:38,520 --> 10:13:41,460 game objects set active and this one is 18370 10:13:41,460 --> 10:13:43,560 going to be into false and this one's 18371 10:13:43,560 --> 10:13:45,000 going to be true okay 18372 10:13:45,000 --> 10:13:47,460 so for show up here on start let's 18373 10:13:47,460 --> 10:13:49,620 actually show it by default even though 18374 10:13:49,620 --> 10:13:51,000 it's actually already going to be shown 18375 10:13:51,000 --> 10:13:54,416 but still okay then for the hind this 18376 10:13:54,416 --> 10:13:56,340 one we want to hide when we press the 18377 10:13:56,340 --> 10:13:57,840 interaction 18378 10:13:57,840 --> 10:14:00,416 however when that happens we don't want 18379 10:14:00,416 --> 10:14:02,700 just this window to hide we want the 18380 10:14:02,700 --> 10:14:04,980 kitchen game manager to change the state 18381 10:14:04,980 --> 10:14:06,360 so we're here on the kitchen game 18382 10:14:06,360 --> 10:14:08,580 manager we currently have the waiting to 18383 10:14:08,580 --> 10:14:10,200 start and that one actually has a timer 18384 10:14:10,200 --> 10:14:12,300 so we count down the timer and then we 18385 10:14:12,300 --> 10:14:14,160 start whereas right now we want it to be 18386 10:14:14,160 --> 10:14:16,500 based on player input so let's modify 18387 10:14:16,500 --> 10:14:18,300 this to not be based on timer so let's 18388 10:14:18,300 --> 10:14:20,220 just get rid of this timer 18389 10:14:20,220 --> 10:14:22,436 and now let's see all these errors so 18390 10:14:22,436 --> 10:14:24,240 I'm waiting to start we are not going to 18391 10:14:24,240 --> 10:14:26,936 count down any timers instead let's 18392 10:14:26,936 --> 10:14:30,120 listen to the game input so game input 18393 10:14:30,120 --> 10:14:32,820 let's listen to the on interact action 18394 10:14:32,820 --> 10:14:36,180 event and rename this to the game input 18395 10:14:36,180 --> 10:14:39,660 okay so when we have this event when the 18396 10:14:39,660 --> 10:14:41,880 player presses the interact action let's 18397 10:14:41,880 --> 10:14:44,160 check if the state if this one is on 18398 10:14:44,160 --> 10:14:45,480 waiting to start 18399 10:14:45,480 --> 10:14:47,400 if so then let's modify the state so 18400 10:14:47,400 --> 10:14:49,020 let's go into State and we're going to 18401 10:14:49,020 --> 10:14:51,360 go into the countdown to start and let's 18402 10:14:51,360 --> 10:14:54,860 trigger the on state changed event 18403 10:14:58,200 --> 10:15:00,300 okay so that's it so we're only going to 18404 10:15:00,300 --> 10:15:01,980 change it on the player input and 18405 10:15:01,980 --> 10:15:04,080 nothing over here on the updates then 18406 10:15:04,080 --> 10:15:06,900 for hiding the tutorial over here one 18407 10:15:06,900 --> 10:15:08,276 approach would be to listen to the 18408 10:15:08,276 --> 10:15:10,500 interact action and hide it but I think 18409 10:15:10,500 --> 10:15:12,416 it makes more sense for this to only 18410 10:15:12,416 --> 10:15:14,460 listen to the kitchen game manager state 18411 10:15:14,460 --> 10:15:16,560 that way if we wanted we could also 18412 10:15:16,560 --> 10:15:18,360 modify how this one changes the waiting 18413 10:15:18,360 --> 10:15:19,256 to start 18414 10:15:19,256 --> 10:15:22,200 so let's listen to distinct over here on 18415 10:15:22,200 --> 10:15:23,580 tutorial we want let's go into the 18416 10:15:23,580 --> 10:15:25,560 kitchen game manager the incense and 18417 10:15:25,560 --> 10:15:29,240 let's listen when the state changes 18418 10:15:30,960 --> 10:15:33,000 so here we are going to check if the 18419 10:15:33,000 --> 10:15:35,460 kitchen game manager instance if it is 18420 10:15:35,460 --> 10:15:37,380 on the countdown to start active so if 18421 10:15:37,380 --> 10:15:39,180 the countdown is active then we're going 18422 10:15:39,180 --> 10:15:40,320 to hide this 18423 10:15:40,320 --> 10:15:42,900 okay so that should do it now let's just 18424 10:15:42,900 --> 10:15:45,416 do one more small thing the delivery 18425 10:15:45,416 --> 10:15:46,916 manager is currently spanning a recipe 18426 10:15:46,916 --> 10:15:48,596 whilst we're still reading the tutorial 18427 10:15:48,596 --> 10:15:50,400 that's not quite right 18428 10:15:50,400 --> 10:15:52,436 so let's go over here on the delivery 18429 10:15:52,436 --> 10:15:55,020 manager and right now this one starts 18430 10:15:55,020 --> 10:15:56,756 off at 0f and starts counting it down 18431 10:15:56,756 --> 10:15:57,720 right away 18432 10:15:57,720 --> 10:15:59,820 instead of only doing it like this let's 18433 10:15:59,820 --> 10:16:01,200 just make sure that we only spawn a 18434 10:16:01,200 --> 10:16:02,700 recipe if the game is playing so that's 18435 10:16:02,700 --> 10:16:04,620 super simple over here kitchen game 18436 10:16:04,620 --> 10:16:08,040 manager instance is game playing if so 18437 10:16:08,040 --> 10:16:10,320 then we are going to spawn a recipe and 18438 10:16:10,320 --> 10:16:12,416 let's do the same thing on the points 18439 10:16:12,416 --> 10:16:14,640 counter so let's go in the plates 18440 10:16:14,640 --> 10:16:15,720 counter 18441 10:16:15,720 --> 10:16:17,700 so here we are on the plates counter so 18442 10:16:17,700 --> 10:16:19,500 we count on time responsive lights but 18443 10:16:19,500 --> 10:16:20,820 let's also make sure we only spawn 18444 10:16:20,820 --> 10:16:22,680 plates if the game swing 18445 10:16:22,680 --> 10:16:25,380 okay so with all of this let's test and 18446 10:16:25,380 --> 10:16:27,300 right away here we are we can see our 18447 10:16:27,300 --> 10:16:28,980 nice tutorial teaching the player how to 18448 10:16:28,980 --> 10:16:30,360 play okay great here we've got the 18449 10:16:30,360 --> 10:16:32,460 controls everything and we're currently 18450 10:16:32,460 --> 10:16:34,500 waiting for an interaction we can see 18451 10:16:34,500 --> 10:16:36,120 over there plates are not being spawned 18452 10:16:36,120 --> 10:16:37,800 and recipes are also not being spawned 18453 10:16:37,800 --> 10:16:40,020 but as soon as I press the E key 18454 10:16:40,020 --> 10:16:41,880 and if there go the countdown starts 18455 10:16:41,880 --> 10:16:43,560 playing and we've got everything else 18456 10:16:43,560 --> 10:16:45,840 any up there you go the game starts and 18457 10:16:45,840 --> 10:16:47,460 after a while yep we've got plates and 18458 10:16:47,460 --> 10:16:50,580 we've got recipes alright awesome so 18459 10:16:50,580 --> 10:16:52,680 next let's publish the countdown visual 18460 10:16:52,680 --> 10:16:54,840 right now it's pretty basic it's just a 18461 10:16:54,840 --> 10:16:56,520 static number so let's add a nice 18462 10:16:56,520 --> 10:16:58,500 animation to it let's go inside the 18463 10:16:58,500 --> 10:17:00,960 canvas let's find the countdown UI so 18464 10:17:00,960 --> 10:17:02,820 the game start countdown okay 18465 10:17:02,820 --> 10:17:04,620 so here it is we just have some basic 18466 10:17:04,620 --> 10:17:07,080 text now let's go into the main game 18467 10:17:07,080 --> 10:17:08,820 object and let's add an animator 18468 10:17:08,820 --> 10:17:10,080 component 18469 10:17:10,080 --> 10:17:12,000 then let's create a brand new animated 18470 10:17:12,000 --> 10:17:14,936 controller so let's create a new down 18471 10:17:14,936 --> 10:17:16,620 here an animated controller for the 18472 10:17:16,620 --> 10:17:19,020 countdown UI over there let's assign 18473 10:17:19,020 --> 10:17:21,300 this controller okay now let's open up 18474 10:17:21,300 --> 10:17:23,220 the animation window so window animation 18475 10:17:23,220 --> 10:17:24,960 open up the animation window okay let's 18476 10:17:24,960 --> 10:17:26,700 create an animation clip and over here 18477 10:17:26,700 --> 10:17:28,500 on let's name this the countdown UI 18478 10:17:28,500 --> 10:17:31,380 number pop-up okay that's great now for 18479 10:17:31,380 --> 10:17:33,360 making the animation we want to 18480 10:17:33,360 --> 10:17:35,096 basically make it shake and also make it 18481 10:17:35,096 --> 10:17:37,680 fade away so one very useful component 18482 10:17:37,680 --> 10:17:39,776 is the canvas group so over here once on 18483 10:17:39,776 --> 10:17:42,120 the parent let's attach a canvas group 18484 10:17:42,120 --> 10:17:44,520 component this one is a really useful 18485 10:17:44,520 --> 10:17:46,500 component in this case the main benefit 18486 10:17:46,500 --> 10:17:48,360 is it let's just easily animate the 18487 10:17:48,360 --> 10:17:50,640 alpha so let's go ahead and turn on 18488 10:17:50,640 --> 10:17:53,220 recording let's go into the frame just 18489 10:17:53,220 --> 10:17:55,200 before one second so let's go into 60 18490 10:17:55,200 --> 10:17:57,180 frames because we are on 60 frames per 18491 10:17:57,180 --> 10:17:59,400 second over here let's record the normal 18492 10:17:59,400 --> 10:18:01,680 keyframe so let's modify the scale on 18493 10:18:01,680 --> 10:18:03,300 the tiny bit just to record it and let's 18494 10:18:03,300 --> 10:18:05,276 reset it back to one okay just to record 18495 10:18:05,276 --> 10:18:07,980 the keyframe then for rotation let's 18496 10:18:07,980 --> 10:18:09,960 rotate on Z then put it on zero again 18497 10:18:09,960 --> 10:18:12,480 just record the keyframe okay great so 18498 10:18:12,480 --> 10:18:14,220 now we can go back into the first frame 18499 10:18:14,220 --> 10:18:16,200 and over here let's first make it 18500 10:18:16,200 --> 10:18:18,120 smaller so for the size let's put it on 18501 10:18:18,120 --> 10:18:20,756 0.6 then let's rotate it to the left so 18502 10:18:20,756 --> 10:18:22,680 let's put 17 over here on the set 18503 10:18:22,680 --> 10:18:25,080 rotation okay like that now let's move 18504 10:18:25,080 --> 10:18:26,820 up by just three frames so on frame 18505 10:18:26,820 --> 10:18:28,800 three over here let's make it quite a 18506 10:18:28,800 --> 10:18:31,256 lot bigger so let's put it on 1.3 and 18507 10:18:31,256 --> 10:18:33,000 let's rotate it to the opposite position 18508 10:18:33,000 --> 10:18:36,480 so -17 okay that's great that's a nice 18509 10:18:36,480 --> 10:18:39,540 start now let's put it on frame 10 and 18510 10:18:39,540 --> 10:18:42,000 over here let's set the rotation to zero 18511 10:18:42,000 --> 10:18:44,936 and for the scale put it on 1.1 okay so 18512 10:18:44,936 --> 10:18:47,880 now finally over here on frame 50 let's 18513 10:18:47,880 --> 10:18:51,120 set the alpha onto one and then on one 18514 10:18:51,120 --> 10:18:53,340 second let's put the alpha zero okay so 18515 10:18:53,340 --> 10:18:55,320 let's preview and if they go a nice 18516 10:18:55,320 --> 10:18:57,720 simple animation okay so that was great 18517 10:18:57,720 --> 10:18:59,700 now we just need to play this when the 18518 10:18:59,700 --> 10:19:01,800 countdown happens so let's stop 18519 10:19:01,800 --> 10:19:04,200 recording let's go inside the animator 18520 10:19:04,200 --> 10:19:06,060 controller so here it is we've got our 18521 10:19:06,060 --> 10:19:08,460 number pop-up and we basically just want 18522 10:19:08,460 --> 10:19:10,256 to play this animation whenever we want 18523 10:19:10,256 --> 10:19:12,540 so let's put it and make a transition 18524 10:19:12,540 --> 10:19:14,340 from the any state onto the number 18525 10:19:14,340 --> 10:19:16,740 pop-up on this transition let's make 18526 10:19:16,740 --> 10:19:18,540 sure we have no exit time and for the 18527 10:19:18,540 --> 10:19:19,620 settings over here for the duration 18528 10:19:19,620 --> 10:19:21,060 let's put it on zero so that it's 18529 10:19:21,060 --> 10:19:23,460 instant okay great now obviously we need 18530 10:19:23,460 --> 10:19:25,680 a condition so on the parameters let's 18531 10:19:25,680 --> 10:19:28,140 create a brand new trigger call this the 18532 10:19:28,140 --> 10:19:30,776 number pop-up let's select that one and 18533 10:19:30,776 --> 10:19:33,720 Trigger it on this trigger okay great so 18534 10:19:33,720 --> 10:19:36,120 now for handling this logic here we have 18535 10:19:36,120 --> 10:19:37,560 the usual question 18536 10:19:37,560 --> 10:19:39,660 so do we put this visual Logic on the 18537 10:19:39,660 --> 10:19:41,640 same UI script or do we separate the 18538 10:19:41,640 --> 10:19:43,980 animations from the UI for me I find 18539 10:19:43,980 --> 10:19:46,436 that UI is usually part of the visual so 18540 10:19:46,436 --> 10:19:48,360 sometimes I like to mix the two and 18541 10:19:48,360 --> 10:19:50,096 sometimes I keep them separate it really 18542 10:19:50,096 --> 10:19:52,380 depends on a case-by-case basis this 18543 10:19:52,380 --> 10:19:54,596 visual is so simple and so connected to 18544 10:19:54,596 --> 10:19:56,640 the actual UI Logics over here let's put 18545 10:19:56,640 --> 10:19:58,680 them together so let's open up the game 18546 10:19:58,680 --> 10:20:00,480 start countdown script and over here 18547 10:20:00,480 --> 10:20:02,400 let's first grab the animator so private 18548 10:20:02,400 --> 10:20:05,040 animator for the animator and on private 18549 10:20:05,040 --> 10:20:06,720 void awake let's just get the animator 18550 10:20:06,720 --> 10:20:08,220 and just get the component of type 18551 10:20:08,220 --> 10:20:10,800 animator okay so we have the animator 18552 10:20:10,800 --> 10:20:13,020 now we basically just need to keep track 18553 10:20:13,020 --> 10:20:14,936 down here where we're modifying the text 18554 10:20:14,936 --> 10:20:17,160 we're doing this on every update but now 18555 10:20:17,160 --> 10:20:18,720 we need to know when this number changes 18556 10:20:18,720 --> 10:20:20,880 so let's basically just keep track of 18557 10:20:20,880 --> 10:20:22,200 the current number and the previous 18558 10:20:22,200 --> 10:20:24,840 number so first of all over here an end 18559 10:20:24,840 --> 10:20:27,060 for the countdown number 18560 10:20:27,060 --> 10:20:29,520 and we're going to get this so this is 18561 10:20:29,520 --> 10:20:31,860 our countdown number and over here we 18562 10:20:31,860 --> 10:20:33,180 set it to string 18563 10:20:33,180 --> 10:20:35,220 okay and we just need to use a different 18564 10:20:35,220 --> 10:20:37,560 function so instead of Cl lets you cl2n 18565 10:20:37,560 --> 10:20:39,060 just to convert the output into an 18566 10:20:39,060 --> 10:20:40,680 integer okay great 18567 10:20:40,680 --> 10:20:42,840 so we have the countdown number now we 18568 10:20:42,840 --> 10:20:43,980 just need to know if this one is 18569 10:20:43,980 --> 10:20:45,900 different from the previous one so let's 18570 10:20:45,900 --> 10:20:48,060 go up here let's define a private tint 18571 10:20:48,060 --> 10:20:51,060 for the previous countdown number 18572 10:20:51,060 --> 10:20:53,820 then when we go down here we've got the 18573 10:20:53,820 --> 10:20:55,680 current countdown number okay then just 18574 10:20:55,680 --> 10:20:58,320 check if it's different 18575 10:20:58,320 --> 10:21:00,120 if it is different from the current 18576 10:21:00,120 --> 10:21:02,520 countdown number if so then let's update 18577 10:21:02,520 --> 10:21:04,200 it so the previous one becomes this one 18578 10:21:04,200 --> 10:21:06,000 and now let's fire off the animation so 18579 10:21:06,000 --> 10:21:07,800 let's go into the animator and set the 18580 10:21:07,800 --> 10:21:09,840 trigger and again we don't want these 18581 10:21:09,840 --> 10:21:11,520 strings so let's go up to the top of the 18582 10:21:11,520 --> 10:21:14,936 file make a private cons string let's 18583 10:21:14,936 --> 10:21:17,520 call this the number pop-up 18584 10:21:17,520 --> 10:21:20,820 and number pop-up 18585 10:21:20,820 --> 10:21:22,980 okay so we have this end down here we 18586 10:21:22,980 --> 10:21:25,436 just set this trigger okay so that's it 18587 10:21:25,436 --> 10:21:27,480 pretty simple and just for fun let's 18588 10:21:27,480 --> 10:21:29,820 also add a nice sound effect so let's go 18589 10:21:29,820 --> 10:21:31,436 over here onto The Sound Manager and 18590 10:21:31,436 --> 10:21:33,416 let's make a function to play sound so 18591 10:21:33,416 --> 10:21:35,040 just like we did over here for the play 18592 10:21:35,040 --> 10:21:37,620 footstep sound let's make another one 18593 10:21:37,620 --> 10:21:40,200 for this one let's go and play countdown 18594 10:21:40,200 --> 10:21:42,900 sound and for this one let's not receive 18595 10:21:42,900 --> 10:21:45,480 a volume or position and we just play 18596 10:21:45,480 --> 10:21:47,880 let's say just the warning sound so just 18597 10:21:47,880 --> 10:21:50,820 down on Vector 3.0 and with the current 18598 10:21:50,820 --> 10:21:52,200 volume 18599 10:21:52,200 --> 10:21:54,416 okay so we have this function and then 18600 10:21:54,416 --> 10:21:56,040 down here just going to sound manager 18601 10:21:56,040 --> 10:21:58,020 instance and play the countdown sound 18602 10:21:58,020 --> 10:22:00,480 again we could refactor this code to 18603 10:22:00,480 --> 10:22:02,276 separate the Yuan logic from the 18604 10:22:02,276 --> 10:22:04,140 animation from the sound that is one 18605 10:22:04,140 --> 10:22:06,240 approach and sectionally one thing that 18606 10:22:06,240 --> 10:22:07,800 we're going to do in the next polish 18607 10:22:07,800 --> 10:22:09,900 stage but this one is also a possible 18608 10:22:09,900 --> 10:22:12,480 thing since the UI is only so directly 18609 10:22:12,480 --> 10:22:14,700 connected to visuals okay so with this 18610 10:22:14,700 --> 10:22:16,860 let's test so here in the options let's 18611 10:22:16,860 --> 10:22:18,480 just make sure that we have our sound 18612 10:22:18,480 --> 10:22:19,740 effects so let's make sure they are 18613 10:22:19,740 --> 10:22:21,900 playing okay great now let's go ahead 18614 10:22:21,900 --> 10:22:24,180 and play and there you go we have our 18615 10:22:24,180 --> 10:22:26,096 nice countdown number and there you go 18616 10:22:26,096 --> 10:22:27,776 it looks great so it looks great and 18617 10:22:27,776 --> 10:22:30,300 sounds great alright awesome as you can 18618 10:22:30,300 --> 10:22:31,860 see just by adding a simple animation 18619 10:22:31,860 --> 10:22:33,300 and some simple sounds that already 18620 10:22:33,300 --> 10:22:35,580 looks so much better now the next thing 18621 10:22:35,580 --> 10:22:37,916 we want to publish is on the stove so 18622 10:22:37,916 --> 10:22:39,776 let's go into our stove back into our 18623 10:22:39,776 --> 10:22:42,300 counters back into 3D and zoom in over 18624 10:22:42,300 --> 10:22:44,820 here okay let's also make sure that we 18625 10:22:44,820 --> 10:22:46,500 hide the canvas just so we can play 18626 10:22:46,500 --> 10:22:48,596 around this all right great so there's 18627 10:22:48,596 --> 10:22:51,000 our stove and for this we want to add 18628 10:22:51,000 --> 10:22:53,276 basically a warning icon on any nice 18629 10:22:53,276 --> 10:22:55,436 sound when the meat is about to burn so 18630 10:22:55,436 --> 10:22:57,360 let's go inside the stove counter prefab 18631 10:22:57,360 --> 10:22:59,340 okay so now inside of this we already 18632 10:22:59,340 --> 10:23:02,460 have a nice generic progress bar UI and 18633 10:23:02,460 --> 10:23:04,200 like I mentioned if you want to get some 18634 10:23:04,200 --> 10:23:06,360 more custom Behavior you can combine a 18635 10:23:06,360 --> 10:23:08,400 generic bar like this one with some 18636 10:23:08,400 --> 10:23:09,960 specific components so that's exactly 18637 10:23:09,960 --> 10:23:11,880 what we're going to do right now so over 18638 10:23:11,880 --> 10:23:14,700 here let's create a brand new canvas as 18639 10:23:14,700 --> 10:23:16,800 usual let's make it a world space canvas 18640 10:23:16,800 --> 10:23:19,080 for position let's put all of this on 18641 10:23:19,080 --> 10:23:20,096 zero 18642 10:23:20,096 --> 10:23:22,140 let's just lift it up by a bit so set it 18643 10:23:22,140 --> 10:23:25,080 on a y of three okay great then let's 18644 10:23:25,080 --> 10:23:26,820 add our super useful look at camera 18645 10:23:26,820 --> 10:23:29,400 component and make it camera phone okay 18646 10:23:29,400 --> 10:23:31,860 now inside let's go ahead create a new 18647 10:23:31,860 --> 10:23:34,800 image let's put it on a size of 0.5 by 18648 10:23:34,800 --> 10:23:37,620 0.5 okay just a nice square and for the 18649 10:23:37,620 --> 10:23:39,840 Sprite there's a nice warning image in 18650 10:23:39,840 --> 10:23:41,700 the asset so it's this one here we have 18651 10:23:41,700 --> 10:23:44,640 the warning okay great basically we want 18652 10:23:44,640 --> 10:23:46,020 to show this when the meter is about to 18653 10:23:46,020 --> 10:23:48,120 burn so let's make a screen to run this 18654 10:23:48,120 --> 10:23:49,860 and on the canvas let's give it a proper 18655 10:23:49,860 --> 10:23:52,080 name so let's call this the stove burn 18656 10:23:52,080 --> 10:23:53,580 warning UI 18657 10:23:53,580 --> 10:23:55,916 okay so let's make this crypto render so 18658 10:23:55,916 --> 10:23:57,596 when you c-sharp script with the exact 18659 10:23:57,596 --> 10:23:59,820 same name and over here let's attach a 18660 10:23:59,820 --> 10:24:02,160 script okay great so now the first thing 18661 10:24:02,160 --> 10:24:03,900 that we need is obviously a reference to 18662 10:24:03,900 --> 10:24:05,640 the stove so let's make a serialized 18663 10:24:05,640 --> 10:24:08,340 film private for the stove counter for 18664 10:24:08,340 --> 10:24:10,256 the stove counter 18665 10:24:10,256 --> 10:24:12,660 okay here in the editor let's drag the 18666 10:24:12,660 --> 10:24:14,276 reference of the sub counter okay great 18667 10:24:14,276 --> 10:24:17,096 so now we basically just need to know 18668 10:24:17,096 --> 10:24:19,020 when the food is about to burn and for 18669 10:24:19,020 --> 10:24:20,520 that we can actually listen to the on 18670 10:24:20,520 --> 10:24:23,580 progress event so let's do a private 18671 10:24:23,580 --> 10:24:25,620 void start and on start let's go into 18672 10:24:25,620 --> 10:24:28,020 the stove counter and let's listen into 18673 10:24:28,020 --> 10:24:30,900 the on progress change event okay so we 18674 10:24:30,900 --> 10:24:32,276 have this one 18675 10:24:32,276 --> 10:24:34,140 and recently we're going to want to show 18676 10:24:34,140 --> 10:24:36,180 this element so let's find a bone show 18677 10:24:36,180 --> 10:24:38,040 we're going to want to show this when 18678 10:24:38,040 --> 10:24:40,080 the progress normalized is above a 18679 10:24:40,080 --> 10:24:42,300 certain amount so let's define a float 18680 10:24:42,300 --> 10:24:45,240 for the burn show progress amount and 18681 10:24:45,240 --> 10:24:46,860 let's say 1.5 18682 10:24:46,860 --> 10:24:49,256 so on this one we show it except 18683 10:24:49,256 --> 10:24:50,936 obviously we don't want it to be shown 18684 10:24:50,936 --> 10:24:53,096 when the food is just cooking we only 18685 10:24:53,096 --> 10:24:54,720 want it to show when it's about to burn 18686 10:24:54,720 --> 10:24:56,756 so that means we also need to check the 18687 10:24:56,756 --> 10:24:58,680 state on the stove counter so let's make 18688 10:24:58,680 --> 10:25:00,060 a function to check if we are in the 18689 10:25:00,060 --> 10:25:01,740 state that we want so we're here on the 18690 10:25:01,740 --> 10:25:03,240 stove counter let's go down to the 18691 10:25:03,240 --> 10:25:03,960 bottom 18692 10:25:03,960 --> 10:25:07,620 and let's make a public bowl is fried 18693 10:25:07,620 --> 10:25:09,660 and over here we just return if the 18694 10:25:09,660 --> 10:25:11,880 state equals state DOT frame 18695 10:25:11,880 --> 10:25:14,160 okay that's great so now here we're 18696 10:25:14,160 --> 10:25:15,540 going to show if the progress is above 18697 10:25:15,540 --> 10:25:18,960 0.5 and the stove counter is on the 18698 10:25:18,960 --> 10:25:20,160 Fright state 18699 10:25:20,160 --> 10:25:22,080 all right so that's the logic that we 18700 10:25:22,080 --> 10:25:23,640 want then we just want to show our 18701 10:25:23,640 --> 10:25:24,540 height so let's make the original 18702 10:25:24,540 --> 10:25:27,240 functions private show and a private 18703 10:25:27,240 --> 10:25:28,740 void hide 18704 10:25:28,740 --> 10:25:31,140 and just do game objects and active into 18705 10:25:31,140 --> 10:25:34,340 either true or false 18706 10:25:36,900 --> 10:25:39,900 and over here if show then let's call 18707 10:25:39,900 --> 10:25:42,360 the show function and if not let's call 18708 10:25:42,360 --> 10:25:44,880 the Hide function and of course on start 18709 10:25:44,880 --> 10:25:47,880 let's start off as hidden okay that's it 18710 10:25:47,880 --> 10:25:50,340 let's test just over here in the editor 18711 10:25:50,340 --> 10:25:52,380 make sure the reference is right and 18712 10:25:52,380 --> 10:25:54,120 let's save the prefab go outside and hit 18713 10:25:54,120 --> 10:25:56,160 on point and yep right away there's no 18714 10:25:56,160 --> 10:25:58,436 element okay great now I place it and it 18715 10:25:58,436 --> 10:26:00,596 won't cooking there's no element and now 18716 10:26:00,596 --> 10:26:02,160 once it's on the halfway point for 18717 10:26:02,160 --> 10:26:03,900 burning and if there you go we've got a 18718 10:26:03,900 --> 10:26:06,120 nice warning okay awesome so now that 18719 10:26:06,120 --> 10:26:07,680 this is working let's just add a nice 18720 10:26:07,680 --> 10:26:09,960 animation so once again let's go inside 18721 10:26:09,960 --> 10:26:11,820 the stove counter and on the burn 18722 10:26:11,820 --> 10:26:14,640 warning UI let's add an animator 18723 10:26:14,640 --> 10:26:16,020 controller 18724 10:26:16,020 --> 10:26:18,000 then let's actually create the animated 18725 10:26:18,000 --> 10:26:19,256 controller so let's create a brand new 18726 10:26:19,256 --> 10:26:20,640 animated controller 18727 10:26:20,640 --> 10:26:23,700 for the stove burn warning UI 18728 10:26:23,700 --> 10:26:26,460 then let's assign it okay and over here 18729 10:26:26,460 --> 10:26:27,840 on the animation window let's create an 18730 10:26:27,840 --> 10:26:29,040 animation 18731 10:26:29,040 --> 10:26:31,256 let's put it on the same folder and call 18732 10:26:31,256 --> 10:26:32,400 it 18733 10:26:32,400 --> 10:26:34,140 for this one let's say flash we're going 18734 10:26:34,140 --> 10:26:36,180 to make it Flash and then again for 18735 10:26:36,180 --> 10:26:37,620 making it flash let's use the same 18736 10:26:37,620 --> 10:26:39,060 component that we used a while ago so 18737 10:26:39,060 --> 10:26:41,520 let's add a canvas group so here it is 18738 10:26:41,520 --> 10:26:43,140 now we can play around the alpha so 18739 10:26:43,140 --> 10:26:45,360 super useful although I should say that 18740 10:26:45,360 --> 10:26:46,980 at this point since we just have a 18741 10:26:46,980 --> 10:26:49,320 single image we could just record a 18742 10:26:49,320 --> 10:26:50,640 change over here on the alpha for the 18743 10:26:50,640 --> 10:26:52,800 image itself however one place where 18744 10:26:52,800 --> 10:26:54,596 this component is super useful is if you 18745 10:26:54,596 --> 10:26:57,000 have multiple images so if over here I 18746 10:26:57,000 --> 10:26:58,620 duplicate this one and I put it off to 18747 10:26:58,620 --> 10:27:00,660 the side if I change the alpha on one of 18748 10:27:00,660 --> 10:27:02,460 them then obviously it only affects that 18749 10:27:02,460 --> 10:27:04,740 one but if I go over here and I modify 18750 10:27:04,740 --> 10:27:06,180 the canvas group that changes the amp 18751 10:27:06,180 --> 10:27:07,860 for both of them so if you have a group 18752 10:27:07,860 --> 10:27:10,080 of images then using the canvas group 18753 10:27:10,080 --> 10:27:12,660 makes it super simple so anyway so here 18754 10:27:12,660 --> 10:27:15,240 we have just our image let's go ahead 18755 10:27:15,240 --> 10:27:17,580 and record and let's say we start off on 18756 10:27:17,580 --> 10:27:19,980 Alpha zero then after 10 frames going to 18757 10:27:19,980 --> 10:27:22,680 Alpha One and after 20 frames back into 18758 10:27:22,680 --> 10:27:25,436 an alpha of zero okay so that's it a 18759 10:27:25,436 --> 10:27:27,416 super simple very basic animation we 18760 10:27:27,416 --> 10:27:29,220 don't even need analogic since we just 18761 10:27:29,220 --> 10:27:31,916 want this animation to play Non-Stop so 18762 10:27:31,916 --> 10:27:33,960 that's great that should be working now 18763 10:27:33,960 --> 10:27:36,060 let's add some sound so for that we 18764 10:27:36,060 --> 10:27:37,620 could make another script but already on 18765 10:27:37,620 --> 10:27:39,960 the stove counter we already have a nice 18766 10:27:39,960 --> 10:27:41,936 sound component so let's open up this 18767 10:27:41,936 --> 10:27:44,040 grip the stove counter sound so this is 18768 10:27:44,040 --> 10:27:45,360 basically where we're playing or 18769 10:27:45,360 --> 10:27:47,580 stopping the sizzling sound so over here 18770 10:27:47,580 --> 10:27:50,276 we can just add the warning sound we're 18771 10:27:50,276 --> 10:27:52,020 going to play the sound just like we 18772 10:27:52,020 --> 10:27:54,240 have over here for the burning UI so 18773 10:27:54,240 --> 10:27:55,916 let's actually copy these same 18774 10:27:55,916 --> 10:27:58,380 components and over here let's face it 18775 10:27:58,380 --> 10:28:00,360 so for this one instead of show let's 18776 10:28:00,360 --> 10:28:03,000 give it a proper name so play warning 18777 10:28:03,000 --> 10:28:05,400 sound except it's not on say change so 18778 10:28:05,400 --> 10:28:06,596 let's actually listen to the other one 18779 10:28:06,596 --> 10:28:08,700 so still counter on progress change 18780 10:28:08,700 --> 10:28:11,096 let's listen down and it's on that one 18781 10:28:11,096 --> 10:28:12,776 that we use this 18782 10:28:12,776 --> 10:28:15,660 Okay so we've got that one and then for 18783 10:28:15,660 --> 10:28:17,400 playing the warning sound we're going to 18784 10:28:17,400 --> 10:28:19,020 want to basically play it every certain 18785 10:28:19,020 --> 10:28:20,220 amount of time 18786 10:28:20,220 --> 10:28:22,320 so let's make over here a private void 18787 10:28:22,320 --> 10:28:25,680 update and an update let's just Define a 18788 10:28:25,680 --> 10:28:28,080 private float for the warning sound 18789 10:28:28,080 --> 10:28:29,820 timer 18790 10:28:29,820 --> 10:28:32,160 and so down here we just count down as 18791 10:28:32,160 --> 10:28:34,620 usual time dot Delta time 18792 10:28:34,620 --> 10:28:38,596 and if this one is under zero 18793 10:28:38,756 --> 10:28:41,520 if so then let's reset it so Define a 18794 10:28:41,520 --> 10:28:42,960 certain maximum 18795 10:28:42,960 --> 10:28:45,540 let's say 10 times or maybe just five 18796 10:28:45,540 --> 10:28:47,640 times per second that should be good so 18797 10:28:47,640 --> 10:28:49,256 we have this but obviously we only want 18798 10:28:49,256 --> 10:28:50,880 this to run if we should be playing the 18799 10:28:50,880 --> 10:28:52,200 warning sound so let's actually save 18800 10:28:52,200 --> 10:28:54,240 this one up here so probably won't for 18801 10:28:54,240 --> 10:28:56,640 these play the warning sound and then we 18802 10:28:56,640 --> 10:28:58,380 set it on this one 18803 10:28:58,380 --> 10:29:00,776 and down here let's just go and we're 18804 10:29:00,776 --> 10:29:02,880 only going to run this if play the 18805 10:29:02,880 --> 10:29:04,256 warning sound then we're going to run 18806 10:29:04,256 --> 10:29:06,180 our timer logic all right and then over 18807 10:29:06,180 --> 10:29:08,040 here all we need is to play that warning 18808 10:29:08,040 --> 10:29:08,700 sound 18809 10:29:08,700 --> 10:29:10,380 so let's actually go into The Sound 18810 10:29:10,380 --> 10:29:12,540 Manager and just like we added the 18811 10:29:12,540 --> 10:29:14,756 countdown sound let's add another one so 18812 10:29:14,756 --> 10:29:16,980 let's say the play warning sound and for 18813 10:29:16,980 --> 10:29:18,540 this one let's receive a vector 3 for 18814 10:29:18,540 --> 10:29:20,520 the position and we're going to play the 18815 10:29:20,520 --> 10:29:22,680 warning sound on this position so now 18816 10:29:22,680 --> 10:29:24,060 over here on the stove counter let's go 18817 10:29:24,060 --> 10:29:26,400 into The Sound Manager the instance and 18818 10:29:26,400 --> 10:29:29,220 let's play the warning sound and pass in 18819 10:29:29,220 --> 10:29:31,380 the stove dot transform that position 18820 10:29:31,380 --> 10:29:34,200 okay that should do it so we now should 18821 10:29:34,200 --> 10:29:36,120 have a nice warning sound and over here 18822 10:29:36,120 --> 10:29:37,740 we should have a nice animation on the 18823 10:29:37,740 --> 10:29:40,080 burn warning UI so let's see both those 18824 10:29:40,080 --> 10:29:42,416 okay so let's pick up some meat and drop 18825 10:29:42,416 --> 10:29:44,700 it and right now it's cooking okay great 18826 10:29:44,700 --> 10:29:47,700 and once it gets a halfway point 18827 10:29:47,700 --> 10:29:49,860 if there go now we have a nice warning 18828 10:29:49,860 --> 10:29:52,560 sound all right awesome let's just add 18829 10:29:52,560 --> 10:29:54,960 one more tiny thing let's make the bar 18830 10:29:54,960 --> 10:29:56,936 itself also flash red when we're about 18831 10:29:56,936 --> 10:29:59,220 to burn so once again let's go inside 18832 10:29:59,220 --> 10:30:01,680 the stove counter and on the progress 18833 10:30:01,680 --> 10:30:04,916 bar UI let's add a nice animator and 18834 10:30:04,916 --> 10:30:06,540 let's go ahead and make one so let's 18835 10:30:06,540 --> 10:30:09,000 create a new animated controller for the 18836 10:30:09,000 --> 10:30:11,520 stove burn flashing bar 18837 10:30:11,520 --> 10:30:13,500 let's go ahead and assign it so it's the 18838 10:30:13,500 --> 10:30:16,020 one on the progress bar let's add the 18839 10:30:16,020 --> 10:30:18,540 stove burn flashing bar then on this one 18840 10:30:18,540 --> 10:30:20,220 let's create new animation let's go 18841 10:30:20,220 --> 10:30:21,960 inside the assets animations let's make 18842 10:30:21,960 --> 10:30:24,416 one and just call it idle for this one 18843 10:30:24,416 --> 10:30:25,860 we're going to want the exact same color 18844 10:30:25,860 --> 10:30:28,320 as the normal color so let's go into the 18845 10:30:28,320 --> 10:30:30,776 bar and set the color just save a 18846 10:30:30,776 --> 10:30:32,580 keyframe over there okay so that's what 18847 10:30:32,580 --> 10:30:34,560 we want now let's make another animation 18848 10:30:34,560 --> 10:30:36,000 so let's stop recording and let's 18849 10:30:36,000 --> 10:30:38,040 actually duplicate this one so duplicate 18850 10:30:38,040 --> 10:30:41,276 it and for this one name it flash now of 18851 10:30:41,276 --> 10:30:42,660 course we need to add it to the animated 18852 10:30:42,660 --> 10:30:44,820 controller so let's go over here and 18853 10:30:44,820 --> 10:30:46,916 drag it on top okay now for the 18854 10:30:46,916 --> 10:30:49,020 animation let's select the Flash and for 18855 10:30:49,020 --> 10:30:50,756 this one let's go ahead click on record 18856 10:30:50,756 --> 10:30:53,220 let's start off on this one and after a 18857 10:30:53,220 --> 10:30:55,500 few frames so let's say maybe after 10 18858 10:30:55,500 --> 10:30:58,500 frames let's Flash in red and after 20 18859 10:30:58,500 --> 10:31:00,360 frames let's copy paste the same frame 18860 10:31:00,360 --> 10:31:02,880 okay so that's our nice flashing bar now 18861 10:31:02,880 --> 10:31:04,140 let's just set it up so let's go into 18862 10:31:04,140 --> 10:31:05,880 the animator and over here we're going 18863 10:31:05,880 --> 10:31:07,140 to have a transition from that 18864 10:31:07,140 --> 10:31:10,140 deformation form flashback now all we 18865 10:31:10,140 --> 10:31:11,460 need of course is an animator to control 18866 10:31:11,460 --> 10:31:13,320 this so let's make a new animator 18867 10:31:13,320 --> 10:31:15,596 parameter let's make it a Boolean and 18868 10:31:15,596 --> 10:31:18,300 call it is flashing and again make sure 18869 10:31:18,300 --> 10:31:20,400 to be careful with cane sensitive 18870 10:31:20,400 --> 10:31:23,640 okay so from idle into flash let's go 18871 10:31:23,640 --> 10:31:25,560 ahead remove the exit time for the 18872 10:31:25,560 --> 10:31:27,900 duration make it instant so zero and for 18873 10:31:27,900 --> 10:31:28,980 the conditions when that one is true 18874 10:31:28,980 --> 10:31:31,620 okay great and for going back once again 18875 10:31:31,620 --> 10:31:34,020 same thing so instant and let's make the 18876 10:31:34,020 --> 10:31:36,360 condition when it's false okay that's it 18877 10:31:36,360 --> 10:31:38,640 super simple now let's make a script to 18878 10:31:38,640 --> 10:31:40,916 run this so let's go ahead create a 18879 10:31:40,916 --> 10:31:43,320 brainy sharp script for the stove burn 18880 10:31:43,320 --> 10:31:46,140 flashing bar UI let's go ahead and add 18881 10:31:46,140 --> 10:31:47,880 it to the bar so that's the flashing bar 18882 10:31:47,880 --> 10:31:50,096 UI okay over here let's do pretty much 18883 10:31:50,096 --> 10:31:51,840 the same thing that we did on the other 18884 10:31:51,840 --> 10:31:52,740 one 18885 10:31:52,740 --> 10:31:54,480 so let's go over here onto the stove 18886 10:31:54,480 --> 10:31:56,460 burn warning UI I might actually copy 18887 10:31:56,460 --> 10:31:58,680 exactly this so let's go on this one and 18888 10:31:58,680 --> 10:32:00,720 paste this one then back here in the 18889 10:32:00,720 --> 10:32:02,220 editor let's drag the reference to the 18890 10:32:02,220 --> 10:32:04,436 self counter and over here the logic is 18891 10:32:04,436 --> 10:32:06,660 going to be very very similar so the 18892 10:32:06,660 --> 10:32:08,400 only difference is we have an animator 18893 10:32:08,400 --> 10:32:11,276 so the animator and we're going to grab 18894 10:32:11,276 --> 10:32:13,256 it on private wide awake and later get 18895 10:32:13,256 --> 10:32:16,020 component of type animator 18896 10:32:16,020 --> 10:32:17,936 so we have the animator then let's 18897 10:32:17,936 --> 10:32:20,700 define the parameter so private con 18898 10:32:20,700 --> 10:32:21,900 string 18899 10:32:21,900 --> 10:32:24,416 for the is flashing 18900 10:32:24,416 --> 10:32:27,360 and let's set it is flashing okay we 18901 10:32:27,360 --> 10:32:29,520 have our parameter and now down here 18902 10:32:29,520 --> 10:32:31,560 instead of showing and hiding we'll just 18903 10:32:31,560 --> 10:32:33,360 go into the animator in order to set a 18904 10:32:33,360 --> 10:32:34,436 ball 18905 10:32:34,436 --> 10:32:37,500 and the bone will be the is flashing and 18906 10:32:37,500 --> 10:32:39,596 let's set it based on show so either we 18907 10:32:39,596 --> 10:32:41,096 show or hide and we actually don't need 18908 10:32:41,096 --> 10:32:43,436 these functions and by default of course 18909 10:32:43,436 --> 10:32:45,900 let's leave it on false okay so that's 18910 10:32:45,900 --> 10:32:48,840 it super simple Let's test just make 18911 10:32:48,840 --> 10:32:50,820 sure to save the prefab and hit on play 18912 10:32:50,820 --> 10:32:52,916 okay let's go ahead and cook so let's 18913 10:32:52,916 --> 10:32:54,596 pick it up and drop it alright so it's 18914 10:32:54,596 --> 10:32:56,700 cooking let's wait for it to be burning 18915 10:32:56,700 --> 10:32:59,580 and as soon as it gets there yeah there 18916 10:32:59,580 --> 10:33:01,256 you go we've got a nice warning a nice 18917 10:33:01,256 --> 10:33:03,540 flashing bar and a nice sound effect so 18918 10:33:03,540 --> 10:33:05,520 all three warnings making ourselves much 18919 10:33:05,520 --> 10:33:08,340 more polished alright awesome now just 18920 10:33:08,340 --> 10:33:09,900 for balancing let's play around the 18921 10:33:09,900 --> 10:33:12,540 timers so let's go into our script ball 18922 10:33:12,540 --> 10:33:14,880 objects on the frying rest BSO let's 18923 10:33:14,880 --> 10:33:17,460 make this one take five seconds 18924 10:33:17,460 --> 10:33:19,560 then on the burning recipe for this one 18925 10:33:19,560 --> 10:33:21,360 let's make it take six 18926 10:33:21,360 --> 10:33:23,276 and finally let's also add another stove 18927 10:33:23,276 --> 10:33:26,040 so let's take our self counter duplicate 18928 10:33:26,040 --> 10:33:28,380 the prefab let's put it over here so 18929 10:33:28,380 --> 10:33:29,880 rotate it to the side and let's get rid 18930 10:33:29,880 --> 10:33:32,640 of this one and put this one right in 18931 10:33:32,640 --> 10:33:36,720 there so on 7.5 0 and minus 1. all right 18932 10:33:36,720 --> 10:33:38,820 so we now have two stoves I can put one 18933 10:33:38,820 --> 10:33:41,340 cooking put another one and I can start 18934 10:33:41,340 --> 10:33:43,916 cutting down some cheese start cutting 18935 10:33:43,916 --> 10:33:45,840 and before they start to burn what's 18936 10:33:45,840 --> 10:33:47,460 actually here there you go that one is 18937 10:33:47,460 --> 10:33:48,720 about to burn so let's pick it up 18938 10:33:48,720 --> 10:33:50,460 quickly and that one is actually gonna 18939 10:33:50,460 --> 10:33:53,040 burn but I got it okay great all right 18940 10:33:53,040 --> 10:33:55,200 awesome everything's working great now 18941 10:33:55,200 --> 10:33:57,300 for one more polish element let's make a 18942 10:33:57,300 --> 10:33:59,160 nice visual when we deliver either a 18943 10:33:59,160 --> 10:34:01,436 correct or incorrect recipe I think it 18944 10:34:01,436 --> 10:34:03,180 wouldn't look good as a warm canvas on 18945 10:34:03,180 --> 10:34:04,680 top of the delivery counter so let's do 18946 10:34:04,680 --> 10:34:07,020 that let's over here find the delivery 18947 10:34:07,020 --> 10:34:09,180 counter let's go inside the prefab and 18948 10:34:09,180 --> 10:34:11,340 now in here let's create a new UI canvas 18949 10:34:11,340 --> 10:34:14,040 let's name this the delivery result UI 18950 10:34:14,040 --> 10:34:16,916 and as usual let's make this a worm 18951 10:34:16,916 --> 10:34:19,680 space canvas so put it on worst face 18952 10:34:19,680 --> 10:34:22,560 and for the position let's actually lift 18953 10:34:22,560 --> 10:34:23,880 it up and then we're going to make it 18954 10:34:23,880 --> 10:34:26,160 look at the camera but just like this it 18955 10:34:26,160 --> 10:34:27,596 might actually go inside the wall so 18956 10:34:27,596 --> 10:34:29,160 let's put it over here to the side a 18957 10:34:29,160 --> 10:34:30,776 little bit so let's put it on this 18958 10:34:30,776 --> 10:34:33,596 position so on the X of minus 1.6 on a y 18959 10:34:33,596 --> 10:34:37,380 of three and on a z of 1.2 okay that's 18960 10:34:37,380 --> 10:34:39,840 the position so right there that is 18961 10:34:39,840 --> 10:34:41,820 going to be unlocking at the camera now 18962 10:34:41,820 --> 10:34:44,756 inside let's create a new UI image it's 18963 10:34:44,756 --> 10:34:47,400 going to be our background and for the 18964 10:34:47,400 --> 10:34:48,840 size the width and height let's put it 18965 10:34:48,840 --> 10:34:51,060 on 2.2 by 0.9 18966 10:34:51,060 --> 10:34:53,340 okay that's our background for the 18967 10:34:53,340 --> 10:34:55,740 Hunger let's tinted in a nice green so 18968 10:34:55,740 --> 10:34:58,020 let's put it something like this 18969 10:34:58,020 --> 10:35:01,200 then let's also add a nice outline let's 18970 10:35:01,200 --> 10:35:04,080 put it on full Alpha and for the size 18971 10:35:04,080 --> 10:35:07,200 let's put it on 0.1.1 then let's also 18972 10:35:07,200 --> 10:35:09,596 add a nice shadow component for this one 18973 10:35:09,596 --> 10:35:12,000 leave it on half Alpha and let's put it 18974 10:35:12,000 --> 10:35:14,220 on 0.2 and minus 0.2 18975 10:35:14,220 --> 10:35:17,096 okay so that's a nice visual now on top 18976 10:35:17,096 --> 10:35:19,680 of it let's create a new UI text let's 18977 10:35:19,680 --> 10:35:22,140 call it the message text and for the 18978 10:35:22,140 --> 10:35:23,220 message we're going to say something 18979 10:35:23,220 --> 10:35:25,200 like delivery and then underneath 18980 10:35:25,200 --> 10:35:27,776 success let's put it on a width and 18981 10:35:27,776 --> 10:35:29,936 height of zero let's put it on a super 18982 10:35:29,936 --> 10:35:32,700 tiny font so let's say just 0.25 let's 18983 10:35:32,700 --> 10:35:34,860 put it in bold and put it down Center 18984 10:35:34,860 --> 10:35:37,140 and get rid of wrapping okay that's it 18985 10:35:37,140 --> 10:35:38,700 let's just push it a little bit on the 18986 10:35:38,700 --> 10:35:41,820 left side so on minus 0.32 on the X okay 18987 10:35:41,820 --> 10:35:44,520 and now next to it let's make another UI 18988 10:35:44,520 --> 10:35:46,916 image for this one call it the icon 18989 10:35:46,916 --> 10:35:49,800 image let's put it with a size of 0.5 by 18990 10:35:49,800 --> 10:35:52,200 0.5 and put it over to the right side so 18991 10:35:52,200 --> 10:35:55,080 on an X of 0.7 okay and now for these 18992 10:35:55,080 --> 10:35:56,936 Sprites including the assets are too 18993 10:35:56,936 --> 10:35:58,860 nice sprites so there's a nice cross for 18994 10:35:58,860 --> 10:36:00,660 when we get it wrong and there's a nice 18995 10:36:00,660 --> 10:36:03,000 tick okay so that's the setup that we 18996 10:36:03,000 --> 10:36:05,340 want now on the delivery result UI let's 18997 10:36:05,340 --> 10:36:06,900 go ahead add our own look at the camera 18998 10:36:06,900 --> 10:36:08,756 component and for this one let's go 18999 10:36:08,756 --> 10:36:10,320 different so instead of the camera four 19000 10:36:10,320 --> 10:36:12,180 let's go ahead with the unlock at 19001 10:36:12,180 --> 10:36:14,160 inverting so there it is this is our 19002 10:36:14,160 --> 10:36:16,320 setup now let's make the script run this 19003 10:36:16,320 --> 10:36:19,500 so let's go ahead create the new UI new 19004 10:36:19,500 --> 10:36:21,540 c-sharp script for the delivery result 19005 10:36:21,540 --> 10:36:24,776 UI let's attach the script and open okay 19006 10:36:24,776 --> 10:36:26,276 so now here on let's make serialized 19007 10:36:26,276 --> 10:36:28,740 films for our elements so a serialized 19008 10:36:28,740 --> 10:36:29,936 film 19009 10:36:29,936 --> 10:36:31,860 first of all for the background image 19010 10:36:31,860 --> 10:36:33,660 and this is actually going to be a Type 19011 10:36:33,660 --> 10:36:36,660 image image inside in the engine.ui okay 19012 10:36:36,660 --> 10:36:38,756 our background image then we're going to 19013 10:36:38,756 --> 10:36:41,096 have another one for the icon image and 19014 10:36:41,096 --> 10:36:42,480 we're going to have another one this one 19015 10:36:42,480 --> 10:36:44,580 is a text mesh Pro e GUI for the message 19016 10:36:44,580 --> 10:36:45,900 text 19017 10:36:45,900 --> 10:36:48,900 okay let's save okay so let's drag the 19018 10:36:48,900 --> 10:36:51,120 references to the background the message 19019 10:36:51,120 --> 10:36:53,936 text and the icon image okay great and 19020 10:36:53,936 --> 10:36:55,800 over here let's listen when a delivery 19021 10:36:55,800 --> 10:36:57,660 is delivered so let's make a private 19022 10:36:57,660 --> 10:37:00,540 start let's go into the delivery manager 19023 10:37:00,540 --> 10:37:03,300 the instance and we have all of our next 19024 10:37:03,300 --> 10:37:05,520 events so we've got a success and a 19025 10:37:05,520 --> 10:37:07,980 field so let's listen into both them 19026 10:37:07,980 --> 10:37:10,200 so both the success and on the recipe 19027 10:37:10,200 --> 10:37:13,020 failed let's listen to all these and as 19028 10:37:13,020 --> 10:37:14,756 always let's write good point code and 19029 10:37:14,756 --> 10:37:17,160 rename this so the delivery manager on 19030 10:37:17,160 --> 10:37:19,916 recipe success and for this one is the 19031 10:37:19,916 --> 10:37:22,560 on recipe failed 19032 10:37:22,560 --> 10:37:25,436 okay we have both of our events 19033 10:37:25,436 --> 10:37:27,000 so over here it's actually going to be 19034 10:37:27,000 --> 10:37:28,916 very simple we just want to play around 19035 10:37:28,916 --> 10:37:30,776 the text the icon and the background 19036 10:37:30,776 --> 10:37:33,300 color so for example when we fail let's 19037 10:37:33,300 --> 10:37:34,256 go 19038 10:37:34,256 --> 10:37:36,360 and we want to set the background image 19039 10:37:36,360 --> 10:37:38,276 to about a red so for defining the 19040 10:37:38,276 --> 10:37:40,380 column let's actually go here and Define 19041 10:37:40,380 --> 10:37:44,096 a color for the success color and we're 19042 10:37:44,096 --> 10:37:46,020 going to have another one for the failed 19043 10:37:46,020 --> 10:37:47,040 color 19044 10:37:47,040 --> 10:37:48,960 and then for the Sprites let's also have 19045 10:37:48,960 --> 10:37:51,240 that so Sprite for the success Sprite 19046 10:37:51,240 --> 10:37:54,240 and another one for the failed Sprite 19047 10:37:54,240 --> 10:37:56,640 okay those are on the elements so we're 19048 10:37:56,640 --> 10:37:58,020 here in the editor let's just set them 19049 10:37:58,020 --> 10:37:59,640 so for the success column let's actually 19050 10:37:59,640 --> 10:38:01,916 use the exact same color by the way 19051 10:38:01,916 --> 10:38:04,020 here's a quick tip if you go up to film 19052 10:38:04,020 --> 10:38:05,340 for example like this one on the color 19053 10:38:05,340 --> 10:38:08,040 you can right click and copy and then go 19054 10:38:08,040 --> 10:38:09,596 into delivery results and over here 19055 10:38:09,596 --> 10:38:11,220 right click and paste there go the 19056 10:38:11,220 --> 10:38:13,320 perfect color then for the final color 19057 10:38:13,320 --> 10:38:15,660 let's go with the red maybe a bit darker 19058 10:38:15,660 --> 10:38:17,460 and also importantly make sure you set 19059 10:38:17,460 --> 10:38:19,800 the alpha to phone okay so we have a red 19060 10:38:19,800 --> 10:38:22,380 nice and like that okay then the success 19061 10:38:22,380 --> 10:38:24,060 Sprite this one is going to be the tech 19062 10:38:24,060 --> 10:38:26,220 and for the fail this is going to be the 19063 10:38:26,220 --> 10:38:28,620 cross okay those are all of our elements 19064 10:38:28,620 --> 10:38:30,900 so over here when we fail let's go into 19065 10:38:30,900 --> 10:38:32,880 the background image and set the color 19066 10:38:32,880 --> 10:38:36,000 and let's put the fan color then for the 19067 10:38:36,000 --> 10:38:37,980 icon image let's set the Sprite to the 19068 10:38:37,980 --> 10:38:39,660 Fey on Sprite 19069 10:38:39,660 --> 10:38:42,720 and for the message text let's set this 19070 10:38:42,720 --> 10:38:46,680 one for delivery and then failed 19071 10:38:46,680 --> 10:38:48,660 by the way this backward slash n this 19072 10:38:48,660 --> 10:38:50,096 means a new line so we're going to let 19073 10:38:50,096 --> 10:38:51,960 you set the text on this one so it 19074 10:38:51,960 --> 10:38:53,160 essentially means that it won't write 19075 10:38:53,160 --> 10:38:55,256 delivery then new line and then failed 19076 10:38:55,256 --> 10:38:57,300 underneath just make sure you're using 19077 10:38:57,300 --> 10:38:58,860 the Packer slash and not the forward 19078 10:38:58,860 --> 10:39:01,140 slash so use the backwards one there you 19079 10:39:01,140 --> 10:39:03,060 go there's a new line okay so that's the 19080 10:39:03,060 --> 10:39:04,800 on recipe film and now on the recipe 19081 10:39:04,800 --> 10:39:07,740 success let's use the success color the 19082 10:39:07,740 --> 10:39:10,320 success Sprite and over here the 19083 10:39:10,320 --> 10:39:12,960 delivery success okay so that's great 19084 10:39:12,960 --> 10:39:15,000 that should be working now just one more 19085 10:39:15,000 --> 10:39:17,520 visual thing let's add a nice animation 19086 10:39:17,520 --> 10:39:19,980 so just like we did previously let's go 19087 10:39:19,980 --> 10:39:21,660 over here over here and let's add an 19088 10:39:21,660 --> 10:39:23,460 animator component 19089 10:39:23,460 --> 10:39:25,320 let's create an animation for this one 19090 10:39:25,320 --> 10:39:27,360 for delivery result UI so let's go up 19091 10:39:27,360 --> 10:39:29,340 here create a brand new animated 19092 10:39:29,340 --> 10:39:31,500 controller for this and let's go ahead 19093 10:39:31,500 --> 10:39:34,256 and assign it so delivery result UI all 19094 10:39:34,256 --> 10:39:36,416 right now let's make an animation so 19095 10:39:36,416 --> 10:39:38,400 this delivery result UI let's call it 19096 10:39:38,400 --> 10:39:40,380 just pop-up and for this one let's do 19097 10:39:40,380 --> 10:39:42,360 just like we did for numbers so let's 19098 10:39:42,360 --> 10:39:45,120 scale and rotate it however if we rotate 19099 10:39:45,120 --> 10:39:47,160 that's actually not going to work that 19100 10:39:47,160 --> 10:39:48,540 is because we have the unlocked camera 19101 10:39:48,540 --> 10:39:49,740 and this one is already going to be 19102 10:39:49,740 --> 10:39:52,080 setting the rotation so we would end up 19103 10:39:52,080 --> 10:39:53,520 with this script finding the animator 19104 10:39:53,520 --> 10:39:55,680 for the rotation so that would mess 19105 10:39:55,680 --> 10:39:57,776 things up however one nice and simple 19106 10:39:57,776 --> 10:39:59,220 solution to this 19107 10:39:59,220 --> 10:40:00,776 basically we just put this inside 19108 10:40:00,776 --> 10:40:03,180 another game object so let's create a 19109 10:40:03,180 --> 10:40:04,800 new game object and let's put it inside 19110 10:40:04,800 --> 10:40:06,840 what's an empty game object for the 19111 10:40:06,840 --> 10:40:08,936 delivery result rewind then look at the 19112 10:40:08,936 --> 10:40:09,900 camera 19113 10:40:09,900 --> 10:40:11,880 so we have this one now the reason why I 19114 10:40:11,880 --> 10:40:13,860 created it inside is that so over here 19115 10:40:13,860 --> 10:40:16,140 we can set everything to zero and now 19116 10:40:16,140 --> 10:40:18,060 with that one on zero we can go ahead 19117 10:40:18,060 --> 10:40:20,220 and drag this outside of this object and 19118 10:40:20,220 --> 10:40:21,596 there you go that one keeps the exact 19119 10:40:21,596 --> 10:40:23,756 same settings and on this one we can add 19120 10:40:23,756 --> 10:40:25,916 the unlocked camera component and set it 19121 10:40:25,916 --> 10:40:27,300 up just like we had so then we'll look 19122 10:40:27,300 --> 10:40:29,580 at inverting and on this one we're going 19123 10:40:29,580 --> 10:40:31,140 to make a channel live down and there 19124 10:40:31,140 --> 10:40:32,756 you go now everything is on zero exactly 19125 10:40:32,756 --> 10:40:34,560 as it should be and on this one we can 19126 10:40:34,560 --> 10:40:36,480 get rid of the unlocked camera and now 19127 10:40:36,480 --> 10:40:38,040 we can indeed play around the rotation 19128 10:40:38,040 --> 10:40:39,776 so for the animation let's just go ahead 19129 10:40:39,776 --> 10:40:42,060 and set it so for this one let's go up 19130 10:40:42,060 --> 10:40:43,380 to one second 19131 10:40:43,380 --> 10:40:45,840 and let's record a keyframe on a scale 19132 10:40:45,840 --> 10:40:49,200 of one and on a rotation of zero then 19133 10:40:49,200 --> 10:40:51,300 let's go back into the beginning and for 19134 10:40:51,300 --> 10:40:53,700 this one let's scale it backwards so 19135 10:40:53,700 --> 10:40:56,160 maybe something like this maybe a 15 19136 10:40:56,160 --> 10:40:58,500 let's put it quite a bit smaller then 19137 10:40:58,500 --> 10:41:00,776 let's go up by three frames let's put 19138 10:41:00,776 --> 10:41:02,880 that one on -15 so rotation on the other 19139 10:41:02,880 --> 10:41:05,700 side and put it quite a bit bigger and 19140 10:41:05,700 --> 10:41:09,360 then on frame 10 put it on say 1.1 19141 10:41:09,360 --> 10:41:11,756 with a rotation of zero just like that 19142 10:41:11,756 --> 10:41:13,860 so there you go there's a nice pop-up 19143 10:41:13,860 --> 10:41:16,740 and for the alpha let's also go over 19144 10:41:16,740 --> 10:41:19,500 here into the 50 and let's just add the 19145 10:41:19,500 --> 10:41:21,720 canvas group let's set this one over 19146 10:41:21,720 --> 10:41:24,120 here is on one and then we scroll it 19147 10:41:24,120 --> 10:41:26,400 down to zero okay so that's our nice 19148 10:41:26,400 --> 10:41:29,160 animation let's stop recording let's 19149 10:41:29,160 --> 10:41:31,140 open up the animated controller and over 19150 10:41:31,140 --> 10:41:33,360 here let's make our nice animations 19151 10:41:33,360 --> 10:41:35,700 transition so transition from any state 19152 10:41:35,700 --> 10:41:37,740 into that one let's make it based on a 19153 10:41:37,740 --> 10:41:40,200 trigger let's call it just pop-up 19154 10:41:40,200 --> 10:41:43,020 and for this one this says no exit time 19155 10:41:43,020 --> 10:41:46,080 duration of zero and let's go when the 19156 10:41:46,080 --> 10:41:47,936 condition when we have this trigger okay 19157 10:41:47,936 --> 10:41:49,800 so that's it although one thing by 19158 10:41:49,800 --> 10:41:51,480 default this animation is going to Loop 19159 10:41:51,480 --> 10:41:53,700 so let's just go ahead we can select the 19160 10:41:53,700 --> 10:41:55,800 animation and over here let's just 19161 10:41:55,800 --> 10:41:57,480 untick Loop time so that way the 19162 10:41:57,480 --> 10:41:59,640 animation will not Loop okay so that's 19163 10:41:59,640 --> 10:42:01,560 great now let's go into the script and 19164 10:42:01,560 --> 10:42:03,360 over here let's get our animator so 19165 10:42:03,360 --> 10:42:06,200 private animator animator 19166 10:42:06,200 --> 10:42:08,460 let's get the animator just get 19167 10:42:08,460 --> 10:42:11,720 component of type animator 19168 10:42:12,960 --> 10:42:15,300 and let's define over here the private 19169 10:42:15,300 --> 10:42:19,400 constring for the pop-up 19170 10:42:22,560 --> 10:42:24,480 so we have this and then when we have 19171 10:42:24,480 --> 10:42:26,820 either fail or success let's just go 19172 10:42:26,820 --> 10:42:28,740 into the animator 19173 10:42:28,740 --> 10:42:31,380 and let's set the trigger for our pop-up 19174 10:42:31,380 --> 10:42:34,436 both up here and over here now we just 19175 10:42:34,436 --> 10:42:36,120 have obviously one issue which is that 19176 10:42:36,120 --> 10:42:37,800 it starts off as visible we don't want 19177 10:42:37,800 --> 10:42:40,080 that so over here we can just do game 19178 10:42:40,080 --> 10:42:42,360 objects set active into false in order 19179 10:42:42,360 --> 10:42:44,276 to hide it and when we get either of 19180 10:42:44,276 --> 10:42:46,860 these let's set it both to true 19181 10:42:46,860 --> 10:42:48,900 then afterwards the animation won't make 19182 10:42:48,900 --> 10:42:50,580 it invisible so it will still be active 19183 10:42:50,580 --> 10:42:52,140 but it won't be invisible so that's fine 19184 10:42:52,140 --> 10:42:53,880 so just with this everything should be 19185 10:42:53,880 --> 10:42:55,916 working as we want so let's test let's 19186 10:42:55,916 --> 10:42:57,480 just make sure to save it and go back 19187 10:42:57,480 --> 10:42:59,756 okay so here we are let's try delivering 19188 10:42:59,756 --> 10:43:01,380 an incorrect plate and there you go 19189 10:43:01,380 --> 10:43:03,360 Gotta delivery film okay great now let's 19190 10:43:03,360 --> 10:43:05,460 try delivering a correct one so someone 19191 10:43:05,460 --> 10:43:07,740 wants a cheeseburger so let's cook it 19192 10:43:07,740 --> 10:43:10,800 slice some cheese let's get some bread 19193 10:43:10,800 --> 10:43:13,020 so bread cheese and pick up the burger 19194 10:43:13,020 --> 10:43:14,936 and deliver and there you go a nice 19195 10:43:14,936 --> 10:43:17,520 delivery success all right awesome 19196 10:43:17,520 --> 10:43:19,740 okay so with these handphone changes you 19197 10:43:19,740 --> 10:43:21,240 can already see how we made quite a big 19198 10:43:21,240 --> 10:43:23,040 difference in our game we didn't do 19199 10:43:23,040 --> 10:43:25,140 anything to change any core mechanics we 19200 10:43:25,140 --> 10:43:26,880 just made what was already there pop out 19201 10:43:26,880 --> 10:43:29,096 we added a nice visual boundary to make 19202 10:43:29,096 --> 10:43:31,320 the map look nice we added some nice 19203 10:43:31,320 --> 10:43:32,756 particles when the character is moving 19204 10:43:32,756 --> 10:43:34,740 then we added a nice tutorial and 19205 10:43:34,740 --> 10:43:36,900 controls right as the game starts we 19206 10:43:36,900 --> 10:43:38,340 also added a bunch of effects on the 19207 10:43:38,340 --> 10:43:40,256 stove so it flashes has a warning and 19208 10:43:40,256 --> 10:43:42,480 some sound and lastly we also added a 19209 10:43:42,480 --> 10:43:44,276 nice pop-up when delivery is delivered 19210 10:43:44,276 --> 10:43:46,500 whether correctly or incorrectly 19211 10:43:46,500 --> 10:43:47,936 now of course we can always keep 19212 10:43:47,936 --> 10:43:49,080 publishing the game until Infinity 19213 10:43:49,080 --> 10:43:51,240 there's always more small things you can 19214 10:43:51,240 --> 10:43:52,800 add to punish the game just a little bit 19215 10:43:52,800 --> 10:43:54,776 more but at this point I'm very happy 19216 10:43:54,776 --> 10:43:56,640 with what the game looks like so after 19217 10:43:56,640 --> 10:43:58,020 all this work let's go into the next 19218 10:43:58,020 --> 10:43:59,460 lecture where we're going to play our 19219 10:43:59,460 --> 10:44:00,960 game from start to finish and see what 19220 10:44:00,960 --> 10:44:02,520 we've done 19221 10:44:02,520 --> 10:44:05,460 hello and welcome I'm your kudmaki in 19222 10:44:05,460 --> 10:44:06,900 this lecture we're going to look at all 19223 10:44:06,900 --> 10:44:08,580 the work that we've done and have some 19224 10:44:08,580 --> 10:44:11,160 fun playing the final game okay so here 19225 10:44:11,160 --> 10:44:13,020 we are in our nice starting main menu 19226 10:44:13,020 --> 10:44:14,880 it's simple but it works I actually 19227 10:44:14,880 --> 10:44:16,980 thinking looks pretty good so we have 19228 10:44:16,980 --> 10:44:18,720 our main menu working and we also have 19229 10:44:18,720 --> 10:44:20,700 the unloading system that we made so as 19230 10:44:20,700 --> 10:44:22,140 soon as I click on Play There You Go 19231 10:44:22,140 --> 10:44:23,880 loads in loading scene and here we are 19232 10:44:23,880 --> 10:44:25,680 on the game scene so we start off with 19233 10:44:25,680 --> 10:44:27,720 our really nice tutorial window and down 19234 10:44:27,720 --> 10:44:29,400 here we have the controls of course some 19235 10:44:29,400 --> 10:44:31,200 of these are dynamics so depending on if 19236 10:44:31,200 --> 10:44:32,936 the player rebinds or something this one 19237 10:44:32,936 --> 10:44:34,916 is going to update so we can look at 19238 10:44:34,916 --> 10:44:36,416 this window for as long as we want the 19239 10:44:36,416 --> 10:44:38,160 game is paused in the background so it's 19240 10:44:38,160 --> 10:44:39,776 on a paused game state 19241 10:44:39,776 --> 10:44:42,540 then whenever ready we can interact 19242 10:44:42,540 --> 10:44:44,400 so again that's the game input class 19243 10:44:44,400 --> 10:44:46,436 listening to the input and again all of 19244 10:44:46,436 --> 10:44:47,820 the code in here is really nice and 19245 10:44:47,820 --> 10:44:50,640 clean so when we press enter key the 19246 10:44:50,640 --> 10:44:52,200 tutorial isn't directly listening to 19247 10:44:52,200 --> 10:44:54,000 that but rather the general kitchen game 19248 10:44:54,000 --> 10:44:55,980 manager that main State machine is the 19249 10:44:55,980 --> 10:44:57,416 one listening to the input and this one 19250 10:44:57,416 --> 10:44:58,980 is listening to that state 19251 10:44:58,980 --> 10:45:01,980 so our logic is very well organized all 19252 10:45:01,980 --> 10:45:03,540 of the elements only listen to the 19253 10:45:03,540 --> 10:45:05,096 things that make sense to them so 19254 10:45:05,096 --> 10:45:06,660 anyways here we have tutorial let's 19255 10:45:06,660 --> 10:45:08,220 interact and there you go we've got our 19256 10:45:08,220 --> 10:45:10,140 nice game start countdown some really 19257 10:45:10,140 --> 10:45:12,000 nice animation really nice sound and yep 19258 10:45:12,000 --> 10:45:14,096 here we are then we've got our clock 19259 10:45:14,096 --> 10:45:15,900 showing the game time and on the left 19260 10:45:15,900 --> 10:45:18,180 side we can see our recipes once again 19261 10:45:18,180 --> 10:45:19,916 all of the elements they're all Dynamic 19262 10:45:19,916 --> 10:45:22,560 they're all spawn randomly and the icons 19263 10:45:22,560 --> 10:45:24,900 for all of the recipes they're also all 19264 10:45:24,900 --> 10:45:26,820 Dynamic so over here we have the 19265 10:45:26,820 --> 10:45:28,560 character control that we built we have 19266 10:45:28,560 --> 10:45:30,416 the collisions that we implemented and 19267 10:45:30,416 --> 10:45:32,276 of course we have the raycast testing 19268 10:45:32,276 --> 10:45:33,960 for interaction so we can identify all 19269 10:45:33,960 --> 10:45:35,340 the objects in front 19270 10:45:35,340 --> 10:45:37,320 let's begin delivering some recipes so 19271 10:45:37,320 --> 10:45:39,240 for example we need to cook some meat so 19272 10:45:39,240 --> 10:45:40,860 let's go ahead put it on the stove so 19273 10:45:40,860 --> 10:45:42,240 here is the really nice tape machine 19274 10:45:42,240 --> 10:45:44,400 that we built so we've got all the 19275 10:45:44,400 --> 10:45:45,776 various States we've got the visual 19276 10:45:45,776 --> 10:45:47,276 completely separated from the logic so 19277 10:45:47,276 --> 10:45:48,900 everything is really nice and of course 19278 10:45:48,900 --> 10:45:50,700 here we have the nice burning elements 19279 10:45:50,700 --> 10:45:52,800 that we added in the Polish lecture so 19280 10:45:52,800 --> 10:45:54,240 that one is burned so let's go ahead and 19281 10:45:54,240 --> 10:45:56,276 use the trash bin to get rid of that 19282 10:45:56,276 --> 10:45:58,500 so let's go ahead cook another one and 19283 10:45:58,500 --> 10:46:00,000 let's make a cheeseburger so let's put 19284 10:46:00,000 --> 10:46:01,620 some cheese let's listen to the aunt 19285 10:46:01,620 --> 10:46:03,416 interaction key and we can slice the 19286 10:46:03,416 --> 10:46:05,756 cheese we can pick up the meat pick up 19287 10:46:05,756 --> 10:46:07,740 the cheese then also pick up some bread 19288 10:46:07,740 --> 10:46:09,720 and deliver the recipe and there you go 19289 10:46:09,720 --> 10:46:12,120 our nice polish visual all right awesome 19290 10:46:12,120 --> 10:46:13,740 so here you can already see everything 19291 10:46:13,740 --> 10:46:15,840 that we've built the character the 19292 10:46:15,840 --> 10:46:17,820 physics the logic the input all of the 19293 10:46:17,820 --> 10:46:19,860 UI elements all of the worm UI elements 19294 10:46:19,860 --> 10:46:21,776 of the various counters and how they are 19295 10:46:21,776 --> 10:46:24,360 on prefab variants of the plates the 19296 10:46:24,360 --> 10:46:26,160 separation between the visuals and logic 19297 10:46:26,160 --> 10:46:28,740 separation between the sounds and logic 19298 10:46:28,740 --> 10:46:30,900 of the Polish elements that we made over 19299 10:46:30,900 --> 10:46:32,640 there the nice shadow graph that we made 19300 10:46:32,640 --> 10:46:34,500 then of course some of the basic things 19301 10:46:34,500 --> 10:46:35,880 that a lot of tutorials won't teach you 19302 10:46:35,880 --> 10:46:37,256 like for example how to make a pause 19303 10:46:37,256 --> 10:46:39,060 menu how to make the options 19304 10:46:39,060 --> 10:46:41,096 how to modify the Sound and Music Volume 19305 10:46:41,096 --> 10:46:43,436 how to rebind the Keys and so on 19306 10:46:43,436 --> 10:46:44,880 so with all that here throughout this 19307 10:46:44,880 --> 10:46:46,256 course we'll learn how to make a really 19308 10:46:46,256 --> 10:46:48,000 nice game with lots of interesting 19309 10:46:48,000 --> 10:46:49,860 interactions which you can now apply to 19310 10:46:49,860 --> 10:46:51,480 any kind of game any kind of genre you 19311 10:46:51,480 --> 10:46:53,276 want so like I mentioned in the very 19312 10:46:53,276 --> 10:46:54,360 beginning 19313 10:46:54,360 --> 10:46:55,980 you can take pretty much what we've made 19314 10:46:55,980 --> 10:46:57,596 here which is really just a character 19315 10:46:57,596 --> 10:46:59,276 controller and a bunch of interesting 19316 10:46:59,276 --> 10:47:00,960 interactions you can take everything 19317 10:47:00,960 --> 10:47:02,400 that you've learned here and make 19318 10:47:02,400 --> 10:47:04,380 something on a Sci-Fi space like for 19319 10:47:04,380 --> 10:47:06,180 example make something like Among Us you 19320 10:47:06,180 --> 10:47:08,340 can make something like FTL or perhaps 19321 10:47:08,340 --> 10:47:10,740 make some kind of survival crafting game 19322 10:47:10,740 --> 10:47:12,416 some of the interactions you would have 19323 10:47:12,416 --> 10:47:14,340 like resource nodes in the world then 19324 10:47:14,340 --> 10:47:15,596 you can interact together those 19325 10:47:15,596 --> 10:47:17,520 resources so with that you could build 19326 10:47:17,520 --> 10:47:19,500 something like rust or Minecraft or 19327 10:47:19,500 --> 10:47:21,596 Don't Starve so hopefully in this course 19328 10:47:21,596 --> 10:47:22,916 you'll learn a ton that you can now 19329 10:47:22,916 --> 10:47:24,300 apply to your own custom original 19330 10:47:24,300 --> 10:47:26,220 projects and if you've made it this far 19331 10:47:26,220 --> 10:47:28,256 then congratulations let's go into the 19332 10:47:28,256 --> 10:47:29,756 next lecture where I'll give you my 19333 10:47:29,756 --> 10:47:31,380 closing thoughts 19334 10:47:31,380 --> 10:47:33,300 hello and welcome I'm your code monkey 19335 10:47:33,300 --> 10:47:35,640 and congratulations you have completed 19336 10:47:35,640 --> 10:47:38,340 this course awesome seriously congrats 19337 10:47:38,340 --> 10:47:40,560 looking at the stats on my courses very 19338 10:47:40,560 --> 10:47:42,180 few people stick with it until the very 19339 10:47:42,180 --> 10:47:44,040 end so if you're hearing this then 19340 10:47:44,040 --> 10:47:45,660 that's excellent you're on the top 10 19341 10:47:45,660 --> 10:47:47,756 percent it means you are serious about 19342 10:47:47,756 --> 10:47:49,320 learning game development and I 19343 10:47:49,320 --> 10:47:50,640 generally hope this course has helped 19344 10:47:50,640 --> 10:47:51,900 you on your own Game Dev Journey 19345 10:47:51,900 --> 10:47:53,580 throughout this course you'll learn 19346 10:47:53,580 --> 10:47:55,860 about the basics of unity and c-sharp 19347 10:47:55,860 --> 10:47:57,120 you'll learn how to make a character 19348 10:47:57,120 --> 10:47:59,160 controller how to do a physics raycast 19349 10:47:59,160 --> 10:48:00,540 and use that for both Collision 19350 10:48:00,540 --> 10:48:02,580 detection and identifying objects to 19351 10:48:02,580 --> 10:48:04,860 interact with you'll learn about c-sharp 19352 10:48:04,860 --> 10:48:06,596 interface and events two extremely 19353 10:48:06,596 --> 10:48:08,936 useful c-sharp features you'll learn 19354 10:48:08,936 --> 10:48:10,800 about script mode objects how to use the 19355 10:48:10,800 --> 10:48:12,720 new input system should graph and tons 19356 10:48:12,720 --> 10:48:14,880 tons more and the most important thing 19357 10:48:14,880 --> 10:48:16,320 of all you'll learn how to build a 19358 10:48:16,320 --> 10:48:18,180 relatively complex game while writing 19359 10:48:18,180 --> 10:48:20,700 good clean code I really hope that's the 19360 10:48:20,700 --> 10:48:22,020 main takeaway you'll learn from this 19361 10:48:22,020 --> 10:48:24,300 course learning how to write better high 19362 10:48:24,300 --> 10:48:26,340 quality code learning how to refactor 19363 10:48:26,340 --> 10:48:28,020 how to keep the visuals and logic 19364 10:48:28,020 --> 10:48:29,700 separate keep the UI the couple from 19365 10:48:29,700 --> 10:48:31,800 logic learning all those things has now 19366 10:48:31,800 --> 10:48:33,540 made you a 10 times better developer 19367 10:48:33,540 --> 10:48:34,916 than when you started 19368 10:48:34,916 --> 10:48:36,720 so I really hope you enjoyed learning 19369 10:48:36,720 --> 10:48:38,276 all that let me know in the comments 19370 10:48:38,276 --> 10:48:39,660 what was the most important thing you'll 19371 10:48:39,660 --> 10:48:41,340 learn throughout this course I really 19372 10:48:41,340 --> 10:48:43,140 hope this was very fun and very 19373 10:48:43,140 --> 10:48:45,240 educational if you enjoyed my teaching 19374 10:48:45,240 --> 10:48:47,096 style check out my other courses I 19375 10:48:47,096 --> 10:48:48,480 really think the turn-based strategy 19376 10:48:48,480 --> 10:48:49,916 course would be excellent for you right 19377 10:48:49,916 --> 10:48:52,200 now it Dives even deeper into some 19378 10:48:52,200 --> 10:48:53,880 Advanced topics and since you've watched 19379 10:48:53,880 --> 10:48:55,620 this entire course all the way you now 19380 10:48:55,620 --> 10:48:57,000 have all the knowledge needed to follow 19381 10:48:57,000 --> 10:48:58,740 that course it will help you really 19382 10:48:58,740 --> 10:49:00,360 simply the final knowledge you gained 19383 10:49:00,360 --> 10:49:02,276 especially everything related to writing 19384 10:49:02,276 --> 10:49:04,380 good high quality clean code and since 19385 10:49:04,380 --> 10:49:06,480 you use Unity check out my ultimate DND 19386 10:49:06,480 --> 10:49:08,640 overview course it covers lots of tools 19387 10:49:08,640 --> 10:49:10,140 and features of the engine so you can 19388 10:49:10,140 --> 10:49:11,580 really use all the tones at your 19389 10:49:11,580 --> 10:49:13,320 disposal to make any game you can think 19390 10:49:13,320 --> 10:49:15,776 of alternatively if you like visual 19391 10:49:15,776 --> 10:49:17,936 scripting I have course on that or learn 19392 10:49:17,936 --> 10:49:19,380 how to make a really nice Builder 19393 10:49:19,380 --> 10:49:21,120 Defender game and definitely make sure 19394 10:49:21,120 --> 10:49:22,916 that you wishlist my upcoming steam game 19395 10:49:22,916 --> 10:49:25,256 total one Liberation I won't be posting 19396 10:49:25,256 --> 10:49:27,120 devlogs and in those you will see how 19397 10:49:27,120 --> 10:49:28,740 the code that I use in my own steam game 19398 10:49:28,740 --> 10:49:30,840 is on the same level of quality as what 19399 10:49:30,840 --> 10:49:32,820 you learned in this course okay so 19400 10:49:32,820 --> 10:49:34,740 that's it for me this course was a ton 19401 10:49:34,740 --> 10:49:36,360 of work so I generally hope it helped 19402 10:49:36,360 --> 10:49:38,520 you a ton on your gamedev journey thank 19403 10:49:38,520 --> 10:49:40,080 you so much for watching and I'll see 19404 10:49:40,080 --> 10:49:42,500 you next time 1417956

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