Help with VirtualKeys

Hello! I need help to put right button, Left button, Up button and Down button, so that my character scrolls by touching the buttons.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class movimientopj : MonoBehaviour {
    public float runspeed = 6;
    public float walkspeed = 2;
    public float turnSmoothTime = 0.2f;
    float turnSmoothVelocity;
    public float speedSmoothTime = 0.1f;
    float speedSmoothVelocity;
    float currentSpeed;
    float velocityY;
    public float gravity = -12;
    public float jumpHeight = 1;
    [Range (0,1)]
    public float airControlPercent;
    public ElementosInteractivos botonIzquierda;
    public ElementosInteractivos botonDerecha;
    Animator animator;
    CharacterController controller;
    // Use this for initialization
    void Start () {
        animator = GetComponent<Animator>();
        controller = GetComponent<CharacterController>();
    }
  
    // Update is called once per frame
    void Update () {

        if(botonIzquierda.pulsado)// Virtualkey left button, when button is pressed;
        {
????????????????????????????????????
        }
        else if(botonDerecha.pulsado)//virtualkey right button, when button is pressed;
        {
??????????????????????????????????????
        }
        else
        {
?????????????????????????????????????
        }
        //Move and Animation


        Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
        Vector2 inputDir = input.normalized;
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Jump();
        }
        if (inputDir != Vector2.zero)
        {
            float targetRotation = Mathf.Atan2(inputDir.x, inputDir.y) * Mathf.Rad2Deg;
            transform.eulerAngles = Vector3.up * Mathf.SmoothDampAngle(transform.eulerAngles.y, targetRotation, ref turnSmoothVelocity, GetModifiedSmoothTime(turnSmoothTime));
        }
        bool running = Input.GetKey(KeyCode.LeftShift);
        //bool jumping = Input.GetKey(KeyCode.Space);
        float targetSpeed = ((running) ? runspeed : walkspeed) * inputDir.magnitude;
        currentSpeed = Mathf.SmoothDamp(currentSpeed, targetSpeed, ref speedSmoothVelocity, GetModifiedSmoothTime(speedSmoothTime));
        Vector3 velocity = transform.forward * currentSpeed + Vector3.up * velocityY;
        velocityY += Time.deltaTime * gravity;
        controller.Move(velocity * Time.deltaTime);
        if (controller.isGrounded == false)
        {
            enelaire();
        }
        float animationSpeedPercent = ((running) ? 2 : .5f) * input.magnitude;
        animator.SetFloat("speedPercent", animationSpeedPercent, speedSmoothTime, Time.deltaTime);
    }
    void Jump()
    {
        if (controller.isGrounded)
        {
            float jumpVelocity = Mathf.Sqrt(-2 * gravity * jumpHeight);
            velocityY = jumpVelocity;
        }
    }
    void enelaire()
    {
        animator.SetFloat("speedPercent",3, speedSmoothTime, Time.deltaTime);
    }
    float GetModifiedSmoothTime(float smoothTime)
    {
        if (controller.isGrounded)
        {
            return smoothTime;
        }
        if(airControlPercent ==0)
        {
            return float.MaxValue;
        }
        return smoothTime / airControlPercent;
    }
}

Please help me to add this code in my virtualkeys.

Please review code formatting here: Using code tags properly

1 Like

With another style of code I add movement to the character with the virtual buttons, but I followed a tutorial and this code now I do not know how to adapt it to the virtual buttons. I do not usually ask for help because I always try to find the solution for myself but… Please help me… :(:(:(:(.