public void SetChildSpacing(float randomSpacingY) { var intervalY = Random.Range(0f, _centerY); HoleDirectionType randomSpaceingType = (HoleDirectionType) (typeof(HoleDirectionType).GetRandomEnumValue()); float downObstacleY = 0; float upObstacleY = 0; switch (randomSpaceingType) { // hole up // 10 - 1 1 // -5 + 5 -1 : Down // 5 + 5 : Up case HoleDirectionType.Up: downObstacleY = -_centerY + intervalY - randomSpacingY; upObstacleY = _centerY + intervalY; break; // hole down // 1 - 10 1 // -5 - 5 : Down // 5 - 5 +1 :Up case HoleDirectionType.Down: downObstacleY = -(_centerY + intervalY); upObstacleY = (_centerY - intervalY + randomSpacingY); break; } _obstacleDown.localPosition = Vector3.up * downObstacleY; _obstacleUp.localPosition = Vector3.up * upObstacleY; }
public static Enum GetRandomEnumValue(this Type t) { Array values = Enum.GetValues(typeof(HoleDirectionType)); var spaceTypeNum = Random.Range(0, values.Length); HoleDirectionType randomHoleDirectionType = (HoleDirectionType)values.GetValue(spaceTypeNum); return(randomHoleDirectionType); }