[MUSIC]
>> Let's get into it.
Again, this stream is being sponsored by Microsoft.
Let's start with a quick review.
We are making a game, Hit the Bricks.
This is like that statistical overview.
It shows you like the different API calls that are happening,
tells you like unique users that have
accessed your game in x amount of time,
the amount of log ins.
It's just a really cool tool to monitor how your game goes.
You can even see where people will be playing your game,
which I think is super dope.
Multiplayer is another cool thing that you can do with PlayFab,
but that is just the beginnings of it.
So our game is called Hit the Bricks. Here is our game.
This is something else really cool about PlayFab.
You can connect to it directly in Unity.
We went over the process for that last stream.
We are going to look really quickly on our game manager here.
Our game manager just basically helps us manage the game.
Just to give you a very brief look at what the heck all this is.
If you're not familiar with code, basically,
this is what makes our game go.
When the game turns on,
it loads all of the different game objects and says,
don't destroy them because we want to use them eventually
and we want this game to run, a little quicker.
At start, we start a new game.
This is a function here.
So you start the game with three lives and a score of zero
and you load level one.
I actually did a naming convention
so that all the system has to do
is enter in what level you're going to and it will pull that level.
When a scene loads,
it says, we're going to call our scene manager,
which is an actual Unity library and it will load scene,
and the scene it's going to load is going to say level.
It's going to look for level
and then whatever you pass into here for this integer.
This becomes a one,
it'll look for level one,
which is exactly what we want
because that is what it is named in Unity.
All of this mess here basically
means it's going to go into PlayFab here.
It says, I need title I.D.
This is my title I.D, so that is what I would put in there.
It is going to ask to create an account,
so we're going to change the script here
to make it call from Twitch.
For this, we want to use Twitch,
so instead, we are calling the log in with Twitch request.
We are going to actually see how this works.
I already pre set it up.
Oh, how did I do this before?
It is actually running the script that we just set,
but basically, it's on actually running to anywhere but here,
because like I said,
we're just testing it right now to make sure all the systems work,
but here is where you can actually log in to Twitch.
Does it work? No, not right now,
because it's connected to a local host.
Back to our block breaker.
This is our actual game, currently looks like this.
This is the game view.
This is what our player would be seeing when they play this game.
We're going to call this paddle,
in this script is something we're going to put literally
right directly on this item right here,
so brief look into what the heck all of this is.
We are going to make a new script.
We're going to drag it onto our paddle,
we just need the Unity engine.
We're not going to use any of these system collections.
The first thing we're going to do,
we're talking about adding in a RigidBody,
so we go back into our paddle.
We're going to add a component Rigidbody 2D.
It's already attached to our paddle.
Basically, these things give us physics.
Box collider means that if an object touches this,
if something else of the box collider touches this item,
it'll say, "Hey, something's touching it.
What do you want me to do?"
Then in the script, you can actually tell it what to do.
This is the Rigidbody here is helping us move.
This will help our paddle move left and right
and then the box collider will help the ball bounce off of it.
We're going to go in here and we are going to make it public
because we want everyone to be able to access it.
Rigid bodies, we're going to call that RigidBody.
We are calling in another awake function.
This is what the paddle does when the game awakens.
Add physics, so public.
But basically, this is helping our paddle move back and forth
and in here with input GetKey, GetKey, KeyCode.
The sentence now says if the input is a
or if the input is left arrow,
the paddle, this direction is left.
The paddle goes left.
This is where we call direction.
I think that's all we need
to make our paddle move, if I am not mistaken.
Yes, physics.
Unity makes it pretty intuitive to actually add them in.
Let's see what they're adding in next here.
Private void fixed update,
which is another Unity integrated function.
If this direction does not equal zero,
you're basically adding force
to whatever direction is currently happening.
Direction, left or right, times our speed,
which is currently, look at all my folders,
look at how organized I am,
wow, look at me.
We did this last stream.
Give it a box collider because it needs to hit it.
Let's just put it here because I know for a fact
that it's a little bit under this panel.
We're going to put it right under here.
This one, we're going to rotate it, tedious work,
all the joys of game design,
and last but not least, WallRight.
Then we're going to move it.
That's not bad, it worked.
But yeah, we added the first of our physics.
Now our paddle, who's left and right, which we did that.
Our paddle is moving,
now we just need to give our ball some physics.
Let's look into this real quick.
We're making everything zero, I think,
we're doing out everything in the paddle.
I was actually right about that.
Fun fact. I was right.
This helps us with,
you know how are things speeding around earlier?
This gives it some mass
so that it can't just zip around all over the place.
If we go into the RigidBody constraints,
we can actually freeze the positions here.
We want to freeze our x, so our left and right, so this way.
Now our little thing won't drop any more.
New script.
This is going to be everything that controls our ball.
If I'm not mistaken,
we only need the Unity engine.
That is correct. We can get rid of everything else.
We're calling the RigidBody,
so now we're going to drag this on here.
Now it's like, I'm not attached anything.
I don't know what RigidBody you're talking about,
now it does, because we put the script on the ball.
Very similar to last time,
we're going to make a function on awake.
We're going to grab that RigidBody
and then we're going to make our start.
Now we're going to add force.
It's saying we don't have any at the current point in time,
we're adding some force to it after the game starts.
We're going to make the ball.
It's also going to have speed of 30.
We are multiplying the force times the speed,
so this little asterisk, this just means multiplied by.
Scripts are sorcery. They are.
But when you actually break them down,
they're not actually that scary.
We are adding force at the beginning
of this function, at the start.
If I remember how Brick Breakers work,
this is going to be the thing that makes our ball go, "Wee, boing"
and bounce off and start the game.
But basically, the randomizer means
it's just going to go in any direction,
either that way or that way, to hit the thing.
But now, when we start the game,
the ball will start going in a certain direction
between negative one and one.
We're probably not going to get to the bounce part today.
We have the very, very beginnings of our game.
The ball drops right down onto our paddle
and depending on which way we move the paddle after that,
we add in our bounce.
It'll go that direction,
and when we fix our walls,
it'll bounce off the walls,
and then we're going to have to add if functions,
probably for what happens with the bricks when they're hit.
The next step will be you all being able to log into this game
and actually play it yourselves,
which I'm so excited about.
We still have a little ways to go.
So you can see, even for a simple game like this,
there's a lot of background work that goes into it.
But yeah, that's all we're going to dive into today.
[MUSIC]