// Will be called after all regular rendering is done public void OnRenderObject() { if (showRays) { CreateLineMaterial(); // Apply the line material lineMaterial.SetPass(0); for (int i = 0; i < populationSize; i++) { GL.PushMatrix(); // Set transformation matrix for drawing to // match our transform GL.MultMatrix(transform.localToWorldMatrix); // Draw lines GL.Begin(GL.LINES); Creature currentCreature = pop.GetCreatureByIndex(i); Debug.Log("Starting Lines for Creature " + i); if (currentCreature.alive) { for (int j = 0; j < NumberOfProbes; j++) { Line currentLine = currentCreature.GetLines()[j]; Vector3 start = currentLine.GetStartAsVector3(); Vector3 end = currentLine.GetEndAsVector3(); // Vertex colors change from red to green GL.Color(currentLine.GetColor()); // One vertex at transform position GL.Vertex3(start.x, start.y, 0f); // Another vertex at edge of circle GL.Vertex3(start.x, start.y, 0f); } } GL.End(); GL.PopMatrix(); } } }