Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 嵌套For循环-在Unity中生成卡坦式十六进制网格_C#_For Loop_Unity3d_Hexagonal Tiles - Fatal编程技术网

C# 嵌套For循环-在Unity中生成卡坦式十六进制网格

C# 嵌套For循环-在Unity中生成卡坦式十六进制网格,c#,for-loop,unity3d,hexagonal-tiles,C#,For Loop,Unity3d,Hexagonal Tiles,正如标题所示,我正在尝试使用C#在Unity中生成一个程序性的十六进制网格 void Start() { //5月中旬 startRowSize=5; 对于(int i=0;i

正如标题所示,我正在尝试使用C#在Unity中生成一个程序性的十六进制网格

void Start()
{
//5月中旬
startRowSize=5;
对于(int i=0;i对于(int row=0;row),在花了几个小时的时间处理代码之后,我发现了为什么它不能正确地迭代。他是经过改进的代码

void Start () 
{
    //5 mid
     startRowSize = 10;

    for (int i = 0; i < startRowSize; i++)
    {
        GameObject newHex = (GameObject)Instantiate(hex);
        hexWidth = newHex.gameObject.renderer.bounds.size.z;
        newHex.transform.Rotate(new Vector3(0,30,0));
        newHex.transform.position = new Vector3((i * hexWidth),0,0);
    }

    for (int row = 0; row < startRowSize; row++)
    {
        for (int i = 0; i < startRowSize-1-row; i++)
            {
                GameObject newHex = (GameObject)Instantiate(hex);
                newHex.transform.Rotate(new Vector3(0,30,0));

            if (row == 0)
                {
                    newHex.transform.position = new Vector3(((i*hexWidth)+(hexWidth/2)),0,-(hexWidth/1.17f));
                }
            else
                {
                    newHex.transform.position = new Vector3((i*hexWidth)+((row+1)*(hexWidth/2)),0,(row+1)*-(hexWidth/1.17f));
                }
            }
    }

    for (int row = 0; row < startRowSize; row++)
    {
        for (int i = 0; i < startRowSize-1-row; i++)
            {
                GameObject newHex = (GameObject)Instantiate(hex);
                newHex.transform.Rotate(new Vector3(0,30,0));

            if (row == 0)
                {
                    newHex.transform.position = new Vector3(((i*hexWidth)+(hexWidth/2)),0,(hexWidth/1.17f));
                }
            else
                {
                    newHex.transform.position = new Vector3((i*hexWidth)+((row+1)*(hexWidth/2)),0,(row+1)*(hexWidth/1.17f));
                }
            }
    }
}
void Start()
{
//5月中旬
startRowSize=10;
对于(int i=0;i

现在,有人能建议一下如何清理一下吗?我的大脑已经失灵了…

只是一个提示,清醒发生在开始之前()

void Start () 
{
    //5 mid
     startRowSize = 10;

    for (int i = 0; i < startRowSize; i++)
    {
        GameObject newHex = (GameObject)Instantiate(hex);
        hexWidth = newHex.gameObject.renderer.bounds.size.z;
        newHex.transform.Rotate(new Vector3(0,30,0));
        newHex.transform.position = new Vector3((i * hexWidth),0,0);
    }

    for (int row = 0; row < startRowSize; row++)
    {
        for (int i = 0; i < startRowSize-1-row; i++)
            {
                GameObject newHex = (GameObject)Instantiate(hex);
                newHex.transform.Rotate(new Vector3(0,30,0));

            if (row == 0)
                {
                    newHex.transform.position = new Vector3(((i*hexWidth)+(hexWidth/2)),0,-(hexWidth/1.17f));
                }
            else
                {
                    newHex.transform.position = new Vector3((i*hexWidth)+((row+1)*(hexWidth/2)),0,(row+1)*-(hexWidth/1.17f));
                }
            }
    }

    for (int row = 0; row < startRowSize; row++)
    {
        for (int i = 0; i < startRowSize-1-row; i++)
            {
                GameObject newHex = (GameObject)Instantiate(hex);
                newHex.transform.Rotate(new Vector3(0,30,0));

            if (row == 0)
                {
                    newHex.transform.position = new Vector3(((i*hexWidth)+(hexWidth/2)),0,(hexWidth/1.17f));
                }
            else
                {
                    newHex.transform.position = new Vector3((i*hexWidth)+((row+1)*(hexWidth/2)),0,(row+1)*(hexWidth/1.17f));
                }
            }
    }
}
void Awake() 
{
   //5 mid
  startRowSize = 10;

  for (int i = 0; i < startRowSize; i++)
  {
      GameObject newHex = HexCreator();
      hexWidth = newHex.gameObject.renderer.bounds.size.z;
      newHex.transform.position = new Vector3(i * hexWidth, 0, 0);
  }

  for (int row = 0; row < startRowSize; row++)
     for (int i = 0; i < startRowSize-1-row; i++)
     {
         GameObject newHex = HexCreator();

         if (row == 0)
            newHex.transform.position = new Vector3(i*hexWidth + hexWidth/2, 0, -(hexWidth/1.17f));

         else
            newHex.transform.position = new Vector3(i*hexWidth + ((row+1)*(hexWidth/2)), 0,(row+1)*-(hexWidth/1.17f));
    }

  for (int row = 0; row < startRowSize; row++)
     for (int i = 0; i < startRowSize-1-row; i++)
     {
        GameObject newHex = HexCreator();

        if (row == 0)
            newHex.transform.position = new Vector3(i*hexWidth+ hexWidth/2, 0, hexWidth/1.17f);

        else
            newHex.transform.position = new Vector3(i*hexWidth + ((row+1)*(hexWidth/2)), 0, (row+1)*(hexWidth/1.17f));
     }
}
private GameObject HexCreator()
{
    GameObject newHex = (GameObject)Instantiate(hex);
    newHex.transform.Rotate(new Vector3(0,30,0));

    return newHex;
}