Hi, first of all happy new year !
I am facing a problem with a powerup system, and don’t know what is the best way to approach it.
I’m building a small game (mobile app) where you can touch some power ups to launch differents upgrades in game (ex : double up score, …).
PowerUps values are stacked into a So :
[CreateAssetMenu(fileName = "Upgrade", menuName = "Settings/Upgrade")]
public class UpgradeSettings : ScriptableObject
{
public string upName;
public int amountStacked, price, duration;
public Sprite icon;
public bool active = false;
public static Action<int> _event;
[TextArea]
public string quickDescription;
/// <summary>
/// Fire virtual method to manage amount of updates aviable && launch action attached to it
/// </summary>
/// <param name="upgradeSlot">Pass upgrade slot to refresh it with new values</param>
public virtual void Use(UpgradeSlot upgradeSlot)
{
_event.Invoke(duration);
amountStacked--;
upgradeSlot.SetupUpgrade(upgradeSlot.upgrade);
}
}
As you see i have a virtual method who is launched by the “upgrade slot” (Ui button where the uprgade is attached to.
And there is my question
do you know a manner to attach individual action to each powerup i create using asset menu or do i need to make a callback passing the upgrade and then apply the effect of the differents upgrades
ex like this :
public void ActiveUpgrade(Upgrade upgrade)
{
switch (upgrade.upName)
{
case "BigNet":
StartCoroutine(BigNet(upgrade));
break;
case "Multiplier":
StartCoroutine(Multiplier(upgrade));
break;
case "Freeze":
StartCoroutine(Freeze(upgrade));
break;
case "ExtraLife":
StartCoroutine(ExtraLife(upgrade));
break;
}
}
Thanks for your replies and have a nice day