Search Unity

Question Need to move player(cube) using ui button on screen

Discussion in 'Getting Started' started by yousuffffkhan01, Aug 27, 2023.

  1. yousuffffkhan01


    Aug 22, 2023
    Hello guys.
    I am new to unity and visual scripting.
    I have knowledge on 3d modelling, animation etc....
    But the problem is I watched all basic tutorials on" how to move an object(player) when I touch ui button(or ui image) on screen". But I didn't find simple tutorial.
    My main issue is: I know to create ui image(left arrow and right arrow on screen) and I know to create cube(player). And I have added component on player input. I m using new input system. When I touch a ui image the player is not moving.
    Where to connect the ui image to player in unity?
    Can anyone type and give me a simple steps so that it works.
    Thanks a lot in advance.
  2. AngryProgrammer


    Jun 4, 2019
    I know it's not what you ask for, but consider learning regular C# scripting. Why? Because it gives you an extra skill that will be universal in any programming. Don't worry it's not so hard!

    Back to the question.
    1. Write CubeController script with methods Left, Right (for start).
    2. Drag and drop the script on the Cube game object.
    3. Make left and right UI buttons on the screen.
    4. Look inside UI buttons components something like "on click", press + sign, drag and drop the Cube into spot "None (Object)". Now you have a reference to the object.
    5. From the list in the same place look for "CubeController", and the next menu Left or Right method you wrote.
    But before you do that you probably need some background on how to move objects at all (link at the beginning).