static void InsertObstacle(Coord c) { float height = Mathf.Lerp( settings.minObstacleHeight, settings.maxObstacleHeight, (float)prng.NextDouble()); Color color = Color.Lerp( settings.foregroundColor, settings.backgroundColor, c.y / (float)room.size.y); ObstacleTile obs = new ObstacleTile(c, height, color); room.SetTile(c, obs); }
void InstantiateObstacle(ObstacleTile obs) { Vector3 position = CoordToPosition(obs.pos); Transform newObstacle = Instantiate(obstaclePrefab, position + Vector3.up * obs.height / 2, Quaternion.identity) as Transform; // set height Vector3 scale = Vector3.one * (1 - outlinePercent) * tileSize; scale.y = obs.height; newObstacle.localScale = scale; // set color // note: done this way to avoid leaking materials in editor mode Renderer renderer = newObstacle.GetComponent <Renderer>(); Material material = new Material(renderer.sharedMaterial); material.color = obs.color; renderer.sharedMaterial = material; newObstacle.parent = loadedRoomHolder; }