using UnityEngine; using DG.Tweening; public class CardAnimation : MonoBehaviour { public Transform axis; // 翻转轴(卡牌右边缘位置) private bool isFront = true; void Start() { PlayCardAnimation(); } public void PlayCardAnimation() { Sequence seq = DOTween.Sequence(); float angle = isFront ? 180f : -180f; Vector3 pivot = axis.position; Vector3 offset = transform.position - pivot; // 翻转 + y方向弧线 seq.Append(DOTween.To( () => 0f, a => { // 旋转 Quaternion rot = Quaternion.AngleAxis(a, Vector3.up); Vector3 newOffset = rot * offset; // y方向弧线:从0升到峰值再回到0 float heightOffset = Mathf.Sin(a * Mathf.Deg2Rad) * 0.5f; // 0.5是弧线高度,可调 transform.position = pivot + newOffset + Vector3.up * heightOffset; transform.rotation = rot; }, angle, 1f // 动画时长 ).SetEase(Ease.InOutQuad)); seq.OnComplete(() => { isFront = !isFront; }); } }