Assing touch controls to buttons mapped to keys

Hey guys, been working on a minigame for days.

I readapted this AMAZING turorial:

As you can see, on screen buttons are mapped to the keyboard keys (Arrows Left, Up, Down, Right).

My idea is to adapt this controls to Touch devices… so touching buttons (first image) can be taped as normal with the finger.

could anyone please help?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ButtonController : MonoBehaviour
{
    private SpriteRenderer theSR;
    public Sprite defaultImage;
    public Sprite pressedImage;
    public KeyCode keyToPress;

    void Start()
    {
        theSR = GetComponent<SpriteRenderer>();
    }

    void Update()
    {
        if(Input.GetKeyDown(keyToPress))
        {
            theSR.sprite = pressedImage;
        }

        if (Input.GetKeyUp(keyToPress))
        {
            theSR.sprite = defaultImage;
        }
    }
}

Hi @farrico

“could anyone please help?”

Help with which part?

You don’t seem to have anything related to touch yet in your code. So maybe start with that?
Here are some useful links:

And you can use uGUI buttons too on touch devices, although I can’t remember what happened with multiple touches, but at least one finger gets detected…

Sorry, my english sucks.

What i need to do is to adapt actual ‘arrow key controls’ to touch controls. I’m a designer… have no idea how to code but watching, coping and pasting codes to see if… ‘that works’ :stuck_out_tongue_winking_eye:

Thanks-