- Home /
How can I make my game work for touch screens?
Hello. Can somebody explain how can I redo this code so I can make my game work for touchscreens. Thanks in advance!
#pragma strict
var moveUp : KeyCode;
var moveDown : KeyCode;
var speed : float = 10;
function Update ()
{
if (Input.GetKey(moveUp))
{
rigidbody2D.velocity.y = speed;
}
else if (Input.GetKey(moveDown))
{
rigidbody2D.velocity.y = speed * -1;
}
else
{
rigidbody2D.velocity.y = 0;
}
rigidbody2D.velocity.x = 0;
}
Answer by JeffreyD · Feb 12, 2014 at 04:55 PM
Hey, Here is a link to the script doc info on touch input.
http://docs.unity3d.com/Documentation/ScriptReference/Input.GetTouch.html
It looks as if the first example may give you what you need (Touch with move direction).
There is much more info on touch processing as you look around the docs. Hope it helps.
Great advice. Take a look at the IOS API or Android API for Touch, depending on your target OS. Lots of info there as well.
Hey NorthernEagle. Which doc is that in? The Script Ref., Component Ref, or Users $$anonymous$$anual. Thanks.
IOS have their API documents. It's in the developers website.
oh, right, Sorry, though you where referring to Unity Docs. Thanks.
It's worth noting that the Unity devs recommend making your own wrapper class for input, so you don't need to pour through lots of code to change from one input scheme to another (eg, keyboard + mouse, controller, touch).
Answer by unimechanic · Feb 21, 2014 at 08:17 PM
Question solved by @JeffreyD, please use the Forums for programming discussions. Adding this answer to remove it from the Unanswered view and give more relevance to other questions requiring attention. Thanks for your comprehension, Unity Support.
Your answer
Follow this Question
Related Questions
2D pong game. HELP 1 Answer
What are the sytem requirements? 0 Answers
A node in a childnode? 1 Answer
Ball in Pong dissapears after hitting paddle 0 Answers
Making an animation play when you press down 2 keys 1 Answer