Welcome back, my fellow game developers.
In this video, we've created money,
so let's get started.
When I run the game.
You can see that I have 0 Bitcoins.
If I hit the GKE,
I have 20, 40,
60, and then I can also remove them from my inventory.
It's nothing very special.
There's nothing to coolants video except for
the really nice-looking symbol
right here of the game manager.
So let's not waste any more time and
let's get to creating money.
O k.
So now we have enemies,
now we have weapons, everything is set.
It's time for sound money.
We need to make some money.
So and I believe in the last video,
I told you that we are going to be creating menus.
Sorry for that honesty.
I don't actually remember what we have.
I just go from one video to the next.
Obviously all the time I know what I'm doing.
Obviously, I know where we are heading.
But anyways, let's continue on.
We have the level manager and this is where we want
to keep track of the money that we have.
So first of all,
we are going to create a variable in here
which is going to be a serialized field,
and it's going to be an end of the current coins.
Okay, so here is where we will have our current coins.
And now it's your job to create two methods
to get and spent the Bitcoins.
So you'll create two methods.
One that adds, I should change this,
you know what, let me check or
no electron will change this to Bitcoin.
So create two methods.
One that adds bit coins,
one that removes the Bitcoins.
Then each should take in a parameter for the amount.
Make sure that we never have
negative amounts of money because that's very bad.
So with that out of the way,
pause the video right now and go do the challenge.
Okay, welcome back.
So instead of current coins,
I'm going to call this the current bit coins.
And if you don't like Bitcoin,
well, you should try it out anyways.
I'm not trying to put anything in your head.
Let's continue on. Let's focus on the main thing.
Now, something in here that you might want to consider.
So it's great. We have Level Manager which takes,
takes care of the whole level.
But when it comes to
the amount of money that we carry with us,
I think it's better to have it in
something called a game
manager that's just for the future.
It's no problem.
You can create it in level manager.
It does the functionality,
but level manager seems like it
just handles the current level that we're on.
When it comes to the mind that we hold,
it should be around the entire game.
So as soon as you start the game,
every single level you collect more coins,
you go to the next level,
you then add to that.
So level manager is a bit of a weird one.
I don't know, maybe we should move it to a game manager.
You know what, let's move it to a game manager.
I've convinced myself.
So in here, I'm going to right-click.
Create an empty game manager, hit Enter.
We'll reset the position.
And in here in the manager's going to create
a C-sharp four script for the game manager at Enter.
And this is exactly why
I wanted to create a game manager just
to show you this weird symbol for some reason,
no other script changes except for this one.
This one has this weird knob on it.
I don't know Why. Don't ask me why.
I'm still not sure.
But anyways now the game manager
has the game manager script.
And as long as we're here,
we have the level manager,
we have the game manager,
we also have the Audio Manager.
There we go, the Audio Manager.
So I'm going to right-click create an empty.
The managers hit Enter.
I'm going to reset its position so that the game manager,
level manager, and the where is it?
Audiomanager. There we go.
So now we have a list of all the managers.
And in the prefabs,
let's prefab the level and the game manager.
So do we have where is the AudioManager saved?
I think he is in the prefabs where z.
Okay, so AudioManager, his Albany himself,
folder managers, AudioManager, level manager,
and the game manager.
Okay, with that out of the way,
let's open up the script again.
Whereas the level manager,
we are going to take the Bitcoins from
here and move them to the game manager.
And then we are going to go ahead
and create two methods in here.
I'll keep the start and update.
I have a feeling that we might use them later on.
So in here, first of all,
the public void, obviously
it has to be public because we are going to be.
Calling it from different scripts.
So public void get bitcoins.
And in here the amount to get.
So we open up the brackets or squiggly lines or whatever.
And the current Bitcoins plus equals the amount to get.
And if you want, we can set it to 21 million,
but let's keep it as infinite.
We can get as many as we want.
And then we are going to create the public void,
spend coins, bitcoins.
And this one is going to be
an integer of amount to spend.
And in here we are going to get
the current coins, excuse me,
get the current coins removed from them,
the amount to spend.
And finally, we are going to check if
the current coins are less than or equal to 0,
than the current coins will be.
Current coins will be set to 0. Save that.
And now let's just create a small Peston near.
So if input and put dot,
get the down key,
coat gene G, so keycode.
So I mean get, if, GET,
then get bitcoins and let's say we get 25 or 20.
Then if the same in here.
But instead of a G,
we use the H,
H spend, but coins.
And how many do we spend?
Let's say 10.
So we get 20, We spent ten.
And finally, let's create a debug.
Oh, we forgot this debug.
I have current Bitcoins
plus equals bitcoins.
And obviously we'll be setting all of this in the UI,
but for now we save,
we go into our game.
I think everything is good.
So we set everything up.
The current coins are always going to start at 0.
So we start the game. There we go.
I have 0 Bitcoins,
so I'm going to get,
get, get, get, there you go.
And then I'm going to spend, spend, spend, spend,
spends, but spend, spend,
and as you can see,
we cannot go less than 10 Whenever I
tried to spend 10 because I only have 10.
And this is something that we will need to
keep in mind if it's less than or equal,
if we set it to less than or equal than 0.
Actually, I think that's a good idea.
So now we can actually spend what we
have problem in here,
Is that, okay, Sorry.
This is how we said the less than or equal.
So there is something that we will need to keep in
mind and that whenever we are spending,
we actually need to have these coins with us.
But this is something I believe will be
handled later on by the Sharp script.
So in here, let's see,
I spend, spend, spend, spend.
Okay, that's still not working.
Hey, welcome back.
So it was totally something very simple.
When we have the collapse right here,
you can see that we start off at 0,
20, 40, and et cetera.
But when I start spending,
when I get to 0, it's already here so it doesn't show up.
And the messages I can
show you if we remove the collapse.
So every single line is not maximize on play, please.
If I click in here,
so now you can see that when I hit the gigi,
gigi, 120, sell, sell,
sell, sell, sell, sell.
There we go. Everything is working.
So it wasn't because of the less than or equal,
it was actually our inability to see it.
So I hope you enjoy it.
Make sure to commit your changes.
And I'll see you in
the next video where we will be actually picking
up the bitcoins and not just adding
them using magic keys on the keyboard.
So see you then.