错误CS0201 C#Unity3d

时间:2014-03-03 06:51:40

标签: c# unity3d

以“for”

开头的3行中的每一行都会出现相同的错误
{
    int _curType; // The blocktype of the next created cube

    for (int i = 0; i < sizeX, i++)
    {
        for (int j = 0; j < sizeY, j++)
        {
            for (int k = 0; k < sizeZ, k++)
            {
                _curType = Random.Range (1,4); // The last number is excluded, this will return a random number between 1,2 and 3
                CreateCube (i,j,k, _curType); // Call the CreateCube function to instantiate a cube
            }
        }
    }
}

为什么?


在我看到你的回答之后(谢谢你真的很棒)我修正了它,这是完整的代码:

using UnityEngine;

使用System.Collections;

public class CubeGeneration:MonoBehaviour {

public GameObject CubeGrass;
public GameObject CubeRock;
public GameObject CubeSand;
// Use this for initialization
void Start ()
{
    CreatePrism(10,7,3);
}

// Create a sizeX by sizeY by sizeZ prism with random cube in it
void CreatePrism(int sizeX, int sizeY, int sizeZ)
{
    int _curType; // The blocktype of the next created cube

    for (int i = 0; i &lt; sizeX; i++)
    {
        for (int j = 0; j &lt; sizeY; j++)
        {
            for (int k = 0; k &lt; sizeZ; k++)
            {
                _curType = Random.Range (1,4); // The last number is excluded, this will return a random number between 1,2 and 3
                CreateCube (i,j,k, _curType); // Call the CreateCube function to instantiate a cube
            }
        }
    }
}

// Create a Cube at the inputted position with a texture matching the blockType
void CreateCube(int _posX, int _posY, int _posZ, int _blockType)
{
    GameObject _CurCube = CubeRock; //Local variable that only remember the good prefab to be displayed

    // _blockType is inputted as an integer. 1 = Grass, 2 = Rock, 3 = Sand
    if(_blockType == 1)
        _CurCube = CubeGrass;
    else if(_blockType == 2)
        _CurCube = CubeRock;
    else if(_blockType == 3)
        _CurCube = CubeSand;

    // Instantiate a new cube at the inputted position, facing identity
    GameObject.Instantiate(_CurCube, new Vector3(_posX, _posY, _posZ), Quaternion.identity);
}

}


现在而不是3个错误我在每个for循环下得到6个coz 它说:错误CS1525:

意外的符号;', expecting)'或`,'


我修好了你告诉我的内容。那么为什么会出现更多错误呢?

2 个答案:

答案 0 :(得分:2)

您的语法错误,您需要;而不是,

替换此

for (int i = 0; i < sizeX, i++)

for (int i = 0; i < sizeX; i++)

同样适用于所有三个for循环

答案 1 :(得分:0)

纠正此事。

int _curType; // The blocktype of the next created cube

for (int i = 0; i < sizeX; i++)
{
    for (int j = 0; j < sizeY; j++)
    {
        for (int k = 0; k < sizeZ; k++)
        {
            _curType = Random.Range (1,4); // The last number is excluded, this will return a random number between 1,2 and 3
            CreateCube (i,j,k, _curType); // Call the CreateCube function to instantiate a cube
        }
    }
}