Hi there! I’m creating a simple clicker game and now trying to use OOP to deal with its Items Shop. Because all the items will have the same fields I decided to create the base class - ItemShop.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public abstract class ShopItem : MonoBehaviour
{
public string UpgradeName;
public int InitialCost;
public Button MyButton;
public Text MyButtonText;
public int LevelOfItem { get; protected set; }
public abstract int CurrentCost { get; }
...
}
Then I created the second one, DefaultUpgradeItem class, which inherits from it and also have some public fields.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DefaultUpgradeItem : ShopItem
{
public int SomeField;
...
}
and declare this derived class as a public field to the Main Game script.
public class Game : MonoBehaviour
{
public DefaultUpgradeItem testDefaultItem;
...
}
But when I’d attached the Game script to a GameObject on my scene I noticed that I can assign any fields to the Both ShopItem and DefaultUpgradeItem classes from the inspector. Is there any way to do it in the Unity inspector or it’s possible only in code?