瓷砖布局错误

Wrong layout of tiles

我创建了一个 int 数组级别。这是代码:

using UnityEngine;
using System.Collections;

public class Level1 : MonoBehaviour 
{
    int[][] level = new int[][]
    {
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 83,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0},
        new int[] { 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16}
    };
    public Transform tile00;
public Transform tile16;
public Transform tile38;

int rows = 12;
int cols = 32;

void Start () 
{

    BuildLevel ();
}

void BuildLevel(){
    int i, j;

    GameObject dynamicParent = GameObject.Find ("DynamicObjects");
    for(i=0; i<rows; i++)
    {
        for(j=0; j<cols; j++)
        {
            Transform toCreate = null;
            Debug.Log (i + "  ,  " + j + "   " + level[i][j]);
            if (level[i][j] == 0)
                toCreate = tile00;
            if (level[i][j] == 83)
                toCreate = tile38;;
            if (level[i][j] == 16)
                toCreate = tile16;

            Vector3 v3 = new Vector3(16-j, 6-i, 0);
            Transform newObject = Instantiate(toCreate, v3, Quaternion.identity) as Transform;
            newObject.parent = dynamicParent.transform;
        }
    }
}
  }

输出画面是这样的:

瓷砖是 50 X 50。我改变了瓷砖的尺寸,我改变了 X 和 Y 的位置。我尝试了一切,但我发现没有 solution.Could 你给我一个想法,好吗?

我想要得到的水平方块的布局是(图片经过paint处理):

最有可能的答案是因为这条线

Vector3 v3 = new Vector3(16-j, 6-i, 0);

你说你的图片每张是 50 x 50 像素。假设您没有将精灵的像素更改为 属性 单位,这将使每个图像在 X 轴和 Y 轴上占用 space 0.5 个单位单位。

现在,在您的计算中,这就是正在发生的事情。


迭代 1 - (i = 0, j = 0)。位置 = Vector3(16, 6, 0)
迭代 2 - (i = 0, j = 1)。位置 = Vector3(15, 6, 0)
...
迭代 33 -(i = 1, j = 0)。位置 = Vector3(16, 5, 0)


现在,迭代 1 和迭代 2 之间的 X 值差异为 1 个单位单位。我们之前已经确定,由于这些 Sprites 的大小,它们将仅占用 0.5 个 Unity 单位。
迭代 1 和迭代 33 沿 Y 轴的情况相同。相差1个单位,每张图片只占0.5个单位。

因此,要么将图像更改为 100 x 100 像素,要么将像素更改为单位