b3agz / Code-A-Game-Like-Minecraft-In-Unity

Project files for a Youtube tutorial series on coding a game like Minecraft in Unity.
304 stars 236 forks source link

Unable to attach World.cs and Chunk.cs script into respective game objects #22

Open user3D-design opened 3 years ago

user3D-design commented 3 years ago

I am getting the following message while I am trying to attach World.cs and Chunk,cs script into the respective game objects. "The script don't inherit a native class that can manage a script" Please suggest what needs to be done.

Code_Chunk.cs.txt Code_World.cs.txt

Thanks in advance

gregdev00 commented 1 year ago

Might be a little late with this, but the issue you have is likely because of the naming of the files/classes. The attached scripts in your comment are named Code_Chunk.cs and Code_World.cs, but they should be Chunk.cs and World.cs as the class names inside them are called Chunk and World

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Chunk : MonoBehaviour {
  ....
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class World : MonoBehaviour {
 ....
}

So the solution is that you either do ONLY ONE (1. or 2.) of the things below:

  1. Rename the files: Code_Chunk.cs to Chunk.cs and Code_World.cs to World.cs
  2. Rename the class names: public class Chunk : MonoBehaviour to public class Code_Chunk : MonoBehaviour and public class World : MonoBehaviour to public class Code_World : MonoBehaviour