Android Touch Input Help!

Hi, I am a university student and have just created my version of 3D Pong but I want it to work on android, at the moment my code for moving the paddle is:

var speed = 500;

function Update () {
	if (Input.GetKey(KeyCode.UpArrow)) {
		transform.position.y += speed * Time.deltaTime;
	} 
	if (Input.GetKey(KeyCode.DownArrow)) {
		transform.position.y -= speed * Time.deltaTime;
	}
	
	transform.position.y = Mathf.Min(transform.position.y, 180);
	transform.position.y = Mathf.Max(transform.position.y, -180);
}

if anyone can help me code this to work on my Galaxy S2 that would be awesome, however I want it to work so that it detects the device its running on so if I was on a computer and went onto my website I could run it using “up and down arrows” but if on a touch device it works using swipe up and down.

if not possible no worry’s I will just build and run using android settings. Thanks Lenny.

For touch detection take a look for the Input.GetTouch function. In scence You will want to change your Input.GetKey statements for the aforementioned function in conjunction with other code and the TouchPhase enumeration. The documentation have an example that will make everything clearer and straightforward.

Also Import the package “Standard Assets (Mobile).unityPackage”. Edit → Import Package → Standard Assets (Mobile) it help you to take advantage of the touch screen availability. Not sure if it is only a Pro feature but take a look.

To detect the device in which you app is running use the preprocessor directives. You will have to enclose particular code inside the proper directives. Examples provided in the doc.