Question by
m4djid · Feb 10, 2016 at 03:30 PM ·
javascriptbeginnertouch controlstouchscreenpong
How can I change my player control method to use a touch screen ?? Pong-clone 2D
Hello, I'm a beginner in programmation and I used Unity to create a little pong-clone in 2D (Web based).
Now I would like to build it for my Android phone, but I can't figure out how to control the paddles (2 players game) at all...
I was reading tutorials and the documentation but I think I'm missing something.
My initial control is very simple using javascript.
Anybody can help me with this endeavour ?
#pragma strict
var moveUp : KeyCode;
var moveDown : KeyCode;
private var pos : Vector3;
var speed : float = 15;
function Update () {
if (Input.GetKey(moveUp))
{
GetComponent.<Rigidbody2D>().velocity.y = speed;
}
else if (Input.GetKey(moveDown))
{
GetComponent.<Rigidbody2D>().velocity.y = speed *-1;
}
else
{
GetComponent.<Rigidbody2D>().velocity.y = 0;
}
}
function OnCollisionEnter2D (hitInfo : Collision2D) {
if (hitInfo.gameObject.name =="Ball")
{
GetComponent.<AudioSource>().Play();
}
}
Comment
Your answer
Follow this Question
Related Questions
Making object follow finger? 1 Answer
Help with touch button (can't call a function) 0 Answers
How to chanege the positionon of the cube when touching the screen? 0 Answers
how to differentiate touch and swipe 2 Answers
Pressing Vs Jumping 1 Answer