| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 | | 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); |  |         } |  |     } |  |   |  | } | 
 |