The first thing that I want you to do in this video is to download a resource that comes with this video.
So I've given you this package called player arms packaged everything up just so it's easier for import.
So let's just click on this in order to open it.
Notice that it's got all of these things it's got a number of animations and it's actually got a character
just WITH THE ARMS RENDERED that we can attach this first person player let's just import all of that
shouldn't take too long to import.
It's not a huge file and there we go.
OK.
So the current to himself is in the player a mean fuse animation his materials etc. and the prefabs
we can see here just is just these arms.
Okay.
And this sets up at the moment though don't worry too much about the position.
It will all make sense later once we attach it to the character.
Now I've also given you something a new folder called graphics asking itself a flash like graphic I
just will next play know if I can gold standard assets.
Got something here called cookies.
See if I can find those it might be under effects.
Light cookies.
Okay so if I double click on these textures we get various cookie effects.
OK that can be used.
What these what you do with these is you attach them to a light and then actually modifies the look
of the light.
So for example this one's a hard light.
This one's a soft light.
This one as a sort of a checkered pattern on it.
These ones are mostly for flashlights.
No no they're not bad to be honest.
They do give the impression of a flashlight.
But I've I've just modified this one slightly so it just looks slightly better.
I think as a flashlight graphic for this game so I've given you this image currently it's a texture.
We need to change this into a cookie image.
We can see from the bottom there it's only 256 by 256 pixels.
So the first thing we need to change is this max size so that much is OK and then we're going to change
its texture type from a default to a cookie.
And then we're going to click apply.
All right we're going to change that.
Now if we find the first person controller from the hierarchy and we find the spotlight.
Now I'm wondering why I've got two spotlights on the
this one.
OK calling must this what's for the animate wasn't it to light up the enemy.
OK that's fine.
So I'm just gonna rename that because it did confuse me a little bit there.
So I call this enemy spotlight
OK.
And this one I'm going to trade you from Spotlight to flash light so that I understand what it is
ok where it sees cookie.
Currently we've got non taxed journalists just track this into their another suicide so the light will
now be projecting this image to wherever it goes.
It looks a little bit more like a flashlight.
It's slightly more convincing.
OK.
And when you play in the game if you want to change any of these values you can change a spot angle
or the range or even the color if you want.
Experiment with it because obviously you can come back to this video and see these default values.
And if you do change the color.
This is the exit some more color that we went with before.
Feel free to experiment.
At least you can always reset the values if you need to.
OK.
So what we're going to work on now is a simple script just to switch this flashlight on or off.
So go fold and my scripts are going to right click to create a new C sharp script and we'll call it
flashlight
OK.
Well up.
Let me double click to open it.
There we go.
Now it's opened.
All right great.
So we're inside of the flashlight script.
The first thing that we need is a slot where we can associate the light to is the flashlight so we can
set it in the inspector.
So to do that.
We're going to see realize it
realize fields.
It is a tie is simply a game object.
We could get into a name and it light and all the rest of it but game objects find it works perfectly
fine.
Nicole this flashlight so we know what we're putting in there.
Then we need another serialized field.
This one is a boolean so it's going to be a type bool
and I'm simply going to call this light on.
This is going to tell us if the light is currently on or off.
OK.
And it's false by default because obviously the light is not switched on just a little bit about serialized
fields.
And if we notice in the current controller there's no serialized field.
Now we simply are private or public so private is hidden from the inspector public is viewable in the
inspector serialized does the same thing as public simply makes it viewable in the inspector.
But the difference is that by serialize in it whatever the variable name is it recognizes that it belongs
to this script in this script alone whereas if you have a public variable doesn't associate it with
any specific script which means if you have two or three different scripts all having the same variable
names unity is gonna get confused and it's going to throw open error.
So by serialized things ensures that unity understands everything and you shouldn't get many errors
by doing that so it's the best way to do it.
I say realizing as opposed to just using public.
OK.
So now we go on the update and in fact we don't actually need this start so I'm just going to get rid
of that for now.
So under update we're going to say f input dot gets key down because we only wanted to do it once not
over and over again.
Key code let's say dot f for flashlight.
Okay.
If you if you wanted out then I would say it's just capital L but I'm going to go with F.
All right whenever it's just a simple letter.
Key on the keyboard it's always just a capital or whatever letter it is.
Now we need to put it in the curly brackets.
We're gonna say F lt is equal to False which currently is then do something.
Now this is gonna enables to use F to switch the light on and off by using this if condition so it can
check if it's currently on or currently off.
Okay.
So if it's currently false in itself then we're going to say.
Flashlight
dart game object with a little g dropped set active
and we're going to set this to true.
So we simply want to switch it on and then we need to tell it that the light is now on light on equals
true
I'm just going to highlight all of this and copy it.
Is it safe to type it all out again press enter.
We're going to press control in V.
Or you could just do paste.
Now we're gonna save light on is equal to true.
What do we do.
How do we reverse all of this.
We set this one to follow suit which is the light up and we set light on back to faults again.
So it recognizes it's now switched off.
And why is this if we don't want to do both of these we want this to be an else if Okay so it's going
to check if it's currently switched on.
Sorry if it's currently switched off it's going to do this but if it's not currently switched off.
Else if it is not switched off if it's on its going to do this.
All right.
So you have to be careful about not just do an F and F it has to be an.
Else if Okay so that that one's not true.
It will then go to this one if that one's true it will ignore this one if you don't do that the light
will instantly switch on the switch off it be too quick for you to see it and you won't notice this
switch down.
OK.
So that's the script we're going to see if that script and I've got an error.
Let me have a look at what area this flashlight member names cannot be the same as their enclosing type.
OK.
So in the words I can't use up because I've used it as a class.
OK.
So one minute to two is when they use a little f on this one flashlight.
So now I'm going to set this one to flashlight and this one also to flashlight.
Here you go.
That will solve the problem.
So what he was recognizing now was the overall class.
So it was trying to switch the class on and off which is we had
IRA should disappear.
Here we go.
Let's pretty clear on all of that.
I'm going to attach this flashlight to the pest control and we can just simply drag it out onto the
FBI s controller it appears and now will tell it to switch the flashlight on or off.
OK.
Now bear in mind that we do have an enemy spotlight as well.
So your task for the next for the next session is to modified this script to ensure that the second
light the enemy spotlight does the same as the first light in the flashlight.
So whenever you switch the flashlight off it will also switch the enemy spotlight off as well.