wall_smash/Assets/Scripts/Level_Generator.cs
2025-04-15 13:34:19 +05:30

36 lines
928 B
C#

using UnityEngine;
public class Level_Generator : MonoBehaviour
{
public Vector2Int size;
public Vector2 offset;
public GameObject brickPrefab;
public Gradient gradient;
private void Awake()
{
for (int i = 0; i < size.x; i++)
{
for (int j =0; j < size.y; j++)
{
GameObject newBrick = Instantiate(brickPrefab, transform);
Vector3 a = new Vector3((float)((size.x-1)*.5f -i) * offset.x , j * offset.y, 0);
newBrick.transform.position = transform.position + a;
newBrick.GetComponent<SpriteRenderer>().color = gradient.Evaluate((float)j /(size.y-1)) ;
}
}
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}