- Home /
Question by
ouazizmed2 · Oct 12, 2017 at 10:39 PM ·
androidtouchinput.touch
How to move an object left or right with android
screenshot-20171012-230254.png
(78.3 kB)
Comment
Answer by TyDoesStuff · Oct 12, 2017 at 10:57 PM
void Update()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.position.x > (Screen.width / 2))
{
GoRight();
}
if (touch.position.x < (Screen.width / 2))
{
GoLeft();
}
}
}
This is a script that I used in my game. Basically, touch on the side of the screen you want your cube to move to. Don't forget to create the two GoRight/GoLeft functions.
— Ty
Your answer
Follow this Question
Related Questions
Swipe control for circle (Can do swipe left/right) 2 Answers
Button Touch for Android 2 Answers
How can I get Rect.Contains to work properly with touch input? 1 Answer
using OnMouseDown instead of touch functions for touch devices 1 Answer
TouchPhase doesn't end when player swipes off screen 1 Answer