Ability system help

Hey,

I’ve made multiple prefab abilities like a sword attack or a grenade throw, when my player attacks, it plays the attack animation and instantiates the prefab ability.

Right now i have two ability slots, the main attack and the secondary attack, for the main attack i’ve referenced the sword attack prefab and the secondary attack the grenade throw prefab

91804-abilities.jpg

I plan to have a lot of abilities that the player will unlock, what would be a simple way to load and unload different ability prefabs in my attack slots and to keep track of which ones have been unlocked?

I’m pretty new to coding, some examples would be really helpful.

So you’re asking how you would put the abilities like Double Jump in the Ability slots?
(e.g. Primary Attack: Sword, Secondary Attack: Double Jump)

Given that your abilities have their own scripts, just add a boolean variable to check if the specific ability is unlocked.

Check first if that ability is unlocked, if it’s not yet unlocked then it can’t be set in the ability slot, if it’s already unlocked, then set it to the ability slot

public class Attack: MonoBehaviour {
	public GameObject WeaponSocket;
	public GameObject PrimaryAttack;
	public GameObject SecondaryAttack;

	DoubleJump doubleJump;
	Dash dash;

	void Start(){
		doubleJump = GetComponent<DoubleJump>();
		dash = GetComponent<Dash>();
	}

	SwitchAbility(int ability){ //e.g. 1 is Double Jump, 2 is Dash 
		switch(ability){
        	case 1: if(doubleJump.isUnlocked) SecondaryAttack = doubleJump.abilityPrefab;
        			break;
        	case 2: if(dash.isUnlocked) SecondaryAttack = dash.abilityPrefab;
        			break;
		}
	}
}

I’m not using Unity right now, I’m not so sure how that will work. Basically add a boolean attribute to determine if the ability is unlocked and store the ability prefabs in their respective scripts