- Home /
Question by
ariansyah · Dec 06, 2015 at 02:40 PM ·
trajectorydrawline
Draw Trajectory in Sceneview
Hi folks,
I did a simple code to draw a trajectory of a gameObject whenever I move it. But, the trajectory was not drawn. was wondering what might be the mistake. Here is the snippet code
using UnityEngine;
using System.Collections;
public class Trajectory : MonoBehaviour {
public Color rayColor = Color.blue;
Vector3 currentPos;
Vector3 prev;
bool flag = false;
void OnDrawGizmos(){
if (!flag) {
prev = transform.position;
flag = true;
}
if (transform.hasChanged){
Gizmos.color = rayColor;
currentPos = transform.position;
transform.hasChanged = false;
}
Debug.Log ("prev: " + prev);
Debug.Log ("curr: " + currentPos);
Gizmos.DrawLine (prev, currentPos);
prev = currentPos;
}
}
From debug info, I saw the prev and curr were different but line was not drawn. Does anyone can help to figure out why this code does not work?
Thanks in advance.
Comment
Your answer
