How to Move object with UI buttons in Unity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in the last tutorial we'll learn how to move a cube with keyboard keys in this video i will teach you how to move a cube or any game object with ui buttons so without wasting any more time let's get started [Music] as you can see i have continued the project and also open up the c-sharp script which we make in the last video and in this video we want to make this cube move here and there with the help of buttons so first of all i i will change background color for better look [Music] so this is looking cool let's right click over here and create ui and canvas again right click ui and make a button put [Music] rename it and call it left and move it little bit to here [Music] duplicate it and move it little bit left and or delete it for right now and let's change its image and search for backward it's looking cool i will let's make it a little bit bigger and [Music] it's looking cool here let's delete the text [Music] again duplicate it and [Music] rename it to [Music] right and move it little bit left and change again picture [Music] forward [Music] so as you can see i have created two buttons looking pretty nice and we want to use this button to move this cube here and there so i will i will go to the script and make a new variable let's make a boolean public boolean is working [Music] and let's make it false [Music] [Music] make add and let's change its name is working left we can make another make another variable call it public boolean is working right equal to false [Music] for left let's delete this code from here and [Music] put put boolean here let's copy this this boolean name copy from here and paste it over here [Music] and for right copy this right variable and delete this code from here [Music] and paste it here [Music] let's make an other function [Music] public white [Music] is trigger left [Music] here you have to make another boolean and call it can move left [Music] [Music] and the sign is walking walking left equal to equal to can move left let's see [Music] let's click on left button and add component and search for [Music] event trigger admin on pointer down and on pointer up just put game manager here again game manager here and click on movement and it's trigger left movement is trigger left check for this boolean and let's see whether it's working or not [Music] so it's working properly again do this for left button make a new function called it public sorry public make another function for right public what is trigger [Music] right and make another boolean here boolean can [Music] move right [Music] again is working right make it equal to [Music] can move right so let's save this and go back to unity and again click on [Music] again click on write button search for event trigger and add component admin data and click on pointer down and pointer up drag and drop game manager here also here go to movement and search for his trigger right again movement is trigger right and check this boolean again so let's check whether it's working or not [Music] okay it's working for left and also working for right awesome [Music] in the next video i'll teach you how to make a main menu and a jump system for this cube i hope you guys enjoy the video so please press the like button and subscribe for more videos [Music]
Info
Channel: Aryan Game Dev
Views: 1,001
Rating: undefined out of 5
Keywords: Unity, Move object, UI button, Android control, How, how, unity, move, object with mobile button, install, windows, windows 11, unity 2d, programming, coding, visual coding, script, aryan, toon, 2 toon, Aryan, Shaheen Technologies
Id: XPQ3nXtcV9I
Channel Id: undefined
Length: 9min 15sec (555 seconds)
Published: Thu Nov 18 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.