Liam Earle
Liam Earle

Reputation: 167

Why are there no variables showing up in inspector

Trying to make a Tile system in Unity. I have my tile class done but when I create a list in the TileManager class it gives me the option to change the size of the list but gives me an empty element with no changeable variables.

Tile Class:

public class Tile : MonoBehaviour
{

public Sprite tileSprite;
public string tileName;
public int tileID;

public Tile(Sprite newTileSprite, string newTileName, int newTileID) 
{
    tileSprite = newTileSprite;
    tileName = newTileName;
    tileID = newTileID;
}

void Start()
{
    SpriteRenderer spriteRenderer = gameObject.GetComponent(typeof(SpriteRenderer)) as SpriteRenderer;

    if (spriteRenderer != null) spriteRenderer.sprite = tileSprite;
}

TileManager Class:

public class TileManager : MonoBehaviour {

public List<Tile> Tiles;
// Use this for initialization
void Start () 
{

}

// Update is called once per frame
void Update () {

}
}

Upvotes: 0

Views: 95

Answers (1)

Aj_
Aj_

Reputation: 502

Use the System.Serializable attribute on Tile class. Also be sure that the Tile class does not inherit from MonoBehaviour, otherwise it will still not appear in the inspector list.

[System.Serializable]
public class Tile 
{
   public Sprite tileSprite;
   public string tileName;
   public int tileID;

   public Tile(Sprite newTileSprite, string newTileName, int newTileID) 
   {
       tileSprite = newTileSprite;
       tileName = newTileName;
       tileID = newTileID;
   }
}

Upvotes: 3

Related Questions