- Home /
 
Input.GetTouch
Hi everyone, I got a simple question how can I make this touch script move in only one direction. For instance I want to move a block by touching my screen and sliding up only, once that happens the block moves only directly up. Heres the script.
 using UnityEngine;
 using System.Collections;
 
 public class TouchFunction : MonoBehaviour {
     public float speed = 0.1F;
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {
             Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
             transform.Translate(0, touchDeltaPosition.y * speed, 0);
     }
 }
     }
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Add keyboard input in ClickToMove 0 Answers
Slowly speed something up to a top speed after a specified amount of time? 0 Answers
"Hover" object up and down 2 Answers
Odd touch input problem 0 Answers