Question by
bluepuppy · Oct 02, 2016 at 12:50 PM ·
c#scripting problemanimatorrendering
How can i draw line with LineRenderer
Here is my code i made A* algorithm which is show the line with gizmo but i want show in my game view not my editor so i edit LineRenderer like this
using UnityEngine; using System.Collections;
public class Unit : MonoBehaviour {
private LineRenderer lineRenderer;
private float counter;
private float dist;
public Transform origin1;
public Transform target;
private int lengthOfLineRenderer=0;
float speed = 20;
Vector3[] path;
int targetIndex;
void Start() {
PathRequestManager.RequestPath(transform.position,target.position, OnPathFound);
lineRenderer = GetComponent<LineRenderer>();
lineRenderer.SetWidth(2f, 2f);
}
public void OnPathFound(Vector3[] newPath, bool pathSuccessful) {
if (pathSuccessful) {
path = newPath;
targetIndex = 0;
}
}
public void OnDrawGizmos() {
if (path != null) {
for (int i = targetIndex; i < path.Length; i ++) {
Gizmos.DrawCube(path[i], Vector3.one);
if (i == targetIndex) {
Gizmos.DrawLine(transform.position, path[i]);
lineRenderer.SetPosition(0, origin1.position);
}
else {
Gizmos.DrawLine(path[i-1],path[i]);
lengthOfLineRenderer += 1;
lineRenderer.SetPosition(lengthOfLineRenderer, origin1.position);
}
}
}
}
}
but it is not walking.... i'm probably wrong but i can't find it please help me i want to fix it
Comment
Your answer
Follow this Question
Related Questions
Help please, movement and animator issue 0 Answers
Movement and Jump with animator 0 Answers
animator and script issue 0 Answers
Delay while using GetButtonDown and Animator 0 Answers
When I run this code Unity crashes(ANIMATOR RELATED) 0 Answers