Answer the question
In order to leave comments, you need to log in
How do you add an item without knowing exactly what class it is?
There are several classes denoting what kind of item it is, for example:
using UnityEngine;
[CreateAssetMenu(fileName = "Weapon name", menuName = "Items/Weapon")]
public class Weapon : ScriptableObject
{
public ItemProp MainProp;
public int Damage;
public int Firerate;
public int Strength;
}
ИЛИ
using UnityEngine;
[CreateAssetMenu(fileName = "Resource name", menuName = "Items/Resource")]
public class CraftResources : ScriptableObject
{
public ItemProp MainProp;
}
public class Items
{
public static List<Weapon> Weapons = new List<Weapon>();
public static List<CraftResources> Resources = new List<CraftResources>();
public static List<Tool> Tools = new List<Tool>();
public static List<Armor> Armors = new List<Armor>();
public static int MaxItemsCount;
public void AddItem()
{
}
}
Answer the question
In order to leave comments, you need to log in
Make the base class inherit from ScriptableObject, inherit items from it, then use switch in the Items class:
switch (Базов класс предмета)
{
case Weapon weapon:
Weapons.Add(weapon);
break;
case CraftResources craftResources :
Resources.Add(craftResources);
break;
...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question