- Home /
Question by
ybh · Mar 11, 2015 at 09:13 AM ·
touch screen
touch and moving help!
i'm beginner of beginner i touched screen but moving only +y(speed) direction T.T (if) code is error? help !
public float speed = 1.0f; // Use this for initialization void Start () {
}
// Update is called once per frame
void Update () {
Touch toc = Input.GetTouch (0);
Vector2 Tpos = toc.position;
if (Tpos.y > 0 && transform.position.y > 0) {
if (Tpos.y > transform.position.y) {
speed = +speed;
} else {
speed = -speed;
}
}
if (Tpos.y > 0 && transform.position.y < 0) {
speed = +speed;
}
if (Tpos.y < 0 && transform.position.y > 0) {
speed = -speed;
}
if (Tpos.y < 0 && transform.position.y < 0) {
if (Tpos.y > transform.position.y) {
speed = +speed;
} else {
speed = -speed;
}
}
if (toc.phase == TouchPhase.Began || toc.phase == TouchPhase.Moved) {
transform.Translate (Vector2.up * speed * Time.deltaTime, Space.World);
}
Comment
Do you want to move object to touch position? It moves +y direction because of Vector2.Up.
Your answer
Follow this Question
Related Questions
Virtual keyboard in Windows Store Apps (Metro) via the TouchScreenKeyboard class 0 Answers
Razer Blade Pro 2016 Multi touch controls not working simultaneously 0 Answers
I need touch input example 1 Answer
Unity and Interactive Whiteboard ( smart board ) 2 Answers
how to calculate Input.GetAxis ("Mouse X") for specific touch index 0 Answers