Want to create a vampire-survivor type upgrade system

So I wrote a basic code that fills a slider based on the numbers of enemies killed and then pauses the game and make the upgrade canvas visible.

Here is how i tried to make different upgrades.

Firstly I made a scriptable object like this.

public class UpradeObject : ScriptableObject
    public string _name;
    public string description;
    public UpgradeTypes upgradeTypes;

Then I searched stack overflow and learned about “abstract classes”

And i wrote this code

public abstract class UpgradeTypes : MonoBehaviour
    public PlayerStats playerStats;
    public abstract void OnActivated();

Now for each upgrade I made a derived class. For eg

public class HealthUpgrade : UpgradeTypes
    public float healthIncrease = 0.1f;
    public override void OnActivated()
        playerStats.health += healthIncrease*playerStats.health;

Now the plan was to assign a upgradetypes script to the SO as seen in the UpgradeObjects script above

public UpgradeTypes upgradeTypes;

Then I would assign a derived class like HealthUpgrade in the UpgradeObjects script slot and call the OnActivated method when the health increase upgrade button is clicked.

Unfortunately my knowledge on this topic is really limited and also I cant seem to assign the script to the SO. Should I approach the problem from a completely different angle? Or can this one work

Actually i somewhat made it work by creating an empty object and assigning the script to that and making it a prefab.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms