Let's make the game for our mobile devices.
So we need to switch to Android.
But before we do, let's import some as some things.
Basically, we're gonna import simple input for our mobile, uh, basically an arrow.
But before we do it, uh, what we need to do, we need to move over to our sample scene or in which
scene we're playing our game.
To do so, let's head over to project Tab assets, and I have it inside this assets folder.
So I'm going to click double click on this simple, uh sample scene.
So just move over to your level scene.
And once we are over here so what we want we want a left arrow a right arrow for mobile devices to touch.
If we just tap on left arrow, then we want this player character to move to the left direction.
And if we just click on the right arrow, then we want this player, uh, game object to move to the
right direction, and we're gonna have a jump button as well as a attack button for mobile devices to
do so.
For what we're gonna do, we're gonna we need to import simple input.
So basically head over to google.com and move over to Unity Asset Store.
Right over here.
And in the top part search this simple input as you can see.
And as soon as you search, you're gonna get this simple input system right over here as you can notice.
And I just open that up.
So basically you're gonna see a add to my assets button right next to this simple input right over here.
So just click on that and it's gonna add to your assets.
And once you done then click on this open in unity.
And then click on this Open in Unity editor.
And you're gonna get redirected to your unity editor and you're gonna be in my assets.
So if so, we can see we have the simple input system.
And you're gonna see a install button right over here.
So just click on that install button and it's gonna install.
And after that click on that import.
You're going to see a import right after install button.
So just click on import.
And in the bottom you're going to see import.
So we're gonna import we can import that as well by clicking in project.
And uh we already done it.
So I'm going to click on this cancel button.
And if you are not able to find then in the left part you're going to see in Project Unity registry
my assets and built in.
So select this unity my assets basically select this in the left bar says my assets and search over
here simple input.
And it's going to pop up.
Sorry.
Uh it's gonna pop up which is simple input.
So as soon as we type it's just popping up as you can notice.
And once you are selecting that then click on this install button and then click on this import to project
and then click on this import in the bottom right you're going to see.
So I hope you get the idea that how you can do it.
And once we done so we can simply cut this tab right now and we can just move over to our project tab
assets.
And we're going to see a plugins folder right over here we can see.
So you're going to see a plugins folder.
Once you are just going to import your simple input.
So basically what you need to do.
Firstly you need to move over to this project tab assets and you're going to see this plugin folder.
Then click on this arrow to select our simple input.
And then click on this arrow to see.
And we're going to move over to our prefabs folder.
And we have many prefab.
We have this arrow all direction.
We have arrows horizontal.
We have arrows vertical.
So since we want arrow horizontal basically left and right.
So we're going to select this prefab says arrows horizontal.
Select that, then drag it on top of this canvas GameObject in the hierarchy, and as soon as we drag
it, we can see by now in the scene view.
But uh, basically we're gonna select our arrows horizontal underneath our canvas, and let's press
down F in order to focus on it.
Make sure you select your arrows horizontal and drag it above this canvas GameObject in the hierarchy
in order to see.
And we're gonna select our arrows horizontal.
And we can just, uh, make it bigger a little bit, something we can hold down.
Also, it's going to resize from center.
Or we can just, uh, we can just, uh, pull up our finger from that alt key to see this.
As you can notice.
And I want to replace this, uh, button arrow.
Basically I want to change with square and this arrows as well.
To do so we can just, uh, select right over here, but we can just click, uh.
But before we do, let's have a look.
So I'm going to click on this play button in the top in order to play our game.
And if we try to click this left or right arrow you will able to notice our player game object.
Not gonna move at all.
So we need to move that.
But before we do, let's have a look on it.
Uh, have a look on it.
So if I just click on this right arrow, we can see our player is not moving at all in the right direction
as well as this left arrow.
So we need to do that for it.
What we basically have to do we need to get out of play mode.
And we need to open up our player script where we just are moving our player.
So we do know that we are doing inside our player.
So we're going to select our player game objects.
Uh, right over here.
Other stuffs I have the player inside.
So select your player game object in the hierarchy.
Then open up your player script by double clicking on it.
And what we need to do now we need to basically use a we need to use simple input.
So just wait a moment to open up our script.
And once we just gonna open up, we're just gonna link that up.
So if we move over to update function, as you can notice right over here, we using this moment equal
to input dot get axis horizontal.
So this movement parameter right over here is responsible for moving our player to left and right.
And we doing input dot get axis horizontal.
Sorry I don't know why are we getting some errors.
So we're getting some errors.
Uh so basically it's uh fine.
Just I'll need a moment.
So it's fine by now.
So we created this movement right over here.
Private float movement parameter, which is responsible for moving our player left and right.
And we can see right over here we just setting it equal to input dot get axis horizontal.
And we do know that this input dot get axis horizontal.
Uh, it's gonna just take if we press down a key on our keyboard, that means this is just going to
be minus one means this movement right over here just going to be minus one means our player just going
to move to the left direction.
And if we press down D key then it's going to be one.
So this movement over here it's going to be one.
So our player will start moving to the right direction.
So what we're gonna do we're gonna leave this.
And now we're going to check we we're gonna use simple input for that.
For this basically we need to type this simple input.
So make sure you type this simple input.
And we can use the same function which is dot get axis.
So we're going to use this dot get axis get axis.
And this in quotation it's going to take the axis in which axis you just want to move your player.
So since we want to move our player Horizontally flow a left or right.
So that's why we're going to use this horizontal.
Basically doing the same things.
So we're going to do the same thing for horizontal.
And make sure you spelling it correct.
And then close that off with semicolon.
So this simple input dot get axis horizontal.
It can be minus one plus 1 or 0 depending upon which arrow we pressing.
Let's suppose we are clicking on this or we or just touching our left arrow.
Then this function right over here it's going to be minus one.
And if we just press down the right one then it's going to give plus one.
And if we just don't tap on tap both of these arrows basically both of this button then this simple
input dot get access.
It's going to give us zero value.
So what we're gonna do we're gonna store it into this movement parameter which can be plus one, -1
or 0.
So what we're going to do we're going to store the result into this movement parameter.
So we're going to say sorry, uh, movement, movement equal to this.
So this movement is just going to be minus one or plus 1 or 0, depending upon which key we're clicking.
If we're clicking the right one then it's going to give one.
Then if we click the left one then it's going to give the minus one means our player.
And over here as you can notice, we're just replacing the x with our x axis with our movement which
can be minus one plus 1 or 0 means if we press down, the right arrow means this player just gonna move
to the right direction.
And if we click the left arrow, then this player will start moving to the left direction.
Basically, we're doing the same thing as we have done earlier with this input dot get axis for our
PC.
And basically we just need to use this simple input dot get axis horizontal for our mobile.
And that's all.
So I hope you get the idea.
So this movement just going to be minus one plus 1 or 0 in the mobile as well.
If we just click or tap on this left or right arrow or buttons.
And now we're going to press down Ctrl S to save our skip.
And now let's move over to unity.
And you will be able to notice that.
So just wait a moment.
And if we click the left one or right one we're going to be able to notice.
So if we just go ahead and then click on the left arrow, then we're going to start moving to the left
direction.
And if we click on the right arrow then we're gonna start moving to the right direction.
And if we don't click or tap or both of these arrows, then our then movement is going to be zero means
our player just gonna stand at one point and it's not gonna move at all.
So let's have a look.
So I'm going to click on this play button in the top in order to play our game.
And now let's have a look on this.
So just wait a moment.
Sorry.
And now if we click the right arrow, we can see our player started moving to the right direction.
And if we click the left arrow or hold down the left arrow, we can see our player is started moving
to the left direction.
Basically, it's working fine.
And means if you just check that out in your mobile, you can do that as well.
And I'm gonna tell you how you can do it.
And for now it let's, let's leave it like this and let's get out of play mode.
And we're gonna do the testing, testing on our mobile devices as well.
Uh, but before we do, we're gonna do these things.
We're gonna just make all the buttons to do, uh, to make the functions, uh, or basically to move
the player.
And I want to change the arrow icon.
Basically, I want square type instead of circle to do.
So what we basically need to do, we need to move over to our hierarchy than canvas.
And then we're going to move over to these arrows horizontal prefab.
Then we're going to select the left or right.
You can select any of them.
Basically we just want to change.
So that's why.
So firstly I'm going to choose the left one.
So make sure you click right over here arrows horizontal and then choose any of them.
So I'm gonna do I'm gonna start with the left one.
So I'm gonna select that.
And after doing that I'm going to move over to my project tab assets.
And then I will head over to my sprites folder.
And then I'm going to head over to my UI folder.
And I have if I scroll down, as you can notice I have a square sprite.
So I'm going to select my left button.
So let's select that.
Then go over to Inspector then Image component in the bottom.
And you need to drag the right sprite right over here with with with which one you just want to replace
with.
So since why I want this square one.
So I'm going to select that and let's drag it there.
And as soon as we drag it as you can notice it just gets changed.
But the problem is that we're not able to see our arrow.
So top of this left we're going to add the image icon.
Basically you can simply say that.
So we're going to select our left arrow.
Let's select that.
Let's right click on it and let's go to GUI and then image in the top.
And we're going to select this image.
And we can call this image to something like icon.
And make sure you do inside this left icon basically inside this square we want that arrow icon.
So that's why we just right click it on this left arrow.
And then we have chosen the image component.
And I'm going to change it with icon.
Basically I'm going to call it icon.
And if we move over to Inspector basically select the icon.
Then go over to Inspector Image Component.
And we can drag the sprite.
Basically we need to drag the sprite right over here.
So I'm going to select the left one.
As you can notice, I have it inside my, uh UI folder.
So I'm going to choose that one.
And let's drag it over to the source image field.
And as soon as we drag it now this is fine.
And I want to resize this arrow icon as the size of my square.
So what I'm gonna do I'm gonna select my icon, then go over to Inspector Transform and then click over
here.
And we're going to hold down alt on our keyboard.
And we're going to select this bottom right one to make the size of it.
Uh as our square button.
As you can notice, it's kind of seems a little bit bigger.
So we can just make it smaller.
So what we can do, we can just go over to drag transform.
And from the left side we can do 100, uh, or we can do something like ten.
I guess doing 20, it's going to be fine.
Let's do it 5050.
Let's do 40.
And from the right side we're going to do the same thing.
40 and from the top I'm going to do ten.
Let's do it 40 instead.
So it's going to be square type.
And if at the bottom we can do 40 as well.
And now as you can notice it seems pretty much fine.
Or what you can simply do.
You can select your icon and you can hold down alt on your keyboard to resize it from center.
Like this.
As like this.
You can do this as well, or you can just put the value.
So I'm going to do 40 and 40 in the top from the top 40 in the from the bottom and 40 from the right.
And now it seems square type and this much this is pretty cool.
And we're going to do the same thing with the right arrow.
So let's do that.
So let's select the right arrow.
Uh sorry right button.
Let's go over to Inspector then image component.
So we need to drag the sprite.
So I'm going to select my square.
Let's drag it there.
And we need to put the icon or basically the arrow right arrow icon to do so.
Let's select our right.
Right button.
Let's right click on it.
Let's go to UI then image component in the top.
Basically basically we're gonna do the same thing.
And now we're gonna call this one icon instead image.
So let's call it icon.
And we need to drag the sprite.
So let's select that.
Let's drag it over here and make sure you go over to Rect Transform.
And then click right over here and hold down alt on your keyboard and select this bottom right one.
And as soon as we have chosen that we can see this does get size of our square button.
So we want the same thing.
So from the left we're going to do 40.
From the right we're gonna do 40 from the top we're gonna do 40.
And from the bottom we're gonna do 40.
And once you are done then you, you can simply just move over to your parent game object, then go
over to Inspector Overrides and then click on this apply all.
So the changes you made, it's going to be fine.
As you can notice this, uh, this seems pretty much cool by now.
And if we just go ahead and then click on this play button in the top, it should work fine.
So if we click on this or just tap on this right arrow, then this player just going to move to the
right direction.
And if we just click on this left arrow then this player just gonna start moving to the left direction.
So let's have a look.
As you can notice uh we can see and the buttons basically working fine.
And you can just do these things in your mobile.
And we're going to have a look on that later as well.
That how we can check with our mobile, uh, basically live in the mobile.
So I hope you get the idea.
So I'm gonna get out of play mode and I'm gonna press down Ctrl s on my keyboard to save my project.
So I hope you get the idea that how you can do it.