UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"move UI element on an arc using LeanTween"
using UnityEngine; using UnityEngine.UI; using System.Collections; using System.Collections.Generic; using LeanTween; public class MoveUIOnArc : MonoBehaviour { public RectTransform uiElement; public float radius = 100f; public float duration = 1f; public float delay = 0f; public float startAngle = 0f; public float endAngle = 180f; private List<Vector3> arcPoints = new List<Vector3>(); void Start() { CalculateArcPoints(); MoveUI(); } void CalculateArcPoints() { float angle = startAngle; float step = (endAngle - startAngle) / 10f; while (angle <= endAngle) { float x = Mathf.Sin(Mathf.Deg2Rad * angle) * radius; float y = Mathf.Cos(Mathf.Deg2Rad * angle) * radius; arcPoints.Add(new Vector3(x, y, 0f)); angle += step; } } void MoveUI() { LeanTween.move(uiElement, arcPoints.ToArray(), duration) .setDelay(delay) .setEase(LeanTweenType.easeInOutSine); } }