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; } } } }