- Home /
Public Array with a class not showing in Inspcetor
I have a class ItemClass and I'm trying to create a public ItemClass[] but I can't see anything in the inspector. Is there something missing? Here is the ItemClass followed by the script with the array:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ItemClass {
private string itemName;
private string itemDesc;
private int cost;
private int dungeonUnlock;
private int attackInc;
private int defenseInc;
private int vitInc;
private int healingAmount;
private string loadScene;
public enum ItemType
{
Accessory,
Armor,
Weapon,
Potion,
Support
}
private ItemType itemTypes;
public string ItemName { get; set; }
public string ItemDesc { get; set; }
public int Cost { get; set; }
public int DungeonUnlock { get; set; }
public int AttackInc { get; set; }
public int DefenseInc { get; set; }
public int VitInce { get; set; }
public int HealingAmount { get; set; }
public string LoadScene { get; set; }
public ItemType ItemTypes { get; set; }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class ShopContents : MonoBehaviour {
public ItemClass[] allItems;
public GameObject[] gameObjects;
public List<ItemClass> availableItems;
void Start()
{
availableItems = new List<ItemClass>();
DungeonCheck();
}
void DungeonCheck()
{
availableItems.Clear();
foreach (ItemClass item in allItems)
{
if (PlayerStatManager.dungeonsBeaten >= item.DungeonUnlock)
{
availableItems.Add(item);
}
}
}
}
Answer by PizzaPie · Jun 11, 2017 at 08:57 PM
[System.Serializable]
public class ItemClass {...
And change the fields to public OR mark them with [SerializeField] to to see them on inspector (properties are not visible/seriazable on inspector)
As for the shopContents class you don't need to mark it as serializable.
Thank you, that made it appear in the inspector, but I can't add to the elements regardless of array size for my ItemClass[]
Not sure what you mean, anyway if you didn't mark the fields with public ins$$anonymous$$d of private OR mark them with [SerializeField] they won't be visible in inspector. To add more elements to the array just change the size of the array on the inspector.
public class ItemClass {
[SerializeField]
private string itemName;
[SerializeField]
private string itemDesc;
[SerializeField]
private int cost;
[SerializeField]
private int dungeonUnlock;
//...