- Home /
Why is this not recognizing as a gameobject?
I have a C# script and at the top is the following code:
public class GameStartScript : MonoBehaviour {
public int width; //Width of playing field
public int height; //Height of playing field
public GameObject tile;
List<Tile> tiles = new List<Tile>();
// Use this for initialization
void Start () {
...
But for some reason, when I attach this to an empty gameobject, it will only let me specify width and height but not the GameObject? I've used public GameObject name; lots of times before and it works fine but for this, it's just not giving me the option to choose anything which is now generating errors when I run my program.
Any advice?
I'm actually getting 4 of the same error every time I run. This is the earliest of the errors:
GameStartScript.cs(12,14): error CS0246: The type or namespace name `Tile' could not be found. Are you missing a using directive or an assembly reference?
Which is the line that says:
List tiles = new List();
Any ideas?
Yeah, if you don't have a class called Tile, than you can't make a List of it.
Answer by Jessy · Jan 30, 2011 at 08:07 PM
Nothing is wrong with that code (except for putting = new List... outside of a function, which is unpredictable, but that's not the problem in question). You should be able to put it in a new project and see for yourself. My guess would be that you have other compile errors, so you just changed this recently, and it won't be allowed to finish compiling until you fix all of your other errors.
Your answer
![](https://koobas.hobune.stream/wayback/20220613101915im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
Get unity to recognize prefab in C# 2 Answers
Translate.transform problems (collision/Rigibody) 0 Answers
Weird GetComponent error 2 Answers
Projectile not 'projecting' because i have to use "var xxx : GameObject = Instantiate" 2 Answers