新人自己试着做的网格,就是在二维数组中存储空间坐标,遍历数组并生成预制件
后续可以去掉预制件,只用这个二维数组中的坐标实现其他功能
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///-----------------------------------------------------------------------------------------
/// Author: AttouchAusturo
/// LatestReviseTime: 2021.12.18
///-----------------------------------------------------------------------------------------
public class MyNewGridMethod : MonoBehaviour
{
public int x;
public int z;
public float size;
public GameObject cubePrefab;
private GameObject[,] createMap;
private void Awake()
{
x = 10;
z = 10;
size = 10f;
createMap = new GameObject[x, z];
}
private void Start()
{
CreateCubes();
}
public void CreateCubes()
{
for(int i=0;i<x ;i++)
{
for(int j = 0; j < z; j++)
{
createMap[i, j] = Instantiate(cubePrefab, new Vector3(i * size, 0f, j * size), Quaternion.identity) as GameObject;
}
}
}
}