how to change keyboard PC button to touch mobile (iOS, Andoird) button

Hi,
I write this question because I didnt see the answer nowhere. Maybe someone here could help me ant the others. The problem is: how to change keyboard PC button (e.g. “R” - means reset the level, “C”-change camera view) to be available on mobile device:

  1. uses GUI. Button and “void onGUI”
  2. uses new UI in Unity 4.6+
    So I have the script like that:

using UnityEngine;
using System.Collections;

public class CamManager: MonoBehaviour {

private CarCamera carCamera;

public int cameraChangeCount = 0;
[HideInInspector]
public GameObject target;

public MainFixedCam fixedCamScript;

void Awake () {

	carCamera = GetComponent<CarCamera>();
	orbitScript = GetComponent<CameraOrbit>();

	if(mainFixedCamera)
		fixedCamScript = mainFixedCamera.GetComponent<MainFixedCam>();

}

void Update () {

	if(Input.GetKeyDown(KeyCode.C)){
		cameraChangeCount++;
		if(cameraChangeCount == 6)
			cameraChangeCount = 0;
		ChangeCamera();
	}

}

public void ChangeCamera(){

	carCamera.playerCar = target.transform;
	carCamera.distance = dist;
	carCamera.height = dist / 3;

And so on…

I need to change "Input.GetKeyDown(KeyCode.C)"to GUI button, but I dont know what is the command?

Anybody could help me / us?

Hey,

Using 4.6 UI is making it easy, very easy !

Create buttons in your canvas, create a script that will contain functions that you will call with your button. Make all the links and stuff you would do for an computer based program … And that’s it :slight_smile:

The ‘EventSystem’ created by Unity when you use a Canvas manages the touch inputs ^^

If you wanna touch the screen elsewhere (ie not on the buttons), that’s an other story (even if it’s not more complicated that listening to your keyboard input) and you will have to use an ‘if’ condition in your update with something that looks like that:

if (TouchPhase.Began){
    float t0 = Time.time ;
}