Answer the question
In order to leave comments, you need to log in
How to draw the trajectory (on which it moved) of the movement of an object in Unity 2D?
I have a red circle, which should leave lines after itself, that is, the trajectory along which it moved. I wrote a small script and attached it to it, but something is not working.
My code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Траектория : MonoBehaviour
{
public Material mat;
Vector2 start, end;
void OnRenderObject()
{
end = transform.position;
GL.PushMatrix();
mat.SetPass(0);
GL.LoadOrtho();
GL.Begin(GL.LINES);
GL.Color(Color.red);
GL.Vertex(start);
GL.Vertex(end);
GL.End();
GL.PopMatrix();
start = end;
}
void Start()
{
start = transform.position;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question