Touch buttons to replace Input GetKey KeyCode

Hey guys, I really need help here, I’m creating a constantly moving 2D game, it’s functioning fully in unity and for pc, but I’ve made it for mobile devices, I’ve looked everywhere online and around here for an answer but haven’t found one that works in my situation

here is the segment of my code that contains button presses:

if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
		if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))

I have made a couple of sprites that I intend to replace the keyboard left and right for touch inputs, I just need to know how to code it using my current code.

Any ideas/help would be greatly appreciated!


First thumbs up for one of the best written questions I’ve had to privilege to answer.
You need to study the Unity docs for mobile input. That is found here:

Particularly check out GUI hittest in the script reference.

here is a code snippet of how i used this to make my game pause when the user pressed the pause “button” (it was actually just a texture that represented 2D space input could be read in as clicking pause):

#pragma strict
    var pauseButton : GUITexture;
    var isPaused = false;
    var timer : float = 0.0;
    function Start () {
    	isPaused = false;
    function Update () {
            // This starts a timer
    	if (timer <= 1.0)
    		timer = timer + .1;
    	var count : int = Input.touchCount;
    	for (var touch : Touch in Input.touches) {
    		if (pauseButton.HitTest( touch.position )) {
                // This checks that timer to make sure it has given the user enough time
                // to lift their finger before it cycles through the remaining code again.
    			if (timer >= 1.0) {
    				if (isPaused) {
    					Time.timeScale = 1;
    					isPaused = false;
    				else {
    					Time.timeScale = 0;
    					isPaused = true;