using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; public class UIMove : MonoBehaviour,IPointerClickHandler { public Transform targetObject; // 目标对象 public Vector3 relativePosition; // 相对位置 private bool isMoving = false; public static bool isStaticMove = false; void Update() { if (isMoving) { // 使用平滑过渡(Lerp)将目标对象移动到相对位置 if (targetObject != null) { targetObject.localPosition = Vector3.Lerp(targetObject.localPosition, relativePosition, Time.deltaTime*2f); if (Vector3.Distance(targetObject.localPosition, relativePosition) < 1f) { isMoving = false; isStaticMove = false; } } } } public void OnPointerClick(PointerEventData eventData) { if (isStaticMove) { return; } isMoving = true; isStaticMove = true; } }