Error: "The namespace '<global namespace>' already contains a definition for 'GenerateChunk'
LetsGoSalmon
1
Reputation point
I am following a tutorial on YouTube for how to make a Minecraft-like 2D game in Unity. Here's the link: https://www.youtube.com/watch?v=4ubrvkefphI&list=PL37wmdqtgqTIfYtBtAOZNUFR7BeE1XUGi&index=3
I have to scripts to generate the chunks of the world, "GenerateChunk" and "GenerateChunks" (notice the s on the end). This is the scripts:
GenerateChunk:
using UnityEngine;
using System.Collections;
public class GenerateChunk : MonoBehaviour {
public GameObject DirtTile;
public GameObject GrassTile;
public GameObject StoneTile;
public int width;
public float heightMultiplier;
public int heightAddition;
public float smoothness;
[HideInInspector]
public float seed;
void Start () {
Generate ();
seed = Random.Range (-10000, 10000);
}
public void Generate () {
for (int i = 0; i < width; i++){
int h = Mathf.RoundToInt (Mathf.PerlinNoise (seed, (i + transform.position.x) / smoothness) * heightMultiplier) + heightAddition;
for (int j = 0; j < h; j++){
GameObject selectedTile;
if (j < h - 4) {
selectedTile = StoneTile;
} else if (j < h - 1 ){
selectedTile = DirtTile;
} else {
selectedTile = GrassTile;
}
GameObject newTile = Instantiate (selectedTile, Vector3.zero, Quaternion.identity) as GameObject;
newTile.transform.parent = this.GameObject.transform;
newTile.transform.localPosition = new Vector3 (i, j);
}
}
}
}
GenerateChunks:
using UnityEngine;
using System.Collections;
public class GenerateChunks : MonoBehaviour {
public GameObject chunk;
int chunkWidth;
public int numChunks;
float seed;
void Start () {
chunkWidth = chunk.GetComponent<GenerateChunk> ().width;
seed = Random.Range (-100000f, 100000f);
Generate ();
}
public void Generate () {
int lastX = -chunkWidth;
for (int i = 0; i < numChunks; i++) {
GameObject newChunk = Instantiate(chunk, new Vector3(lastX + chunkWidth, 0f), Quaternion.identity) as GameObject;
newChunk.GetComponent<GenerateChunk> ().seed = seed;
lastX += chunkWidth;
}
}
}
Please help me!
Sign in to answer