Main

Visual Scripting Touch Button for Mobile Games :: Unity Basic Tutorial - Part 13

💬 Turn on [CC] to translate to any Languages [JP/FR/GR/EN/VI/CN/KR/ES... all supported] 🐾 This Video : How to learn Visual Scripting - Part 13 . How to move Player with Buttons on Mobile Games or Phone Touch . Multi Touches supported ! . Fast response on slow devices . Using Pointer events ( Work better than Raycast on Buttons ) . How to use free Macro to do it in 1 node only ! . Work on any Touch devices , any iOS , iphone , ipad , Android , tablets ... ✅ Download Button Icons & All scripts & Free Macro-OnPointerPressing : https://www.mediafire.com/file/0wwye9estlcwygk/UI_Button.zip/file ( This is better Multi Touch , but can get only Button on the top of UI Layer - Use Touch with Raycast for multi layers Buttons , link under ) 🎬 Touch Button using Raycast ( This is better if you have many UI Layers of Buttons ) : https://youtu.be/yAvGjKMK_Ds ✅ Download all project files source ( if you want to publish ) : https://drive.google.com/file/d/1YKOJOjN8NNUgN2_jk9XmfpM7A6lakXhh/view?usp=drive_link ✅ (APK) Try the game on your Android : https://drive.google.com/file/d/1g7UMZkCcgqJeudPuSW6qPkhsesLkfNOy/view?usp=drive_link 🎬 Touch Button using Raycast ( somehow you will need this ) : https://youtu.be/yAvGjKMK_Ds 🎬 All tutorial series : https://youtube.com/playlist?list=PLcNb7VR72tXP1Mqcd-vXnn_F6MJE-bbCP === 🔥 Download Visual Scripting Plus from Unity Asset Store to support me : https://assetstore.unity.com/packages/slug/219926 === 🏂 Any questions about Unity or Visual Scripting : https://discord.gg/MsmQ64rX9y ( me @Leo69 ) Follow me at : - Instagram: https://www.instagram.com/leonnguyen0609/ - TikTok: https://www.tiktok.com/@leonng_333 - Twitter : @unitynocode #visualscripting #madewithunity #gamedev #unity === Chapters 0:00 - Intro 0:37 - Create UI Buttons 3:25 - Fix Correction of Button Clicks 5:26 - Button Jump 7:41 - Button Left Right 12:34 - Test Buttons on real phone 14:07 - Button Run 17:50 - Using free Macro

Unity No Code | Leo N

9 months ago

In this video : Create UI Buttons ... ...that can work well on any iPhone, and Android. Using "Pointer" Events easy and fast response on slow devices Learn how to create "Button" Pressing in basic or use free Macro to do it in 1 node only It supports Multi-Touch... even work well with many touching buttons in 1 screen First of all : Let's learn how to create UI Buttons You can download free these icons with link under video Create UI > Button Make sure you set up the Scale Size of UI already Thi
s to fix position of UI Buttons in various resolution devices Add the icon for this Button then fix its size We don't use Text inside Button... so delete it Hold key ALT + Click to move button to corner Rename it to Button Right Duplicate to create Button Left It can work now. You can test it ! Let's change its color when Button is pressing Change any colors you want Now you can know whenever I click it on my phone screen Change other status of button to 100% white Duplicate to create 1 more fo
r Button Jump Add icon A for it Move it to the right bottom corner So we can Play it with 2 or 3 fingers easily now Let's group these Buttons We finished with Buttons creating [Button] component doesn't use Collider Button can be clicked even you clicked outside of it We need to add some script to fix it Create new Visual Scripting script You can create it in any folder you like We will fix all buttons click at game starts Use [ Set alpha Hit minimum ... ] input [This] will be object that has co
mponent [Image] Add Button we want to fix in change its value to 0.1 Press play ! If Button is clicked, it will show an error It said that it needs the permission to read and write on this image Choose icons and turn on "Read/Write" permission Now press Play to try it again ! The Button can not be clicked outside anymore The issue was fixed ! Let's do the same for all others buttons Next : Let's add script for Player Jump if Button is clicked We already have Jump events Instead of doing jump dir
ectly after a Key... Let's create a custom event for it name it "Button Jump Press" It will trigger the custom event and make Player jump To make Player Jump, we just need to call this custom event. Copy it! You can use [On Button Click] for a 1-click Button input [This] will be object that has component [ Button ] Add name of "Button Jump" Press Play and it should work "On Button Click"... working only if user clicks down and up at once I want Player Jump right after Button is clicked down Let'
s use [On Pointer Down] [Pointer] event can work for PC Keyboard, Mouse , Pen, Phone touch Just add Button's name on it. And it will work now Press Play to try it again ! Player Jump right after Button is clicked down It works very well Next : Let's move Player left & right with thse UI buttons These buttons are different They move Player whenever mouse or a touch hover over the button But they don't have that event with "Pointer" So we need to create it with "On Pointer Enter" and "On Pointer E
xit" "On Pointer Enter" triggers whenever a touch hovers on a button We need to create a Graph variable to check if Button is pressing When a mouse or touch hovers and stay on a button... it means that Button is still be pressing After "On Pointer Enter", this Button is started to press Turn this variable to TRUE Do the same for Button Left After Mouse is up or touch is leaving the button ... it will trigger [ On Pointer Exit ] Turn this variable to FALSE if button is not clicked any more We fin
ished setting up the variables Press Play to see how it works When mouse hover on a button, variable value = TRUE and when it left the button, the variable = FALSE Let's update the moving event If variable "Button Right Press" is TRUE Every frame , it will move Player to the right name this custom event is "Move Right" Do the same for Button Left If no Buttons are pressed, Player will stop movement Let's add these custom events to Player movement events [D] to move right, [A] to move left and if
no buttons are pressed, Player will play "Animation Idle" I will copy these buttons So we can move Player with Keyboard or UI Buttons anytime create the destination for our custom event Add them to Player Movement events Done ! UI Buttons can move Player now But we need to turn off Keyboard Buttons first You can turn on Keyboard again whenever you want Player can Jump now and move right or left with our new UI Buttons Next: Let's try to run it on a phone Connect your phone with a cable to your
computer we're using Remote to play the game on the phone You can see your phone name now and follow my settings to make it work faster a little bit Remote will have very slow response from Buttons It will be the best option to test your game on slow devices It works, but Player not stop moving when I stopped clicking buttons To fix this issue "On Pointer Exit" We need to give it a little bit time to turn off the variables just delay it about 0.1 or at least 0.05 second Press Play to try it agai
n on our phone Player can stop movement if Button is not pressed now Player can jump while moving as well Multi-Touch is supported ! All buttons worked well... Let's add 1 more Button for Player Run If Button Run is on pressing, Player will move faster Remember to turn on "Read/Write" permission for it too Add event to correct its click ... Now let's add some script for it ! Its event will be exactly the same "Button Right" or "Left" Change its name to "Button Run" add new variable when "Button
Run" is on pressing We can know whenever "Button Run" is pressed and not pressed now After that, add custom event to Player Run events When "Button Run" is on pressing, Player will run faster and when it is not pressed, Player will move normally again copy these custom events ... We have a keyboard button for Player run here Replace it with our new Custom Events Turn off Keyboard Button for now Press Play to try it on our phone It works well. Player can run faster Multi-touch works well even pre
ssing many touching buttons at once It still work well if you use 3 fingers to play If you are lazy to add a lot of script like this You can use my Macro to do it faster just keep the Button Jump. We don't need to remove it ! You can download this folder free with link under video Copy this event to do it ! If you have Visual Scripting Plus That event will locate inside folder Macro-NoMacro They are the same ! Just copy and use everywhere you want Open our script This event uses "Pointer" event
that we just made it ealier Now it in 1 node only to use it easier Just add the Button Name and it will work the same what we did Let's copy these custom events.... Whenever "Button Right" is on pressing, move Player to right and if this button is not pressing any more, stop Player movement Do the same for "Button Left" And "Button Run" It's too fast That can save you a lot a lot of time And you can re-use it again on any your projects easily So I recommend to use a lot of Macro in your project
All done ! Let's try it It works very well because it is using "Pointer" event But "On Pointer Exit" trigger 1 time only So we need a little fix on our "Animation Idle" If Player touches a ground, Play "Animation Idle" ...Press Play again Everything works perfect You can publish your game to Apple Store or Google Play right now I exported it to my Android phone This phone is old and very slow... But the Buttons still works perfect Even I use 2 or 3 fingers to play ... it responsed and work immed
iately Comment to tell me if you love to use Macro or not using Macro ^ ^ Thank you for watching !

Comments