Increment position every different value (C# UNITY)

by TheGinxx009   Last Updated May 28, 2018 04:13 AM

How can I increment the position of the X and Y depending on its value

Here's my code :

#region BIG EYE ROAD
    for (int col = 0; col < table.GetLength(0); col++)
    {
        for (int row = 0; row < table.GetLength(1); row++)
        {
            if (table[moveCol, moveRow] == null)
            {
                col0 = table[colIndex1, row];
                col1 = table[colIndex2, row];

                if (col0 != null)
                {
                    sum1 += 1;
                }

                if (col1 != null)
                {
                    sum2 += 1;
                }
                counter1++;
            }
            else
            {
                if (counter1 == 0)
                {
                    data1 = table[firstTableCol, firstTableRow];
                    data2 = table[secondTableCol, secondTableRow];
                    data3 = table[thirdTableCol, thirdTableRow];
                    data4 = table[fourthTableCol, fourthTableRow];

                }
                else
                {
                    if (moveRow > 1)
                    {
                        firstTableRow = moveRow;
                        secondTableRow = moveRow - 1;
                        thirdTableRow = moveRow;
                        fourthTableRow = moveRow - 1;
                    }

                    else if (moveRow == 1)
                    {
                        firstTableRow = 1;
                        secondTableRow = 0;
                        thirdTableRow = 1;
                        fourthTableRow = 0;
                    }

                    if (moveCol > 1)
                    {
                        firstTableCol = moveCol;
                        secondTableCol = moveCol;
                        thirdTableCol = moveCol - 1;
                        fourthTableCol = moveCol - 1;
                    }

                    data1 = table[firstTableCol, firstTableRow];
                    data2 = table[secondTableCol, secondTableRow];
                    data3 = table[thirdTableCol, thirdTableRow];
                    data4 = table[fourthTableCol, fourthTableRow];

                }
                if (data1 != null && data2 != null && data3 != null && data4 != null)
                {
                    redBead();
                }
                else if (data1 != null && data2 != null && data3 == null && data4 == null)
                {
                    redBead();
                }
                else
                {
                    blueBead();
                }

                if (moveRow + 1 < table.GetLength(1))
                {
                    moveRow++;
                }
            }
        }

        if (sum1 == sum2)
        {
            redBead();
        }
        else
        {
            blueBead();
        }
        //reset
        sum1 = 0;
        sum2 = 0;

        if (colIndex1 + 1 < table.GetLength(0) && colIndex2 + 1 < table.GetLength(0))
        {
            colIndex1++;
            colIndex2++;
        }
        else
        {
            //nothing to do
        }

        if (moveCol + 1 < table.GetLength(0))
        {
            moveCol += 1;
        }
        if (moveRow + 1 < table.GetLength(1))
        {
            moveRow = 1;
        }

        #endregion
    }
}
void blueBead()
{
    p = Instantiate(big_eye_gameobject) as GameObject;
    p.transform.SetParent(pos_big_eye_road);
    p.transform.localScale = Vector3.one;

    img = (RawImage)p.GetComponent<RawImage>();

    img.texture = NewTexture[0];
    p.SetActive(true);

    p.transform.localPosition = new Vector3(bigEyeXIndex * 56, bigEyeXIndex * -45, 0f);
}

void redBead()
{
    p = Instantiate(big_eye_gameobject) as GameObject;
    p.transform.SetParent(pos_big_eye_road);
    p.transform.localScale = Vector3.one;

    img = (RawImage)p.GetComponent<RawImage>();

    img.texture = NewTexture[1];
    p.SetActive(true);

    p.transform.localPosition = new Vector3(bigEyeXIndex * 56, bigEyeXIndex * -45, 0f);
}

What I am trying to do here: I have this variables called int bigEyeXIndex = 0; and int bigEyeYIndex = 0; . So everytime that my value is different and not the same it will increment my X and Y axis for example like this

enter image description here

But what is happening to me right now is like this

enter image description here

Tags : unity c# android


Related Questions