using System.Collections; using System.Collections.Generic; using UnityEngine; public class cs01 : MonoBehaviour { float speedX, speedY, speedZ; //滑鼠或觸控,某個單一物件,可以用OnMouseDown()函數 private void OnMouseDown() { //2秒後執行ZeroMoveY()函數,讓向上速度speedY=0 speedY = 1.0f; Invoke("StopMoveY", 1); } void StopMoveY() { speedY = 0.0f; } void Update() { float dx = speedX * Time.deltaTime; float dy = speedY * Time.deltaTime; float dz = speedZ * Time.deltaTime; this.gameObject.transform.Translate(dx, dy, dz, Space.Self); } }