- Home /
Question by
Palanysamy · Feb 11, 2014 at 05:12 PM ·
gameobjectarraygizmosdrawline
How to draw line between array's gameobjects
Hello my friends, I've been searching all over unsuccesfuly for an answer: I have an array of gameobjects, and I want a line (doesnt matter if is a gizmo or a debug.drawline) going from one object to another to another. Any advice? Thank you, P.
Comment
Answer by robertbu · Feb 11, 2014 at 05:14 PM
function Update() {
for (var i = 1; i < array.Length; i++) {
Debug.DrawLine(array[i-1].transform.position, array[i].transform.position);
}
}
Change 'array' to whatever you've named your game object array.
Answer by Palanysamy · Feb 11, 2014 at 08:47 PM
Thank you Robertu, this might work on javascript but not in C# as position is treated like a method not like a variable. I can´t figure how to add this drawline into my code:
public GameObject [] checkpoints;
public GameObject NextCheckpoint (GameObject current) {
if (checkpoints.Length < 1)
print ("ERROR - no checkpoints have been detected to array!");
int arraySize = checkpoints.Length;
int nextIndex = 0;
int currentIndex = -1;
for (int i =0; i < checkpoints.Length; i++){
if (current == checkpoints[i])
currentIndex = i;
}
int lastIndex = (checkpoints.Length - 1);
if (currentIndex > -1 && currentIndex < lastIndex)
nextIndex = currentIndex + 1;
return checkpoints [nextIndex];
}
}