 All right, so let's start our attention now to the engines. All right So I want to literally have like a game on object per engine for this that contributes the forces That makes you know, the drone actually fly just to simulate, you know semi-realistic Version of the physics for for these drones, you know, we're just making a really basic version But I want to show you guys how to set this up because it'll give us an opportunity to use interfaces Okay, so let's take a look Okay, so the first thing I want to do is I want to focus on the interface side of things here so C sharp interfaces allows us to basically Determine or just or say that if if a particular class inherits from an interface It has to have whatever has been declared inside of the interface So it basically ensures that you know certain functions and variables always exist which Basically allows us then to use the interface as a way to find objects of the similar type, right? So let's actually walk through this I'm going to right-click on the scripts folder and create a new folder and I'm going to call this enter faces like so All right, and inside of here what I'm going to do is create a new C sharp script And I'm going to start it out with a capital I All right, so it stands for interface just so you know you'll see this a lot in other people's scripts as well So we're going to call this an I engine All right, and this we're doing this because you know, we might have lots of types of engines You know you might have certain engines that do produce their own force So maybe you know another type of engine sends all the forces up to the main rigid body There's lots of ways you could you know build out this particular drone controller This what I'm showing you is just a way And it might not be the best way or the most awesome way, but it is a way All right, and so what we're gonna do is we're gonna create an interface. I'm gonna go and set the icon here All right, and Let's click off of it So it applies that icon to it and then we'll open this up inside of visual studio by double-clicking it All right, so what we want to do is create an interface So let's actually put it in the namespace of any pixel. All right, so it's any pixel like so Just so we know because you know unity might have its own Interface called I engine and I don't want to conflict with those so by putting you the name namespace We get rid of any of those conflicts. All right, so This is going to be an interface. So what does that mean instead of a class? Let's let's call it an interface. All right, so that's that's a C sharp term there Now by making an interface, we can't actually extend or inherit from money behavior So we got to get rid of that there and we can't actually have our function declarations in here either because Interfaces are really just there to say, you know what? I'm gonna have this set of variables and this set of functions in the in a class that inherits from me, okay? This interface basically and so it's kind of like a contractor saying yes By inheriting from this interface, we're gonna have all these particular items in our class All right, so let's take a look at this so What I want to do is I want to create a new function inside of this interface called in it engine like so and I want to do and there we go And I wanted to do another one called update engine All right, so all engines will have these two particular functions. They have to That's what we're saying what we create an interface and that's literally all we have to type All right, this is just the instructions for that class or the definition Not the implementations definitions. Okay, so let's go and create the engine script now So let's go back to unity over here and Outside of the interface folder. Let's go and create the engine. So we're gonna create a new C sharp script Say IP drone engine All right, and we'll give it the little icon again Like a self so we'll say other and we'll look for that indie pixel icon There we go Let that update there real quick. And then let's pop this open up into visual studio and add our namespace All right, so in deep pixel. There we go And what we want to do now is we want to see how how can we inherit from mono behavior and This interface I want to be able to do both with this because I want to be able to access all the functions and classes that come with Mono behavior, but I also want to do This particular definition inside of this interface. Okay, so how do we do that? All we need to do really just put a comma and say I engine All right, and there we go now right off the bat You're gonna see that there's this little you know red squiggly line, and that's just because IP drone engine does not implement the interface member in it engine or update engine All right, so remember this is just the definition these when you inherit from an interface you have to have those in there So a really quick way to implement them. All right It's just a select it all and then right click on it do a quick actions and refactoring And we're gonna say implement the interface And look at that we have all of our functions and they come with a throw new system not implemented exception. All right So let's actually get this reorganized a bit. All right, so let's do our custom or call these the interface Methods, so we'll do a new region call that interface methods and Region then we'll just put them in here Like so and we'll keep they not implemented This is you know a good thing to do before you actually implement any code into them Just so you know because it'll throw an error over in the console for you And if you might end up forgetting to implement something right and so Just you know good habit to get into really All right, so that means because we're going to be updating the engine from the drone controller. All right We don't need the update here, so we can actually get rid of that update function All right, and we don't actually need to start because we're going to call the init function from the drone controller as well So look at that. So now we only have you know one start and one update function Here in our drone controller keeps it much more organized Alrighty, so let's go and do some variables. So say region variables and end region like so alright and What we need let's do this we'll do a header and We'll call this the engine properties There we go, I'll capitalize this guy over here and I think all I really need let's do a private float max power We'll allow the user to set You know how powerful these little engines are on the drone and let's do our serialized attribute So serialize the field Cool. All right, so now let's go and get it such that The drone controller is finding all engines that have been assigned to any child underneath its game object. All right, so let's take a look at this. All right, so let's go and Open up the drone here and what we want to do so we want to you know assign some engines here. All right And I want those particular engines to be just empty game objects. All right, so what we could do is We could use the propeller, you know as a position or the arm. Let's actually just Create a new empty game objects under here Yeah, let's do this here. So it's creating the empty game object from the roots We'll call this engines like so just say nice and organized and I'm gonna create a new engine And I'm gonna call this engine for now All right, let's do that So With that done, let's go and drag and drop our drone engine script onto it So we have it all nicely ready to go and let's also put a Box collider on it and actually Rather than you know having to remember that why don't we just go into the script here So let's go to the drone engine and do a require Components let's do a require components and we'll do a type of box collider there you go and Let's go back here, and let's actually remove the component and let's put it on again So we'll say let's select the engine there and drag and drop this so we get a box collider Very cool, and let's make it a lot smaller say point one point one point one for defaults Looks pretty good now what I want to do. Let's actually go into like a top down here So let's hit the little gizmo up here, and then let's go into orthographic mode like so and You have to use the alt drag and Usual the old unity navigation method, and let's actually just place it right over one of those engines Just so we know and it doesn't need to be perfect, right? Only the propellers really need to be centered up on the engine these guys really are just all about generating a force They're gonna be responsible for generating the forces now Let's go and on the box collider component over here in the inspector. Let's hit this little edit collider button and Let's go and Hold down alt was it alt or control and shift control shift Nope I thought there was that equal you could do it Equal I just forgot. Oh, well, let's just do each one of these guys here. All right Yeah, I just want to kind of fit it around there Just so we have some sort of co collision for the engine itself Look at that little icon popped up there. Let's edit that collider again. There we go So yeah, now, you know because we have our little icons assigned to it You can now just select the little icon in the scene It's cool. It makes it feel more pro All right, so now we've got that guy all set up. This is the left front engine. So it's name it appropriately cool, so I'll say LF And let's duplicate that now and let's move this guy over here And again, you can go up to the top go to orthographic view now that we know everything is, you know, basically situated on the y-direction We just do that and we'll call this the RF engine For right front and then let's just duplicate both these guys and then move them back Like so and let's just rename these as well So I'm just hitting F2 on the keyboard just to go into renaming mode. We'll call this BF and Sorry that is not exactly what I wanted I wanted Back left. There we go. And then back right Or RB Yeah Totally knows that but that's cool. There we go We're back Okay, so now we got all those engines all set up there awesome Yeah Cool. So what I want to do now is in the drone controller itself Right is I want to basically find all the engines for my particular drone And now I want to do that dynamically that way, you know I'm not assigning them to some list or array that I've exposed here in the drone controller script I just want this to happen by default now. You don't have to do this. I'm just showing That you can and I actually do do it quite often Because I don't want to have to have you know designers or whoever is setting these up or like an artist or something like that Have to remember to do that They appreciate it too. So Let's make a private Let's do a private Let's do a list. All right, and we're going to make a list of Engines so IP drone engines. All right And we're going to call this engines and we're just going to initialize that to a new list of drone engines like so Alrighty and then in the start function here. We need to go and find all those. All right, so we're going to say that engines is equal to Get components in children So you want to get the right one so we want to get components in children there it is And the component that we're looking for it's not IP drone engine, right? It's actually I engine That way we know that we have access to these two functions. That way we can have lots of I engines right and different types of engines But we know that we always have access to the init engine and the update engine function Whereas, you know, we can have a bunch of different types of engines that are set up with a bunch of different sets of code All right, so this makes your code a little bit more flexible to work with All right, so we're looking for I engine all right, and You'll notice that by doing that first off. Let's put a semicolon here That's not going to work because this get components in children actually returns an array all right, and This is a list All right, we declared it as a list not an right now. You don't have to Make this a list you could Make it an array as well. I'm doing it because I want to show off the using system link like so And inside a system.link, there's a function that allows us to cast this array to a list And that function is called to list And then we just need to give it the type that we want to go to so I engine and then just put some parentheses there And We are getting an error And that is because it can't cast from an I engine We should have put I engine here as well. There we go So now all is good There we go. So we're converting a list or converting an array of I engines to a list of engines This is really cool because now we can do rather let's comment this out So if you want to you can always put it in two forward slashes or if you want the hot key It's ctrl e and c as in cat All right, so Now what I want to do is I want to loop through each engine, right? So we're going to say for each I engine We'll call it engine in engines. All right For each one of those guys what we're going to do is we're going to say engines Dot update engine And we say engine sorry update engine So you can see we have a very limited amount of access to Our particular drone engine and that's because we only have access to the interface methods All right, so hopefully that's starting to make more sense So we say update engine like so So now let's just verify that this is working. So in our update engine Let's get rid of our system exception there and we'll just do a debug dot log. So let's say debug dot log We'll say like running engine and we'll say gameobject dot name like so So you know that each engine is actually calling it. So let's go back to unity now And let's run the game and open up our console here. So we can see Our glorious code running error free. Let's hit play And look at that. We're running all the engines All right, it's dynamically finding all the engines. We're using interfaces. So we keep it nice and modular And we are now calling the update engine function. So hopefully that makes sense All right, so I'm going to close the lecture out there and move on to the next. Thanks so much