# Help with VirtualKeys

**URL:** https://discussions.unity.com/t/help-with-virtualkeys/672409
**Category:** Scripting
**Tags:** Scripting
**Created:** [July 27, 2017, 10:40pm UTC](https://discussions.unity.com/t/help-with-virtualkeys/672409 "2017-07-27T22:40:14Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Jose-daniel](https://avatars.discourse-cdn.com/v4/letter/j/da6949/32.png) [@Jose-daniel](https://discussions.unity.com/u/Jose-daniel)
#### Post date: [July 27, 2017, 10:40pm UTC](https://discussions.unity.com/t/help-with-virtualkeys/672409/1 "2017-07-27T22:40:14Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

### Author: ![Kurt-Dekker](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/kurt-dekker/32/101578_2.png) [@Kurt-Dekker](https://discussions.unity.com/u/Kurt-Dekker)
#### Post date: [July 27, 2017, 11:03pm UTC](https://discussions.unity.com/t/help-with-virtualkeys/672409/2 "2017-07-27T23:03:20Z")

</div>

Please review code formatting here: [Using code tags properly](https://forum.unity3d.com/threads/using-code-tags-properly.143875/)

---

<div class="post-metadata">

### Author: ![Jose-daniel](https://avatars.discourse-cdn.com/v4/letter/j/da6949/32.png) [@Jose-daniel](https://discussions.unity.com/u/Jose-daniel)
#### Post date: [July 28, 2017, 9:56am UTC](https://discussions.unity.com/t/help-with-virtualkeys/672409/3 "2017-07-28T09:56:25Z")

</div>

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… :(:(:(:(.
