Domanda

Getting same error for each of the 3 lines that begin with "for"

{
    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
            }
        }
    }
}

WHY?


After i saw your answeres (THANK YOU SO MUCH YOU ARE GREAT) i Fixed it, Here is the full code:

using UnityEngine;

using 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);
}

}


and now instead of 3 error i get 6 coz under each for loop it says: error CS1525:

Unexpected symbol ;', expecting)', or `,'


I fixed what you told me. so why more errors?

È stato utile?

Soluzione 2

Correct with this.

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
        }
    }
}

Altri suggerimenti

Your for syntax is wrong, you need a ; instead of ,

Replace this

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

with

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

and same for all three for loops as well

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top