 All right, welcome back. So in this lecture, we are going to set up the logic for the fader. So the fader is gonna be an automatic way to fade between two screens, okay? And it also will allow you to set some artistic design choices as well. So let's jump over into Unity and get this started. Alrighty, so here we are inside of Unity. So the thing that we need to do is add another image. And in this case, we just want a single image. And again, I'm going to stretch it by holding down Ctrl Shift and Alt and hitting the anchor button up here and just expanding it so that it fills the entire screen. And for this particular case, I'm gonna just set it to a black, not totally black, but dark enough to feel like it's fading out to black kind of thing. I don't wanna go full dark, you know what I mean? It's always good to not make it fully black, all right? So I'm gonna rename that to fader, okay? So now in our UI system, the UI system is basically going to control this fader. So it's gonna fade it up and fade it down. And it's actually quite simple. Unity provides us some functions, some built-in functions that automatically do this for us. So I just want to implement that functionality into the UI system. All right, so we're gonna pop up in the UI system there. Okay, and what I need to do is create a property that is the fader. So I need to allow someone to assign the fader UI element to this particular script. Now we could automatically find it. Oops, I forgot to capitalize that. We could automatically find it, but let's just let someone assign it because I don't wanna do some more searching around in the start function, right? It'll be easier this way. So we'll just call this the fader properties. All right, and these headers just help you clean up your inspector editors, all right? Just helps kinda componentize the properties. It makes it easier for the end user or people who are using your component to figure out what the properties do, okay? So what I'm gonna do is just say public image. So I want an image. And in this case, I need to, in order to do that, I need to include the unity engine.ui namespace. So I'm gonna say public image mfader, okay, perfect. And with that, we're pretty good to go. The next two things is I wanna set in some values so that the end user can actually change the amount of time it takes to fade in and out. So I'm gonna say fade, duration, or actually we'll say fade in duration, like so. We'll initialize it to a value of one, so it takes one second to fade in. And we're gonna say float m fade out duration, okay? Is equal to one f. And I wanna name that properly. So float, not flay out. All right, so let's go and get this taken care of. So in the start function, what I wanna do is I first wanna make sure that we have the fader. So I'm gonna say if mfader, then we're cool. So we have it. So what I wanna do is if it's off, right, because it might be turned off, maybe someone who is like a designer is working on the UI for your game or your app and they accidentally left the game object off, I wanna turn it on. So I wanna say mfader.gameobject.setactive to true. Just so we know that it's gonna be turned back on, okay? So that basically initializes the fader and then we just need two public functions, okay? In here, so I'm just gonna insert them right here. So we're gonna say public void fade in, all right? And then we're gonna say public void fade out, like so, cool, all right? So in each of these, what we wanna do is we wanna say if mfader, because we don't wanna throw any sort of null reference exceptions. So we're gonna check to make sure we have it. It could have got deleted somehow at some point. So we need to check, okay? So if that's true, then we're gonna say mfader.crossfade alpha. All right, and you can see the arguments for this particular built-in function. We have an alpha value, a duration, and an ignore time scale, okay? So what I wanna do is I wanna say if I fade in, I wanna basically make this fader disappear. So I'm gonna set it to zero in the alpha. So it's fully transparent. And then I wanna pull in that fade in duration, and then I wanna say false for the ignore time scale, because I do want it to adhere to the current time scale of the game, okay? So let's copy this, and we're gonna say crossfade alpha, and when we fade out, I want this to be fully opaque, and I wanna use that mfade out duration, like so. All right, so there we go. We now have the ability to fade in and out between the screens, okay? And so basically, all we need to do now is we can just call fade in right here. So basically now the UI will just fade in, okay? Because we're gonna leave this set to true, and by default, the fader's gonna be fully black, so when this thing starts, it's gonna fade in, show you the screen, and then we're gonna utilize an animator to animate the transitions between all the screens. So this is, think of it as a global fader. When we leave, enter, or leave this particular level, it'll fade in, fade out. It's really nice, it's a nice effect, so. Let's actually assign it now, very cool. And the last thing we actually need to do, okay, is turn off raycast target, because I don't want this particular image to block the raycasts from the mouse when I'm hitting buttons. If this is, because currently, this is at the bottom, okay, of this hierarchy here, so it's the last child in this hierarchy. So that means that it is sitting on top of all the other UI, and that's why we can't see the other screens, right? And so if we have this raycast target on and I click, this particular fader image will block that raycast and it won't hit the buttons. So that's why we turn off the raycast, so now the raycast just goes through this particular fader. All right, so now we are ready to go. That was super easy. And now we have global fading working. Super awesome, okay? So I'm gonna leave you guys there. And in the next lesson, we are going to set up the animator and we're gonna start to get these guys to transition between one another. We're almost there, so hang in there. I'll see you guys in the next lecture. Thanks so much.