There are a number of ways to structure a system like that to avoid nested if’s, and they don’t require a central manager - though they’d benefit from some static methods. Here’s an example of a possible system below that’s highly extensible and flexible - it’ll be really easy to add new abilities.
My first thought for designing this system would be to have a base class that represents an ability - literally any option you can pick on the “menu”. Then you can extend this class for each type of action you have. If this is unfamiliar territory, probably watch the inheritance tutorial.
public abstract class CharacterAbility : MonoBehaviour {
public abstract void Execute();
public abstract string abilityLabel { get; }
public virtual bool isUsable { get { return true; } }
}
public class MeleeAttack : CharacterAbility {
public override void Execute() {
// pick a target here, and then queue up whatever it is this does
}
public override string abilityLabel { get { return "Melee"; } }
}
So you can attach these components to your character, and the character can use GetComponents() to get a list of all the abilities that character has. If you have equipment or spell objects that add new abilities, you can add them as children of your character and use GetComponentsInChildren() and find all of them.
You can also add, in addition to the abilityLabel, an abilityCategory. This can be used to sort your abilities into submenus. e.g. Each item might be an ability with its abilityCategory as “Item”, which makes a handy way to pick and use items from your inventory.
The isUsable property will let you gray out your “Revive” ability when none of your characters are dead, for example. But the default is for abilities to always be usable, unless you override them.
Let’s make a ComboAbility that can detect copies of itself. I’ll assume you have a central list of party characters available, and I’ll call it PartySystem.characters and assume it’s a List - adapt as needed (or ask for help in making one).
public class ComboAbility : CharacterAbility {
public override bool isUsable {
get {
var comboCharacters = FindCharactersWithAbility(this.GetType() );
return (comboCharacters.Count > 1);
}
}
public static List<Character> FindCharactersWithAbility(type t) {
List<Character> list = new List<Character>();
foreach (Character c in PartySystem.characters) {
if (c.GetComponentInChildren(t) != null) list.Add(c);
}
return list;
}
}
so that class will, essentially, find characters who have a copy of that same script, and if there are 2 of them (this doesn’t exclude the current copy), that ability is usable.