Unity Game Tutorial: Whack A Mole 3D | Octo Man | Skillshare

Unity Game Tutorial: Whack A Mole 3D

Octo Man, Let's make your dream game a reality!!

Unity Game Tutorial: Whack A Mole 3D

Octo Man, Let's make your dream game a reality!!

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
37 Lessons (4h 23m)
    • 1. #0 Intro Whack a Mole

    • 2. #1 Import&SetMoleAnimations

    • 3. #2 AnimatorController

    • 4. #3 Snapping&Prefabs

    • 5. #4 Ground&Camera

    • 6. #5 ComeDownAnimation

    • 7. #6 Spawning Moles

    • 8. #7 Destroy Moles

    • 9. #8 Prepare Collision Detection

    • 10. #9 Handling Colliders

    • 11. #10 Hitting Moles

    • 12. #11 Destroy Moles On Trigger Hit

    • 13. #12 Quick Recap

    • 14. #13 Hit Points

    • 15. #14 Avoid Double Spawn

    • 16. #15 Score Manager

    • 17. #16 UI Manager

    • 18. #17 Play Timer

    • 19. #18 Win & Lose Check

    • 20. #19 Optimize Show Score

    • 21. #20 Level Up System

    • 22. #21 More Moles

    • 23. #22 Spawn Rarity

    • 24. #23 More Mole Score

    • 25. #24 Popup Text Animation

    • 26. #25 Popup Text Coding

    • 27. #26 Score Fix & Countdown1

    • 28. #27 Countdown2

    • 29. #28 Particle Effect

    • 30. #29 Instantiate Particles

    • 31. #30 Game Over & ScoreHolder

    • 32. #31 Reset Score

    • 33. #32 Blinking Text

    • 34. #33 Main Scene

    • 35. #34 Clean Up

    • 36. #35 Conclusion & Ideas

    • 37. #36 Extra Spawn Holes

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

In this Unity Video Course i will teach you how to create Whack A Mole 3D Game using the Unity Game Engine. You can later on upload to final Game to a website, build an app from it or even put on Steam if they let you ;).

The course topics are the following:


  • we are using Inkscape which is free to create:

  • Texture Sheet for the Particles

  • Texture Sheet for Countdown Grafics


  • You will learn to create the complete process in Unity and setup everything needed

  • You learn how to import and setup the provided Mole 3D Models as well as the Hole

  • We use the Canvas System for Grafics or Score later which requires Unity 4.6+

  • We go over Raycasting, Countdown System, Timer, Score Popups


  • We will put in functionality with scripts using Monodevelop and C# (you can also use Visual Studio)

  • We will create code for all funtionalitys for all systems as for timer, spawning moles etc.

It's time to Whack some Moles ;)

Level: Beginnner
Video Course Length: ~4hours
Unity Version required: 5.3+

Meet Your Teacher

Teacher Profile Image

Octo Man

Let's make your dream game a reality!!


Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Your creative journey starts here.

  • Unlimited access to every class
  • Supportive online creative community
  • Learn offline with Skillshare’s app

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.



1. #0 Intro Whack a Mole: Welcome to my welcome all introduction video. In this video serious, you will learn how to use buttons. We will learn how to create account on system as well as a score and the timer system. We will create all of these moles also, with all these particle facts going on wherever we are hitting them. Also, we're gonna create those floating scores and negative numbers as well. Like when we're hitting red moles, there will also be a golden more. We will also talk about rarity like how rare a specific mold can be like we gonna create several different malls like one also was a blue hat like this one in here Once again, there's also going to be one where which is completely golden, which will give us a big score amount. And also, when the time is over and we are unable to fulfill the complete squad needed for this particular level, then we're gonna go to a game overseen. That means we gonna have or see what our score was, what our best level has been. There's a cold more and now we made it to the next level and also we will increment these numbers least thescore numbers. According to some formulas, we're gonna do all the calculations. Meanwhile, we are doing this course as well as we're gonna find you in some things. Yes, there were going to go over the back fixing. We're gonna go over debugging, and we'll also go over gameplay at all. In the end, I also give you some possibilities to, let's say, implement game more game play features we gonna think about what? Can we improve this one? And also once again, when we are done with this complete round, I don't go and I get more score now Or maybe just some here there. Then we are actually able toe also build this one into an AB like an android EB or anything that just needs some small changes in the game overseen. But basically, that's what we all talk about. And now I let the time run out to show you what the game overseen Looks as you can see, there's like a game over. The score will be stored as well, showing as the correct level. And when I know press space later on, can you can also implement buttons and stuff and we're gonna go back to the wack, a mole main scene and all of that, including all the three D models I use except the grass and the stones are going to be inside the course as well. So that's how you later on gonna learn how to create such a game like this. How to implement stuff. How do you make use of all this three D models and all the other things you will learn in this course since we're wanting and see you Hopefully in the course Bye bye. 2. #1 Import&SetMoleAnimations: welcome to Part One, and here we want now toe under the file I was providing in the course, which is containing three FB X Files we have to import in the Assets folder in here. I created a three D models Ford already where I can place all these models in. So I want you to unzip with any program of your liking the FB X Files, and select them and to direct them all over into the three D Morals folder there will also create automatically and materials for that. We're gonna take care off in a bit, but at the moment, I just want you to make sure that everything is important here. Let's start. Was the whole police directors into the hurricane panel on Mexican sees. There's a strange rotation happening by 90 degrees on the wrong axis. As you can see on the X axis is also this 90 degree angle access or rotation. So I want you to do it like and create is the rotation. Or make sure that the rotation is going to be set to zero. Make sure you do this year in hierarchy when you have selected this one by the way I'm using unity 5.6 so you can use that or even, I believe, 4.6 plus. And also the later versions, like two K 17 or even to Kate 18 which is already available on the unity website. Andi. Yeah, that's everything. Basically, for the whole. Now what? We want to go and take the mole. So the 1st 1 and again see, it's just a small street D model. I already animated those and made them, Let's say, usable for our game we're gonna create here. The next one is I want you to open this up in the Inspector soldiers by left, clicking it directly inside of this. What? You also need to remember that this small science here with the letters you can or was that little paper sheets you can see that these are FB X files. Well, as you can see, there's also a slider here If you don't know what's what, you can always go in and reduce or increase. The size is over here, but you don't see the Aikins at this point, so it might be helpful for you later on, since pre fabs, which we're gonna create later on s Well, don't have this paper sheet next to the Eiken. So it's up to you how you want to create those, or you want to take care of that. Okay, so what do at first want is we want to set up all the animations for the small, since there are three involved. But as you can see, since exporting just creates one take, we have to split them up a bit. So and this is also a good training for you in this case. So you can see how these clips, or actually, how we can change these clubs according to what they are. I gonna tell you all the numbers now, So the first animation is going to be the come out animation. You can use that this time slide over here directly in the bottom window. If you don't see that, it probably ever I click that or anyhow, closed it so or you have that somewhere on your screen. But we're in close it. It should be seen over here again. If you're left, click it. You can see it's reduced to zero. So make sure that you have that left click So you see that small window? Okay, So what we want to do is you want to take the lift animation and this coming out over here and this is going to take some frames. As you can see over here, there's a frame number. So our first animation goes up until frame 35. So what I want to do do it is create or actually go into the end here and type in 35. Also, we can directly rename it in here. So this is a come up animation, and that's basically it's no press on the plus over here. Somehow it doesn't change the 1st 1 so we're gonna do it again, come up. And probably it's better to directly apply the changes to that animation. And now it has renamed it. So this one now the next animation here starts from a frame 35 goes up until number 85. So frame 85 this is going to be like an idol or look around. I gonna rename this animation, look around and apply that as well. The apply button. Mexican sees a very bottom part or at the very bottom position off the complete inspector with no in here. Make sure you are in the animation step. Of course, at this point, And as you can see when you replay this one is the moles just looking around so it doesn't know what we have, what's going to happen to him next. But it doesn't matter for us anyways, since it's waiting for the hammer to come up or our finger to touch it. So we get a point and the last animation is going to be another plus over here. And the last animation is going to be a get hit animation. So I named this one, Get it? And this lasts from frame 85 to frame 100. Don't forget to apply this a swell. And when, you know, open up the mole over here inside the project folder. You can also see that these three animations are now created for us later on a kidnapping. When you're you're buying from the asset store several different ones. It can also happen that this animation are preset already for you, or they are already stored directly in the F bags. While it'll depends on how much a Ford is going to become inside and how much? Yeah, knowledge to the people have in creating these animations and exporting them. I did that because I wanted you to understand how these animations are going to come along . So and that's basically it for the mole, for the normal More. Now, what we could do is we could take all of this animations from the mole and take them into the hat mole as well. But also, we can use the same animations and later on, provide these animations with an overwrite controller, an animator override control for the head mall. We're gonna do this later on. So basically, when we know press play, nothing will go is going to happen because we don't have one of thes controllers. Set it up and that's what we're going to do in the next part. 3. #2 AnimatorController: welcome to Part two in this part we want to create the animator controller Inter animator overwrite controller and put them onto our moles So let's start with the normal more because we already started with that working on it and what we're gonna have is as like in no control are in the animator component off the mall itself. The more also contains all the gap bones and structures and all the other stuff we can I can take a look later on into as well for the moment it doesn't matter what we want to do, is we since we don't have any animator control or we have to create one And since we knew you need some animator controller or overwrite controller, as I already explained in the last video, I got to create a new folder in here by right clicking into the assets Hula emp say it is an animation fold up. We need this animation for for later Poritz or actually, for all the animator control us we gonna create. You can also see keep all of that stuff inside of this read immoral folder. But it's important that you can a structure, everything in your game as clean as possible. So we now create is an animator controller by right clicking create animator control There's any major controller is going to be just our mole controller You can you name it whatever you like and we can double click this in. This will automatically open the animator control a window with in any state and an entry. This entry is just the entry for the next animation coming in which will be connected to our first animation here Now, since we have this one already open, we can also go to the mall. Now open this one up We can drag all this re animations we created in the last video on Put them directly in here. So the first state in this particular case is going to be our come up. So as you can see now from entry, there's a connection to come up. We can now drink also, the other one's in sight, like looking around and get it get it will be played When, for example, are we gonna touch the mold with the mountains or with the finger? When you were late on creating a nap out of it for the yet for the Google Assets Store, for example, or Google play store in this case and come up is going to be just to come up animation. We gonna Yeah, create light on. There's one problem with that, probably later on, but we're gonna take care off all the animations and stuff later on anyways. So what we're gonna do is we go from, come up and we want to make a transition when this come up is done to go to the look around . So we test, say, make transition and click on look around. So when this has been played and it is done, of course, we need to make sure that it is going to work like that, that we want to make sure that it is going into the next animation. So you can also click on the transition arrow and you see these animations coming here, meaning when this is a next time and this exit time means that the animation will be displayed until the end. We're gonna do a transition from the exit into the look direction. As you can see after that, when we had done was Dad, we basically want to go back to come up. So meaning we go and make a transition back to that. The point was that has come up in here is reversed. Lee Plate, as you can see. So what we need to do is we need to create another come up, which is basically a come down. So what we can do is we Hold on, I believe shift or we just say we called me this and Paste is in here and we're gonna create a come up zero. We can double click it if we like to, But what we want to do is we want to change the speed from from one tu minus one. That means this Ah, yeah, animation will be played reverse, Lee. So instead of creating the transition to hear when look around is done, I can had the delete button to delete the transition. I want to make a transition to come up zero so meaning come down In this case, it's using the same, but the speed is going to be reversed. Let's see what this is going to look when we are on our mole. And I was seeing you or Actually, we can also check this directly in here on the transition, meaning the look around is going to happen. And now the animation plays rewards and the mole is going back as it came out like that. Pretty nice and pretty need it. So since we have done that already, we also need to implement Get hit. Get hit is basically an animation which can be done from any state. No matter if we're currently looking around or coming up, is going to be down basically or were coming out of it. But usually or probably we are unable to do it when we're transitioning to look around. But what we can do for now is we can create a transition from any state to get it, meaning no matter where we are, we should be able to play, get it, Teoh, get the hit and then everything else should go forward from wherever it has bean, for example, to look around and so on. We also may change some off these states from any point of the game or from any point in Crete, adding all off these, so it can also happen that we later on just change some transitions over here Based on some speed or on any specific para meters We don't know at the moment what I want you to do know is go to the animations Fooled again And now we create in Animator Override Controller This is the second option from this animator parts and this is going to be our head more. We can also name it a C for animator or in this case, a O C for animator overwrite Controller We can say this is going to be for our head more what this is doing It is taking any other animator controller and make use of it so we can take mall in here. What we now can do is we can take the other mole and override its current animations with these animations. Looks simple When we know press play nothing is going to happen But when we are in the mole in here we now dreck the Norma Mole Animator controller and put this year in top We should see a coming out off the mole looking around and going back inside. The same can happen also was the other head mall which don't have all the animation clip set up. So when we now put this one in here we want to achieve the same without having any problems . Let me just direct this 11 on two units to the left as well as I duplicate this whole. You don't need to. I just want to see or want to show you how this is working Now this mall, this hat mall has also an animator controller. But we want to take the AOC had more I would put this on to this more. As you can see, this head mole is now using the same animations as to use A mole is going to dio And that's what we wanted since we can now or we safe time in creating or actually avoiding in creating all off thes animations. So once again you contested out as well and you see both So using the same But the head more is just using our animator override controller Since the animations are basically the same 4. #3 Snapping&Prefabs: In the last part, we created the animator and the animator control of component, or the animator override control of for both moles or both type off moles. And we could later on also make sure that we copy and paste that. And even if later on, we're going to implement more Mawr's with different hats, for example, we can easily do this without any problem. And what I also showed you is that you can copy and a stuff around. So let's take a little get copying stuff around. When you have selected one of thes holes, you're gonna be able to duplicate them by holding down control and press deep. You can see it automatically create a new one. Now what we want to achieve is that we snapped that one unit to the right. How do I snapped that? Especially to one specific position without going always here and putting in or you're placing in full numbers? Well, that's a setting for it. It's called in added snap settings, and in here you can say how much you want to snap thes axes to, in which, actually, yeah, direction, for example. So, for example, if we are dragging something in the accent. The why or even in the Z of value are here. We can say we want to snap like half a unit. Half a unit is like one meter in the rial world. So one unit is one meter in the world knew in the real world, and you can snap to these points. Usually this is set to be 10.1, like in all axes. But we you need something like 0.5 and accidents that the sad axis is going to be the forward exercise. You can also see in this Cross X is going to be from left and right. Why is up and down since we don't need? Why at the moment or probably not later on, I gonna set this a swell like this. And I set my rotation to be 15 degrees. If we need to do rotate something. But I guess not. You can also select pieces and say you want to snap them toe all the access depending on the settings you're gonna have here. But we don't need to sense minus a snapped already. So fill in order snap settings, as I have done here Now, How do you actually snap? Snipping is used by control key as well. So hold control and dragged in one preferred axis. Whatever you want to snap there, that's nice, because you can basically create some, you know, big play field now with all snapped and without any overflows in any axes. That's how you can later on also create the Playfield was like 78 or even 100 halls air where later on we gonna create or the malls insight. So what I want to do is now I want to delete all of them since we have to do this later on anyways. But before we dio, I want to create some pre fabs out off one off. The other piece is so I just have one hole left one mole and one had mold in. My asks what I want to create a new folder called Pre Fabs. And in this pre fabs full that I want to drag all these three created or already set it up . Yeah, three D models or three D objects. So I take the whole and drag it into the prefects. Wilder. What is it? Prefab? That prefab is like a prepared or already prepared mother or a parent object which you can light on instant. She ate stuff from as a prefect, of course. And you can also apply settings to that particular one and everything. According to this mother object apparent object is going to be changed if it is the same or actually deriving from this particular game object in our Prefects folder, you can also name the full that would every like. But this is called the Prefab. So that's why I call them this Full the prefab. Also, you can see the Aiken has changed. It's not like with the three d model where a pay, but she just next to it. It is just an empty or blue cube, in this case indicating that this is a prefab. So any setting I gonna do here in this hole except four transforms I can change here like I can disable the measure, Andhra, and instantly you will see in the scene that this one is going to lose its mesh just because I disabled that inside the prefects folder meaning we later on is the enable or disable stuff. We change materials and so on all of that inside the prefects folder. It will also reflect everything into all the game objects in the scene which are related to this prefect. Let's do the same for the mole and of course, for the head more So now we have, like everything. Set it up Also, you can see the head mold, for example, still knows this has the override controller or the animator overwrite controller from the mole and the other mall already has also all the settings we have done so far. So what we can now do is we can delete all those three objects. But we still have all the information. We already said it inside these pre facts. 5. #4 Ground&Camera: Let's create a ground plane which is basically being like the playfield. Yeah, sir, Face you can later on also put thumb flowers around it in some stones and grass and whatever you please unlike which are currently not available for or inside the package. But maybe later on, I'm gonna put some or inside, if not feel free to create your own graphics. Of course, any time you'll like. So what we do is we create in use three d object in from inside the hurricane. That's going to be a plane. As you can see, this plane is not going to be a zero z resume, so we make sure we gonna put this onto zero. What? You also instantly notices that the whole we create our we are implemented when it is set to position 000 It already met just the ground. So we don't need to take care of anything else but putting some material like on or here on this plane. We can already take a material from the three D Models folder, but currently there are no brown materials involved. You can now go to the materials for the itself and you can just create a new material. We can name it brown or whatever the color is. You prefer we can change the color, of course, to any color we like. Once again, we're gonna take some brown here and we can take this and put this onto the plane. We can also say that we don't want to have any speculum highlights, so it's going to be like a dull or raise a doll ground. It depends once again, everything. How you want to have that If you don't want to have reflections? Of course, you can take care of that as well. So that's all of that about this particular material. We don't need to take care of anything. Well, at least not for the moment. And now we can also set the camera to whatever the ankle should be or whatever you please like. For example, we can take the current camera and sentences looking from the wrong direction. We're gonna have to rotate it by left. Yeah, 180 degrees on the Y axis. So that's what we're gonna do it first. So now I can see it is looking into the other direction. Well, right, now direct the camera back in here. We gotta see that these small holes are going to be in our view again. You can now decide where you want to have that more hole. For the moment. We just need that one. Later on, we might go in and create or change some carol settings. Anyways, since we want to have or want to see several more roles with holes, we want to make sure that we also ankle the camera a bit down warts. So what we can do here is like we need to rotate it over the axe excess, for example, by minus 30 or in this case, 30 degrees vice versa. If 30 is not enough, of course, you're free to go with 45 or 60 or whatever you think is going to match way again. Well, sixties too much for me. I'm gonna go. Where's 45 now What you can see I have these axis here are locally arranged. If you don't like this set up or how this is working, it can always go from local to global. So you can easily direct this camera up and down, left and right, and so on and so force according to what you are after. Maybe I don't like 35 as well, since tankers rather big or high. Maybe I'm gonna stick with that so d degrees for the moment. So when we know would press play and, of course, hit pause when our moles are in top, you can see now that we should be able to hit thes easily as well as when there's coming some behind it, we should also be able to hit them. This, of course, is stuff we're gonna take care off later on anyways, like when we are implementing everything about the collisions or colliders. 6. #5 ComeDownAnimation: Before we go forward into scripting, I want you to change a little thing. First opened the more pre FAP go to the comer animation and hit control de for duplicate. Now we can actually rename this by hitting F two on the keyboard and I renamed this one to come down. What I also want to do is or you to do is delete Come up zero from the animator window and dragon come down I will explain in a moment Why then make a transition to come down Go to come down again and make a minus one over here as before Why is that important? Since we want to put code inside animations we need the animations separate Lee here Probably it is not possible to do it directly on the same motion. That's why I just created a new animation for this since and come down We want to put code because when the mole is coming back down, we want to destroy it and that can be happen by code directly on the mole. But also we can say we're gonna do it by the intimation itself, like in an animation event. That's what I wanted to take care of, that we are able to do it later on without any problems 7. #6 Spawning Moles: let's start to create the first script, which is actually taking care off instance, creating moles and putting them off course outside because the the animation is going to do that as well as putting them back. And after a given amount of time, which we gonna do is decide, like random for the moment into. Yeah, put another one outside. And also let's choose from the two different moles, like at first from, for example, the normal mold and the head mall and randomized these as well what we're gonna do. At first, we go to the assets well done, creating youthful than name this one script off course, Open this another right click and creating you see shop script, and we can name this one whole behavior later on. We might change that, but I want you to see what we're going to do and what's going to happen in between. We also want to do is you want to put this whole behaviour script onto our whole and applied the changes to the prefab. Applying the changes to the Prefect means when, later on, we're going to do any changes again onto the Prefect directly. We're gonna put this onto all the Children or child objects which are actually deriving from that particular prefab going to have the same changes. Let's open the script up and mono develop or visual studio by just double clicking at here or there and let's see what we're gonna have and what I want. Whole needs to be around. We can put in some interesting things here for the moment we want to. You make use of starting up tight. I just get rid off the commands because we don't need those so light on. We can put in some dynamic features, which we don't put directly in the whole. Maybe, but for the moment, let's create an array. We wanted this to be a public array, off type game object, and then a raise is created by two square brackets behind it, and we call this just malls. So this is basically nothing else in the list of game objects or an array of game objects, which we can choose from. Since it is public, we're gonna have exist later on inside the inspector. Now, the next part is, by the way, you can also use list if you like to, But it doesn't matter for at the air for that, since we don't want to change the real length off the ray or anything, or even the content inside of it. So in a race more than enough for this in start, we want to create. Let me get rid of update. We don't need that anymore. At the moment we want to call a function called Spawn. We need to declare this as avoid function, since we don't return anything inside. So it's just a simple white want to hear. Do here is born. We want at first deter mine. Renda. M'lee What is the game object we want to spawn. So I create a local Inter John and I call this one just numb for number. So just a random number. And to make a trend, um, we say random door range and an open close parentheses. We can set up a many moment of maximum value. The many member he was going to be zero, since the smallest element in an array is going to be element zero comma. And now we want to have the maximum lengths off the current array at for us. We need to define the ray itself. It's malls got and Lemon can put in lengths, so the maximum things off the array is going to be the last number. If we have later on, like 20 different malls, it's automatically taking the maximum array lengths off the mold array list. The next one is we want to invoke this born after a given amount of time. So in start, we say invoke in book means we're going to call a message after a specific amount of time. So and the as you can see, it's going to be a string message, so we need to put in quotes at first. Then we name it Spawn. Make sure that it is the same name as this one, but put it in the quotes. Otherwise it doesn't work. Now. We need to define a time since we start and start over here. We might want to start after three seconds, so we put in three F or just three. Now. What we want to do is when we end spawn and we go through that's born after in way invoke has been cold in the very end. We want to invoke that once again. But in here we don't want to do this in three seconds again, because it will be just yeah, doing that the whole time, over and over and over. We want to render Mayes that as well. So we can say random. Of course, we get rid off this RIA first random dot range and always start at the smallest number, which should be around three F, which is going to be the animation. Lang's off all the frames from the animations, like going up than Idol or look around and then going down again should be somewhere around three seconds plus minus a bit. And now we want to have a maximum, for example, can use seven. So a number between seven and three is going to be taken randomly to invoke the same Sporn . Once again, this is all going to be happening every time and continuously until we stop or cancel this invoke before we actually do something else we want to Instant. She ate the choosen random game object. The more I would do that is, we define a new game object since we currently don't know if you want to do something with it. Later on, we call adjust mole or D or whatever you like. When we say equal. Still instance, Yate. And what do we want to intention is, of course, moles. So we take from the most array and in square brackets we now put in Numb. So numb is the random number week for calculated beforehand. And put this in here So the random number is the element in the list or in the ray we have chosen. If you're using lists Inter instead of a race, you can do the same method because everything is about the same. So and of course we cannot say What's the transform? Where do we want to spawn? Our more So we say Trans home that position. The transponder position is going to be taken from the hole where the script is sitting on . Don't forget, the Underline was a semi colon here, but before the semicolon and after the last parentheses, we need to say as game object, because we need to typecast this instance she ate in or actually this object into a game object. Otherwise it will be Justin object and we will get in a row. Don't forget to save the script and let's go back to unity and see what's happening. They have someone small problem in here. I guess it's just this dot Transform. Okay, So what else we want you to do is delete the mole and the hat mole from the game or from the hierarchy? So they are not present any more on the scene? Just a hole. And now what we can do is we can open this moles array and change its size to maybe two. So what we now conduce, we go to the prefects. Will that make sure this stays active? The whole states active in the hurricane or in the Inspector? And now we drank the mole in one off these slots and the head mole as well. What now is going to happen when we press start? It should create a mole after given amount of time. Oh, uh, this the transform is wrong. We need to say transform duck position, comma. And now we need to have the rotation. It's going to be quarter nian dot identity. The quarter nian is taking care of the rotation off the game object which is going to be inst Enshi ated. Since we're taking cartoonion identity, it's going to take the quarter nian off the identical prefab pot. So off the court, off the year off the prefab orientation. Don't forget to safe once again. And since we have that already here and the list, we can say who press play. And now Ammon should be instance. She ated after three seconds directly in the hole, no matter which, and it's going down. As you can see, it still stays in the hurricane, but it also creates a new mall after somewhere between three and seven seconds. And also they're coming head malls outside off this whole, just because off the coat to test things out, we can easily go and duplicate this whole this complete whole here several times to wherever we like to. We can snap it as we already talked about, and we can fill some spots just to see what's going to happen in here. Maybe like that, it doesn't matter where the camera and stuff is at the moment, since we want to change things later on anyways. But what you can see now is after three seconds, all of them going to be filled, and after that, everything will be randomized. That's not what we want. We want to probably randomized this in focus. Well, so again obsessed Double some are calling here. Gonna delete it. We want to invoke this. 1 may be randomly between three and seven seconds. A swell. So I just take this. Copy that all over into the start message. Don't forget to save the script and that's test again. So, no, you can't see after some random amounts here. And they're all this malls from different qualities, like with yellow helmets. Always no helmets are going to come out, and we should be able to hit them when they are off course in that particular Idol state, for example, or whenever we think we gonna need this, that's pretty descend, and that's what we want it. You cannot delete all the holes again, since we have understand, hopefully how prefects are working and everything else as well 8. #7 Destroy Moles: Now let's take care off the molds than when the animation has been still playing that we're gonna destroy it from the area. So we don't have a lot of moles later on. When the game is running like several, I don't know, minutes or hours. We don't want to have, like, a hundreds off moles flying around the scene, even if we don't need those. So what we're gonna do is we gonna take our mole and I will have more and want toe, apply some script to it. Let's go to this. Groups will then create one C ship script and it's just a destroy script. Later on, we probably put stuff together, but for now, let's do it like this. Destroy me. Just call it like that and open those on urban model developed once again or visual studio as whatever you prefer. And what you want to do is you want to get rid off starting update, since that is just going to have our own function. In this case, it's a public function off type void and we call it just destroy all BJ like object. And in that in curly braces, we say destroy and an open, close parentheses. We say Game object. We can also say this start game object basically doesn't matter. Copy that name off the function, since it will be important in just a moment. And we can basically get rid off the monitor develop since we don't need that anymore. Well, at least not for this part. Now what we want to do is we want to direct destroy me onto the mole prefab as well as on the hat mole prefab. Don't forget to apply the changes. And now let's go to our three d model smolder and there's that would come down animation. We created and direct this one into animation, since we need this one into the animation solder. Actually, it doesn't matter where it is, but in here we later on find it easily. Meanwhile, it is blue and selected. Go to window animation. What we have here is the animation reverse Lee running when we are going back into the earth or into the ground with the mole. So what we do is we played this one reverse not from zero frame Teoh that frame to 100 streaming. Whatever it is, it's playing reverse meaning we gonna create over here at the zero strain and animation event. What you gonna do? It's you select this smaller white arrow here, pointing down with a plus next to it at event. And this one here will appear in the animation event. Inspector, What you want to paste and function is the function name. Destroy Obi day. That's basically it. Nothing else is going to happen. We can leave the other fields blank. Let's close that. And every time the mole or the head mall will lend onto the zeros key frame off our reversed come down function or animation there will be destroyed. Let's test it out. We're gonna put them up and on D Rose frame there will be automatically destroyed now, as you can see. So this way we can make sure that when the animation play has been ended, the mole, no matter what is going to become destroyed, that means any time we don't hit the mall with our finger or the mayor mounts later on, that is not going to happen. Of course, when we later on yeah, delete this before this frame is going to happen. That's pretty important Now we can basically delete the mole and the had more once again. Now again, Once again, tested out was 100 holds or even five. If you like Teoh so you can actually test it out. Also, what you need to do later on is, of course, a the scene when you're coming back later on. So in this case, we're gonna create just a demo seen here for the moment. So everything in hell will be fine. And we're gonna have in the Essence folder now a demo scene where we can easily load up this scene every time we're going to reopen this yet this object or the scene or this project 9. #8 Prepare Collision Detection: since we wanted Teoh have some collision detection onto our moles. Meanwhile, they're coming out and stuff like that. We want to add some collision detection on it. So let's drag out our first mall in the year and go toe at component and add a capsule collider to it is sceptical. Lighter might not fit our size, as it concedes. Small, less justice fear. So what we no need to figure is how big we want this. At first, I don't want to have the radius bigger than there in a radius off this hope. So that's why I start off. So I reduce the radios to a probably point well, three or something around there. Also, this might not fit the height, since when the mall is coming out this size off, the collider is a bit too small. What I want to do now is I want to go to added mode, which is that button. Here. We can take the upper point and drag it out as much up as Renate, so it fits. Maybe the upper head area. You can be as picky as you like. You can make it a bit bigger or even smaller, depending on where and how you want the players to hit the malls. Once you're happy with the result, like when you think now it's fitting your needs were good to get. Maybe that is going to be kind. Okay can always be reduced by half a centimetre or something, and that's pretty much it also sensitive Collider. We want to make sure that we set this one, too is trigger so we can trigger that instead of using actual physical collisions. The next thing I want to add is a rigid body component, so type in our eye for rigid body. I am what we want to do. They want to de activate, use gravity. Rigid body components are important for collision detection, so you just don't you don't just need a collider for it. You also need a rigid body. So when you have that done and of course, you have to have done inside the hierarchy apply the changes to the prefect. So everything which has been bold is now just usual means it is also stored on our prefab from the more since we also have a hat more, we just go in here and copy this component by going to that gear to the cap sickle lighter and say copy component. Then we go to head more go to next year. Whichever you can even use the gear from the animator and say paste component as new. It will automatically copy all the changes Ankara and sizes and stuff we have done in the capsule called lighter already. Same for the rigid body. We can basically copy this one as well or we just creating user won't. Yeah, easily a new one. Just put in that and deactivate use gravity. So when we know press play and and ah, any off these moles are going to be created. They should have a rigid body components as well as the capsule collider. So for that mole now, when we select it and we gonna see here in the had more clone, you can see that there is the capsule collider we just created. If it is to small for you, you can always get into it and make it as big as you like. Or a small as like You can yeah, put Reese your rearranged all of that and so on. And so force 10. #9 Handling Colliders: in the last video, he created the possibility to destroy the mall. When it is going down using the animation come down since that is Ah, not just a read. Only animation like the other ones are. We also now want to take care of that. The collider object is going to be disabled for, let's say, the 1st 15 frames and in the last 15 frames going to be disabled already. So the player is not able to hit it When of course, the mole is not there or we can do with Dad is actually at first Let's go and use the mole itself. Open this redeem model mole like this one where all the animations have been sent and scroll down. Make sure that come up is going to be active in here. We also have events and as you can see, we can also add any event on the timeline off this particular animation. Come up. This is the only way to do it directly for these animations. Why is that, sir? Because once again, when you take this and say you want Teoh go to animation window, it will say here read only So we are unable to put in an animation event except we extract thes and used the abstracted animations for that. So what we can do instead is instead of using that directly on the animation, we're gonna use the possibility directly on the mole inside to come up, clip scrolling down inside the events tap before we can do anything off. Guzman need to function to disabled enable the collision objects the collider itself. Since we already created a small script inside our prefab which is taking care off the destroying, we can also use that for the moment. Maybe later on, we just once again changed things in there. At first, when this object is going to become created, we want to store the collider which is sitting on it. No matter what kind of collider, we can just name it call. And since we don't have access directly or actually we have access to it, we need to fill in data to this particular like collider. We can do this in their wake or start message. So we say, actually doesn't need to be public. So we say void Start was a big s. So since the dad is unity provided function open, close curly braces and anyway say call equal. And now we want to get the component from the game object. Which soft type call Ida Collider is a special class, which is talking toe any particular color or any collider. It can be circle at a box collider capsule collider. And since we use the capsule collider, we don't need to directly define what kind of collider were using. We just want to make sure that we have access to it to earn able and disabled by script and speaking off, unable on disabled, we say also, cold don't burn abled is equal toe false. We want to make sure that on start this collider is be disabled. Now we want to create a switch function. We just need to be public itself that void and we name it Switch collider and then open goes Prentice's we're gonna put an integer and we named this one numb this number will represent will be checked against If that number is zero, for example or any number we say it. If that is going to be zero, we're gonna disable the collider if it's enabling with the number one for except with them . We can do this as well. Instead of riding an if else statement, we can also me or you make use off S s I s expression. So a traditional expression like an if statement. So what we can do was dad, is rez a simple we can at first type in what we want to dio So we want to set the coal, but enabled. That's going to be what we want to want to make sure And we want to set this to be equal to and now in open close Prentice's we need to have the check against, like, what is going to return A true or false like a normal statement is going to do probably as well. In this case, we want to request if numbers equal to zero when it is going to become here, we want to say question Mark And then we said it to be false. Otherwise, we say Coleman true, it means any other number except number zero is going to return. True, but zero itself is going to return false once again. It's about the same as we say. If open close parentheses, numb is equal to zero going to do the same. And then we're gonna put whatever the condition is we can. In this case, I called on er enabled equals true comma, or in this case, and it's going to be falls. And also then it comes to in else state and open close Cooley braces don't write this. Just look at it and can say els cold or enabled equals True. So that is basically the same stuff in just one line of code. So no matter what you do, and no matter how you like to do it, you can do this or that. But I would recommend this one, since it's hopefully easier to understand, I don't know if you don't understand this. Of course you can use this. Those parts are going to do the same. I'm gonna delete the else if stuff in here once again gonna zoom in a bit, maybe you see that better than so, What we can do here is once again the same stuff, but in this case are gonna delete it. You can also commanded out for later use usage. So maybe you understand this one night on better don't forget to save that. And we want to remember this switch Collider. So I copied this name off the function, since we will use it in just a second onto animations. So at first we go to our mole again till pre fabs. Oh, no. In this case, three D models mole, every scroll down to events. Now we go to maybe frame 15 in the animation using this red slide over here and say we're frame 15 is where the head off the mall was already a bit sticking out. We can say on here we want to earn able the capsule collider. So what we do is that friend 15. We said we add an event and the event is going to be switched. Collider, the one we just created and want to pass in a one as an integer over here. As you can see, we are unable to put in a bowling. So we make use of indigenous If you're using later versions off unity and probably you have unintelligible Ah, pulling operator here. But for this we gonna use an integer Don't forget to apply that and this will also now happen to the had mall, so you don't need to do everything for they had more. You just need to do it once, since the animation is only available in the mole and the head more is using an animator overwrite controller was basically the same functionality and off course when we go down with the mole. So we go to animation, come down and once again, open window animation. We're gonna go here to frame 15 as well. Since we played this reverse Lee at another, um animator animation event, Name it or call switch Collider and put in a zero as an inter job. So basically, we don't need to do anything, which will make sure that it is disabling the collider at frame 15 when it's running from this site in the left direction. It's cool on. Basically, that's it. Now we can test it, since everything is based on the prefab. So we haven't done anything directly in here, So I gonna pours a bit here and there to be quick enough and to note or actually to test it out. So there's a had more coming out, and it's against the capsule colliders automatically they deactivated. I don't know let it run some more frames again. Just a skipper had several frames at a specific point like that frame. 15. As you can see, the collider becomes activated. Then the animation will happen, and the mall was going to go down now again, up until a specific point. And here, at this point, that collider once again gets disabled, as you can also see in the Inspector. And the player is unable to hit the mole at this point, and this is also happening to the other moles. It doesn't matter which one, as long as they have the same set up. Don't forget to say that, saying that the changes into your scene as well and let's go into new in the next port. 11. #10 Hitting Moles: in this part. I want to create some input so we can actually hit the mole with our mouths buttons. So it was the left mouse button, for example. And, um yeah, let's react to it like this, trying it, playing the get it animation and all that stuff. So what we're gonna do it first is we need to open our script from the destroy me. And since I don't like the name, destroy me. And also I want Teoh. Let's a get a bit more based on the mole. I just rename this in here. So there are two things to rename. At first, you need to rename the complete last name, so I call it moral behavior. The problem is, when you save it like this, now it's going to give you an aero Are because the sea ship script is not named as the class name gonna show you. So it probably give you Ah, Red Arrow. In here, that number more behavior is not correctly. Whatever. What you need to do is on the left, inside the solution window. Um, you gonna have to rename this script to be the same as the class name that's based on, um yeah, Monica. Heavy off course or mano development. This case, but I'm not sure about it was a visual studio, but I believe it's the same. So when you will rename this class name here, then you have tow rename the seesaw See shop script, probably as well. And you get also some errors now because the middle data is out of date and stuff like this . But unity she usually goes and changes everything to our needs. Okay, So when that is now, let's say cleaned up the effects. We just want to make sure that in our pre fabs on the mall, this scripts are going to be the same as before. So we just put in the mall behavior here on the mall s goal is on the head mall. We're gonna use or actually choose the moral behavior script. Now, since the other ones have been destroyed or actually renamed so Unity otherwise does not know what to do. Let's create an empty game object. And I call this one input manager. You can also name this one. Let's say, gay manager, that basically doesn't matter game manager and we can literally talk to it anytime we want . Of course, as long as it is persistent in this scene. Well, at least for the moment, it does because we created it. If you like again, zero this one out by resenting that's transform position by going to the G s a reset or justly root out all you keep it wherever it is again. Do whatever you like when I want you to go, is to a scripts and creating new Z ship script. And we call this one input manager. So now we want to drag the input manager script onto the game manager over here. Once again, there are some things probably some warning. Something is not really correctly done and so on. It's a force we gonna do and take care of that all that stuff later on as well. So, like, a lot of these warnings and stuff. Okay, so when we are in here, we can open up the input manager and put some off girls input inside of it. Gonna zoom in a bit. So against Steve stuff, Hopefully better. So what I want to do next is I want to create something in the update loop off this input manager. What I want to do is I want anytime I collect the left mouse button, I want to shoot a ray into our three d scene and see what we're hitting. And depending on what we're hitting, we want to react to it. Let's start. So we say. If input dot get mouse button down and then open close Prentice's, we have to define the mouse key. In this case, the left most button is number zero. The right is number one. The middle is number two. So we if anyone any time presses the zero most wins, has left most button. We want to check thoroughly things. And first we want to create a ray. We call it just Ray, and this Ray is going to be based on our camera dot main. Don't screen point to Ray, and this green point to rain takes one input of type rectus three. In this case, it is going to be our input dot mouse possession. So what we do is we create this ray from the camera to wherever we are pointing into the screen in shooting, arraigned this direction, the next one as we need to create also a red cast hit. We just call it hit. We don't need to do anything, but later on, we can react to it as well. Now we're gonna do some physics checks. So if physics don't read, cast and now we define the ray we're shooting. In this case, it's the ray we created from the camera to the screen point comma. And then we say, out hit. So the hits or so the rate cast hit. So when we hitting something, we want to check something. Of course. At first we want to say What, actually are we hitting so we can debunk that? So it's a debug dot log and we can log anything we want. For example, we can say hit dot cool eider don't game object Plus And then we can put some quotes and put on like goods hit something like this. So let's test it out. Nothing full will happen now. It will just shoot, array and see when we hit something. So when hit is true, we can debunk. What did we hit in this case? So what's the name of what what we hit? And also what has a collider. So, for example, we hit the plane and say, It's okay, the plane got hit. Now we can also hit that mole. It was ahead. More clone got hit as well as we can hit the well when it has a collider. We should also be able to hit the hole. But it's the whole, hasn't a collider and is nothing reacting to us. That's good. So now we have a debug line, which is telling us that we're hitting something wherever we click. If we doesn't know if we don't hit anything, of course, we don't get any D book line and returns. It's good. So what we now can do is we can use disinformation and coal functions on this object were hitting. For example, at first we need to define, since you also can request the plane and all the other game objects, and we're gonna we want to avoid and in our references, because some scripts are not available on specific ones onto, like on the plane directly. We want Teoh also do a request like if hit don't Kaleida dot tags or attack our more than just a second, it's equal to mold only then we're gonna go forward. So what we can do now is you can also debunk that we're gonna safe that by control s as a short cut when we no need to do is we need to tag all our moles. So we go to a prefect solder mole and on the right, in the inspector, you on the left side, you can see there are several tax we can make use off. We're gonna add a new tack press on the plus and type and mole hit enter. When you're done going back to the mall again, we need to assign this tag to this small. Same for they had more. We go there and Taggart was a mole. Don't forget to say the scene, of course, by control s So when that is now done and a mole is coming out, we should get the game objects name. If we are hitting now, the plane, nothing is happening. But hitting the mole will give us the request. That stuff that's good, since now we don't have any Eros or problems when we're hitting like grass or planes or whatever which are basically taking care off. Yeah, just getting as some aero us when we going to do so, why do we get a rose? Because now we want to actually take the more behavior and talk to it. For example, we want to switch the collider off, so we are unable to hit this particular optic twice. Also, we want to start a different animation. Speaking off the animation, we want to have an animate of component connector over here. So we say, animator and, um in the more behavior so we can talk to it and then start. We want to say Annam is equal to under off course. We want to get the component off the game object we are currently sitting on. So we say Adam is equal to get component animator, open close parentheses behind it. So we now have the connection and we can talk to it by using an um or we also can do is we are Actually what we have to do is we have to set this one public. But since we don't want to have directly excess inside the inspector, since everything is driven by code, we can put some special in square brackets. Um, info in here. What we can say is hide in Inspector. So we don't see the animator component even if it is public in the Inspector and we don't confuse ourselves later on. But we need to be public or create a help of function to excess it. So what we now can do, is it first we can de Buck Or in this case, we catch mole behavior and we call the Just more is equal to So every time we gonna hit this collider was this particular mould tag, we want to get the component more behavior from the hidden object. So what we say is hits dot collider dot game object dot And are we gonna once again get the component as spoke off open, close trying of records and we say more behavior open, close parentheses and close the line was a semi colon. Now we have direct access to the script sitting on directly this particular Yep. Guy. So what we now can do is we can say mole dot and now we have access to an, um, to play a specific animation. But also, since we have a public animation here, we can switch the collider on off. So we say Molded Switch Collider. And then we say zero. So we turn it off once again. Remember, we created the switch collider by taking them and when it's returning zero, we turned off the collider off this particular game object. And that's cool, since we now have access to it and can also make make use of it. So we can easily test that as well as we can trigger an animation event or anything we like Teoh and put in or play a specific animation. 12. #11 Destroy Moles On Trigger Hit: Now let's input the functionality for the animation off, the more behavior. So when we get it, of course we want to trigger it. But before we can trigger it, we need to create a para meter, which we can talk to to actually activate it. So go to the animator component off your more yeah animation, go to para meters and click on Plus. Now we choose Trigger and we call this trigger just hit every time hit gets triggered. We want to play, get it? So we go to the transition from any state to get it. We say condition is going to be hit. If it's not in here, of course, Just press on the plus and choose hit. Also make sure that your deactivate has exit time. That's everything for the animator component late on or at the moment. You can already go in here from get it, create or make transition to look around and just leave it as is that's later on needed when we have multiple hit points on specific molds like the hat More, for example, is going to have one hit point. Now you can go into the input manager and you can put in Let me as a minute it. Now we can trigger that animation whenever we hit a mall so we can say mole dot Annam dot set trigger. And now we can talk to their particular trigger. In this case, we put this into codes and call it hit. This name needs to be the same as to hit trigger in our para meters window off the animation. And that's how we can no trigger the gets hit animation. Currently, we have, like, the public void, destroy object, but we can also use it or actually creating. You want out of it for later on points and stuff. So I call it not destroy object, but maybe got hit. So what we're gonna do is we type and got hit was a big deal Big age for now, we just keep it as is. And we can also say we're gonna give it in command line over here. So put two slashes and say four hits or appoints later on. So we're gonna do another one. I go, Oh, I do put in points here, So that means when we call this function, we also later on at points to our system, which is actually taking care of how many we already have killed and so on and so forced, like before the time I ran out, for example, or whatever the possibilities are for the game. Don't forget to save and let's see if that is working what we are after. So when a mole comes out, we're gonna hit it. And now it's repeating this animation. This repeating animation is happening because we're not destroying the object after the animation has been completed. How can we change that? We go to the mole in this three D Models folder again, since it's ah, read Onley function. We need to use this particular event, so go to get it animation events and go to the last frame. We can do this by taking once again the slider to the frame number 100. Probably it's not easy to hit frame 100 since it's rather far to the right and can easily be overcome and get it back to a frame. 50 Air 85. So what you want to do is tried to hit anyhow, frame 100. If it is impossible, you can also right. Click it and try to put it in here. So maybe it's a bit easier. Teoh, you know, hit the last rain. But I guess it's not easier. So once you are there at frame 100 we gonna create hit or actually in the animation event trigger, which is the sign over here at event. Now what we want to have, it's called. Got it. Copy that. And we go here and say, Got hit. Don't forget to apply the changes. And now, when it's called the game object should be critiqued, killed or deleted. Once the last room off the got it, animation is hit and there we go. 13. #12 Quick Recap: Let's make a quick Requip what we have done so far. We created holes which are spawning malls in a given amount of time. Also, when you duplicate like everything in here, they're gonna spawning here we are able to hit and destroy them after we already hit them. Meanwhile, there are outside and when we also can't do now we can deactivate or actually commend out this debunk line in the input manager, meaning we don't need to know which Graeme object were hitting because we already know that everything like that is going to work pretty well. What we can now do is we can take care off or create a score manager and several other things to the game and also you get maybe some effects later on so we can create particle systems on hit, for example. But all of that will come up in the next couple of videos 14. #13 Hit Points: let's introduce some hit points for our moles. So, for example, the Norman mole is going to have just one hit point. And for except with hat mole needs to hits. How can we do this? It first we opened the mall behavior. And since we have the got hit information or yeah, function in here, we can extend this a bit. But at first, of course, we need to implement an integer which is taking care off that. So we say end hit points and we can set this one to be equal toe one, for example, or anything else we like and we also can do is we can make this one public so we can set this directly in the inspector also. What? When we get hit, we want to say hit points minus minus. That means minus equal one so you can type and also minus equal one that is up to you minus minus is a short way just to put in minus one. Now what we want to check is how many hit points we have left. So at first we want to say if hit points is greater than zero. So, for example, where one left. Then we want to say coal dot er enabled equals True. So we have the possibility to hit the mall again. Don't come into the else statement and in here we can say we're gonna destroy the game object because we don't have any points left, and we can easily just or actually get rid off the more. Don't forget to save the changes. When we now go to the hat mole and give it to hit points instead off one hit point, we should be able to see that this is working. So we have to hit this one now twice before it is getting destroyed, so these won't get destroyed. But as you can't eat, this ones need to be hit twice before we actually destroyed them. That's what we wanted 15. #14 Avoid Double Spawn: to avoid double sporting the moles in the same hole. We want to make sure that we create a bowling which is protecting. Ever seen like in there more behavior. At first we create a new public bull. So it's just the rejoining tool false and we call it has more every time we spawn. And, um, all we want to set the mall to be known that it has a specific parent object and the parent object is going to be basically, the more behavior or actually the whole where this more get spawned in. So what does it mean? In start? We can say if we don't have a mole like, if not, has more everyone to invoke I was born and since we protect it with the bowling, we can already start to do it and starting from zero between zero seconds and seven seconds , for example, any other amount we want and like also when we go to spawn, we also want to protect it. So if we don't have em also, if not, has more not in this case means is not equal toe. Then we want to spawn our game object like so so we create an integer and of course we spawn them all. What who also want to do is we keep invokes, born this line outside off that because we want to probably re invoke that one, even if that doesn't match it. So we restart like everything again can be that there are, like, I don't know, seven seconds or even Mawr. Probably 14 seconds no more actually respond in a specific spot when there is a super big mall inside. Whatever. What we also want to do is meanwhile were spawning. We want to talk to the more behavior and give it apparent. So we want to give it apparent in here. So what we want to do at first as we want to create a public game object and we call it my parent, my parents, in this case is going to be the whole where this mole gets spawned in. But we also want to hide this inside the inspector so we don't see this. And don't you know, get confused by that game object. We don't because we don't need to set this. But what we want to do is, since we have no a public game object we can talk to was para meter. We can, in the whole behavior can say that. We want to say mole don't and I would get the component off the more behavior, often close parentheses dot And now we can talk to the my parent, and my parent is going to be equal to this adult game object or just game object. Meaning wherever this whole sits on, gets set into the mole, which is created or insane. She ated s the parent off this meaning when we destroyed this object. At any point, we can say or talk back to the whole behavior because we have the connection to this particular game of deck by its idea and tone, and we can talk to it and say we are We have no more anymore. So what we can also do is when we instance she ate this that we say we have, um also has more is equal to true. Don't forget to save the whole behavior. Let's go back to mold behavior in the mall. We want to say when we destroy this game, object by its animation end. For example, we say that my parent dot get component because we need to get the whole component against . The whole behavior overflows Prentice's dot and now we can say the bowling has more is equal to fall. Since this game object does not exist anymore, make sure that you do this before you destroy the game object. Otherwise, it's not working, and the whole never ever will create ones again. Don't forget to safe and go down. Meanwhile, or before we destroyed the game object. Here is the same approach we need to set the my parents get component whole behavior to be the or actually them has more. The bowline needs to be set to false at this point as well. So when we get pointer, get it and we have no health points left before we destroy it, we're gonna reset the whole, so it is able to spawn a new more once again. Don't forget to save anything or everything, and let's get going and see what's happening now. As again, see, that will be only one more per hole. Every time we hit one, we're gonna destroy any, and they are able now to get more outside of it, and it can happen that one day everything is full. But there will be no new sports because there are other ones, probably ins. I site the whole and we don't need to take care of that at any point. So that's nice. So we can actually fill in any hole at any time with only one mole. That's nice. That's what we need it. 16. #15 Score Manager: Let's create a score manager, which is taking care of how many score we get. Meanwhile, we are hitting malls, so go to your scripts, fel the and creating new siege of script and call it score manager. This score manager can also be part off the game manager, since it is just a staying there and will hold all the data for us, drag it onto it are directly another input manager if you like to and open this one up in Model, developed or Visions studio and what we're gonna do is we just in group? Yeah, we put in some score. We cannot first put a public field on here, but the later on we gonna protect the score. So it's not as easy, let's say, accessible from outside. But at the moment we just put it like this. I recall it just score or no one to created some functions which are able to read the school and ed to the current school so we can react and your public void add score. And instead of just empty Prentice's, we can also put in arguments. In here, an argument can be an integer or a bowling or whatever in this case is going to be an integer. It's going to be any amount we like, meaning one particular game. Object can, for example, or like a mole, can give you more points than the other. So it's not always adding one to our score, but probably three or five or 10 or whatever the amount is we want to put in per mole. We can also decrease the amount mean using this one so we don't need to reduce, especially weaken, suggest implement in negative number and which will automatically decrease the score by whatever we want. So to excess is this particular function director sitting in the score manager, we just need to make sure that it is a public function as usual. And now we're gonna say the score is going to be plus equal. Whatever the current amount is, we gonna send into this function now for later issues or for later things. We want to read scores. Well, so we in this case we want to return in integer so we say public end and we name it Read score. It's basically is same as avoid front, but in this case, we can return an integer directly without requesting it and sending it anyhow back. So every time we now request this function, we can say we want to return to whoever is requesting it a specific interject this inter just going to be our score, meaning now off. For example, when we want to update user interface, we can call or request the score by the score manager and see by using the read score. If it is well, whatever it has to bay like, for example, to get to the next level or just to show user interface stuff like How many score the player really has is toe can show this inside the canvas and so on. So now we have the possibility toe add to the score. But the problem is, the score manager is not directly accessible for us since, well, it is not directly related to any off this game objects we can change that by, for example, we could create a aesthetic. Yeah, scoring here. So, like aesthetic into job, which means we can make this one accessible from any point was just calling. The Storm airs court manager later when we just need to make sure that we ah, here reset the score when we start the new round. The problem with this particular aesthetic, by the way, is also that we are unable to our use this particular function. So what we need to do for that is we also may need to make this particular function here aesthetic function So we can talk to this a swell If we don't have an integer, which or if we don't have aesthetic interject like this, we would get in our reference or actually a problem, that this is a non static member. So this function as aesthetic function only works when this Inter Gia is aesthetic as well . So this era will disappear at this point. No, What we can do is that is we can go to the more behavior and every time we gonna destroy this game object and we put some points into it, we can now request the score manager. Then we can call the function at score since is this aesthetic function and we get put in any amount we like. Let's say this is setting sitting on the mall Anyways, we can say public in score, we can set the score inside the inspector and send this later on inside or to the score manager. So what would say score manager at school and we implement Score s the argument. Now, when we let's say, go to any more like the normal more, you can see that the score for this mall is one point. When we go to the hat mall, we probably want to give three points or maybe five to make it more year useful for this particular more. Don't forget to do this directly in the prefab, so everything inside will later on changed by this. So we can now check this as well. The problem was, Dad, as with those statics, we are unable to see them. Even in debug mode off the manager, we are unable to see how much aesthetic score we have. So what we're gonna do is we need to request this particular score for the user interface directly in here or we bry every right a d buck line which is telling ice every time score gets add it to see how much we in total half so we can say D Look, don't look in this in this at school function just for the moment before we create later on user interface, we can say current school a colon space plus And now we can put in any argument after your after this. Plus, in this case, we want to de Buck school. Now we can go here. Press play an answer. Consul, let me go out off, maximize on play in the console. We will see when we hit something that we get current score is one. Now, when we created more kill one off thes yellow guys, we gonna get plus five score And as you can see, it's adding up even if we are unable to their d back this one directly. But that's nice since now we can also create an update or user interface manager which is always reading this school from here. So we have access to them. I believe we can also get rid off this particular public one since we don't talk to the integer directly in here and it doesn't need to be accessible from outside. Meanwhile static, so we can do the same since we're using the function for it. And as you can see meanwhile, we are creating what you're getting rid of small ones. We going to get score still, don't forget to save everything. If you haven't already, that's it. And let's go forward to the next port. 17. #16 UI Manager: let's create a user interface. Actually, what I would currently want to do is I want to see the score Somehow in my game view, what we can do for that is we can create a new u I canvas and this is just our canvas in here at the first thing you want to do as you want to change inside the cameras. Scaler is from constant exercise to scale with screen size, no matter what. So what we also want to do is we want to create in you. You I text meanwhile, canvases activated, and we can call this once again whatever we like in please. In this court case that probably it's just score. Now what we need is a user interface manager was which is taking care off the connections to our tax components so it can be automatically filled, for example, from the canvas. So I renamed this one to you. I canvas just because I like it. So now we need a connector for the U I canvas, which is able to get all the info and put it into the correct into the coric parts. Why is that, sir? Because when it comes to pre fabs. Pre fabs can only hold connections directly to child or child objects are related to it, but when it is somewhere outside, it is impossible to access them. So what we can now do us, we can create a new siege of script. We call that you I manager. We can't put the, um manager directly on the canvas once the compilers completed. Of course, if you have trouble to put this on, then there's the you should be. You should stay away from. Our space is I did it so I know what we named it and everything is fine. So now I can double click this and to used us canvas user interface stuff. We need to make sure that we use the name space using unity engine dot you I So we have access to all user interface possibilities like images, text components and all the other things. So what we want to have as a new public taxed field was a big tea that is going to be all a score text. Every time we get score, we want to update the user interface by calling us more For example, a specific function, which is taking care off all the score or any input we like and police. For example, when time is updating and so on and so force. How can we do this? We create another public off time void and we say update you. I I often close friend to CS and open those curly braces. Of course. So what we want to do here is we want to update the score text according to whatever the score manager as info has, how can we do this? We create a actually, we take our score text. Then we say dot text, which means we pass in the string para meter it's equal to. And now we can put in something in quotes like directly, for example, score colon space and then we can say plus and now we can read score from here from this read score message. We can only do this when this read score is also aesthetic. Ah, yeah, aesthetic function. So what does it mean is we can all say score manager dot and now we can say read, score open, close parentheses and and the line was a semi column. So what? We don't need to do is every time we want to do something or actually want to read the score when we get points like, especially at this point when we add score. Who also want to talk to the update you I manager. Once again, there are several other possibilities instead of just using aesthetics for now, let's just keep on and stick wisdom. So I want to create here a public static warrant update you I If that doesn't work as we know now score Texas not a static one. It is a bad decision. What we now can do is we make the you I manager aesthetic actually aesthetic class. So what we can say is public static. You my manager, we give it an instance. Name instance, in awake. We need to say white, awake awake is a unity provided function we can use for this, we cannot say instance is equal to this. Meaning is this is the only instance based or taken care off this particular aesthetic instance this is important. Otherwise it is not working the way it iss Now. What we can do is we can call the U I manager instance and then request the update. You I don't forget to save the script. And when we now are in the score manager on, we add score in no matter if plus or minus, we can say Hugh I manager daughter instance dot And now we have access to the function, which is saying update, Do I open close parentheses and enter Lyon was the semi colon. Now we shouldn't have that aero anymore because we're not trying to excess a non static member. Also, we still have no the possibility to put in a score text element inside the inspector. This is not possible when we are using static text fields so we can now put in the score text. This is based or chilled a child off you. I canvas so it will not lose the connection on reload, for example, don't forget to save the scene as well And now what we can do is we can place the score somewhere visible in our screen. As you can see currently, it is rather small and badly seen, and I don't even or barely see it here. So I make us one bigger and maybe another color. For example, I don't know white. You can also put in any foreign to you like currently there's aerial only, but you can import like hundreds off thousands off different funds. If you like, you can make them bold. You can make the phone size director or you can say best fit. Best fit means it can fit it to or in between minimum maximum size according to how big this field is. That switch to two d. So we get this handled is here. What? I want to do them want to keep it always in top and in the center, like in the center off this particular field over here. So we can also now center this one here. Now we go to anchors, Hold on old and put the upper anger Now it's related always to the upper area. You could put it off course to any other Ankara as well, and then drag this one a bit down from the position to keep a space to the position or to the to the side off the playfield, or actually off the camera view. Speaking off the camera, you can always go in and change the background to any color off your We are what you please and like you can put in an a specific specific Tooni. Ah, yes, Guidebooks around whatever you condone, not a lot of things and so on and so forth. Or you can even make this ground playing bigger and put some plants and trees and stuff around as you police and like So now when we are actually getting any school we should see in this new text area over here that we have score one and now we should have score six. But also as he notice this text is only updated ones we are requesting at school. So what we want to do is or what we want you I manager to do is we want to update the you I already when we are in start on awake over here. So we want to update you. Are I already when we are able toe So we're not starting with new text, but with score zero And there we have score 18. #17 Play Timer: since Welcome Ole is usually based on a timer system, meaning if you have enough points after a specific amount of time, for example, to go to the next level, I want now to implement a timer as well. We basically do the same as we have done with you. I manager. We connect, taxed and all the other stuff in just its second or even minute. So what we want to do first is well, we can use any off the managers we already have created, like, for example, the score manager directly, or even the EU I manager. But I want to create a game images instead. So I created news bishops grouped on and call this one game manager. So everything managing about the game and everything we need to know about the game itself , like what's the current state of the game and so on? All of that will be inside the game manager, And since we already have a game in the object, we can also put this on to the game manager object. So the game image of script let's open this one up and model developed or a vicious studio and nice zoom in a bit so you can see stuff better. So what we want to do first is to create the timer. Well, let's get rid off updates. Since we don't need update for this, maybe later on we needed. But well, not for the moment. So what does it time a need? I got a command things out. So we later on the know what the stuff is about. We're typing in here. At first I want to create an integer and I call this play time They don't want to have to other inter jets, which is a seconds and a minutes. Basically, we don't use minutes, but what we can do is with that we can sent this data no matter what the playtime is laid on. And we gonna sent this over to the U Y. Manager Teoh. We are to update it so we can store the current seconds and the current minutes according to everything, and also depends on where we want to start and how long a one round is going to be. The next one we want to create is a co routine, a current 18 also called I e numerator in C sharp is nothing else than a time based function. So what we want to do is we want to cruel call this one timer or probably play timer. We don't need to put in any arguments. And here just open closed parentheses and open cause curly braces. So in an in Nakuru team, we always have to return anything. It depends on in what kind of situation we are. And to keep this I e numerator or karate in running, we're going to create a while. Loop while loop is nothing else and it repeatedly do stuff until a specific condition is set. And this time, the condition is going to be. If flight time is bigger than zero, they don't want Teoh. Keep Contin ear, Whatever is inside this while Luke. So while this is true everything and you will be performed when we are leaving this while loop, we go into the next line depending on what's coming inside. Okay, so let's create the timer at first when we start the time at all or when we start this co routine. The first thing is, of course, we check of playtime is bigger than zero. So what we can do, for example, is who can play time or set play time to be 60. So 60 seconds is going to be the number in here. Why is it 60 seconds? Because we gonna say here, yield, return new. Wait for seconds. Open close parentheses. Put a one inside. So every time we come into this wild Lupo, meanwhile we and here we wait a 2nd 1st What we don't do afterwards is we decrease ply time by one so flight time minus minus those. This is not 60 anymore, but 59. And all of that is going to happen the wool time until this is not true anymore. So when playtime is actually zero okay, so what? We want to do it first. We want to calculate the seconds so seconds is going to be equal to. And now we want to know is the current playtime and we want to set it to model 60. That means the model who cuts whatever the number is the playtime to 60 in the maximum. So it will never be higher than or actually reached. 60 will always be like 00 or 21 word 59. But never 60. Once it comes 60 it will resent to zero. In this particular case, we're gonna see this later on, and we're gonna have minutes and minutes is going to be the same. But it is the plight time divided by 60 in this case, 60 seconds. Model 60. Also, that means once again we kept minutes by 60 so the maximum and year would be 60 minutes to play. But play time divided by 60 means one minutes is, of course, once is 60 seconds long. So that's what we're gonna take here. Okay, The next step here is we want to update the user interface when we're coming to this point . And what we also want to do is when we had done with that time, I was a d barca dot log. So we want to know if the timer has run out completely debugged good log time or has ended . So that's going to happen only when we're leaving, the while loopy. Otherwise, we still hear keep inside this loop, looping completely waiting for the yield and return something. In this case, we returned the wait for seconds. Okay? And also after this decline, we can late on defined the wind condition or the lose condition. That's what we want to decide later on as well. Okay, so what we now need to do is we need to start this core attain in start. Of course, when we start with, I start. Corentin often cross parentheses and inside we can say in quotes pill a timer. So play time in this case, is going to be the name off the Gordon off the I N m aerator here, which we need to start here. There are several possibilities t to start a co routine. The other one would be not using crow roads and put it inside like this. But we could also put it with parentheses behind it, like a message name. So when we, for example, need to implement some arguments inside the eye numerator and we can put them into the parentheses. But the problem was dead, as we cannot directly end this started call routine like that. So, in this case, we can directly call or make sure that we end the playtime er co routine when we say stop protein and pass in the name off the currently running one which we might later on Want to Dio, for example, if we have one earlier or when there is a pause, then we might want to pause all of that and maybe stop the Cortina at this point. And don't forget Teoh. Start at the flight time when we are starting this one once again. So all of that can be done when we now go to our you I mend a we need a score tax or actually, in this case we need a tax which is showing us time. So we say public text, our time text or something like that. So we put the time text into Dad into the inspector. Also, we need a function which we can activate once the timer has changed. That means it's a public point of date time. We can once again named these functions however we want, as long as they're not unity provided everything is fine for that. So into update this tax, Of course, we're gonna put in like time text don't tax. So we put in something into the tax directly in the text field s a string para media. So what we can do is we can at first pass in Inter just here for the minutes or just men comma and in in seconds so sec or backs and mins and we can use thes they Yet these arguments to fill in the text in here so we can say mince. And now we can't convert this to a string, even if we don't have to dot to string on. What we could do was that to string as we can put in a decimal format in here, so we can't say d two, but it is important that this is going to be an integer coming and he otherwise. The decimal is not working. It's not working with floats. Otherwise we would have Teoh typecast as floats into inter Jess when there are floats again , we can say now, plus that we put a quote and the colon in between, for example, and we can know plus again and say, I want to say the sex don't And now we can also say dot to string, and we put in the argument details so we will have to decibel numbers. If you put in the one off goes, there's only one. If you have three than there will be Syrians on its the force. Okay, so that's it for that part. And now we just need to create a tax field end in a way we can also say we want to say we want to update the time and we pass in some perimeters, like one comma zero. We can also pass in any other stuff. So, for example, and we could say that the game manager here has or actually we read Maybe later on the time the polite the current point time from the game manager directly. And we can passes one in here to update the time. Or we're gonna do this directly from the game manager and talk to this one. It is all up to us. We can put the stuff back and force into this situation. Okay, so the last step is basically, don't forget to safe. We can go toe you y camas and to duplicate the score text, for example, and name this time. What time? Text. And we drag this one down a bit year, make sure that you go to to demote, so it's easier to handle and maybe drag it down for the moment. We don't need to put in any textile, any arguments or any values and a new I can. This we want to make sure that we see the text field. So we have to Yeah, we have to save at first. And after that, we are able to drag the time taxed into the time Tax one here. Okay? And the final step is we go to our game manager and we want to update the why. So we can say you are a manager dot instance dot and now we can say update time. Now we put in open close parentheses, and inside of that, we pass in the minutes, comma, the seconds were, you know, safe and press play. We should see a timer running from 60 backwards until we're hitting zero, as you can see. And now we should be able to use that timer for going to the next level, for example, where the moles can become harder, or when we go and spawn more moles or less moles or special malls or whatever and bonus levels and all the other stuff. You can do all of that just based on the time so when we have a specific score and a specific point, we can go forward or we just say we reached the minimum score and then we are able to go to the next level. 19. #18 Win & Lose Check: since we have a time and now we should also be able to check if we are winning or losing a specific round or level that comes when we are actually calling a winning condition to this or at this specific point. So what we can do in our game in a job we can say we create in your void. Check four win open close parentheses and inside curly braces. We can put now some requests. So, for example, if the score manager has a specific score at the specific point, then we are able had to go forward to the next level. Otherwise we don't and speaking off the next level. Since we are in the game manager already, we can create it. Eso we have a possibility to count up the current level, so we create. For now, a car level is going to be off type integer car level, or you can also type it out current level and we started one or also want to have is maybe a base score like not a multiply about a base score, which we can start with base score and we can set us, for example to be 100. So that means in leather one, we would have a based school off 100 or this is going to be more or less the multiplier. And for example, in never to we can say we do. We multiply this the current level when it is level two by the base score. And we can also once again put in a yeah, any multiply again. And what we also want to have is an integer which is actually yeah, taking care off the score to reach. So this is basically this one where we take one use or make use off the calculated base or actually the calculated score. So what we can do and start, of course, is scored to reach is going to be equal to current level times Base score. Now, since we have the score manager already, we can have or we can make use off the score directly since we can read it from this point , meaning Now we know what the score is for this particular level, two needed to be reached. So what we want to check now in our check for win is if the score manager and now we want to read the current score Open goes Francis is Of course, if that is bigger or equal discourse reach at the point when the timer is over. So we're gonna call that in here after the time I has ended. Then we want to say Debunk, Dad, log. Well, at least just for the moment you won the level and we also can't do is if that is not the case, we can say we're gonna send you to high score or game overseen. Game over. We can also Deepak this one year as well de Bark dogs Lord, game over. And so in this case, we can now wait until the timers down are gonna cheat a bit and put maybe just five seconds here so we can easily test this one out. And, of course, we need to implement the wind condition. And here, like check for wind open, close, run to seize. I need to call the function, of course, in the playtime and last in the last year line of code. And when we know press play and we are at a specific point, you know that we're going to get a game over in here. As you can see, the time has ended. The score was Just do it or not enough and we were game over. At this point, we can basically go to any new scene and loaded to show. For example, our highest level reached our current score. We got and so on. It's a force if you go and bring this one back to maybe 60 seconds and test this one out and I was going to Regis, actually, or actually the score, many just score is higher than the score to reach. We could go basically to the next level. 20. #19 Optimize Show Score: let's optimize our score text or actually the input for the score text a bit. So the player also understands. Oh knows why he hasn't reached foreign Sound bold the nice level. So what I want to do is you don't have to, but you can. I want to implement some kind off info for him. So he has, like, his score slash. And then we put in the number he needs to reach for the next level in the time in the very top, for example. So how can we do this? At first we go to the school manager we currently using the read score just to get the score, but also we when we are updating the user interface after we adding score, we talked to the U. N manager and let the, um, manager updated, but the other you I manager and update you. I'd goes currently back to the score men. Just so it's doing the step twice to read the squint. Give it us. So I want to do is I want to at first put the score directly into the request off the update. Ey. So what I do, I mean by this I gonna create an argument for Abdulai as we have done for minutes and seconds and this is going to be also in inter junk and it's going to be the score coming in . Also, I want to put another argument. Is the score to reach? I was out cynical. So what we now can do is when we are updating this user interface, we gonna have to feed in the score and the squirts reach the problem with scores. Reach is at the moment when we are starting again, we don't need actually, we don't know it. So what we could do, Oh, should do is instead off updating the U. Y here. And the Wag message is doing that by the school manager directly at start because the store manager at the score manager, its start will know what be was what is going to be the score to reach, because we're going to send it there. So for the moment, let me put in score. Then we're gonna put in Crude's a slash, then another plus and then scored to reach like that. So that's what I want to play it to see. So he sees this current score. Is this one than a slash off Lauritz. It is like off the maximum to reach. Okay, so now what we need to do is we need Teoh. Give the score manager the number to remember what is currently inside or what we need. So we said we create a public and score to reach. We want to do it. One Teoh, hide this in the inspector. So I don't want to see this in the inspector of the score manager. But I want to have a public. For the moment, they don't. We can think about aesthetics, but well, at the moment, it is not important. I would say so. What I want to do is I want to feed this score to reach by the game manager in the very start. So, like when we have coca lighted the score to reach, I want to pass this over to the score manager. Meanwhile, I think about it. I'm gonna make aesthetic as well. Otherwise it is not funny because we shouldn't or we couldn't directly add to this static. They are number here. So what we now do is at the very start in the game manager after school to reach has been set. We talked to the score manager and then we're gonna take the score to reach and set this one equal to score to reach. So the one we have calculated here now, every time we gonna update in score manager, the ad score we also need to put in the argument will not a net score. But here and up that you I we need to put in score here as an argument and the score to reach, which is said here, don't forget to say and then you I manager, we should have this one as well. And here once again here we sent this data only ones. Since we only do this, let's start at every time we load the level new as a small typo, it seems okay. And what we're gonna do is we get rid off, update you I in the U I manager wake message because we don't do it in this. Put me in this case anymore because the game manager can do it in start as well so we can talkto you. I manage other instance dot and now we can already calculate that and show it so we can say update, Tom, the u I and when we pass in is at first a zero score comma and then also in here We could just simply use the squatter reach. Since we know what you already as well. So we update the user interface at this point off the game manager. If we now ah, safe the scene. Of course, when we have changed something, we want to see if everything is working, as you can see now is showing us zero slash 100. So this is the current score we need to make it through. And also we have the time still running. We have no problems at all. So no arguments or the French or anything else. Everything is accessible, and that's what we want. So now when we play seriously and try to get as much points as we like to in 60 seconds, we're gonna go for the big moles, so we are hopefully able to do it. We also can get some small malls. The player later on will figure what's going to give him more points or we tell him in a specific scene like a tutorial scene or something. Okay. And now we got it. So we have, like, a score off 101 off 100. And when the timer is done, it should tell us that we have one in the D book line and we should be able to go forward also. You can see the time a stops here. I got a press. Yeah, and this so you can see time A has ended, has been fired. And you won. The level has been fired at this point as well. That's good. 21. #20 Level Up System: That's pretty quickly going to an upgrade. The level every time check for win is going to give us the correct stuff. So, for example, we want the level because our current score we need to reach is higher or equal. Don't. Yeah. Then it is that we're gonna increment a level. The problem currently is when we updated and we go to the next scene or basically, when we reload the scene, all of that will be reset back. That means this a current level needs to be static. So it's going to be actually Safed up until we're reaching the next level. So make current level being aesthetics every time we incremental it will not result on a level restart or on any in the new level. We're gonna load so in check for win when we are actually winning the level over here, we can say we want to increment current level by one. So we say current level plus plus Now we want toe load the same scene, the same level, or actually, whatever level you like, so we can go forward with the game. What we need to implement is a new name, space and this is going to be called using unity engine dot seen management. This is available, I believe, from, Ah, unity 5.3 and over. So everyone under that's going Teoh has to use the old method. So I recommend using the Yeah, a new version or a newer version after 5.3 off unity. At this point, however, what we want to do is you want to say seeing manager dot load scenes, I want to load and you seen and in open close parentheses would say once again, seen Manager don't get actor scene of those fantasies dot name. We need the name because this is requesting as actually a build index. So an interview or a string pyramid er, in this case, we pass into string perimeter off this particular scene we're currently in. So basically, we reload the same level every time we make it so that we are able to reach the school. So what does it mean at all? The incremental level will be upgraded. The base score is going to say the same, of course. But the score to Regis always adding up. The only thing we currently don't dio is we do not reset the score so the player would be able or has to do, Let's say a bit more than before. Also, it's going to be a razor easy game at the moment since we always have a good amount off moles. And also we can make more malls in one round. So we don't have to do more malls in the last round or for the next around and so on. So all of that is stuff we need to take care off later on. Also, we might want to increment the base score times as something or we would reduce it here and give it a multiplier times three or something, meaning when we go and set the base scored 2 50 we gonna do another multiplication here, maybe something with current times current level, plus whatever. So, like a plus two or something, or we can divide that by something, or we can do a lot of mess medical calculations in here. The only downside is currently we are only using inter just instead of flowed. So we are not able to do strange calculations. Times, point numbers, you know, times 20.0.4 times 0.5. So what we're gonna have to do is we need to narrow this one down by something else. Okay, So for example, we can say current level times the base score, and we maybe want Teoh multiply the base score times at the current level, for example, so meaning in the first level. Of course, a base score is times that, and then we multiply that once again. By that meaning in the first level, it's going to be 100 points because based court times current level. In this case, we can make 100 again. So it's easier toe calculate Now, then, the next one this is going to be a doubled. So when we know stopped the game, for example, I can show you also that is working, of course. So we gonna hit the big malls here, so we're gonna get enough points in the game time or meanwhile, I'm talking and trying to explain. So once we have reached the school off, whatever we need to go, we're gonna increment the level by one and go to the next level. Also, you will see in just a moment that the level will be darker than it's usually is. This is a unity problem which might have been fixed in a later Belgians. I don't know. Is this normal? So this will not be in the built light on or whenever we build to an A P K or whatever. So I have now like more than enough points for this round. But also this scores not resetting. So for the next level, we would need 400 points. I guess so. It has, like a small incremental possibility. No, so it can see now we need 400 points in the next level. We would need 900 in the next level. So we now have to really struggle and see how we can get enough points to get at least a year to the point of 401st because we don't get more time. So yeah, we have to take care of all that calculations make the game interesting and hard for the players at the same time. So when they are not playing the game, actually then they might lose in the second round, as I do currently, so I will not make it to 400. But you probably get the deal. So the next round, basically once again will be like 900 points in leather foil would be like four times 400. So it's going to be part of 1600 so on and so force as against you. Time has stopped, everything's fine. This can be like just a usual calculation, since we only have introduced once again. But it can work. You can also go down with the base score so you can started 50. So it will be in the first level. Of course, 50 points and the second level it will be 200 points. So it is always calculating times, Dad. And in the next level. So instead of 50 and 72 hundreds in the next one, the Level three would be like three times five times street of times when I have 50 would be foreign, it 50 and so on. All of that once again depends on how you want the players experience, but in this case is going to be pretty interesting off course. 22. #21 More Moles: to make the game more interesting. Let's create some more malls at the moment we're gonna create to a random or which is going to decriminalize score instead off incremental score. So actually, the player needs to take care of where he's going to hit, as well as let's create some kind of golden mole which give us an insane amount off score. How can we do this is because we just go to any off hour pre fabs and drink this one into the scene so the set up is basically done already. So take the first mall because probably we want this one to be the golden more without any hat and we can actually do anything. We're wound was them. So what I just want to do. Since everything is set up already, I just want to change the colors and to do so, we can basically go to our material sorter in our three D model students you have. We have ever any color, which is, let's say, Rhett, if we don't have a distance, I don't have one. I create one so I can say go material and create just a red one and it goes, go to the LBD General and make this one Retz. If that is read that read is not ready enough for you. You're always able to change it. Now what I want you to do is you can basically take this red color and drag it into the scene onto the mall directly, as you can see, since they are two different materials or in this particular case, three different ones. We can put the color onto any of these materials, like the nose and the beard, the eyes as well as the claws or just the body. So I direct this a red onto the body. You can also go in and make some more materials, like for the clause, maybe. And the nose You might want to have some I'm pinkish color, for example. So to highlight this Badme or maybe a bit more so I can create another one, another material and name it pink or whatever you please. And I can go here and make it more like skin toned. And I can take this skin tone to put it as a swell on the nose and as well on the claws. I also are renamed this more to Be bad mole or Red Mole. So that's what we're actually what doesn't matter for us at the moment. Just hit enter. So also it is written here. So once done, was that change? You got dragged bad more now into the prefects folder. So we have a new prefect we can work with as against, you know, this is what it looks on. I believe it's easy to see, and if it's not well, the player will remember this. Colors light on this more is going to have only one hit point for May, and I want to give score off minus five. Or we can also be not that hard to the player and only put minus three. But let's assume we're gonna decrease the amount of score bomb minus five. Now. What we also can do is we can, for example, create ahead more with there's also read or has any other color was more hit points. Give us more score as well as we can use the head more as a time mall, for example. So we he has probably a red or a blue hat in this case, like I don't know we can't even give it another object on top like a clock. So we can increased heimer later on when we want to, as well as we can create a golden more, I would also once again take I can delete the bad mall Now since we are set it up already, we can also create another more which is just golden everywhere except maybe the beard. So we can go with once again to the materials folder create and your material and we make gold material. So go to hear, change somewhere or see where the gold material could be or the golden color is maybe maybe something like that on my like on a small orange. 1 may be a bit more or less into that. So yeah, you need to figure it out as well as I go and bring the metal nus up. So it is going to shine like a golden ball. We can also go up a bit more with smoothness so you can see it's looking more and more like a golden thing or gold material. If you're happy was a result in the gold material. You can off course. Ah, well, I gonna rename it by hitting F two again and make it gold. And now I can put this onto our mole as well, like on the nose and on the body. And also, I can't rename its here to Golden Mole. Also, when I'm done was renaming it. I go to my prefects folder and direct this one in here and for the golden More. I probably want to give it, like 50 choir, 50 school, or maybe 30 or or 25. Maybe is a bit better. Will, a least for the moment. We can also decide if we want to give it, like several more hit points or if we want to keep it, as is just one and we get a good amount off money or score in this case out of it. That's cool. So since we have the year this one, the prefab already done, we can delete the gold more from the scene. Let me also create another mall with using ahead. As I already spoke about I direct. This had more into the scene. It can also reduce it or sedatives years. Israel. Does Metarie really at this point what I want to do. They want to tent the head like Sai in like a specific color off the helmet should indicate that this is going to be a time a mole. So once again, I go to my materials. We'll see if I have a material like this, but I don't. So it created new material and the main aim. It's Salyan and I go to the color here and to make at super science, and off goes directors directly onto the hat. Now I renamed this more to be time mole. So every time we hit the time or we get, of course, some special score, maybe a score off 10 a sensitive that is a bit better as well as may be reduced the hit points to be won or keep it as too it doesn't medicines. Helmets ones might be a bit more protected than in the user balls. Now I direct this time all back here into my proof of solar. So I have access to this as well, and they don't can react to it since when we hit this. We can also say, since this is a time all we can give ourselves some time back for just one example. Don't forget to delete the time all now from the scene, and we can go and create some more interesting game play now. 23. #22 Spawn Rarity: in the last part, we were creating more moles was different year points and stuff like that. But since we don't spawned than at a to a moment, we need to take care off, spawning them according to for examples and kind of rarity. First off, let me go to a whole and let's check what we have here. We have a size off currently two elements like a normal more and ahead more get going to be spawned randomly. We can also increase that Teoh be a size of five and also we can now draggin like more one . Is it element? Zero more to the head more than usual, one might be it'll element one at element to are gonna put maybe the time or no, Let's say we're gonna put this at number four and the bad mall is going to be number two and the last element four is going to be the golden mole. These numbers are later on important mind. Meanwhile, in script, because when we now create some kind of rarity against or inside their small behaviors, we don't want to pick some off these just randomly, just from the list as we currently Dio, which means when we now, for example, press play, any of these five moles are going to be created no matter what. Also the rat more as you can see and also a lot of gold malls. But that's not what we want it since currently those golden walls give us too much points and it would be too easy to play the game. So what we want to do instead is we want to set some rarity like this. More is going to be like a lot off times more creator than a gold more. How can we do this? We go to our whole behaviour. Meanwhile, in Spawn, we want to check or actually, instead of taking just a random all we want to increase or create some kind of rarity. How can we do this? We create in your function off type int since we want to return an integer which is taking the correct mall. Based on this interview, we can call this maybe calculate rarity, open close parentheses. We don't need to have any arguments in here, but we return something. If we don't have any match, we need to return a number and I would say the usual number is going to be zero. So this number will represent this number, like the number off the first Maurin Element zero off the array. So when I bring this a bit, you can see Element Zero in this case would be just the usual mole. So when nothing works, we needto leased to return zero. Also, what we want to do is, instead of picking them randomly, I commend in out the random range line. I want to create a new line. It's going to be basically the same in Numb is going to be equal to, and now we call, calculate, rarity, open close parentheses and close the line and was a semicolon. So at the moment when we call this, we just would return zero meaning just the first more. We can now implement some more if statements beginning at the smallest number possible at the smallest rarity amount. But off course, before we can do this, we need Teoh. Let's say, roll a dice between zero of between one and 100% as a return rate. Let's create the randomness. At first we create a new local inter John or temporary into chocolate numb, going to be equal to random dot range. Basically, we do the same as we have done before, but we're not taking from the list lengths. We gonna calculate that between, let's say, zero comma 101 Why do we use 101? Because the last integer is not going to be in the calculation later on, we're going to change that. But for the moment we do this. So what we need to do is we need to create an if statement and we say if numb is smaller or equal one, for example, like 1% off a chance. Basically, it's 2%. Maybe we're gonna start here one, but not a do so when we hit like one, just that Number one. We want to spawn a gold mole. So we return. And number four, why is that the four? Because element for here and the list is going to represent the gold more. That's why these numbers here are now important. We can also get go a bit further. We can say else if and it is important that you put in else in front of it otherwise it will not fire. Or we would have, like several different one moles in one hole, which is bad at all else. If then, if the number is smaller or equal, let's say 25 like 5% then we probably want to spawn a time or if five justice more. We can also use number 10 number aid or whatever number we want. We can also increase this range of numbers from 100 to 1000 and one or whatever we please like. So this is just something where we have to figure what is the rarity. What's the chance to get one off this specific moles? So if that is, for example, of 5% chance to get a time mole, which currently doesn't do anything except giving us points and stuff, we gonna say we want to return three at this point else, if we can do this now for all the other ones, since I have you understood, now let's say number is smaller or equal to 20 or 30. What we want to do here is we want to send out a bad mall, so it's a return to, since once again, bad Moelis sitting in element to off the game object array. So if the number small or eagle, let's take 50 for example. Then we want to create or instance she ate ahead. Mole head mole is, of course, another one. We just need to have to it points, But we're getting more points then from the other malls, for example. So if none of them have been matched already, then we're gonna spawn another one. I think this number 30 here is going to be a bit too big. Probably gonna do it. 20. So we have a total number between 20 and 50 year. That's going to be the range like in between is going to be like a 30 range where we are able to get a head more. Maybe we're gonna have to fiddle around with these numbers later on is well, a bit. So once again, the head mall is the one we want to spawn now, in between 20 and 50 probably We also later on changed a complete system here. We want to return one, and if nothing off that is going to fire, we're gonna return zero. We can also put another Elza statement in here. Like once again, if we don't return anything in front, we're gonna always send out a normal more. And let's say that and tested out, we could even calculate or check out what is the amount off stuff or creatures we gonna get here. The Golden Mall will be super rare, but probably we find some also can see the red mole is present several times, which is good. And every hole is calculating this word on its own. So we don't actually know how much off that stuff is going to happen. The once again. As you can see, it is super rare that a golden mole is going to appear because it only has the number one. Even the blue one is rather rare. But even that doesn't mean we don't get one. And we can now test it out as long and as much as we like. Until we probably one time gonna find a golden mole, we can even increase the number off the golden mole to maybe two and once again is dark because of unities problem in here. So the Goldman might not be easy to see at this set up But I believe because of the color we gonna we would be able to see it no matter what. So as you can see once again, the even the Time mall or the blue had more is not easily seen here just sometimes so was a resolute chance. Actually, between those you have points or the school, that's pretty decent, since we now have the possibility to boost the gain. And we can also test if the Red Mole is giving us negative points. As again see the red more decreased our points by five. So even that is working 100%. And that's good. And that's what we wanted there to get. Golden Meow. Wow, we had so much luck. 24. #23 More Mole Score: since the game becomes harder over time because we yeah, calculate everything times the level and we need to get more and more points over time. But the malls are not going to become yeah quicker or anything. Well, at least not for the moment. We might want to go in and implement the score by mole times, whatever the current levels. Well, how can we do this when we go to the whole behaviour? Were inst enshi aiding the malls. And also we have the aesthetic level, the Starik current level sitting in the game manager which we should be able to Yeah, excesses will. So what we can do is meanwhile we are sporting our new mole. We can go and Greek calculate the current score from the mall times the current level. So what we can do here is we actually catch the mold behaviour a bit better. So we say mole behavior and we give it just ah, any name mold. Oh, no, not more. But mole be, for example, is equal to. And now we do all of that stuff. As before, I I just get rid off their parents stuff because I will need Thio added again, he is always a Moby dot and now we put in the parent. My parent is going to be tested game object. What we also can't do with that more be We can also access now hit points and what we also can do is we can access the school so we can say Moby dot school is equal to Moby Score times gay manager dot current level. If that is not accessible, we gonna have to check it out pretty quick. Okay, Current level is just aesthetic, but not a public aesthetic. So we changed this one to a public static into current level. So from more ba hair from whole behavior, we should be able to access this now, as you can see dot car level so this molby score will be changed or the mall score will be changed times. Whatever the current level is, that means when we get our at level two, we gonna take the current mold score and multiply that by the current level, so meaning in level two, every normal mo will give us two points and instead of one point, every helmet mall will give us 10 instead of five. So what you can do is that as a kid, yeah, easily re calculate all of these scores according to the level as well. So So it is not impossible to beat the level at level two because currently it is not really easy to make it to come to level three, actually, because it is too hard and the moles don't give enough score. 25. #24 Popup Text Animation: let's create some text element, which is a floating number representing how much score is specific mole Give us. So the player actually knows what he has to hit best or what he don't have to hit to get or increase his score. And also meanwhile, were talking to that specific game Optical, that text element. What we can do We can tint the text elements color if we like to. And yeah, work on that. What? We want to do it first. This we want to goto you. I can miss and we're gonna create. And you I text we can now make it s Yes, nice as possible. So we can, for example, type in a plus one here. Just when we get one plus plus one point, we're gonna give it a color. Maybe white The color at the moment doesn't matter. I make it bold and I want to activate best fit. So it's always fitting as yet in our text field. Also, I want to send to this one out, like, in here, and maybe increase the size off the text field itself so it's can be seen in the scene. Light on better with than when we're playing the game. It's going to be seen easier or better. So you can also name it's pop up text or anything you like full of text and what I want you to do as well as create in the u I canvas an empty game object. This is going to be off top. Correct. Transform that we can later go in position that inside the U. Y Camas according to what or where we wanted to be. I'm gonna name it may be pope up holder. So what I now want you to do is take the pop up text and make a child off the pop up holder . So and also now we can send through this one. So at 000 in the middle, how big the probable that is, it doesn't matter. We just need the position off that same for the public text. You want to make it as big as you like to see this damage field or this damage taxed well, not damage text, but score taxed inside the field. When you're done with Dad, you want Teoh, go to the pop up text and create Aidan animation for this. We do this, we go to window animation, we create a new animation. And I called this may be just hope up. And when you have done was that you want to add a property off type wreck transform You want to choose anchor position and press on the plus. Now what we can do is we can reduce the last key frames of a here to B 0.30 or whatever your reason. Like make sure you take all off the key frames. And now what you want to do is you want to add a new property off type text and go to color president a plus. Now what you want to do is we want what we want to just want to animate the Alfa Channel off this color. So I take this lower one near this lower key. Direct us to the middle off the animation. Now go with the timeline to the very end and type in zero here. What's going to happen now? What you can also see in the preview when I go with the times lighter, this is going to be invisible. But I also want to do is with the anchored y position at the very last frame. I wanted to go up so I can now change this number here at any point. I like Teoh. Maybe before we changed, helpful to see better. We can go from zero to any number so we can use the slider in here and bring it up. Maybe to this position where it is, and even if it is outside of the game, object doesn't matter. So what's going to happen now? It's going upwards and meanwhile is going up. What? It should also go transparent. So I changed that on the last key. Frame the Elvir off the text color back to the room so it goes up and disappears if you want to. Later on tin to this number, it is better to get rid off the RGB values in the animation. So we go to this little sign and remove the property. Otherwise, it's going to become overridden by the animation since we're now done, was that we can actually get rid of it so we can close this animation window, go to the pop up holder, and what we want to have now or it'll create now is a little script to excess all the components. So go to your scripts for the right click and create a new C ship script and call it pop up text or whatever your prezant reason, like Now go to the pop up holder again and pop direct the pop up text script directly onto it and opened this one up in mono develop or visual studio. 26. #25 Popup Text Coding: In the last video, we were creating the pop up holder, including the animated pop up text. In this part we want to go and to fill the pop up text script. So what? We want to do it first. We want to make sure that we are able to access text elements. So once again, we're gonna put in here using unity Engine Dog do I name space and we also need to define two variables. The 1st 1 is a public off type text. This is going to be our pop up text directly. So this one which is the child off the pop upholder, So pop up text and the next one is going to be the animator component. So animator and I call adjust. And, um, the animator does not need to be public. Since you don't need to drag stuff inside, we can actually request this 11 start in start itself. We want to make sure that we off course get the connection to the animator component. So we say Annam is going to be equal to and now we say get component in Children and we can type in animator So the first Children, which finds. And then he made a component will be the animator. And since there's only one, there's no trouble. Was that Well, we know want to do is we want to store the animator clip info about this animator component . So we say Animator Kalitta Info and this is returning and array or actually saving data as an array. So we put in some angled or square brackets here and we call it maybe just info on. We set this want to be equal to an, um dot and now we want to get the current animator clip info like the first option over here. And as you can see, it requests an integer and in next, and we're gonna put in zero. So we want to take the first in the list, the first animation clip info and put this into or from the first layer basically and put this into the info array over here, or we now want to do it. We want to destroy this game object after the animation clip has been ended. So what we can do is at first we say with the game object we want to destroy is going to be the pop up text over here because we don't need them after we have destroyed them. No way. Say comma. And now we can say info. And now what we can request here is in square brackets, the first element element zero dot Now we can take whatever the current calypso iss were playing plus lengths. So that means that links returns afloat after we can destroy this pop up text game object after we have. Instead, she ated we're going to go into the instant she ation a bit later, so we don't need updates so we can get rid of it. But what we want to do it you want, of course, to excess the tax component, the public text Over here, What we need to create is a public Reut and always say so, text and then open close Prentice's. We're gonna put in the amount we want to pass over. We now want to do us we want to. So pop up text dot text, and we want to set this one to whatever the amount is. But we want toe. Also check if it is a positive or a negative number coming in so we can give it a plus sign or a minus sign. We're gonna do the request and hear about the amount. So we say if basically, if the amount is bigger than zero so the amount coming into then we can say question mark in quotes. After that, we're gonna put a plus and then we put plus amount means this will return a pleasant than the amount off whichever we're seeing otherwise. So, Colon, we're gonna say amount dot to strength, open, close parentheses and close the line. Was this in my corner? So once again, this is an expression. So like, yeah, like the expressions we have done already in the other videos. So if that is greater than zero, then we return this amount. It was a plus sign in front of it. Otherwise, we're gonna use a negative one, so the negative number will automatically have a minus in front of it. But the plus ones don't have. So we have to put a plus extra onto this over here. Don't forget to save. Even at this point, we could also tend the text. If we like Toso, the public takes you directly so but That's what we gonna do, probably later on. What we now need to do is we need to goto more behavior into our got hit function inside off the else statement over here. We're gonna add score here. And of course, we reset our whole to be empty. But after that, we also want to pass over the text component or we actually want to request it. Or in this particular case, at first we want to make sure that we instance she ate this so and to incent yet that we're gonna need to have a connection to it first. So we se public game object and we can name it. Maybe also pop up text those. This is going to be the pop up text hole that we're going to drag into every mall we gonna have. So the mole is able to instant she ate that. And now what we need to do is we need Teoh. Instance she ate this. So we say game object. I just name it P o P. For pop is going to be equal to. And now we instance she ate the prefab first. What do we want to instance? She ate. Of course, we want to insensate pop up text with a small P, and we also say as game object now, since we have created this one as a game object here we have a direct connection to pop, and we can now talk to that. So the first thing we want to do and this is important the first thing we need to do is we need to set its parent. We could set the parent directly inside the instance Jiating method to save a line here. But let me do it at first year. We say pop dot transformed that sets parent and an open, close parentheses, we can say, or we can request any parent object. In this case, it's going to be our you I canvas, which needs to be the parent. Otherwise, we are unable to see the text because it is only visible in a canvas. So what we can say here is we want to have a connection to hear why manager daughter instance dot transform and what we also that's also important here. We need to say comma, and as you can see, that the world position states we can set this one to be true or false. We want to set this 12 false. Otherwise, we are unable to change its position. That's why we need to do with this first and now we can change the position. So we say pop dot transform dot position is going to be equal to and now we need to have the camera related position. So we say keira a dot main. So the main camera in the scene, the SI camera, which has the tack main dot And now we take the world to screen point and this is going to return a Vector three or actually needs of actor story in this case and what we want to put in its transform your position. So that's the position off. The more so the position off the mole gets translated from a world point to a screen points or can see this inside the canvas and it will yeah, organized that so that the canvas has eyes actually holding the information about the pullup text. Also we want to do is we want the score to be soon. We at first catch Papa taxed was a big P. Then we can name it, maybe m text or anything. It is good to be equal to the M tax. And the m just means maybe message text or you can even name it. Pay p taxed or pop text that up to you just don't confused yourself. And also do not name it Pappas. Well, so the pop text in this case is going to be equal to a pop dot And now we need to get the component off the pop up text. So is that get component open close, trying the brackets, and inside we're gonna request pop up. Text was big p open goes behind it, the brackets and yeah, close the line was a semi colon. Now we can talk to pop text. So pop text dot And now we want to request show text, shall show text open, close parentheses. And this once again is requesting the amount off the score. This is the score which is sitting directly here on the mall. So when we now go here into our prefects, will that we want to make sure that we create a prefab out off the pop up holder. So by dragging it from the hierarchy panel into the prefects part a folder in here. What we also want to do is we want to drag the tax component into it. So I select it here once again. Take the pop up text and make sure that is over here. And since it is a bold, we're gonna have to apply the changes to all the pre Perhaps, and we can now delete it. Okay, let's test it out. Every time we now hit a mall, the pop up text should appear wherever the mole is. Except this this variable pull up a signed reference. And of course, this unassigned reverence exception comes from the mole itself. What does it mean? The mole needs to have the pop up text game home pop, upholder over here in the pop up text in the more behavior script inside the Inspector. So now we go to all moles we have. So at first I start was a normal more and I put the pop of holder into the public text. Same for the time. All gonna put the public text in there taking the head mole put it in here as well and taking the golden more put the probable that the end, the last one is going to be the bad more We're gonna put it here as well. No press play answered work. So whenever we are hitting, though, some of these moles they're gonna instant She ate the correct number at the position where they are. If you don't like to have it always at the very bottom sense it is. Instead, she ated on the pivot point off the game object, which is like next to the ground. We can always go in and lift that up later on. So it probably comes more like over the head or whatever the position is you prepare. And that's everything for now, for the pop up text. 27. #26 Score Fix & Countdown1: in this part. I want to fix that. The score when we're entering the second level is not going to show zero slash and then the scores reach. But the current score slash the score to reach at first. And after that, I want to create a countdown before a new game or before a new round is starting that we always see a countdown over here. So we give the player the possibility to get some small break and then let them continue. This is not needed or actually might break whatever the the style of the game you want. But I want to show you how this is working before we continue with Yeah, some party girl facts, for example. So at first to to actually take care off that the U I manager is not showing zero and start when the new round is going to begin, I want to change this zero to be the actual score we gonna have already here stored in the school manager to do so. We just instead off using the zero. At this point, I want to use or actually use the function off the score manager, which is called score manager door to read, score open, close parentheses and that Basically, it's so every time we reach a new level, even at the first double, we should see a cause, dear. Oh, but as well as since this interview is going to be starting at zero anyways, no matter if we set it to something or not, it should return zero as well. Which also means when we are starting that don't forget to save, by the way and when we're going to started, this is going to return zero in here. And when we now play a bit around in the levels and stuff like that, then we're gonna get the number and the number is going to stay. Whatever it has bean in the last round to Yeah, actually. So the correct number at this point, I can do a small cut in here, so I'm gonna get if some points and we'll be back in just that's 30 seconds. So I'm done with the round. And as you can see now, the score states 156 as it has bean in the last round. So, actually, we are just restarting the level and keeping the correct information basically for the player. So he always knows what the current score. Even if the game starts. That's good. So now let's create a countdown. A countdown is nothing else than an animation, of course, which it has a specific lengths. And at the end of the lengths off the countdown, we said the bowling in the game manager to tell all the game objects. Yeah, that they're able to start acting and they're going to request this as long as we are, how often they are going toe like that to create accountant. We can use just simple text elements directly in here. We can also use graphics or whatever you please and like, but we need to animate them. Let's go and use escape for grating something like that. I just gonna go, Yeah, I just going to create a countdown, which is saying 321 and then go. So I take the textile, Then I of course it makes you that I bring this one a bit up so it can actually scale that . And probably when you are directly in the text field, you might want to give it any different style. For example. I like to use yard sale for my project so I can see stuff better. That's rather bold. Also has a bit of a comic style, so it resume fits me. I can also duplicate this number three now and drank it all over with the control key held down and can change this 1 to 2 and going to do the same once again, Selected control de on drug it all over again. Go to the text tool and changes one toe one and finally I just need to go text so I can just basically copied this one here again. Bring this all over, go to the tax tool, the lead it and say Just go. Maybe it was an exclamation mark in the end, so that makes sure that all of the year off the Aikens or all off the tax is going to stay or be at the same size. So and all of them will have the pillow point later on in the centre, except we're going to change that. But even that doesn't really matter for us. You can now go in and ah actually change the look of them. If you like to or to keep him black or making white When we're making him white, let's try to do this. At first, I add a border around. Um, so I got in a press The shift key. Impressive black color over here. So they're gonna get a border now. Impressed the white color. And this is going to be filled. No, was white. It may be. Doesn't look as you like to yourself. It depends on what the style off the text you're using but the causing about why it is We continue this later on also directly in unity. As long as it is white directly. Or maybe not. Let's say not any other color than white or her light gray, for example. So when you add up, done and heavy was the result, you can even put in some Grady INTs in here. Make its shiny mechanize, make it whatever a gummy beer, like whatever you can always go Also go and export it. So what you can do is you can say you want to export the selection that I say export ass, and you're gonna put this anywhere and I'm gonna name it. Maybe count down, Say safe, save it anywhere I like. And then I suppress on export before I do. So I also want to make sure that size in the height and the West are going to be big enough . Maybe a height of 250 should be fine in here. So there's going to be a pixel so and then we're going to export it. Now, when we are going back to unity and we go to our folder, wherever we have saved that we are able to actually, yeah, directors want directly into unity. So I now take this count on image and put this into yeah, any folder at first so I can't lie. Don't make sure that it's working. I can also create a new sub folder and he and, like, go to assets. Will the create new folder and maybe name it textures or you I elements or call it whatever you like, since I direct this one into the scripts, will that I want to make sure that I put this one into the Texas water and it is going to be here. As you can see, it's right in the centre on black outside, so we have to change the tax, the type of this image to be a sprite. Two D. U. I also, we have to change the spread mode from single to multiple, since there are several different graphics on it we want to use. And then we open up the Sprite editor and apply the changes. As you can see now we have 123 and this is going to be one more. And we can, basically, depending on the size and if there are intersecting each other, we can automatically slice them. So we say, Just slice. When that is done, you can see here that these numbers all are going to be sliced according to it's size. What I want you to do is if they have different heights, like, for example, that's exclamation mark. It's higher than the other, and the's are going to be lower. Basically in its height. You might want to go and take the full size off the complete image and put this to the bottom into the top completely. But don't change anything and in lengths like in the West, Okay, so just make sure everything works. You can also go in and rename them if you like to. And you can say you want to have the pivot not in the center, but we gonna use it once you're done was that we can apply the changes once again You can rename this year to be just 3 to 1 girl gonna show you induce a cyber hit three to one. I guess this is not it. This is a one here. Oh, it's going to be three. Sorry. So three, then this once again is going to be a two hit enter to apply the changes just in case. And this is going to be our goal with an exclamation mark. So we later on find them easier, applied the changes in the editor in the top right over here and close the window. So what we now have is like four different yeah, sprites and here which we can make use off. So the causing is we can now create a new animation which is going to take all care off their 321 go. But before we going to do that, we're gonna create an in our you I canvas a new image where we can put at least any number off these inside, We can make sure everything is going toe work. So go to you, I can miss. And now we create a new you on image. So we can do is that we can just place in the sprite just a number one, for example. And what you can see. This is going to be not hell holding the aspect ratio off the image already. So what we're going to do is, we say, expect or preserves the aspect ratio with this butter. Also me right mean we might want to go and scales one up. You might also want to check how goal is going to look. And if gold doesn't really fit the size, for example, you can spread it out in here bits, so make a bit bigger. And, of course, the bring the complete size of it down. So in the end, like goes when go fits and hear, all the other numbers will also fit in here because of the size off the privy or the one we have. Cut it inside the game in the stride editor. So we have that in its year. So we now do is we need an animation for this. So we go to add component, or we go to window and say animation and we create a new one. And I call this animation gonna put this into the assets animation folder in here. And I named this maybe countdown and hit apply to save the changes. Now, what we're gonna do is we, dragon, like all images here inside this bar and what you can see, it is just like an image, an image Sprite, which is changing its appearance. And what we can do is we take can take go, for example, and bring this to, let's say, the sort second. So we're gonna started X ray. So everything go here to three, then I gonna take. That's a number two and I'm a one. Number one might be a two seconds Number two might be at one second and number three is going to be at zero second. So what does What does it mean is just check this animation over here. When we play this, it's going to play 321 go. But as you also have seen is that the goal is not long seen or anything. So we need to duplicate this goal and put it may be on to a force second as well. Okay, since we have the problem in here that we are unable to directly copy and pacers, I just drank another goal. Maybe hear directly on 2nd 4 What we want to do is so in this case, that holding down another Ah second in this case, you can even reduce the size if you like to. But we also want to do is we want to add here an animation event at the last Rehm or maybe a front of frame before this animation event is going to trigger a bowling. We don't have a the moment, but we want to do so. Actually, we create that in a moment so we can just add this animation event to this specific function. So what we want to do is with dad image. We want to maybe rename it to count down or countdown in its whatever you like. And in start, this is going to be deactivated. So and also, since we want to talk to the game image as a specific point, we need to create this group for our countdown. So we go to our scripts folder and create a new see ships gripped. Call it countdown and we open up in Amman. This amount of developed over just Ilya whatever you like in place. So we need now to functions at first a public function which is triggering a bowling in the game indigent to this able or unable countdown. And if the countdown is done or completed, then we want the game to really start so we can create the public warrant. And maybe we're gonna say, say, set countdown open, close parentheses and then here we just need to talk to the game manager. Well, we also want to do is you want to trigger that countdown and want to disable the count on itself. Also at start. So in white, start looking close parentheses. We want to make sure that this game object where this sitting on is going to be disabled. No, actually, we want to make this one er enabled. So we say this dot game of dec's dot said active is going to be throw because in the next round, this one might not be seen because we're disabling this one in here in the set Countdown. And so let's go to the game and its own creative bowling. I gonna trade aesthetic ball for this. So aesthetic bull count down. Done. And this is going to be said to be false in the beginning, so we don't need to do anything but what we want to do. You want to? Yeah, keep track on this and we want them to make sure that set Countdown is talking to the game . Energy count on down is going to be equal to truth. 28. #27 Countdown2: since we also have the problem that we not just can access aesthetic bulls except there are private. But also we later only to make sure that we are able to start the plane time. I'm gonna choose a different or another way in this case. What I'm gonna do is we're gonna make this game into just static class so we can. Over the instance, name always talked to it. So how can we do this? We say in public aesthetic game manager. So it's going to be the same as a class name and now we give it an instance name. What can now do is that instance name actually can directly access all the bullies and all the other stuff when they're public instead of using aesthetic one in here. We can just make this count on down to be public as well. But we don't need to make aesthetic because we are unable to call the play time. And when we are just using aesthetic member or very able also, what I want to do is I want to say white, a wag, open, close parentheses and then here we want to say instance, is going to be equal to this. That makes sure that we are always having an connection to this aesthetic game manager instance every time awake is going to be called. So since we have now the countdown done here nous accessible for us. We also have the possibility to start the Corentin play timer from the count on Down faction. So, Steve, even so, this countdown is no accessible So we can say game in a gentle it instance. You know, it's count on Done is going to be equal to trip. So and then the final steps are basically we want to make sure that this game object is going to be set to be fold so invisible when we're done with the countdown. So he set this one here to false. Also, when we want to do is we want to start the plane timer. So we say game in a gentle instance dot start co routine and on close parentheses. In in quotes, we say play timer and off course, and the line was the semi colon. When we go back in here and you are not sure what the play timer name is going to be, then just look at it CO p It may be and put this director here, but make sure you put this in quotes. Now we go to the whole behavior, which is actually taking care of the spawning directly, meaning when we are in the spawn, we want to make sure that we say and if the game manages, So if there's no hole in the more and more in the hole and game inundated instance, dot countdown done is going to be saying is equal to true or we just say Count on done. Only then go here and create a more. And the final step is just we need to call the set count on function from the animation event. So you copy this name over here, then you go to your countdown image. Ignore the arrow messages will disappear anyways. Also, make sure that you drag countdown script onto your calm down image over here and open the window for animation. Now, when you are in the less train, you might might want to check if you are able to select the function directly here from the list or you just drag it or paste it down inside of this functionality. So what you gonna do is just cruel. Super march down to the very, very, very, very end over here can take a while and there's going to be our set countdown function once again. If that is not available for you, then you couldn't go and use the other approach, which is just where you have to feel in the debt A completely. So just make sure that this is sitting on the last key frame over here, and then you can actually close this over once again. So make sure countdown is always enabled in start so or actually unable in your you I canvas and now we When we press play, we see 321 and go and wants to go is done. We're gonna get this moles here and we see that the timer is running. And also meanwhile, we are playing in the next level is going to be loaded. Everything should be. It's so that the counting is going to restart itself again. Like once again was 321 go because it's activating itself automatically after the time has year run out and we should be able to continue when ones that the goal is going to be deactivated. So I just wait out the seconds and here to show you the result. Now, the last two seconds and in the next level, once the timer is over Oh, I haven't got enough points. That's bad. But again, this is going to work. There's no problem was that even if I had didn't had enough, Ma, yeah, stuff in here and the count on down will automatically earn able itself, because in start, it's going to set itself to be active to be true in the next level. And also the whole behavior, once again is taking care of everything, sporting only when the game manager insists is actually done or the count on in this particular case is done. 29. #28 Particle Effect: Let's create some particle fact, like every time we're hitting a mole that on the hit position, we're going to create a small particle affect like stars, Or I don't know anything you like. Or maybe some swelling elements, whatever. And two so that the player was able to hit them completely or the more completely. Also, the last thing I wanted to tell about the count on image Over here, you can always go and intend this white, as I already explained, probably in the last video. But I didnt showed how you do this. So I can easily go in and make this one, like into any color you like maybe some green red, whatever. But make sure the your choose to correct one, since this is going to be a global color over here, like for every image. If you want to change this like in the animation, then you're gonna have to go into the animation and put in the color off this image and change it over there according to whatever. Then, yeah, the number is going to show, but nothing fancy was dead. You can easily do this no matter what. Okay, so for the particle systems I would create like a star and maybe some little let's face, not sparkles. But maybe some long images which are just spreading out in two different directions to have ah rather it good impact on this. I gonna using escape once again for this. Since there are stars easily created, we can just say how many corners we want to have to select this yellow button over here. I want to have, like, six spikes and I can't drink one out. What I can also do is I can say how round I want thes corners to in the cause of death for in the negative direction. I probably don't want to have it like that. So maybe it's something like this. Also, I can say what's the distance or the spikes in between those so gonna reduce it a bit, Ian There, maybe I find a cool number, which is not like this. Let's 8.5 is going to be that so maybe 0.7 or something. I don't know if that is Yeah, not appealing for you're probably gonna change back to five. I don't know it. Maybe we're gonna put in a 50.6 year, which might look a bit better. You can also tend thes or you just leave in white feel that was a black surrounding or get rid off the black surrounding completely. All that once again, it's up to you and what you also want to do it is you want to have some kind of, I don't know, just some slim, bold arrow something I don't know. What's also important is that we're gonna put some black background as a rectangle gonna create one When I hold down old key, I can make this like Ah, yeah, evenly spread when I go with diagnosed, then it's going to be the same size in all four directions. I want to make the one black and get rid was holding down shift key off the border. Since I don't like to have this border and I want to duplicate this and bring this to the right and make sure I snapped this to the corner by activating this little function over here and of course, somewhere here, like are snapping together. So this is going to be my spreadsheet, basically for my particles. So when I direct these over and cannot see them. So I want to bring them into the very upstate for the star. Bring this up here as well. Maybe position that according to whatever, it's under it. So it's centered inside of its so to center that you're gonna use thes past tools here gonna say center like this center like that. Same here. We can't center it here as well, like was thes two options. Okay. And that's basically everything we need for our little effect, and now we can export it. So there's going to be just a text to seat in here if you don't like to work with cheats and your can just simply use one and like one piece and then the other piece. But it is important that you have a black background and these, otherwise, it might not be as nice as you think off. So I select them all once again, a choose a pause, will want to have those or just renames something here and there. So it's going to be my party girl stars or something. You can name it whatever you like. Once again, you can also say export to and can direct to go into the into the unity full that if you like Teoh and then you want to decide the size so might not be smaller than 2 50 in height , but the higher the better because of the quality. But I don't think that is too much is needed. Maybe 3 50 or something should be more than enough and that I just press on export. So once again, back to unity. We're gonna see that not at the moment. But I gonna direct us in from my little folder in here. Bring this into the textures holder so I can see this. Once that is done, we gonna have to create a material for this. So I go to the materials fall there are created your material and I named this one particle a fact or something, and you can also name it stars whatever they like. And what you want to make sure that you put this texture to the material you have created into the poor in the to the l B D O town. Also want to go from standard shader to be a mobile shader and then you go to particles and in here you're gonna have additive so as against it will automatically cut off everything which is black. And everything which is white currently is just yeah, what it has to be. And that's nice, since we now can make use off this texture sheet also in particle systems. So let's create the particle system. We're gonna go in here, and first I want to have an empty game object. I got zero this out so I can see this one better. So I reset the position completely and and name. It probably acts on the school particle stars or just stars, whatever and what I want to make sure it is. I want to create the particle system as a child of it. So we say particle system and I can see it's seen already here in the scene because it is centered already at the 000 position in this game screen. We can also double click and go next to it, so I can't see how big this actually is going to be. But also you can see it's not looking as we want it. So since it's just spreading in one direction from wherever, so what we want to do is what I want to do is I want to change the emission type to be a burst type. But before we do so I want to make sure that I create a sphere instead off a yeah code. You can also reduce the Yeah, the radius 2.1 or something. It doesn't really matter. And since we're gonna have, like, a one impact at a time anyways, also, we want to make use of a Texas sheet animation. So in this case, we just want to make sure that we're using stars at first. So we are not taking the wall, She but baby a single rope. And this thing road comes, of course, from the material we created. So we go to the renderers and shoes instead of the particle or D for particle here, we gonna shoes our creative particle. The fact over there, as you can see, it's like of wrongly oriented or actually is the orientation is correct, like it's always Bill boarding to the camera. But also we need to see, like, bows like the star and this little sparkle thing. So what we want to do is we want to go to the single roll of fact here, and we want to change that tiles. Toby, on X, we have two tiles and we have one tile on the Y axis. So we only see the stars now, since it depends on which rain we're starting. We started frame zero in this case. So we're gonna see this little stars over here. So when we know want to do is we want to reduce the size of it. So they're not too overwhelming in the scene, of course. Meaning we gonna go to the start. Ah, size a. Probably direct this one down. Like to this, like 2.4 or something. We can also make sure that we're gonna say, render between two constants. So we gonna get lots something like between point for two, as we already have chosen. And maybe it's something smaller 20.2, so they're gonna randomize its size a bit. Yet there also the lifetime does not need to be that long. So probably a one second and after that, want to destroy its aim for the duration is not longer than one, and it will automatically repeat itself. But we don't want to look this, but we gonna deactivate this later on. Also, we content is already like, but random between two colors or based on a Grady int or whatever we like. So we maybe want to do something like random between Retz Ah, maybe something yellowish orange. So it's always changing that color to whatever we want, like a randomized over here. And that's basically everything so far for the particle fact. We just want to make sure that the emission type is not rate over time. So we set this 1 to 0, but we add a burst. So we say plus, and now we want to burst like 30 in the 30 pieces off particles in a specific direction. If 30 is too much or the lifetime is too long, we can always go in and do something against that. If the speed is too fast, of course, you can reduce the start speed to everyone. So it's just like it's slim over here, so I'm gonna direct the particle affect a bit up. So probably that's why we have some little issues when it is going through some areas over here in this three D, probably there's something we gonna need to take care of it. It's changing itself by the animation type, so it is currently at first showing the star, and after that it's showing this stripe. What we want to do is we want to change the frame all the time to be to. In this case, we can also set this one toe wonder. Doesn't really matter what you want to make sure that it is keeping on that. So when we are taking the zero, you can see it's only taking stripes and frame over time. But when we're putting at one or higher, it's going to use stores, which is good, so we can always see stars on the screen as you can. Also see this size off. The stars might be too big again, so we probably want to really use them to appoint 12.2. So it's not that fancy affect. So also we can rename now the particle effect to just be stars, and the next one is going to be a bit different. But it's going to use the same particle fact, of course, so we can now duplicate this instead of using stars. We want to use the stripes now. So we go to the Texas sheet animation on. We change the frame over time to be zero. Also, we need to go to the Render and change this one to be stretched billboard. So these stars stripes are going to come from the center and, of course, spreading out as the stars are doing. So we can also go here rename this to be maybe Stripes, and that's pretty much nice. The last change we might want to go is a color over Lifetime opened this one up and take the right flak over here and change its l for to be zero. So it's going to become invisible over time. You can do the same for the stars. So you go to color over a lifetime, opened this one up, go to the upper right flag and reduce Alfa 20 So it's automatically disabling itself. And the complete effect is now looking like that. So we have some stripes and some stars go through the complete scene over here. Also, you can see some how the stars are now always taking the stripes with them. Why ever I don't know so and That's our complete particle system we want to create light on . At first, we want to make sure that we have set this one not to be looping, so we disable looping over here and here. We need to destroy script directly on the particle fact. So to create this destroy script for the particle fact, we go to create new seizures script, and I call this destroy me and on the particle or in the F X particle stars, we're gonna put the doors, try me script over here and in start. We don't need update for the script. In start. We just say we want to destroy this particular game object. So destroy, open, close parentheses, inside would pass and game object comma. And then we're gonna put pass in a destroy time. We will create this in just a second. So I copied the name, destroyed time and put it over here. It's afloat, destroyed time. And I said this 1 to 1.2 FSO 1.2 seconds, Meaning I wasn't our country. Our animation runs like one second because the lifetime of the particles it's not longer than one second. And after one point to the animation should be completed and disabled and stuff like that so we can easily destroy this particular game object. After this time, you could also make this from public in here. So we're gonna make like that. And the cool thing about the public is we can easily excesses later on, also from this particular particle system. So we can pass in any data in any number we want. We go to a previous water and put the particle effects stars directing here so we can actually yeah. Instance, she ate them on hits. 30. #29 Instantiate Particles: the final step, for instance, she ating now the particle effect after we're hitting or where we are hitting the mole is pretty simple. We're gonna open up our input manager and in here we just froze Create a public game object . So we want to have a connection to the particle system or particle fact we created. We call it, maybe FX stars or something. And now when we are hitting a mole, I want to make sure that we instance she ated over here. So we say instantly, eight close parentheses and now we want to incense she eight FX stars, Comma. Now we want to know, where do we want to add this? We can say hit dot point. This is going to return the mouse position or actually the the hit position on the World Point basically, And then we say comma quarter nian dot identity. So for the original rotation off the Yeah, actually, the ethics stars, So that's basically it. Of course, we need to make sure that we delete ethics stars from the scene. Otherwise it is going to be or state in the scene. And once the countdown is done and our time is running and the first most coming out, no matter what kind of more we're going to get in undersigned reference, because we forgot to say Game in a job and give it our created ethics particle system. So we go to the game, injure and direct the ethics particle stars into the ethic stores slot into the input manager. Don't forget to save everything and try again. So once again wants to count on. It's done. At the time I started, the first more's coming out and we hit It may be here. You can see it's going to be created wherever we are hitting the mall. It doesn't matter which more you're hitting. But every time you hit, the more you're gonna have that impact or that particle system created, and also after the given amount of time, the body go system is going to destroy itself after, well, whatever the destroy skirt script, Saiz 31. #30 Game Over & ScoreHolder: now, since we have done the countdown and also particle effects on the mall where we're hitting them, we can also go and talk about the loose condition. That means when we end the game image, of course we gonna have, like, the check for wind functionality. But also, we are not doing anything on game over. We have a ton of possibilities to do so we can blend in some user interface. We can show the score in another scene. We can do so much things according to whatever we like in place, So before we do so I want to make sure that I hide the count on done into the inspector. So I just put in this little square brackets once again and say, Hide an inspector since we don't want to have access to it or change anything by, like, accident or something. So I just at this one in here, So talking about once again, the check for wind, the easiest approach in here would be just we pass over data to some school, hold ago, a game object or something, or actually script and go to a game overseen where we are showing the player what you've made so far. So what we can do by that is there is a simple We can just read data from here. We need to check or actually change some things inside the game in inter anyways as well. And then we take over the current score or the needed score from the score manager, of course, and put this into another score holder objects, for example, or a score holder script, which is doesn't need to be necessarily yet in the scene. So how can we do this is first, I would go and create the game overseen, so it's just a new scene. We can already saved that. So we guess a safe scenes and say, there's going to be a game over and just save it. It's empty. Nothing in here, but what we can create is like user interface. So I create a new can this, for example, and this campus doesn't need anything except the chemist. Scaler changed that from constant exercise to scale with screen size. So just to make sure that all the U elements later on are going to have the same size according to whatever and wherever they are in what scale they do off cause as well. So now I go to the camera and make this one maybe black, maybe yellow. You can put in images. You can design it as much s you like. I'm gonna make it black and put a solid color off a here instead the camera. So we don't see the skybox anymore. But we have just a background color off black once again, you can make in any color in here whatever you like in the cameras. Already or also, I want to put in text element and put the text in here like game over. Or you can put in anything you like. You can also put in like you lose or whatever in motivating text you're gonna find gonna name this one as game over attacks over here. And I want to make sure that I put a best fit as well and make the color. Maybe repped so can see this one better. And we can also go here into to demote and scroll down a bit. And of course, make sure that we scale this s much as we please and like, and also maybe put the maximum size to be 60. So game we're gonna have something to play around with, as well as putting the pot the fund style to be bald. Then we can center this one, maybe, or put this anywhere we can make animations you'll really know how to do. So my putting something up and down, making it invisible. Just let it bring Link or whatever you please in like So Andrew, the game over tax I want to have, like, what's the best level you had so far? Or the player hats? So I gotta duplicate game over text and put in something like your score. We're gonna put or change this one later on as well. So is maybe it's something like 100 I put this one a bit down in here and reduces toys off this little box a bit. So it fits maybe better like that, and turn to color to probably white or anything else. And we can take this one once again. Off goes rename it. So it's going to be a list squad text like this, and we can duplicate this once again as well. So press on it duplicate again And if you have these painting error here, just drag around some values or some yet out some text that's going to update, then this is going to be maybe our level tanks. So the highest level we have reached so far, so your highest level or whatever you like, and it's going to be it's any number if you think this is going to be too small like when you're putting any number. And here, like level 1000 or 100 that you can always go in and make this year but longer like to. So there's more space in between. And actually, there can be like super big numbers inside, as long as the interviewer size is not going to become, Yeah, let's say two bigot this case. Okay, that's pretty much everything we need in here. Now. We just need to have the canvas, a connection to these texts elements and update them like when the scene is loaded. So we need another text or actually a script in here. We say we named this one game over a screen or something were menu. We also can create some input for this, so we go to the canvas itself and we put the game over screen stuff error in here and open this one up in model, developed or visual studio. And basically, we just need to have connection to tax elements. So at first we implement once again using unity engine Do I. Otherwise, we don't have access to text elements on. We have, like, two holder objects in here. So we have, like, text in this case, a public one. So public text, it's going to be our level. We'll always score texted first, maybe score text, and we're gonna have another public text was a big tea on level text like that and these are going to be filled according to whatever the score manager is going to do is a score holder we haven't created yet. But we will in just a second. So on and on, start, we just want to make sure that we are updating the score text to whatever the text has to be. So in this particular case, we can say, for example, the same as we have filled in here like school text dot text is going to be equal to that. We're gonna put in some text like your score, as we already have done, then that may be a space, and then we can After that we can put in any value and I'm gonna keep the value. For now, we're just gonna copy that line as well. And we say, Instead of school text, we use level text, don't text, and he is going to be your A level, for example, your level. It's going to be this and in here we going later on putting arguments where we can read from, and what we can do is we can create a new script which is holding that data. So and we just laid on When the game is over, we feel in the data and we reset like everything else. So we created use teachers groups and we call it maybe score holder and, of course, opened this one up in mono. Developer visions stood you and school holder does not derive from money behavior. So we can, since it's just going to stay a extra class. We don't need direct access to it, but what we want to have it's like two very able stored in sight. So at first, want to store the square itself. So we say, Probably ecstatic. And then we say, score and an open close. Kohli braces. Oh, it's off type in today, of course. And we say score and open close curly braces, we say gets semicolon set semicolon. So we able to read and set this data from any point in the game, no matter what, Even if it is a non static, I guess it should work as well. And we can do the same for the level. So is gonna put in level and just save that so we can say, plus score holder God's as you can see now we have access to a level and score and we just pick score. So and this is just getting reading out now. So what we can also do here is we're gonna put this level in here as well. Don't forget to save. And now, when we would press start, we should have, like school this whatever it is with two zeros over here. Except there's any error that's clear. The consul. No, no, Everyone So and now we're gonna get in our reference because we don't have set the text and the level text for these. So we go to the canvas and then here we drag now the score text into that score text and the level text into this little text press play and I cant see scores 00 in the next part. We're gonna send over the data to the school holder. So we have in the in the game overseen the correct data. 32. #31 Reset Score: in the last part, we were creating this game over screen. But now we need to take share care that the score is going to become the correct score and be soon inside the game over screen. So what we need to do is every time we lose, like in the losing condition, we want to load the scene. But beforehand we want to upgrade or update the score holder taxed over here. How can we do this? We go to our game manager, open this one up in model, developed, introduced studio or of it is visual studio. I mean, and we scroll down where we see game over here, like in our check for wind functionality. So at first, what we can say is score holder dot score is going to be equal to score manager dot reid school open, close parentheses and close the line with a semicolon. So we get the current one. Since we are in the game energy, we also know which. Yeah, what is the current level over here so we can passes over into that as well. So score holder dot level. It's going to be equal to current levels of Carl level, and we're gonna put this inside of that as well. And the last port is we gonna load the next scene. So the game overseen So we can say, See, Manager, don't load scene. We now can put in any string number or the build number, the built in next number. Whatever. I just use this game overseen as we have actually safe that one. So and this debug line will not fire anymore because we are already in the next scene. So we can just get rid off the D back line here, and that should be it. So when we know go back to the other scene, like toe a demo scene like here. We, of course, safe the changes if we haven't already and we play around and we gonna maybe not win so we don't get let's say we get some score, but we don't want to get like a true, you know, score, but as Yeah, at least a bit So it can see that the system is correct. Correctly working And of course, um yeah, we understand or actually, the system shouldn't know which level we are in. We are currently not showing this for the player. But if you like to, you can always do so. Then we gonna wait until the timer is done and we should end. Where's a bad number, or actually, just 80 points in the score holder and this goal holder should hold or should have this number until the next time it's gets its gets overridden. That means when we're starting the game completely new, of course, the school there will not take care off the Yeah, whatever numbers on site, but as long as the dest attic, it's not getting over written. There are some problems with problems with Dad as well, so actually for the game and the job. But we're gonna take care of thes later on, no matter what. So ends the game over could not be loaded because it's not into seen build. So we goto file built settings. We want to add the current open one, and we can also drank the game overseen in here as well. That's where if you want to load the build and next year the numbers behind that are going to be the building next, so we have toe actually make a recheck over here. I could even go and reduce the time or the time at all. Why? I just do a cut pretty quick here before or until the time has run out. So we have the last two seconds over here, and now we can see we have the same score as we had in the end, off the video on the end off the round off 88. And the current level, or our level has been one. And also the game overseen has been loaded. So no problems with that. Now, we just need to have an extra input over here like, well, actually, just any input, Like hitting the space bar to get back into, like, the menu or to restore the game. That's what we can do already or actually implement already in the game overseen. Yeah, Port over here. So meaning since we don't have a menu yet, we gonna actually set it a bit different. So we say, if input don't get key down, and now we can put in a key code. So we said he could dot space. So when somebody is in the game view and per hitting the space at this particular point when we say we want to load the new scene or any seen using Ah Unity engine dot seen management is important over here, as we already learned. So we say seen manager dot load scene and we can now once again lowered a built in next name a C name or whatever. So at this point, we probably want to reload demo, and that's basically it. And later on, if you have a menu seen, then you want to go to the menu scene. And the thing is, we can now testers went out again. Oh, it I'm a little type of and here it's get key down, not get buttoned down. So just make sure you have that already. I believe I talked about it but were written something wrong. So we don't have any problems in here as well. And when I now go, for example, to the game over scenes, I go to assets demo in this case, game over and press play, and I'm in here now in a pro space. I should start in your round in the game. The only thing we don't do is probably is resetting the score on game start when we have done something already so I can test this one out. I'm gonna skip ahead a bit and you can. And I explain what's going to happen after the time has run out. So now I played like two rounds. I will lose in the second level, so I can't see it. Is updating to your level is level two your score wars as 386 as it was. And when I now hit space, everything is still the same school. And that's a problem, since we need to make sure that we reset the score to whatever the scores has to be, as well as reset the static level. And to do so, we gonna have to go to the game miniter and create a bowling. And this bowling is going to be our protector as well as our update er, absence on start. We need to reset this according to whatever the bulls say's. So at first, let's create this bull. So it's a pool. We a name. It has lost, and we said this one equal to fall. So actually, we don't need to set those, but we can so in start. We want to make sure that if has lost is equal to true. So it has lost over this rant is's. We want to make sure that we set has lost to be equal to falls. So we set everything back. Also, this bull needs to be aesthetic bull just in case. Or actually, it needs to be aesthetic bull. When we set this, it needs to stay static so it would ever status. And also now, when it has laws, we gonna reset like all the score. So we say, score Manager, don't. And now we gonna need to create a new function. So we say score manager dot School needs to be reset ID so we can create in the school. Mention your function here like public static void rename it reset, score, open goals, parentheses And then here was just say, score equals zero. So we just recep the school and in our gay manager back in our game manager again. We say score manager dot reset score open goes friend to seize, and that's it. Also, since we're currently here in the game manager, where's the current level stored? We say current level is equal to zero or in this case, toe one. Since we want to restart everything on level one once again, don't forget to save, and that's pretty much it. Except we need to talk to the game and just bull has lost. Now we can say has lost is equal to true. So now we protect everything by this bullying and every time has lost is going to be true It everything is going to reset it like the reset score as well. Ask the level time to test. So I start once again in the game. Overseeing doesn't really matter. I let the time around and off course I now skip ahead like several seconds again s Yeah, I did already. And the other ones. And once I'm there, I'm gonna show you that it is going to resent itself once we have lost. And once we gonna start in you round. So now I have 37 points in here are going to get them all over to the game overseen. Also, the level is going to be one. But when I know he hits a space, keep everything is reset to whatever it has to be because according to the current level as well as the current score, and that's what we wanted 33. #32 Blinking Text: Now we can also create some little year tax element which is going to blink or going Teoh become unable to disabled over a specific amount of time or something just in animation, off a text with a showcasing that we have to press start or the player has depressed start or space or whatever, or maybe a button or whatever you like and police. You can go and put a button here and whatever once again you like. And just to indicate that the player has to get press the space key or whatever the button . So how do you do this? You just creating you text? Let me just copy my level text in here. Just don't duplicate this. It's a press space one. Also, it has to say press space to continue basically, and we gonna make sure that we direct this one down over here as well. We make it like, a bit bigger, and we can also say that we want to put this in the center like everywhere recent center here in center there. Make sure there's no line as lips line over here, so it's a big enough, and we have no can once again. Oh, that's a bit too big. We can now scale this up where we can't just hide. Ah, and show the Yeah, actually, the color off the text so we can go to window animation We create in your animation off course in our animation. Full, uh, it's like so hide was something or blinking text bling gang text and in linking text, we just add a property for the text itself and we're gonna pick the color and you can also tip the color over time. If you like. Teoh, I go and remove the other color properties. And here's I can prayer probably make another color in here, and then I go to you one second. Or let's say we take this elf of l U and put this year to 30 seconds. Then I go with the timeline over here and create another property, which is also a one. And in the center I gonna use this property and reset or set this 1 to 0. So so meanwhile, we gonna start here with elf off one, Then we go here. This key should now be zero. Do that again and go here to this key frame and this should be the key Frame number one. So we know press play. You can see that the pray that the press space bar key over here is just animated or just attacks is any made it by its l for once again, you can make it bigger and smaller. You can scale it. You can rotate it whatever you please like. Or you put buttons instead of text toe. Highlight this information over here. So this one just needs to be centered a bit. Maybe put it a bit up. I don't know. It's up to you how you want to design that. And don't forget to save the changes. So when you know, press play once again, you can see as a blinking text overhears nine press base so the player knows. Okay, I have to press base to go back, for example, to the menu or wherever I like. When you go mobile, you might want Teoh instead of using space. You want to use buttons at this point 34. #33 Main Scene: now, since almost everything is done, we can also create some kind off menu, see, nor main seen or whatever you police and like. So we created you seeing I may be called this one main seen or some things I can't go to file and safe scenes. And I want to make sure that this is the main seen or just main. It's up to you as a typo gonna rename this one in here pretty quick. So instead of from game going to game over, you might want to go to the main one in here. Once again, you can be as creative as you like. And please, you can put in any images you please and like you can put in text like the name off the game. Whatever you're creating, like in this case, you maybe what probably want to say welcome all and there's a probably is going to be your main title. You want to center this probably out in here, give it a fancy nice color or you color it by a rainbow. You can also use escape to create all of the's. It's all of that is up to you how you want to create this. You can once again any mate that things make that one bigger and smaller Play music in all the other things in here. And of course, you want to create buttons to go to the correct seen. So let's create a button here. There's going to be our play button. So, like we opened this one up and in here, we gonna put a play. You can also put an arrow on arrow in here. You can once again again here. You can also make this one as big as you like a small issue like you can into to demote. You can make these buttons big, Small. You can position them anywhere you like. You can put settings, buttons and all the other stuff is all up to you. Once again, even the main camera you can get rid of the sky box. You can also use three D elements. I can use particle facts like falling skies, rotating whatever, making some animated movies coming out of holes or just create anything you want in here. What do you want to what I want to show you is how to make this button function now So at first on this button or anywhere, we need a script where we can have actually, Yeah, well, we can't click on so we can take this group and put this directly on the canvas or directly on the button. Actually, it doesn't really matter as long as this has the connection to the canvas or anywhere s a mother or a main object. Once again, you can also put this script directly on the button. I'm gonna show you. So we go to the scripts, will and maybe named this one the menu script or something on main, just Maine. And I can put this once again directly on the canvas. It doesn't really matter And put this on here and I need a function on this where this button can talk to. So what does it mean? That the button needs to be a po Are the function you to be a public function? So we say public, then its all time void. Since it doesn't return anything we say play button. You can once again name all of that. However you please and like open goes Prentice es and behind that, we just want to make sure that we're loading a scene so we can say using Ah, unity engine the door. See management in here so we can load new scenes. So we say, see, manager dot load scene when we're pressing on this button and we want to load the demos seen so we just say demo. So if yours is going to be a level one or just level whatever the name is, you can put this also, you're able to use that once again the built index if you like to eat up to you and that's basically everything the but needs to do. And so there's deriving one of behavior and we need to have to take direct access to the play button. We could also use some other functionalities, but this is the easiest one. We're gonna create this and make sure it works so far. So for this button, you can also rename this one Teoh, if you like to to apply button. So you know later on what this button is about. And what you want to do is you want to add an on click event and now you drag in the canvas where this group to sitting on. And now we're gonna go to our main and from the list we gonna choose Play button. So everything which is sitting on the play button and were pressing on this we're gonna do whatever is in the function off the play button. In this case, it loads the scene demo, That's it. And now we need to make sure that we put in the main menu into the build settings as well. So it's a little settings on. We put main into the list. Now we can test this one also when we press play And, of course, get rid off that you can also see that Ah, something wrong here. And But when we press play, we're gonna go to the demo scene. And, as you can see or have seen, that is has been reduced its size. We forgot to put the canvas scaler from can constant exercise to scale a screen size. So once again, when you're doing this and you might have to argue yeah, actually rearranged these items, Maybe you make them bigger once again, according to a screen size, you're gonna have, like, a mobile game or whatever. And when you know, press play, everything should be and the correct size. Once again, when we're no pressing play, the game is going to start, and that's everything we need. So far, there's one more thing you want to change is when you're going to the game over screen in here and open this one up in Montana develop and precious studio or visual studio. You want to change this run from Lourdes in Demo, You want to change this one to load to the main. So when your game over and you're in the game overseen, don't forget to safe. Like every change you have done so far in the main seen as well. And we go now to the game overseen and press play and we hit space. We go to the start screen and then here once again, we're gonna have to play button and we can go and play the game. It's basically everything we need so far to have one round or actually one way from one point to the to the other as one most more thing you might want to take care is that the main seen the like the starting screen is always going to be in top off this, lest if you're unable to pit, put this one in top of Let's just take the demo one and put this one down. So and do this until mane is going to be on top, like on level zero, because the zero built and X in here will be the 1st 1 loaded inside the build the other ones don't met doesn't matter because we are talking to them by the name. Also, if you re arrange these items, make sure that you update that build index. If you are using the building next instead off the level name or seen name in here, that's everything. Just make sure you're safe once again, just in case. Also safe the project settings if you have done any product things in here, but basically that's everything we need to do for this particular game. So far, 35. #34 Clean Up: There are some small, simple things we gonna have to do in here. Like when the game is starting. We and we are hitting, for example, some malls. We're going to get some D buck lines like in the console. The point is, we don't need thes debug lines anymore in the game. Also, like everyone were game over. We don't want to have any game over here with when we are when the timer is over. We don't want to get the time over D Brookline and all the other staff because we don't need them. So what we can do by this is like we go through everywhere and commend out any D Brookline we have in the game. So we can basically look for them like wherever we have debug lines like, for example, here, time has ended so we can get rid of it. In here. We attack for win. We don't need the you want the level. And also when we have, like, anywhere else, any d Brookline's left, we don't need them anymore. So make sure that you get rid like off all debugging purposes, debug lines and everything else hitting the console even if it doesn't, needn't even if we don't need them anymore and make sure you get rid of them. So clear the consul tests again and see if there are any debug lines coming up. Play. Test your game until the end until you don't like to anymore End, Of course. Make sure you can create a bill from these now, since everything is set up so far except, let's say, great game over screen or great main menu. But once again, you can design this to whatever you like and place. That's pretty much everything and concludes the complete welcome or course thanks a lot for tuning in. I hope you learned and enjoyed it, and I hope you have no questions. But if you do so, feel free to ask me any time you like to get your game super nice. 36. #35 Conclusion & Ideas: So as a conclusion, I want to give you some more ideas which you can implement, maybe for this particular game or kind of games. For example, what we didn't show is a lay A level text, so you won't maybe show the player every time you change a level or he's going to the next level and so on. You maybe want to keep him. Update was another text element. And since you already know how to do it, I think you are able to do so also what you can introduce. Probably a combo system so you can get like a 10 tennis combo when you don't he or when you don't hit a more than you break the combo, and I believe you can do this as well, if not, feel free to make a request. And I gonna implement this later on a swell toe. The course and there are several other things you might can implement here as well, like increasing the animation speed off the malls when the level becomes higher and so on, and so forced to make this game also challenging for the player because currently it doesn't or isn't there challenging I guess maybe it starts to be challenging a bit later on in the game. Maybe when the numbers are getting really high. But also you might want to reduced some points here and there or recalculate the point you're going to give to the player. Meanwhile, you are playing the game so all of that can be implemented as well. End. Yeah, once again, you know where that positions are once again. If not and you need some more ideas. Teoh, make this 1 may be a bit more appealing. You are able to do so also. For example, if level 10 you might want to add, like two more holes or even more rose off holes to make this one more interesting. So you have, like Thanh off holes to hit or where all those moors air coming out off? Yeah, out off. So you just have to create more scenes. And when the scene level, when the current levels, for example, level 10 then you don't not load this level, but maybe the next level and maybe change the background, put some more interesting stuff inside, maybe put some extra features like floating around objects, which you can collect, Maybe put some poems around or anything else you can come over to make this one super interesting. Also used to time, um or maybe to increase time when the time is not enough. And when the time a mole gets hits, then you add to play time, for example. So blade time is going to be longer and so on and so forth. There are so many possibilities to improve this complete game once again, if you have any requests and so on for free. True, ask them. And I going to see how I can implement them as, like, student requests or extra content. Once again, thanks for tuning in to this course. I hope you enjoyed it. I only learned something and I hope you create nice welcome or games from now on. See you in the next course. Feel free to check out my other courses. Of course, it's well, thanks for watching and bye bye. 37. #36 Extra Spawn Holes: Welcome back to the course. This has been a request from a student, and he was asking how to create the whole before a more appears on this position or on any off these positions. So to clarify that we need to think about how can we do that? We have several possibilities, are gonna list some at first, and then we talk about how to create that. What we need to do it for us is we need to understand how the moles and how the holes are acting at first. What we can do is we can put all these holes into a list, deactivate everything on start and once and whenever start her and the countdown has been done, we can actually go through that list. Pick a random number from the size of that end. Of course. Make sure that we activate the game object, activating the game objectives just by Cote said Active or like Truell fools for whatever the whole is we want to do. Whenever we're doing that, we also start the animator, and we can also do the same stuff for the whole behavior if we need to. So the whole behaviour has the possibility to restart its invoking if we need to do that. Also, on the other hand, we can say we spawned the complete holes and from a list, So meaning we gonna create some little spoon points, some empty game objects where we spawn one hole at the time. If we like Teoh, then we do the whole more behavior, and then we deactivate or destroy the whole another. One would be. If you want to keep that holds active, you can also set active and inactive the whole behavior. So only one whole mole, for example, can come out. But I guess that's not the request. So I keep that you out of the weight. So what we can do is, or what I would do is probably I keep that holds him, and I create an empty game object or just corpus spawn holes. So sporting might not be the correct one over here, the correct naming convention. But it doesn't really matter how your name stuff as long as you know what it ISS. So what we need to create is a script which is actually able to excess all these halls at the same time or whenever we need to. So we can actually take all these holes, make them active or inactive, and take care off the mold behavior. So we don't have any double sports and stuff like that. Okay, so how can we do that? Are gonna create havoc, Created a request full of year. So for you doesn't really matter at all if you have that arranged in your yes groups, although it's pretty much fine. So I call those once borne holes. Eso Actually, maybe it is a wrong naming convention, since once again, we're not directly sporting holes. But maybe you want to just set them in active or active at runtime. So I'm gonna direct the Spawn whole script into the spawn holes behavior or yeah, empty game object. Once the compiler has done, of course, and double click and open this script in mortal develop or visual studio's whatever you please and like, so I zoom in a bit so against the stuff better. Oh, and by the way, this video can be a bit longer. So I'm probably splitting this one up in two or three if we have to, or if I have to Okay, so once again, we need a list off objects or off whole behaviors. It depends on how you want to do that in a side here. So it needs to be a public list. Otherwise, we don't have access off and can pick them. We can also do this on start and automate things, but actually dragging stuff inside the inspectors shouldn't take you too long. Right? So what we say is we need a public list. And once again, if you don't have access to a list, make sure that you are adding using systems, conduct collections, dajun Eric. Since they are part of that, those are these lists, and this list is off type. Well, game object for now, let's test it out with game object. So Ah, and I just call this one whole list and we've got already say it is a new list off type game, object, open, close parentheses. Antos along was a semi colon. So this is important. So we have access to these holes later on. So whenever we're going to almost born holes yeah, script Over here, we're gonna have a whole list. What we can do is we can basically take all these holes and bring them into the whole list . I can try Teoh, select them all at the same time, but I don't think that it's always is working. That's good. So you can select them all. And how did I do? This is this is a little yeah, Let's a little lock symbol here when the longest closed. Then you're gonna keep the inspector window open, whichever you have. So like when I close the lock, I can select anything else. But the inspector will not change. And if opened this one, it goes automatically once again through whatever the moles and the whole stuff are going to pay so or whatever game on that you are going to select. So you could select them all and close the lock, for example, before you do that like once again. So then you select them all, hold shift to do it like easy, and direct them directly on the name off the list over here so you can have them all directly on that. Okay, that's pretty cool. So we have access to all the holes. Pretty simple. No, What we need to do is we need to set them all d active or inactive whenever we start the game. Right? So we need to wait before we actually can start and pick one off the holes in the whole list and to make them active or inactive and to act. However, we want them to act. So there are some prob problems we're gonna and contra late on. I guess so. My be like a double spawning and stuff like that. But we want Teoh asked to go and take care of that in the pit. Okay, So first we want us and start, we want to deactivate the complete whole list all the holes we want. We don't want to see them because we want to make them act. If, right so we say we create a new fault. We looked through the complete whole list dot Lang's or in this case, don't count, since we are using a list instead of an array. So we looked through the complete lists and set all of these lists items to be inactive or deactivate them. So it's a whole list don't. And now not don't, but in square brackets I since I s the letter were using to its rates room dot And now we can say set active like this or set where the big s and in brackets begin. Say true false. In this case, we're gonna set all of them toe false. So when the game starts probably have to put this into awake since we might need a little bit faster. But Ashley doesn't matter, since we only reacted this or assets set them all active or what? Whichever we want to set active by a bowline which is located in the game Energy, if you remember, like count on Done So what we can do know is when we press start all off the holes, although mainly be gone See, all of them are deactivated. So you can also see this in the inspector as well as in the hierarchy panel. So everything is in active and it will not act since everything is inactive, does not work. What we cannot do is when the countdown is done, we can say OK, we want to start activating and deactivating elevating holes in whatever behaviour we wanted to be, so that can happen or we can say OK if one of these in the list is not active anymore and then we can spawn another one. What we can do this was to and we need to protect it. It bitsy and they're actually we don't need update since we can invoke that aura started cool routine to do this for us or whatever we want in place for the moment, we just keep it as is. Maybe we're going to set yet the bowling later on to protect that in update or check this out. However, there are that once again, there are several possibilities to do all of that so we can make use. Often I e numerator, for example. So I numerator is called a co routine and the core protein is going to do stuff as long and repetitive or time based on however we want that it's like invoking something. But you can put in Maurin Formacion into that, and we can repeat this over and over again after a specific amount of time. Basically same once again, s invoke or invoke repeating, which is another possibility to make use off Burdon. I numerator is just running not directly based on update or something like that. It is like, Yeah, it's running in the next race threat. I would say so. An eye numerator. Once again, we can a name. There's Ordell. Activate or just activate. Activate hope. So often close parentheses. Basically, it works like a function. We have some specials in here, which means we can make use of a while. Loop on. We can just say while true. And that means where while this is running here, this particular are you numerator Then we can run stuff inside at this. Why loop so? And for us, we might want to say yield, return new. We need to always have a yield statement inside. Any request in and I numerator even if we just returned zero, we need to have some. So you'd return you and then we want to wait for seconds. And the seconds can be maybe whatever the speed is off. How fast you want to activate a deactivate one hole, for example, After three seconds, you want to detect it or activate another hole. So now what we know what to do is we want to check if that particular whole list has some to pick or actually want to pick from the whole list. One of thes. Basically, we can take the complete for loop from here. We loops row, and but we want to do is we want Teoh uh, pick a number. Basically, we don't even need to look through that. We just pick a number. So we say int num equals and what we no need to do is a random good range. So with the pick from a range between zero and the whole list of count, we pick a number or want to do it After that, we want to set this picked number from this whole list to be active. So we say all this then in square records, I dot said active. And now we take that particular number. Well, actually, it is not I It is off course and numb in here. So we pick holders numb and set this one too active to be true. OK, that's basically everything we need to do after a specific amount of time. We go and do that. What will also can do is we can check if that particular one is already active. So we can actually avoided or pick another random number. Meaning we can put a small if statement to protect that we like to. We don't have to. So if whole list and grab rockets numb, don't. And now we need Teoh actually request this by act of self. So if the local active cell state off the if that is actually active already, then we can say we pick another random number in here. We repeat the process. Since we already created this interview over here, we don't need to put another interview over here with just one pass in the same one because it is the same same loop I would say over here. So why looks a bit tricky. So whenever we're starting an idea numerator and we have a wire loop inside, we need to make sure that after the wire loop or that the while loop is not going to interfere by something or we don't have something outside which is keeping that unlimited without doing the way for second stuff in here, like light on when we have. We invoke that we have that active and we want to start this one off course in the in the start function so that they can start quarantine on close parentheses, and now we just put in the name Activate hole. And what we need to do is we need to put this into quotes since so if we want to late on, put this one Ah, as a function, we don't have the possibility to deactivate this by its name. So we need toe, actually start or stop every core ity. So when we stop now into this game, object is going to be active in here. After three seconds, we gonna spawn one whole s against C, and then we spawn another hole and then was born another hole into unanswered force. And that's going to happen like the wool time. Like every three seconds, we gonna spawn a new home. And if nothing happens, and then it probably means that this one has been active already. So what we no need to do is is we need to deactivate all these holes once again and make sure that the moles are not going to come out off that holes like the wall time since we are now activating and deactivate or acid just activating those holes, we want to make sure that we deactivate them off course when the mole is gone. So we don't get out a second more after the spawn point on this hole is going to be actually deactivated. And we don't get any arrows since probably we're going to get some missing reference exceptions if we yeah, actually delete the whole by itself. So we let the mold do the work for us? Is that what we can do with that is we go into the more behavior, and Hannah did some a little markings in him. So what we're gonna do is we destroy the game object whenever we actually hit that. Also we deactivate or actually said has more to before I want to do is we want to set this particular Mol asses game of it Or this particular moles parent object. We want to set this 12 d ec. So we deactivate the whole same here. So when we hit, the more we deactivate, of course, or get rid of hit points, and in the end, we're gonna destroy the mall itself. But we also want to deactivate at this point, the my parent game object, which isn't in this case, is going to be the more so what we're gonna do is or how we do that is my parent not set active, sensitive type game, object, weaken. Just easily. Set this one to be force here, and we can do the same on the other side. So I just copy this line. Ah, down here into the ghetto. Got hit function, and that's pretty much it. So what? We're gonna do the test now? If the mole is gone, the whole gets deactivated as well s. Ah, yeah. If the more gets when When the more gets hit that everything works the same. So we wait for the more in the end, let it disappear. And once this has disappeared them a whole should be gone, As you can see then he is spawning a new one. Like every three seconds. This one does not have any. No. So we need to make sure that we fixed that a resource as well. So how do we fix that? It's a resin. Simple. At first we need to go to the whole behavior. As you can see, we are still sporting, invoking new spawns Whenever we are once again, we're on the whole behavior and we don't want to destroy. Of course, something in here. But I want to stop invoking you. Hey, holds or more zendesk eight. So we stopped the invoke after we was born to one hole or more, one more. And now, once again, that's tested out. So we got rid of that invoke line so we don't repeatedly get more moles out. So there shouldn't spawn any malls on in Native came out. It's I just keep on waiting a bit. So I want to make sure that everything works so far and everything gets activated and deactivated correctly. I just wonder what these polling points currently are not coming back, but we probably see some sooner or later. So again, yes, here. If everything works so far and off course, maybe this is just ah yeah, not working correctly anymore. But this is going to keep become active. But the fun part is the other malls in here are just not doing anything. So what does it mean is we might need to cancel the invoke. So the next us we need to do is at first we want Teoh, Let's say would use to kill the invoke time so we can see either what's going to happen here as I reduce the random range spawn invoke somewhere in between zero and one seconds. Oh, maximum of two. Since ah, the layoff, a maximum of seven seconds is going to be razeq where we are resolute high now since we're spawning the whole, then we don't want to wait or want the player to wait a t least there seven seconds before something is going to happen here. So how can we do? Or what we do know is I just deactivate that the maximum that my time here. So in two seconds, we want to make sure that this is going to be yes, started. And as against see the invoke timer is somehow you get over written but not really activate itself. So we need to avoid that, since currently it can happen that this invoke is never happening anymore. And this is going to happen to sometimes to all the other holes as well. As you can see, These three holes are now not doing anything. They're just there, and that's it. So what we need to do is we need to cancel the invoke if there's one running already. So as you can see, we're starting the invoke. But we want to do is before that just when it's coming to start, we want toe cancel. Invoke. So he's saying, Cancel, invoke And in open close parentheses we can define is string Pyramid A off the function we want to cancel. In this case, it's going to be the function name spawned. Don't forget that the line was descending colon in here and that's test it out again. So once again, after two seconds at the maximum, we want to make sure that one more is coming out and the whole was going to get deactivated . And once again, the canceling is going to happen only when the function is going to be called again. So once again, we go into that. If there is one invoke running already weak, just disable toe and broke by using Cancel Invoked this Yeah, at this point. So if we still have a problem like as you can see, we still have no hole no more here, normal there No Memmel there want to do that a bit different. How can we fix that? Actually, we are not able to do all that the cool time in start. So we changed that to be in the update loop. It is not cool, but currently it's the best solution since we don't want to have a nine numerator running the wool time. Even if we don't eat that so and update will only run off course when the game object is yeah, able to be updated. So in update now, we gonna cancel them, walk if there is a more and then everything gets destroyed or asked Lee got rid off or get rid off So and also when we now would go in the Liederman, we also want to make sure that they are canceling, canceling their invokes somehow, As you can see, the timing is still anyhow, strange sometimes that they are not a sporting a more directly afterwards. Also, as you can see when we're hitting the mall and getting rid off the game object off the mall itself. The yeah, the whole destroys Wiz. Yet where's the hole was? The more so everything works again. So let's see if there are any problems in here once again. Sometimes it seemed to be at timing problem. But maybe it is just because of the two second year, two seconds, a spam or spawn time where the invoke can happen. So if two seconds for you is a bit too long, you can also say you want to have a range between zero and one on the invoke message. Once again, we are in whole behavior in here. I just saved that. Let the compiler run and see if that is reducing this. Yeah, this complete behavior at all. So every three seconds now whole gets spawned by the i N m aerator off the spoon halls function, we can once again hit those moors without any problem and the whole disappears wisdom all when you want to have delay in there as well, you can even do that. Ah, I guess. But you need to have another time based action, So everything should be good to go right now. And we should not be able to activate, of course, the same hole at or at the complete time over here. One small addition to picking these holes over here inside. I was born. Whole script is we can create another function which is checking which hole already is active in which is not. And by doing so, we can, for example, not pick a whole from the whole list, but from a let's say usable list or usable or useful whatever hope. What does it mean as we create a private list in here where we want to put in on where I can put in game objects? By running through that, there's going to be maybe our possible list off holes or possible whole list. I'm gonna explain in just a second what I mean by that. So we want to create a new list once again. Off type game object open, close parentheses enclosed the land was a semicolon. So once again, this possible holders will list or will hold all the possible the inactive, basically inactive game objects. Otherwise, we're gonna clear it off and make a new list. And what we're gonna do is when we go into that wild Lou, but we wait for a second. Then we'd pick any number from the whole list, and then we activate a check of it is active, and if it's not, we're gonna pick another one, which is not a good idea. I guess it's better to have a possible whole this. So we passing all the possible holes inside the possible whole list and clear it whenever we need Teoh and only pick from the possible whole list. So everything which is active or once when, whenever we want to spoon anyone, we want to pick from the possible whole list and not foretell from the whole list. So we always get. After three seconds, we get one hole. It's like avoiding a double spawn. It's going to be the same. So when you have some spawn points where you want Teoh, check If there are possible holes of possible spoon points, which are not taken at this particular point, then you can do the same as well. So how can we do that? At first, I'm going to create a new void attack Or actually it is update possible sponsor or possible positions possible horse, whatever a corner, whatever you like once again, so update possible holes. So when we need to do is we loops through all the wall holes and see who's active and not so I say four double tap once again and now we go to the come on through. The complete whole list don't counts. So I want to car go through all of them. And what we want to do is we want to do this the same check in here. We say copy that, but instead off positive. If it is active self, we want to make sure that is false. In this case, number is going to be I. Of course, since we're iterating, I hear So if not whole list idol, active self. So if it is not active, then we want to put this whole We're currently iterating through in the whole list to the possible this so it's a possible holes or whole this daughter add. So we want to add this particular one in this case, I air, but I is not the correct when we need to pick this from the whole list. So it's a whole list in square brackets. I since that is the correct ah list were want to pick the item from so once again, we pass in all of that and we have this now inside at the possible whole list. I want to make sure that we, uh that this is 1% working, so I make this one public first. So what we're gonna do is we need to update the possible holes before we are picking in your random number in here. So we say after maybe the three seconds of weight time we say we want to update the possible holes. So we just call. The function was open, close parentheses, and what we do is we pick from the possible whole list number. So possible list Don't count. Also, we gonna pink or actually we can get rid off this if statement in here. Like so we don't need all of that. So we don't need to re pick anything because we already to have taken care of that. So when we're going to do as we say possible whole list adored, active is going to be true. And let's go back to unity and see if the possible hole this is going to get filled correctly on start or actually, when the timer is after three seconds. Done. So what we have is now all the holes are inside that except whole number three or that C 675 or three. Okay, So what now The problem is we activate this holes That is correct, but also what he can see us, We activating or actually adding more holes to this list. So but not number four, for example, Number four is now active in the hurricane year, so it's not getting active. So now in the next iteration, let's say we're gonna get a number one is deactivated. That since this is one currently active, and once again every time an inspiration is going to happen, we're gonna add this particular hole all the holes which are not active in the seat. This is bad, since we have no picking from a possible whole list, which is extremely long. That we want to do is we want to clear the list before we want to add this newly possible sports to that's always say possible. Whole list don't clear. So we just make this one empty on the first spot that were filling all the possible spawn points. And then we pick one and sectors want to active or even not. So once again, we update this possible holes. Then we picked from the possible whole list. No matter if the whole list X. Yeah, in this case is acting for not And since we are once again clearing this one the world time , like fiddling up new data on you based on, if something is active or even not, then we're going to make sure that we only pick from the possible whole list, and that's cool and that I want that. So once again, I can and stop this out by seeing if the whole list is going to become cleared. So the first time we're gonna get, like, all the seven holes, as you can see. So since none has been active, 2nd 1 is we're clearing this list, and now we're picking only some from Aware Number four is not inside, as you can see for is not in the whole list. So we can choose whole number seven. And in the next generation, we're gonna do the same here. So now number seven is active, so we can easily pick anything else the but not the one which is already active. And so this is the way to protect double spawn on the points directly as well as you only make use off the holes which are active And if there are none, I'm not 1% sure there's going to be something, but well, if there is no possible number to pick from then off course, nothing will change. I guess, since once again this is going to be active anyways. So once again, if you want to have more at the same time you can decrease this number over here. And then you're good to go. Don't forget to save ever seeing and see you soon.