How to call functions based off of an int?,Making Items with unique effects

So I’m trying to make a rogue-like game where every item has a unique effect when picked up.
I figured it would be a lot better performance wise to make a Scriptable Object for Items which holds variables such as itemName, itemID, itemSprite etc.
But it would also need to hold a list of the unique effects and call specific effects based off of the itemId. My question is how do I make this list and how do I call functions on that list based off of the itemId?
Any help would be appreciated.

Hi!

You can do this with inheritance! Basically you start with some base class that you want your effects to influence:

public abstract class BaseBehaviour : ScriptableObject
{
    public abstract float CalculateDamage();
}

Here we for example want each behaviour to calculate damage, but how they do it is irrelevant to the base class.

Then we can derive our behaviours from this base class, instead of scriptable object or monobehaviour or whatever:

[CreateAssetMenu(fileName = "New Behaviour", menuName = "Behaviours/CriticalChance")]
public class CriticalChance : BaseBehaviour
{
    public float baseDamage;
    [Range(0,1)] public float critChance;

    public override float CalculateDamage()
    {
        if (UnityEngine.Random.value < critChance) return baseDamage * 2;
        else return baseDamage;
    }
}

[CreateAssetMenu(fileName = "New Behaviour", menuName = "Behaviours/MissChance")]
public class MissChance : BaseBehaviour
{
    public float baseDamage;
    [Range(0, 1)] public float missChance;

    public override float CalculateDamage()
    {
        if (UnityEngine.Random.value < missChance) return 0;
        else return baseDamage;
    }
}

Notice that each of these classes override the calculate damage and use their own unique variables.

To actually use these behaviours we can do something like this:

public BaseBehaviour behaviour;
private void Awake()
{
    Debug.Log(behaviour.CalculateDamage());

    if(behaviour is CriticalChance)
    {
        Debug.Log((behaviour as CriticalChance).critChance);
    }
}

The great thing is you will be able to drag both miss and crit chance into the same base behavior field, which is extremely useful.

If for whatever reason you need to do something with a specific type like crit chance, you can still cast it into that type.

This way you can give all of your items easily customizable behaviors.

Hope this helps!