-
Notifications
You must be signed in to change notification settings - Fork 0
/
Route.cs
25 lines (19 loc) · 960 Bytes
/
Route.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Route : MonoBehaviour
{
[SerializeField]
private Transform[] controlPoints;
private Vector3 gizmosPosition;
private void OnDrawGizmos()
{
for (float t = 0; t <= 1; t += 0.05f)
{
gizmosPosition = Mathf.Pow(1 - t, 3) * controlPoints[0].position + 3 * Mathf.Pow(1 - t, 2) * t * controlPoints[1].position + 3 * (1 - t) * Mathf.Pow(t, 2) * controlPoints[2].position + Mathf.Pow(t, 3) * controlPoints[3].position;
Gizmos.DrawSphere(gizmosPosition, 0.25f);
}
Gizmos.DrawLine(new Vector3(controlPoints[0].position.x, controlPoints[0].position.y), new Vector3(controlPoints[1].position.x, controlPoints[1].position.y));
Gizmos.DrawLine(new Vector3(controlPoints[2].position.x, controlPoints[2].position.y), new Vector3(controlPoints[3].position.x, controlPoints[3].position.y));
}
}