Unity3D中的IL代码错误无效

时间:2015-06-29 11:21:48

标签: unity3d unityscript perlin-noise

我正在尝试使用perlin噪声来使用Unity3D(版本5.0.2f1)生成terain但我收到此错误:

InvalidProgramException: Invalid IL code in TerrainGenerator:GenerateFloor (): IL_0045: call      0x0a00000c


TerrainGenerator.Generate () (at Assets/TerrainGenerator.js:36)
TerrainGenerator.Start () (at Assets/TerrainGenerator.js:23)

代码:

function GenerateFloor(){
    print("The function was called");
    if(!(seed > 0)){
        Debug.LogError("Seed not valid. Seed: " + seed + " .");
        seed = Random.Range(0, 1000000000000000);
        Debug.LogError("Generated new seed. Seed: " + seed + ".");
    }
    for(var i = 0; i < heightMap.length; i++){
        if(currentX == Math.Sqrt(size)){
            currentX = 0;
            currentZ++;
        }
        else if(currentX > Math.Sqrt(size)) Debug.LogError("How did this happen?! currentX = " + currentX + " size = " + size + " .");
        var height = Mathf.PerlinNoise(currentX, currentZ);
        heightMap[currentX * currentZ] = new Vector3(currentX, height, currentZ);
        print("For loop worked");
        //yield;
    }
}

1 个答案:

答案 0 :(得分:2)

Random.Range中的param 1000000000000000超出最大值。也许你想要int.MaxValue?这将是2147483647

有趣的是,IL2CPP引起了这样的编译错误!