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);
}
}
}
↧