Untitled
unknown
plain_text
3 years ago
1.4 kB
4
Indexable
using System.Collections; using System.Collections.Generic; using UnityEngine; public class TouchSc : MonoBehaviour { public Vector3 firstPos, secondPressPos, currentPos; public float speed; public CarFallow carFallowSc; void Start() { } // Update is called once per frame void Update() { if (Input.touchCount > 0) { Touch t = Input.GetTouch(0); if (t.phase == TouchPhase.Began) { firstPos = t.position; } if (t.phase == TouchPhase.Moved) { secondPressPos = new Vector2(t.position.x, 0); currentPos = new Vector3(secondPressPos.x - firstPos.x, secondPressPos.y - firstPos.y); currentPos.Normalize(); if (currentPos.x>0) { print("sağ"); } if (currentPos.x < 0) { print("sol"); } transform.position = Vector3.Lerp(transform.position, new Vector3(t.deltaPosition.x, transform.position.y, transform.position.z), speed * Time.deltaTime); } if (t.phase == TouchPhase.Ended) { currentPos = t.position; } } } }
Editor is loading...