60 lines
1.7 KiB
C#
60 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class LevelGenerator : MonoBehaviour
|
|
{
|
|
public GameObject cube;
|
|
|
|
[Header("Spawn")]
|
|
|
|
public int minBlocks=2;
|
|
public int maxBlocks = 5;
|
|
public Vector3 minScale = Vector3.one;
|
|
public Vector3 maxScale = new Vector3(2,8,2);
|
|
public float rotationRange = 15;
|
|
|
|
public float distanceBetweenBlocks = 10;
|
|
public float rowSpacing = 20;
|
|
|
|
public int curBlock = 1;
|
|
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
float t =0;
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if(PlayerController.instance.transform.position.z > (curBlock-3) * distanceBetweenBlocks){
|
|
GenerateBlock();
|
|
}
|
|
}
|
|
|
|
|
|
void GenerateBlock(){
|
|
int cubesCount = Random.Range(minBlocks, maxBlocks);
|
|
float baseX = PlayerController.instance.transform.position.x -Random.Range(rowSpacing /2f, rowSpacing);
|
|
for(int j =0; j < 5; j++){
|
|
bool flip = false;
|
|
|
|
for(int i =0; i < cubesCount; i++){
|
|
float z = distanceBetweenBlocks * curBlock;
|
|
|
|
Vector3 size = new Vector3(Random.Range(minScale.x,maxScale.x),Random.Range(minScale.y,maxScale.y),Random.Range(minScale.z,maxScale.z));
|
|
float x = baseX + (i * size.x * (flip ? -1 : 1));
|
|
|
|
GameObject newCube = Instantiate(cube, new Vector3(x,size.y * 0.4f,z), Quaternion.identity);
|
|
newCube.transform.localScale = size;
|
|
newCube.transform.Rotate(new Vector3(0,0, rotationRange * ((float)i / (float)cubesCount) * (flip ? 1 : -1)));
|
|
flip = !flip;
|
|
}
|
|
|
|
baseX += Random.Range(rowSpacing / 2f, rowSpacing);
|
|
}
|
|
|
|
curBlock++;
|
|
}
|
|
}
|