You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.9 KiB
59 lines
1.9 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class DrawTrail : MonoBehaviour {
|
|
[Header("Trail")]
|
|
public float framerate = 30.0f;
|
|
public float duration = 30.0f;
|
|
List<Vector3> trail_positions;
|
|
float stamp;
|
|
|
|
// Use this for initialization
|
|
void Start () {
|
|
trail_positions = new List<Vector3>();
|
|
stamp = Time.time;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update () {
|
|
float dt = Time.time - stamp;
|
|
if (dt > 1.0f / framerate)
|
|
{
|
|
stamp = Time.time;
|
|
trail_positions.Add(transform.position);
|
|
int max_count = (int)(duration * framerate);
|
|
while (trail_positions.Count > max_count)
|
|
trail_positions.RemoveAt(0);
|
|
}
|
|
}
|
|
|
|
void OnDrawGizmos()
|
|
{
|
|
Color hex_color;
|
|
// Trail
|
|
if (trail_positions == null)
|
|
return;
|
|
|
|
if (ColorUtility.TryParseHtmlString("#F29F05", out hex_color))
|
|
{
|
|
Gizmos.color = hex_color;
|
|
if (trail_positions.Count > 1)
|
|
{
|
|
for (int i = 1; i < trail_positions.Count; i++)
|
|
{
|
|
float alpha = (float)i / trail_positions.Count;
|
|
Gizmos.color = new Color(hex_color.r, hex_color.g, hex_color.b, alpha);
|
|
Gizmos.DrawLine(trail_positions[i], trail_positions[i - 1]);
|
|
}
|
|
}
|
|
Gizmos.DrawSphere(transform.position, 0.1f);
|
|
Gizmos.color = Color.red;
|
|
Gizmos.DrawLine(transform.position, transform.position + transform.right);
|
|
Gizmos.color = Color.green;
|
|
Gizmos.DrawLine(transform.position, transform.position + transform.up);
|
|
Gizmos.color = Color.blue;
|
|
Gizmos.DrawLine(transform.position, transform.position + transform.forward);
|
|
}
|
|
}
|
|
}
|
|
|