using System.Collections; using System.Collections.Generic; using UnityEngine; using System; public class BezierMove : MonoBehaviour { public float duration = 2f; float timer = 0f; Vector3 p1; Vector3 p2; Vector3 p3; Action onEnd; public void Begin(Vector3 _p1, Vector3 _p2, Vector3 _p3, Action _callBack) { p1 = _p1; p2 = _p2; p3 = _p3; onEnd = _callBack; this.SetActive(true); timer = 0f; } void LateUpdate() { timer += Time.deltaTime; var t = Mathf.Clamp01(timer / duration); this.transform.position = Bezier.BezierCurve(p1, p2, p3, t); if (timer > duration) { if (onEnd != null) { onEnd(); onEnd = null; } this.SetActive(false); } } }