public void UpdateObstacles() { foreach (Transform t in Obstacles) { FlowObstacle f = (FlowObstacle)t.GetComponent(typeof(FlowObstacle)); if (f.graphNodes != null) { SetHeightAtNodes(f.graphNodes, t.position.y + t.localScale.y * 0.5f); } } }
void Start() { GameObject box = GameObject.CreatePrimitive(PrimitiveType.Cube); Vector2 spacing = new Vector2(bounds.x / res.x, bounds.y / res.y); Vector2 boxOffset = new Vector2(-spacing.x * 0.5f, -spacing.y * 0.5f); Vector2 objOffset = new Vector2(-bounds.x * 0.5f + spacing.x, -bounds.y * 0.5f + spacing.y); colliders = new Transform[(int)res.x * (int)res.y]; // Create Boxes box.renderer.enabled = false; box.transform.localScale = new Vector3(spacing.x, boxHeight, spacing.y); FlowObstacle fo = box.AddComponent(typeof(FlowObstacle)) as FlowObstacle; GameObject fv = GameObject.Find("FlowVolumes"); fo.FlowVolumes = fv.transform; for (int y = 0; y < res.y; y++) { for (int x = 0; x < res.x; x++) { Transform newBox = Instantiate(box.transform, new Vector3(x * spacing.x, 0, y * spacing.y), Quaternion.identity) as Transform; newBox.Translate(boxOffset.x, -boxHeight * 0.5f, boxOffset.y); Destroy(newBox.GetComponent <BoxCollider>()); newBox.parent = transform; colliders[y * (int)res.x + x] = newBox; } } transform.Translate(objOffset.x, 0, objOffset.y); GameObject.Destroy(box); }