Game_CodeMM/Assets/00_scripts/GridManager.cs

30 lines
749 B
C#
Raw Normal View History

2025-09-27 20:03:16 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GridManager : MonoBehaviour
{
public int width = 10;
public int height = 10;
public float cellSize = 1f;
public GameObject cellPrefab; // 预制体: 一个格子
void Start()
{
GenerateGrid();
}
void GenerateGrid()
{
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
Vector3 pos = new Vector3(x * cellSize, y * cellSize, 0);
GameObject cell = Instantiate(cellPrefab, pos, Quaternion.identity);
cell.transform.parent = transform;
}
}
}
}