Build 8 Android Games with Unity : bit.ly/3tvSuUS Build 10 2D & 3D Games: bit.ly/45oC51S Move To Any Specific Part Of The Video(Click Below): 1. 00:00 - Introduction To The Game 2. 01:00 - Creating New Unity Project 3. 02:30 - Setting Up & Importing Assets 4. 04:00 - Setting Up Ground Player & Block 5. 11:15 - Creating Player Controller Script 6. 23:45 - Coding The GameManager 7. 33:30 - Creating Tap To Start 8. 34:15 - Creating Score UI 9. 43:00 - Adding Title Text 10. 44:25 - Play Testing The Game 11. 45:10 - Building an apk 12. 47:40 - Learn More With My Courses | -------------------------------------------------------------------- | Check Out These Courses: 1. Build 8 Android Games with Unity : bit.ly/2zSG65S (20+ Hours of Video Content ) 2. Build 3D ZigZag Racing Game with Unity : www.udemy.com/course/unity-android-3d-zigzag-racing-game-development/?referralCode=1DDDDB09430C2DA6DA0F 3. Build 5 Games in Unity & C# (21+ Hours) : www.udemy.com/course/unity-2d-game-development-by-example/?referralCode=F9C6AE2574D7550AB4A0 4. Complete C# Scripting for Unity (25+ Hours) : www.udemy.com/course/unity-c-sharp-scripting/?referralCode=7BDB9FB29D828838D623 5. Unity By Example : 20+ Mini Projects www.udemy.com/course/unity-mini-projects-game-development/?referralCode=9BC92E1A7A8FD44EAFCA Happy Learning :)
@RiseOfAquarius Жыл бұрын
I had never written code or an app, or used Unity before, and made this game in a few hours thanks to this tutorial! It's on my phone right now. Thanks.
@ChargerGames Жыл бұрын
Great job, Glad it helped :)
@DannySantana-tx1uk6 ай бұрын
@@ChargerGames Bro tienes un tutorial en espanish?
@csiwele617 Жыл бұрын
I am so impressed Raja is a boss. Only getting into game dev now as a hobby and I know watching more of your videos will def super charge my skills. Please never stop the great work you are doing. you are giving people the tools to improve lives.
@ChargerGames Жыл бұрын
Thanks a lot, Glad I could motivate you in your journey. Keep Building 😊
@AlfaShockk Жыл бұрын
I have to say something.... I watched about 40 tutorials on youtube trying to create a simple game to work and everytime something was incorrect with they code or the expalnation was not clear. You are the only one that done it rith from start to end! you explaint it well my friend and THANK you for that! I defantliy looking up more videos of yours :)🥰
@6039EktaMukeshsingh4 ай бұрын
can you please help me with the project
@mohdsala92637 ай бұрын
Thanks a lot! That was a real full package. At the very end of the tutorial, I thought that you were not going to talk about how to release the final apk and surprisingly, when I reached that part I was totally satisfied by your complete tutorial. Thanks
@ChargerGames7 ай бұрын
Thanks, Glad it helped :)
@ChargerGames Жыл бұрын
Build 7 Android Games in 1 Video (5+ Hours) 🤩 kzbin.info/www/bejne/h5bXpJubqNGbgpY Hope You'll Enjoy watching this video. All The Best 😊🤞
@lanemathlessons Жыл бұрын
48:18 This answers the question I was asking the whole time, what about device independence? Unity matches the height of the intended layout to the height of the device and sets the width of what is showing to match the device aspect ratio. In this case, it messes up your maxX, your starting text, the intended width of your ground sprites, etc. The ipad had a clear cutoff with the ground sprites, and the pixel phone afterwards also was a little taller than 16:9 and caused the boundaries and full width of the starting text to be slightly off screen. You pretty well explained how you could use UI to fix the tap to start portion, but the other issues were not corrected (see 44:46 where the block is slightly off screen compared to your intended parameters). I believe in making applications work in both portrait and landscape also, which would quite break this had you not disabled landscape. Anyway, it sounds like you would just need to get the device parameters and detect orientation changes in order to update maxX and the width of the ground and placement of colliders to work with that particular device.
@JustAnOrdinarySimmer11 ай бұрын
Yes, but this game is intended to be played only in portrait.. why the fuck would you want a game like this is landscape?
@luisdelgado0510 ай бұрын
I really happy to see this video, simple, funny and great well know !!
@ChargerGames9 ай бұрын
Glad you liked it!
@RichardFirOey Жыл бұрын
This is the nicest tutorial and really easy to understand so far. thank you very much
@ChargerGames Жыл бұрын
Thanks Richard, Glad it helped :)
@christianruelasgodoy12788 ай бұрын
Thanks bro, I am software developer but i am new in Unity and this video help me too much
@ChargerGames8 ай бұрын
Glad I could help
@rafaferdi Жыл бұрын
thank you sir, for the tutorial video. very helpful. this is my first game, which i made for android. Once again, thank you so much.
@ChargerGames Жыл бұрын
Glad it helped! kzbin.info/www/bejne/h5bXpJubqNGbgpY You can check out this video to build 7 different Games :)
@rafaferdi Жыл бұрын
@@ChargerGames Thank you very much sir
@rohithr.a8 Жыл бұрын
this is my first game that i have created in my life thanks mate 💌
@ChargerGames Жыл бұрын
Great, Congrats :)
@AAK4454 ай бұрын
Very useful Tutorial. Recomended!
@jihedbouchnak Жыл бұрын
perfect good job one of the best mobile tutorial ever
@ChargerGames Жыл бұрын
Glad it helped
@preguica_net6 ай бұрын
In first, I want to have a idea about Unity Hub in action and you help me. It is possible, so now I will study Unity in more details. Very nice video, thank you.
@TadasX Жыл бұрын
Game starts automatically without any tap "TAP TO START" [EDIT] Problem solved -> 32:30 (have to disable the block)
@ChargerGames Жыл бұрын
Great to see you solved it yourself 😊
@Mystic_Ash2 ай бұрын
Omg u saved me thank youuu
@gaiomuzioАй бұрын
Also solved for me thanks
@TechBoxNorth Жыл бұрын
Why is the variable touchPos a Vector3 and not a Vector2 ?
@ChargerGames Жыл бұрын
Position is part of Transform, and it has 3 Values you can check from the Transform component of any object.
@LunchTimeSimulations10 ай бұрын
Thank you Raja, great tutorial - much appreciated! New sub!!! 👍✌
@ChargerGames9 ай бұрын
Thanks, Glad I could help :)
@Draculinio Жыл бұрын
You are my hero man.
@ChargerGames Жыл бұрын
Thanks man, Glad it helped :)
@sadunimadhushika7331 Жыл бұрын
Nice tutorial Sir. Please Make More Videos about Mobile Game development Thank you very much 💖
@ChargerGames Жыл бұрын
Thanks, I'll try creating more. There are already many android videos on the channel, you can also check them out :)
@sadunimadhushika7331 Жыл бұрын
@@ChargerGames Ok Sir . I will check
@vanhxaychannel18852 ай бұрын
This Videos very Useful
@rodyjeanbaptiste5176 Жыл бұрын
I do everything but they say i make an error in mine , can somebody help me please 16:47
@khrukhy_dev693211 ай бұрын
same bro
@KohithaNarahari5 ай бұрын
at 33:04 minutes can any one tell why i am not able to get the blocks as shown while playing the game but in my unity block(clone) is creating in hierarchy in SpawnPoint can anyone tell why
@nailcutter892011 ай бұрын
block: if(transform.position.y < -6f) { Destroy(gameObject); } Player: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class Player : MonoBehaviour { public float moveSpeed; Rigidbody2D rb; // Start is called before the first frame update void Start() { rb = GetComponent(); } // Update is called once per frame void Update() { if (Input.GetMouseButton(0)) { Vector3 touchPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); if(touchPos.x < 0) { rb.AddForce(Vector2.left * moveSpeed); } else { rb.AddForce(Vector2.right * moveSpeed); } } else { rb.velocity = Vector2.zero; } } private void OnCollisionEnter2D(Collision2D collision) { if(collision.gameObject.tag == "Block") { SceneManager.LoadScene(0); } } } Gamemanager: using System.Collections; using System.Collections.Generic; using System.Xml.Schema; using UnityEngine; public class GameManager : MonoBehaviour { public GameObject block; public float maxX; public Transform spawnPoint; public float spawnRate; bool gameStarted = false; // Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0) && !gameStarted) { StartSpawning(); gameStarted = true; } } private void StartSpawning() { InvokeRepeating("SpawnBlock", 0.5f, spawnRate); } private void SpawnBlock() { Vector3 spawnPos = spawnPoint.position; spawnPos.x = Random.Range(-maxX, maxX); Instantiate(block, spawnPos, Quaternion.identity); } }
@kaushaltrivedi88772 ай бұрын
hey, i also tried to make this. but when i start game, blocks are visible in only scene not in game. when it collide with player game start from 0 everything working only block are not visible in game view. i watch video 2 time i do everything same as you,
@mdshourovmolla2000 Жыл бұрын
Everything works fine. But the left & right wall is somehow not in correct position. It works fine on unity editor. But when I play the game in mobile device the player is still going out of screen a little bit. How to fix the issue?
@Wikarian99PL Жыл бұрын
Because this game works only fine for 1 Resolution/Aspect Ratio, its not scaling with screen As You could see at 40:15 with iPad Emulator, screen was to wide, showing to much When He swiched to Google Pixel 5, game just cutted left and right view, as You can see by to wide "Tap to Start" text and how Block at 40:30 is also cutted, making Your wall same outside visible screen The more screen height and less width device have, the more view will be cutted, making playing at other devices really bad or even impossible
@lanemathlessons Жыл бұрын
This is exactly what I just commented about! I've done android, and I've done unity, but never in the same project. So while I don't know what syntax would be used here, you could get the device pixel size to determine its aspect ratio and modify a few values at runtime (maxX, location of boundary colliders, width of ground sprites). The start() function would be helpful for this but would reload every time you die. You could use a dontdestroyonload if needed to only do it once, but I don't see it being a big deal.
@Nuke-France Жыл бұрын
at the one { at line 6 of the block code is a error help at 10:30
@Nuke-France Жыл бұрын
asked chatgpt
@imanonymous028 ай бұрын
a cool tutorial 😀👍
@ChargerGames8 ай бұрын
Thank you! Cheers!
@AkankshaJadhav-jr4zy9 күн бұрын
In my unity When Trying to write velocity it will convert linear velocity to any other option.
@devrimay7017 Жыл бұрын
how can i make the "dodge block" text without background like yours? i used meteors instead :)
@gol_d_beard Жыл бұрын
Great video. I'm not a professional but I guess there is flaw in it please correct me if I'm wrong after moving our character it's better to put * Time.deltatime Because I did as you send but I faced speed variation with refresh rate. As I said please do correct if I'm wrong. Thanks but really this video helped a lot.
@ChargerGames Жыл бұрын
Yes you are correct, That's a good suggestion :)
@gol_d_beard Жыл бұрын
@@ChargerGames thanks then if you dont mind under your comment pin mine too or you can add a comment so others can change their code too. :). like your tuts.
@abhagupta-ashishkumar4707 ай бұрын
Thank you ❤
@ChargerGames7 ай бұрын
You're welcome 😊
@LazarSenicic-g3k4 ай бұрын
Hi. I'm new to unity and just wanted to ask, if you made game horizontal, how would you make box move from right to left side. Every solution I tried to find points me to creating scripts for player movements, can't find anything on making objects move on they own on x-axis. Thanks.
@berat8865 Жыл бұрын
32:47 Blocks fall randomly every second, but I don't get even one block, what is the reason for this?
@Diemermakes Жыл бұрын
Check the Block in the Assets/Prefab folder (NOT the one in the Hierarchy/Game panel). Ensure that the checkmark between the blue cube and the field that says Block is checked. This makes sure the prefab is added to the scene. My guess is you, like me, had the original one unchecked when you created the prefab and so it starts in that default off state.
@PotatoGamer-ScreamerNL Жыл бұрын
Can u also mak one for IOs bc me and my friend have an iphone or is it the same?
@TheSpikeyManMc9 ай бұрын
i assume instead of switching to android build u would have to switch to Ios build. then same tutorial and at end u create ur ios build. This is just an assumption, not sure if it would work. thx.
@MohamedElHanoun3 ай бұрын
This should be recommended By Unity for beginners
@Plague_7 Жыл бұрын
hello man there is an error with literal characters yeah can u help quick am tryuing to fix it for about 2 hours
@jaychau210 Жыл бұрын
thanks for your video
@ChargerGames Жыл бұрын
Most welcome
@aaa1123-s6i17 күн бұрын
What do you think about making mobile games for Android or iOS in terms of earnings?
@ANGELx-tu8dx Жыл бұрын
i need help here, after i dropped dblock script and doubleclicked on block, it opens something else. what should i do? it doesn't open same page as you
@juliaalder2007 Жыл бұрын
Nice tutorial. 😊 How is this text autocomplete feature called?
@ChargerGames Жыл бұрын
It's Visual Studio IntelliSense
@juliaalder2007 Жыл бұрын
@@ChargerGames Thank you. 😊
@vishakharoy14233 ай бұрын
I'm unable to setup with visual studio as there it's showing application isn't installed
@blgn99447 ай бұрын
please moore tutorials😊
@ChargerGames7 ай бұрын
There are a lot of Videos on the channel and more coming Thanks for watching :)
@techpankaj44026 ай бұрын
How to get assets for game without copyright and i have a questions if i make a game and some assets already use by other game will they file case against me
@Nuke-France Жыл бұрын
on the block file the one { on line 6 is a error and i have no idea what to do
@ElTigre-v8g4 ай бұрын
Hi can we use the code provided on the tutorial as a baseplate and implement/add new features on top of it and then create our own game in the genre to publish it on google play store?
@captain_fact5 ай бұрын
Can you show us how to build an android app using urp instead of 2D? The old renderer and 2D don't give any errors but urp gives errors
@BierGarten1008 ай бұрын
The Objekt like the block is not displaying after play ... why? ... Its create every and every time a "(Clone)" Object and doesnt remove it after fall out from screen and doesnt show. I do everythink what you do.
@ChargerGames7 ай бұрын
Check the Prefab, make sure it's activated :)
@a1MinecraftPlayer Жыл бұрын
can you make a currency, and a shop and you can unlock new charters, and make the player can move while sliding your finger, also how can I make current score and best score?
@ChargerGames Жыл бұрын
All those things can be implemented, this is a short tutorial on how to get a Game going in less than 1 hour :)
@a1MinecraftPlayer Жыл бұрын
@@ChargerGames can you make a toturial about it.
@frickingcore1o_ Жыл бұрын
thankyou so much finally i made it
@ChargerGames Жыл бұрын
Great, Congrats 😍 Here's what you can do Next : kzbin.info/www/bejne/h5bXpJubqNGbgpY All The Best
@sagarmore49688 ай бұрын
Thank You
@ChargerGames8 ай бұрын
Glad it helped :)
@sagarmore49688 ай бұрын
@@ChargerGamesWhen I build for Android in my phone the player is running slow, but in software it's normal speed. How can I solve this? Please tell me
@By888Tj Жыл бұрын
hi there. if i want to speedup the spawnrate overtime, for example, every 10 score, faster the speedrate spawn 0.5 how to do it? thanks
@ulfp8025 Жыл бұрын
can i edit the game and stuff using Android as build settings but then change to web and get it built for web but with touch implemented?
@ChargerGames Жыл бұрын
Yes you can, this code works on both platforms :)
@ulfp8025 Жыл бұрын
@@ChargerGames Awsome and thanks for an awsome tutorial
@michelkrieger9756 Жыл бұрын
Sehr Sehr geil danke
@rohithr.a8 Жыл бұрын
Move speed is not showing for me please help me 16:43
@ChargerGames Жыл бұрын
Probably there's some error in the code
@nnapster009 Жыл бұрын
instead of public float moveSpeed; try to use [SerializeField] public float moveSpeed;
@kding09 ай бұрын
What would cause my score text to change from 0 to display TextMeshPro ) ? Thanks
@ElTigre-v8g4 ай бұрын
Hi, can we use the code in the tutorial as a blueprint and implement new features on top of it to make our own game in the genre and publish it?
@BlessingBeast Жыл бұрын
Hey bro. I am trying to build an android game in unity. But when I click on build I get too many gradle errors. Can you help me bro?
@ChargerGames Жыл бұрын
Check if you have Android SDK, jdk and build tools installed properly
@BlessingBeast Жыл бұрын
@@ChargerGames can we talk on insta?. I will send you screenshots of the error.
@TidalWoW Жыл бұрын
@@BlessingBeastI had Gradle errors in my build too. I removed the Mobile 2D packages and the Adaptive Performance packages and I was able to build after. Something to try.
@VigoClips8 ай бұрын
I don't know what happened but when ever my player Collide with a wall the game was restart😢 Any Solutions?
@ChargerGames7 ай бұрын
Check the tags correctly :)
@JustAnOrdinarySimmer11 ай бұрын
I followed this and all is good.. I did my own research though to change some things, such as pressing, holding and dragging the pig. One thing what is irritating me though is this strange "score" system which is acting more like a timer... could you do a follow up on this video and show us how we can implement score when the block goes through the bottom of the screen? Since the block is a prefab, you are not able to drag in TMPro text.....
@SUBHOJITSADHUKHAN-p1g Жыл бұрын
I don't understand couple of things.. Please Clear it out. 1. Just before creating canvas , Player, Camera, Ground was visible in Scene section but somehow all got invisible 2. Scoring should be updated after the box passes the player not while generating the box, how to do that ? 3. in mobile screen half portion of boxes are getting cut of by the screen how to fix that ?
@TheSpikeyManMc Жыл бұрын
did u find an answer for ur question?
@Fulfinsen Жыл бұрын
Hello. Can I add this project in my portofolio (of course, with the link to the tutorial)? Until I have my own assets, I want to have this project as a refference for my portofolio
@cucun1q10 ай бұрын
I checked my codes but it still after the second one there is no guı no score no tap to start text
@rohithr.a8 Жыл бұрын
Bro should I upload my game on play store first and then would I only be able to add ads after that? Please reply
@ChargerGames Жыл бұрын
You can see ads even without Uploading :)
@spooky_1067 ай бұрын
it gave me a compile error when i saved the script as in the block script
@TheoWiese-e6t Жыл бұрын
cool video)
@alibaig7001 Жыл бұрын
Why Your Block Destroy Scripts Not Working Well, When I Play the Game The Block Destroy Scripts Disappeared the block From First.
@Nxtsuu11 ай бұрын
my boxes are not constantrly respawning, i followed everything exactly , any ideas?
@bushydev205011 ай бұрын
make sure your code is identical to his.
@rohithr.a8 Жыл бұрын
Bro I can use 2022 visual studio instead of that I used 2019 would there any issue?
@ChargerGames Жыл бұрын
Yes, no problem
@samplays675Ай бұрын
can i add this game to my portfolio
@0xTheDarkArtist Жыл бұрын
Native link step faild at Burst compiler , can u help ? ?
@abdullahahmed3364 Жыл бұрын
❤I have a problem that I did not understand. The moving code applied it, but it touches the screen exit from the edges. What is the solution? Thank you. I am following you and your fans.
@ChargerGames Жыл бұрын
I'm not sure if I understood your problem correctly. Do you mean when you touch edges of the screen the Player moves ?
@nnapster009 Жыл бұрын
@Abdullah Ahmed You didn't add the wall collider or added but those are not in right place, just because of wall collider your player will stop to cross the right/left edges.
@thepocotrampo Жыл бұрын
Thanks
@adampro-b1h3 ай бұрын
can people copy this and post it to google play?
@Akgamer0050 Жыл бұрын
block is falling down but not restarting ? please help me
@K-Dingo9 ай бұрын
Not sure what I've done but the block lands on my head and the game doesn't restart lol.
@ChargerGames9 ай бұрын
Check the Tag , make sure it's spelt correctly
@xyz-vv3dm6 ай бұрын
please i need the scrips, the link does not load
@jitusa4972 Жыл бұрын
how to show final score
@cozmoyt Жыл бұрын
How to add sound .. please reply
@tmkk7 Жыл бұрын
[Adaptive Performance] No Active Loader was found. Make sure to select your loader in the Adaptive Performance Settings for this platform. Can anyone suggest solution for this, as i am unable to run in game mode
@DeanJWell13 Жыл бұрын
did you work this out? i have the same issue
@TidalWoW Жыл бұрын
Adaptive Performance is a package that allows you to change how your game runs at low battery on a mobile phone, to save battery life. If you aren't using it, you can just disable the package (might need to disable packages that depend on it and unlock it so it can be removed).
@rohithr.a8 Жыл бұрын
Bro I got new problem , block is falling down but not restarting ?
@ChargerGames Жыл бұрын
Check the tags properly :)
@boltbuild9 ай бұрын
For me it always says cradle build failed can someone help
@math_solver_N Жыл бұрын
Hey can u please help me. When I played it on my phone it was a lot pls tell me how I can minimize the lag pls 🥲
@Gamingworld0912 Жыл бұрын
How can i add background music and jumping sfx
@ChargerGames Жыл бұрын
Add an AudioSource , and in the audio add any audio, it will keep playing :)
@gelomelo89689 ай бұрын
thank a lot vro, finally maine khatm kar diya ye game banana and i can say bahot kuch seekha , thanks vro really thanks
@ChargerGames7 ай бұрын
Great job, All The Best for your Learning :)
@gowrisankaran.r2590 Жыл бұрын
bro In gamemanager script update function is not working for I mean the game start running without mousebutton pressed help me bro....
@TadasX Жыл бұрын
Dude I have the same issue and there are not any answers 3 months later, I'll keep searching until i solve the problem.
@TadasX Жыл бұрын
32:30 have to disable the block
@enriquecajunsheriff4104 Жыл бұрын
so i can't try the game on my actual device without having to create the apk???
@ChargerGames Жыл бұрын
You can try using Unity Remote App
@BeingMtVjy4 ай бұрын
How to add a high score in this??
@rohithr.a8 Жыл бұрын
Mate can you make a video on how to make sprites
@ChargerGames Жыл бұрын
I have a few videos on the channel with Inkscape, you can check them.
@ashmantv5646 Жыл бұрын
hı touch code say rıgıdbody 2d not found type or namespace error can you help me player movement code
@TheZizzly9 ай бұрын
rıgıdbody isn't rigidbody
@sebz0h5 ай бұрын
"Can't add script component 'Block' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match."
@PuppyNation25 ай бұрын
Is your block’s name block?
@thoraxtreuwig517 Жыл бұрын
In the beginning you can choose between 2D and 2D Mobile. Why u choose the normal one and not mobile?
@thoraxtreuwig517 Жыл бұрын
Thx for the awesome tutorial :)
@Zee-l1s Жыл бұрын
How does the box hit the pig but not the floor and pass through it?
@Zee-l1s Жыл бұрын
I found it, assigning different layers and under edit-project settings-physics 2d there is a matrix
@tawny5474 Жыл бұрын
How can we Add it on the App Store pls ?
@ChargerGames Жыл бұрын
That's a pretty long process, but there are some other stores where you can publish your game just now. I have made a video about google play store alternatives you can check that :)
@tawny5474 Жыл бұрын
@@ChargerGames ok thanks !
@abdulhadisyed4690 Жыл бұрын
can someone please tell me how can I create a sprite like "Tap To Start"?
@VS-mt5tz Жыл бұрын
If you don't know how to make a sprite then maybe you should go back a few steps bud
@redghost6386 Жыл бұрын
Hi, thank you for the tutorial. I am having this issue: when I press the mouse button the player moves once lets say I click 10x the player will move once if I hold down the mouse button the player moves once and stops. The code has no errors and is exactly what you have shown me. Could this be my settings in unity? To move the player I have to set moveSpeed to 10000 lol as I say the code is exactly what you have shown.
@redghost6386 Жыл бұрын
I solved this issue with this code using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour { // Variables here public float moveSpeed; Rigidbody2D rb; private bool isMoving = false; // Flag to track whether the player is moving // Start is called before the first frame update void Start() { rb = GetComponent(); } // Update is called once per frame void Update() { // Check if the left mouse button is pressed if (Input.GetMouseButtonDown(0)) { // The player starts moving when the button is pressed isMoving = true; } else if (Input.GetMouseButtonUp(0)) { // The player stops moving when the button is released isMoving = false; } // Apply force only while the button is held down if (isMoving) { // Variable that tells us where the mouse position is Vector3 touchPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); // Find out which side of the screen is being touched to move based on that if (touchPos.x < 0) { rb.AddForce(Vector2.left * moveSpeed); } else { rb.AddForce(Vector2.right * moveSpeed); } } } } Thanks for the tutorial :)
@redghost6386 Жыл бұрын
using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerControl : MonoBehaviour { // Variables here public float moveSpeed; Rigidbody2D rb; // Start is called before the first frame update void Start() { rb = GetComponent(); } // Update is called once per frame void Update() { // Check if the left mouse button is pressed if (Input.GetMouseButtonDown(0)) { // The player starts moving when the button is pressed MovePlayer(); } else if (Input.GetMouseButtonUp(0)) { // The player stops moving when the button is released StopPlayer(); } } // Move the player void MovePlayer() { // Variable that tells us where the mouse position is Vector3 touchPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); // Find out which side of the screen is being touched to move based on that if (touchPos.x < 0) { rb.AddForce(Vector2.left * moveSpeed); } else { rb.AddForce(Vector2.right * moveSpeed); } } // Stop the player void StopPlayer() { // Set the player's velocity to zero to stop movement rb.velocity = Vector2.zero; } } this code is the one that works lol was a headache.