0
我試圖在使用x和y循環放置它們之後保存已放置圖塊的座標。我想要做的是獲取這些瓷磚的座標,並將它們放置在二維數組中,或將它們保存在某個位置,以便在水平面加載瓷磚時,這些瓷磚的座標將被保存,以後我可以使用它們。我正在嘗試將這些積分用於玩家,所以他可以一次一個點地從一個點到另一個點。在2d vector3數組中保存xy座標,然後將結果打印到控制檯C#Unity
我不知道我是否正確地進行了操作,並希望能夠在控制檯中打印座標以查看它們是否已保存。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MapGenerator : MonoBehaviour
{
public Transform tilePrefab;
public Vector2 mapSize;
[Range(0, 1)]
public float tileOutline;
public float[] tilePointX;
public Vector3[,] positionArray;
public Vector3 tilePosition;
void Start()
{
MapGeneratorMethod();
}
public void MapGeneratorMethod()
{
for (int x = 0; x < mapSize.x; x++)
{
for (int y = 0; y < mapSize.y; y++)
{
Debug.Log("TEST");
tilePosition = new Vector3(-mapSize.x/2 + 0.5f + x, 0, -mapSize.y/2 + 0.5f + y);
//getposition of tile = position array
Transform newTile = Instantiate(tilePrefab, tilePosition, Quaternion.Euler(Vector3.right * 90)) as Transform;
newTile.localScale = Vector3.one * (1 - tileOutline);
}
}
}
public void findTilePoint()
{
for (int x = 0; x < mapSize.x; x++)
{
for (int y = 0; y < mapSize.y; y++)
{
tilePosition = new Vector3(-mapSize.x/2 + 0.5f + x, 0, -mapSize.y/2 + 0.5f + y);
positionArray[x,y] = tilePosition;
Debug.Log(x);
}
}
// Debug.Log(x);
}
}
謝謝邪惡的羊!非常感激! –