Welcome back, My favorite game developers in this video,
instead of every single time having
to look either in the console for
the debug or to look on the object
of the game manager to know how much coins we have.
We've actually created the UI canvas
to register all of the Bitcoins that we have.
So as you can see, we have 0 right now,
but if we pick up a coin, we get that.
So let's not waste any more time and let's
get started in this really simple video.
Oh, okay, So now it's time to actually display
the Bitcoins that we've picked up on our UI canvas.
So I'm going to make the scene a bit bigger.
I'm going to find the Canvas and here somewhere.
So double-click on the UI canvas.
Let's open it up.
Let's see what we have
and click on View UI canvas so we can see everything.
We have the weapon UI health,
and let's go ahead and create a new empty game up.
No, not, sorry, not on the health on
the UI canvas create an empty game object.
And this will be the coins or whatever.
But coin tracker, I don't know,
with corn occur. There we go.
So Bitcoin tracker, and here we are going
to add in the UI and image,
and this will represent the image,
the image. There we go.
And it's just going to be,
let me look through the sprites.
Sprites make these smaller.
There we go, the coins,
whereas the coin I just saw it, coins, star coins.
And let's add the image therapy goals at the sprite.
We can set to native size.
There we go. I think it's good enough.
We put it right here
just next to you can put it wherever you want obviously,
as I always say,
but I'm just going to set it right here.
And then I'm going to create a,
another UI in here.
Oh, so sorry for that.
We should not have put the image.
Let me just set the image.
Position bug will move the entire object in just a bit.
And I'm going to create text much pro in here.
And obviously I'm going to make it,
let's say 99, 99, bold,
and change the font on it,
make it the one with the robot thinking,
I'll move this whole object here.
I'm move the image a bit to the left.
There we go.
And then the text a bit to the right.
And this will be the amount of BDC text.
And we'll keep it at my 99 just to represent everything.
And we'll set it in the middle on the alignment
and set it to auto size, increased the maximum.
And let me change the text a bit. There we go.
That looks good. I think.
Yeah, that looks good in my opinion.
So we have the number right here
displayed above the health and every time we pick up,
we should get this.
Okay, great, So I'm going to save this.
I'm going to go into the UI canvas
and I'm going to open up the UI Manager.
So in here, obviously we'll need a reference.
So the first reference is going to be
a serialized field of the type text.
What was it text Mesh Procore,
taxed mash Pro GUI.
You I agree.
Okay, that's it.
And the BTC text.
Save that.
Okay, so let's go back in here.
Let's get a reference to this day. Now.
There we go.
And let's apply the changes
on the UI canvas so it's applied everywhere.
Okay, great.
Now back in our end here,
what are we going to do?
Well, obviously every single time
we pick up a coin or we start again,
or we spend the point,
we want it to be displayed right here on the UI canvas.
And this is going to be your challenge to set
the value of the coin and updated every single time.
So create a method that updates
the coin text and the UI Manager,
set it at the beginning so we will not
need to know where is the beginning, where do we sell it?
And also make sure that every time we add or remove
coins to update it in the UI canvas.
So that out of the way,
pause the video right now and go do the Chaldean.
Okay, welcome back.
So in the UI Manager,
whereas the UI Manager,
and let's scroll down and in here let's
create a public void,
Update Bitcoin text.
And in here all I'm going to do is access
the PTC text, text, text.
And it's going to be equal to the integer right here,
which is the amount of BDC.
And it's going to be equal to amount of BTC. There we go.
So this does not work because you
cannot convert into string.
So I'm going to add the dot two string.
Save that.
So this is a bit of a trick.
Maybe you didn't know how to do that.
There are other ways around this,
but this is one way that I'm going to show you for now.
So back in the game manager,
as soon as we start.
So in start or you know what?
As long as we have the awake,
let's sell it in the awake.
But the problem with the awake is that it
might start before we have an instance of the UI Manager.
So for that, let's just do it and start for now.
It's a bit safer.
Ui Manager, dot instance,
dot update, Bitcoin texts,
and it's going to be the current Bitcoins.
And then when we get the Bitcoins,
we are also going to update this
and the spent after
we sell it because we don't want to have negative,
so we're not going to sell it in here.
We said it after we check if we have
less than 0 and then we make it 0.
So save that.
Back in our game.
We are going to run the game.
Let's make this a bit bigger.
So run the game, we should see 0 in
here because we don't have any coins.
There we go. We have 0.
And now when we pick this up,
so please mute audio.
When we pick this up, we should see that we get ten.
Excellent. So now we can pick up
our coins and we of course also can spend them.
We don't have the opportunity to spend them,
but in a bit we will start creating
shops and that's when we will be able to spend them.
So with that out of the way,
I'm not sure why I keep saying
this mixture to commit all of your changes.
I hope you are enjoying and I'll see you in
the next video where we will learn
how we can actually earn
our bitcoins and not just pick them up off the floor.
So see you then.