- Home /
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.
Answer by VicM · Dec 01, 2012 at 01:52 AM
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.
http://docs.unity3d.com/Documentation/ScriptReference/Input.GetTouch.html
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.
http://docs.unity3d.com/Documentation/Manual/PlatformDependentCompilation.html
Your answer

Follow this Question
Related Questions
What is the best way to move a paddle accurately in a circle? 2 Answers
GuiText instantiation at position? 0 Answers
unity 3d pong improve AI 0 Answers
3dmax model .fbx exported in unity 3d 0 Answers
install, textures, problem help!! 0 Answers