private void ShowPath(List <Vector3> positions, PathRenderingType pathRenderingType) { while (spawnedGameObjects.Count > 0) { Destroy(spawnedGameObjects.Pop()); } if (pathRenderingType == PathRenderingType.LineRenderer) { lineRenderer.positionCount = positions.Count; lineRenderer.SetPositions(positions.ToArray()); } else { foreach (var position in positions) { GameObject instance; if (prefab != null) { instance = Instantiate(prefab); //I recommend implementing object pooling for this drawing method } else { instance = GameObject.CreatePrimitive(PrimitiveType.Sphere); } instance.transform.position = position; spawnedGameObjects.Push(instance); } } }
public void DrawPath(Vector3[] corners, PathRenderingType pathRenderingType) { var positions = new List <Vector3>(corners); SubdividePath(positions); ShowPath(positions, pathRenderingType); }