繁体   English   中英

大于6 C#Unity时移动X轴

[英]Move X axis when it's greater than 6 C# Unity

目前,我在执行此操作时遇到了麻烦

在此处输入图片说明

我正在发生的事情是

在此处输入图片说明

这是我的代码

string[,] table = new string[104, 6];
int xIndex = -1;
int yIndex = 0;
int counter = 0;


if (table.GetLength(0) < xIndex)
{
     break;
}

if (result.Equals(newPreviousValue) && yIndex < table.GetLength(1))
{
     yIndex += 1;
     counter++;
     table[xIndex, yIndex] = result;
}
else
{
      xIndex += 1;
      yIndex = 0;
      counter = 0;
      table[xIndex, yIndex] = result;
}
if (result.Equals("T") && yIndex < table.GetLength(1))
{
    yIndex += 1;
    table[xIndex, yIndex] = result;
}
     newPreviousValue = result;
     //new position
 if (counter < 6) { 
     bigroad.transform.localPosition = new Vector3(xIndex * 19, yIndex * -19, 0f);
 }
 else
 {
      bigroad.transform.localPosition = new Vector3(xIndex * 19, yIndex * -95, 0f);
 }

我想要的是,如果newPrevious(由BLUE,RED和GREEN组成)具有BLUE / RED / GREEN的值并且超过了6的值,它将自动在X轴上移动一个值,但沿相同方向移动在排队。

有人可以帮我吗。

编辑

我使用Ignacio的代码

if (counter > 6)
{
     xIndex2 += 1;
     yIndex2 = 0;
     table[xIndex2, yIndex2] = result;
}

if (counter < 6)
{
    bigroad.transform.localPosition = new Vector3(xIndex * 19, yIndex * -19, 0f);
}
else
{
    int reminder = counter % 6;
    bigroad.transform.localPosition = new Vector3((xIndex2 + reminder) * 19, -95, 0f);
}

但这给了我

在此处输入图片说明

如果您仔细观察的话,它的预制件处于相同的位置,先生。

因此,问题的根源在这里:

if (counter < 6) { 
     bigroad.transform.localPosition = new Vector3(xIndex * 19, yIndex * -19, 0f);
 }
 else
 {
      bigroad.transform.localPosition = new Vector3(xIndex2 * 19, yIndex2 * -95, 0f);
 }

由于您乘以-95,因此将其放在第一行。

相反,您应该做的是这样的:

if (counter < 6) { 
         bigroad.transform.localPosition = new Vector3(xIndex * 19, yIndex * -19, 0f);
     }
     else
     {
          int reminder = counter % 6;
          bigroad.transform.localPosition = new Vector3((xIndex2 + reminder) * 19, yIndex2 -19, 0f);
     }

因此,基本上,您将继续将块放置在最后一行,在这种情况下,您将值-19乘以索引。

提示将帮助您改为更改列,即在X轴上移动块。 因此,例如7%6 =1。然后,您将向该块添加一个(右侧的1个位置)。 如果8%6 =2。您将在右边添加两个位置。

编辑:

可能是因为这部分。 您是否已经在此处增加了轴值?

if (counter > 6)
{
     xIndex2 += 1;
     yIndex2 = 0;
     table[xIndex2, yIndex2] = result;
}

编辑2:

我不确定您的第一个位置是yIndex = 0还是yIndex =1。我假设第一个位置是yIndex = 1的时间。请问是否是yIndex = 0的情况。

if (counter < 6) { 
         bigroad.transform.localPosition = new Vector3(xIndex * 19, yIndex * -19, 0f);
     }
     else
     {
          int reminder = counter % 6;
          bigroad.transform.localPosition = new Vector3((xIndex2 + reminder) * 19, -19, 0f);
     }

编辑3:

您现在需要删除此部分,因为您要在此处向xIndex添加额外的+1

if (counter > 6)
{
     xIndex2 = 0; //Here you were adding + 1
     yIndex2 = 0;
     table[xIndex2, yIndex2] = result;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM