[英]Making a tile grid in Unity
我正在統一創建一個簡單的益智游戲,我想制作一個瓷磚地圖。
我在編程方面有一些不錯的知識,所以我完全對這不起作用感到困惑。
代碼很簡單:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class GridMaker : MonoBehaviour { public GameObject tilePrefab; public Vector2 gridSize; public void GenerateMap() { for (int x = 0; x < gridSize.x; x++) { Instantiate(tilePrefab, new Vector3(x, 0, 0), Quaternion.identity); for (int y = 1; y < gridSize.y; y++) Instantiate(tilePrefab, new Vector3(0, 0, y), Quaternion.identity); } } }
可能是我累了,但這應該可行!
這是一個關於它在生成時的外觀的 2D 可視化:
前任。 gridSize 設置為 (3,3) 1's 代表瓦片
111 111 111
但它的外觀如下:
1 1 111
這是為什么? 考慮到它從最左邊的一個開始。
附注。 我要去睡覺了。 大約 12 小時后上線。
答案很簡單,我為犯這樣的錯誤感到愚蠢。 這是修復:
從
for (int y = 1; y < gridSize.y; y++) Instantiate(tilePrefab, new Vector3(0, 0, y), Quaternion.identity);
到
for (int y = 1; y < gridSize.y; y++) Instantiate(tilePrefab, new Vector3(x, 0, y), Quaternion.identity);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.