using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.U2D; public class LevelGenerator : MonoBehaviour { public static LevelGenerator instance { get; private set; } public SpriteShapeController spriteShapeController; public int LevelCount = 1000; public float groundLevel = -5.5f; public float maxHeight = 5; public Vector2 minDiff, maxDiff; public Vector3[] points {get; private set;} void Start() { spriteShapeController.spline.Clear(); points = new Vector3[LevelCount+1]; for(int i=0; i < LevelCount; i++){ if(i ==0){ points[i] = new Vector3(0,groundLevel); spriteShapeController.spline.InsertPointAt(i, points[i]); continue; } Vector3 addition = new Vector3(Random.Range(minDiff.x, maxDiff.x), Random.Range(minDiff.y, maxDiff.y)); float newX = points[i-1].x + addition.x; float newY = points[i-1].y + addition.y; while(newY < groundLevel){ newY += Mathf.Abs(addition.y); } while(newY > maxHeight){ newY -= Mathf.Abs(addition.y); } points[i] = new Vector3(newX, newY); spriteShapeController.spline.InsertPointAt(i, points[i]); } points[LevelCount] = new Vector3(points[LevelCount-1].x, groundLevel); spriteShapeController.spline.InsertPointAt(LevelCount, points[LevelCount]); } void Update() { } }