Unity3d 瓷砖布局错误

Unity3d 瓷砖布局错误,unity3d,unity3d-2dtools,Unity3d,Unity3d 2dtools,我创建了一个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,

我创建了一个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;
        }
    }
}
  }
使用UnityEngine;
使用系统集合;
公共类级别1:单一行为
{
int[][]级别=新int[][]
{
新的int[]{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,0,0,0},
新的int[]{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,0,0,0},
新的int[]{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,0,0,0},
新的int[]{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,0,0,0},
新的int[]{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,0,0,0},
新的int[]{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,0,0,0},
新的int[]{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,0,0,0},
新的int[]{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,0,0,0},
新的int[]{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,0,0,0},
新的int[]{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,0,0,0},
新的int[]{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,0,0,0},
新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}
};
公共转换瓷砖00;
公共转换瓷砖16;
公共转换tile38;
int行=12;
int cols=32;
无效开始()
{
BuildLevel();
}
void BuildLevel(){
int i,j;
GameObject dynamicParent=GameObject.Find(“DynamicObjects”);

对于(i=0;i最有可能的答案是因为这条线

Vector3 v3 = new Vector3(16-j, 6-i, 0);
您说您的图像每个是50 x 50 px。假设您没有更改精灵的“像素到单位”属性,这将使每个图像在x和Y轴上占据0.5个单位的空间

现在,在你的计算中,发生了这样的事情


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


现在,迭代1和迭代2之间的X值之差为1个单位。我们之前已经确定,由于这些精灵的大小,它们只占0.5个单位。
对于迭代1和迭代33,沿Y轴的情况相同。相差1个单位,每个图像只占0.5个单位


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

呃…目前还不完全清楚您希望代码执行什么操作-您能否澄清运行代码后您希望场景的外观?否则我们只能猜测这里可能出了什么问题。尝试了所有方法以获得什么解决方案?您不知道我甚至没有指定你想要的布局。@Serlite-我发布了一张我想要的布局的图片。是的。你说得对。我把像素改为50像素,就可以了。谢谢