Unity give me this error:
Assets\TerrainGeneraion.cs(100,41): error CS1061:
Color[]does not contain a definition forEvaluateand no accessible extension methodEvaluateaccepting a first argument of typeColor[]could be found (are you missing a using directive or an assembly reference?)
Error is locate in public void DrawBiomeTexture() where is
Color col = biomeColors.Evaluate(v);
Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TerrainGeneration : MonoBehaviour
{
[Header("Tile Atlas")]
public TileAtlas tileAtlas;
public float seed;
public BiomeClass[] biomes;
[Header("Biomes")]
public float biomeFreqency;
public Gradient biomeGradient;
public Texture2D biomeMap;
[Header("Trees")]
public int treeChance = 10;
public int minTreeSize = 4;
public int maxTreeSize = 6;
[Header("Addons")]
public int tallGrassChance = 10;
[Header("Generation Settings")]
public int chunkSize = 16;
public int worldSize = 100;
public int heightAddition = 25;
public bool generateCaves = true;
public int dirtLayerHeight = 5;
public float surfaceValue = 0.25f;
public float heightMultiplier = 4f;
[Header("Noise Settings")]
public float terrainFreq = 0.05f;
public float caveFreq = 0.05f;
public Texture2D caveNoiseTexture;
[Header("Ore Settings")]
public OreClass[] ores;
private GameObject[] worldChunks;
private List<Vector2> worldTiles = new List<Vector2>();
public Color[] biomeColors;
private void OnValidate()
{
biomeColors = new Color[biomes.Length];
for (int i = 0; i < biomeColors.Length; i++)
{
biomeColors[i] = biomes[i].biomeColor;
}
DrawTextures();
}
private void Start()
{
seed = Random.Range(-10000, 1000);
DrawTextures();
CreateChunks();
GenerateTerrain();
}
public void DrawTextures()
{
biomeMap = new Texture2D(worldSize, worldSize);
DrawBiomeTexture();
for (int i = 0; i < biomes.Length; i++)
{
biomes[i].caveNoiseTexture = new Texture2D(worldSize, worldSize);
for (int o = 0; o < biomes[i].ores.Length; o++)
{
biomes[i].ores[o].SpreadTexture = new Texture2D(worldSize, worldSize);
}
GenerateNoiseTexture(biomes[i].caveFreq, biomes[i].surfaceValue, biomes[i].caveNoiseTexture);
//Ores
for (int o = 0; o < biomes[i].ores.Length; o++)
{
GenerateNoiseTexture(biomes[i].ores[o].rarity, biomes[i].ores[o].size, biomes[i].ores[o].SpreadTexture);
}
}
}
public void DrawBiomeTexture()
{
for (int x = 0; x < biomeMap.width; x++)
{
for (int y = 0; y < biomeMap.height; y++)
{
float v = Mathf.PerlinNoise((x +seed) * biomeFreqency, (y + seed) * biomeFreqency);
Color col = biomeColors.Evaluate(v);
biomeMap.SetPixel(x, y, col);
}
}
biomeMap.Apply();
}
public void CreateChunks()
{
int numChunks = worldSize / chunkSize;
worldChunks = new GameObject[numChunks];
for (int i = 0; i < numChunks; i++)
{
GameObject newChunk = new GameObject();
newChunk.name = i.ToString();
newChunk.transform.parent = this.transform;
worldChunks[i] = newChunk;
}
}
public void GenerateTerrain()
{
for (int x = 0; x < worldSize; x++)
{
float height = Mathf.PerlinNoise((x + seed) * terrainFreq, seed * terrainFreq) * heightMultiplier + heightAddition;
for (int y = 0; y < height; y++)
{
Sprite[] tileSprites;
if (y < height - dirtLayerHeight)
{
Color biomeCol = biomeMap.GetPixel(x, y);
BiomeClass curBiome = biomes[System.Array.IndexOf(biomeColors, biomeCol)];
tileSprites = curBiome.tileAtlas.stone.tileSprites;
if (ores[0].SpreadTexture.GetPixel(x, y).r > 0.5f && height - y > ores[0].maxSpawnHeight)
tileSprites = tileAtlas.coal.tileSprites;
if (ores[1].SpreadTexture.GetPixel(x, y).r > 0.5f && y > ores[1].maxSpawnHeight)
tileSprites = tileAtlas.iron.tileSprites;
if (ores[2].SpreadTexture.GetPixel(x, y).r > 0.5f && height - y > ores[2].maxSpawnHeight)
tileSprites = tileAtlas.gold.tileSprites;
if (ores[3].SpreadTexture.GetPixel(x, y).r > 0.5f && height - y > ores[3].maxSpawnHeight)
tileSprites = tileAtlas.diamond.tileSprites;
}
else if (y < height - 1)
{
tileSprites = tileAtlas.dirt.tileSprites;
}
else
{
//top layer of the terrain
tileSprites = tileAtlas.grass.tileSprites;
}
if (generateCaves)
{
if (caveNoiseTexture.GetPixel(x, y).r > 0.5f)
{
PlaceTile(tileSprites, x ,y);
}
}
else
{
PlaceTile(tileSprites, x ,y);
}
if (y >= height - 1)
{
int t = Random.Range(0, treeChance);
if (t == 1)
{
//generate a tree
if (worldTiles.Contains(new Vector2(x, y)))
{
GenerateTree(x, y + 1);
}
}
else
{
int i = Random.Range(0, tallGrassChance);
if (i == 1)
{
//generate grass
if (worldTiles.Contains(new Vector2(x, y)))
{
PlaceTile(tileAtlas.tallGrass.tileSprites, x, y + 1);
}
}
}
}
}
}
}
public void GenerateNoiseTexture(float frequency, float limit, Texture2D noiseTexture)
{
for (int x = 0; x < noiseTexture.width; x++)
{
for (int y = 0; y < noiseTexture.height; y++)
{
float v = Mathf.PerlinNoise((x +seed) * frequency, (y + seed) * frequency);
if (v > limit)
noiseTexture.SetPixel(x, y, Color.white);
else
noiseTexture.SetPixel(x, y, Color.black);
}
}
noiseTexture.Apply();
}
void GenerateTree(int x, int y)
{
//define our tree
//generate log
int treeHeight = Random.Range(minTreeSize, maxTreeSize);
for (int i = 0; i < treeHeight; i++)
{
PlaceTile(tileAtlas.log.tileSprites, x, y + i);
}
//generate leaves
PlaceTile(tileAtlas.leaf.tileSprites, x, y + treeHeight);
PlaceTile(tileAtlas.leaf.tileSprites, x, y + treeHeight + 1);
PlaceTile(tileAtlas.leaf.tileSprites, x, y + treeHeight + 2 );
PlaceTile(tileAtlas.leaf.tileSprites, x - 1, y + treeHeight);
PlaceTile(tileAtlas.leaf.tileSprites, x - 1, y + treeHeight + 1);
PlaceTile(tileAtlas.leaf.tileSprites, x + 1, y + treeHeight);
PlaceTile(tileAtlas.leaf.tileSprites, x + 1, y + treeHeight + 1);
}
public void PlaceTile (Sprite[] tileSprites, int x, int y)
{
if (!worldTiles.Contains(new Vector2Int(x, y)))
{
GameObject newTile = new GameObject();
float chunkCoord = (Mathf.Round(x / chunkSize) * chunkSize);
chunkCoord /= chunkSize;
newTile.transform.parent = worldChunks[(int)chunkCoord].transform;
newTile.AddComponent<SpriteRenderer>();
int spriteIndex = Random.Range(0, tileSprites.Length);
newTile.GetComponent<SpriteRenderer>().sprite = tileSprites[spriteIndex];
newTile.name = tileSprites[0].name;
newTile.transform.position = new Vector2(x + 0.5f, y + 0.5f);
worldTiles.Add(newTile.transform.position - (Vector3.one * 0.5f));
}
}
}