-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathMoveToPoint.cs
49 lines (41 loc) · 1.15 KB
/
MoveToPoint.cs
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
46
47
48
49
using UnityEngine;
using UnityEditor;
using System.Collections;
public class MovetoPoint : MonoBehaviour {
public Vector3 point;
public float duration;
public enum MoveType
{
EaseIn,
EaseOut,
Instant
}
public MoveType moveType;
private float startTime;
// Use this for initialization
void Start () {
startTime = Time.time;
}
// Update is called once per frame
void Update () {
if (moveType == MoveType.EaseIn)
{
transform.position = Vector3.Lerp(transform.position, point, (Time.time - startTime) / duration);
}
else if (moveType == MoveType.EaseOut)
{
transform.position = Vector3.MoveTowards(transform.position, point, (Time.time - startTime) / duration);
}
else if (moveType == MoveType.Instant)
{
transform.position = point;
}
}
public void OnDrawGizmosSelected()
{
Gizmos.DrawLine(transform.position, point);
Gizmos.color = Color.red;
Gizmos.DrawSphere(point, 0.06f);
Handles.Label(point, " " + moveType.ToString() + "(" + duration + "s)");
}
}