Error: The namespace '<global namepspace>' already contains a definition for 'GenerateChunk'

Hi, I’m following a tutorial on YouTube on how to create a Minecraft-like 2D game, here’s the link:

Right now I’m working on the world generation, but i get this error: see title. Here’s the code for the two 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 ().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 ().seed = seed;
lastX += chunkWidth;
}
}
}

Please help me!

Code Tags ?

The class name “GenerateChunk” probably already is taken try renaming the file that causes the error and find the duplicate class/file and remove it.

Just like the error says, a GenerateChunk already exists in the global namespace. Check whether you accidentally have a duplicate script in the project. And it’s best to put your code in its own namespace.

This might sound a bit n00by, but explain the last sentence…

I use always Namespaces, normally the project name.
This is very useful for managing code and at some point also necessary, because otherwise name conflicts will certainly occur.

namespace SampleNamespace
{
    class SampleClass
    {
        public void SampleMethod()
        {
            System.Console.WriteLine(
                "SampleMethod inside SampleNamespace");
        }
    }
}