using System.Collections; using System.Collections.Generic; using UnityEngine; public class CarController : MonoBehaviour { float speed = 0; Vector2 startPos; void Start() { } void Update() { //(新增)取得滑動長度 if(Input.GetMouseButtonDown(0)) { //點擊滑鼠時的座標 this.startPos = Input.mousePosition; } else if(Input.GetMouseButtonUp(0)) { //放開滑鼠時的座標 Vector2 endPos = Input.mousePosition; float swipeLength = endPos.x - this.startPos.x; //把滑動長度轉換成初始移動速度 this.speed = swipeLength / 500.0f; } transform.Translate(this.speed, 0, 0); this.speed *= 0.98f; } }