unity实现物体移动固定距离

时间:2025-03-30 08:21:18
using ; using ; using UnityEngine; public class Player1Control : MonoBehaviour { // private Rigidbody2D playerRig; public float speed; private bool isMove = false; private float process = 0; private Vector3 dest; private void Awake() { // playerRig = GetComponent<Rigidbody2D>(); } // Use this for initialization void Start () { } // Update is called once per frame void Update () { if (()) { if (!isMove) { dest= new Vector3( - 1.2f, ,0); isMove = true; process = 0; } //(new Vector2(, )); } if (()) { if (!isMove) { dest = new Vector3( + 1.2f, , 0); isMove = true; process = 0; } } if (isMove) { process += ; if (process < 1) = (, dest, process); // = (, dest, process); else { isMove = false; } } } }