How Could I Make An Inventory With A Primary, Secondary, Lethal, Tactical, and melee.How Could I Make An Inventory With A Primary, Secondary, Lethal, Tactical, and melee and then fill that inventory slots based on a users class selection. Would I use an array?
I want to make sure I understand your question before answering. So for one particular inventory/item you wish to have different modes that would exhibit different behaviors?
“and then fill that inventory slot based on users class selection” Can you clarify this a bit more? What do you mean by fill that inventory slot. Is it the slot that has the different modes associated to it and whatever item you put in that slot, that item inherits that mode? Or am I getting this wrong?
Okay so on start the players inventory will have a slot for the primary secondary lethal and tactical weapons. Upon selecting a setup those slots will be filled
Ah I see.
Yes, you can store the weapon loadout in an array, probably the easiest way. During the selection process you decide which array to associate to the inventory.
Now if the customization and logic would differ greatly per setup and if it is dynamic depending on situation, I would go with something like a LoadOutManager class, and have an Interface called LoadOut or something and implement LoadOut for different character classes
public interface LoadOut {
GameObject getWeapon(WeaponType type);
void addorChangeType(WeaponType type, GameObject newWeapon);
}
public class NavySealLoadOut : LoadOut{
Map<WeaponType, GameObject>() weaponToType;
public NavySealLoadOut(){
this.weaponToType = new Map<WeaponType, GameObject>();
this.weaponToType[WeaponType.Primary] = (code to fetch or load gameObject);
this.weaponToType[WeaponType.Secondary] = (code to fetch or load gameObject);
}
public GameObject getType(WeaponType type){
return this.weaponToType[type];
}
public void addorChangeType(WeaponType type, GameObject newWeapon){
//assign weapon to the type dynamically
}
}
public class WeaponLoadOutManager {
public LoadOut getNavySealLoadOut() {
return new NavySealLoadOut();
}
}
public class ScriptCode : MonoBehavior {
WeaponLoadOutManager loadOutManager;
public void Start() {
loadOutManager = new LoadOutManager();
}
public void Update() {
LoadOut loadOutResult = null;
if(selected == "NavySeal"){
loadOutResult = loadOutManager.getNavySealLoadOut();
inventory[0] = loadOutResult.getWeapon(WeaponType.primary]
inventory[1] = loadOutResult.getWeapon(WeaponType.secondary]
}else if (selected == "unity programmer"){
loadOutResult = loadOutManager.geUnityProgrammerLoadOut(); //of course you need to implement this
}
}
}
This way you can have separation of concerns in your code. You can do all the crazy logic inside the LoadOut implementations for different types of loadout, how you store them, how you fetch them based on whatever situation depending on the loadout type. That logic goes there.
Then the WeaponLoadOutManager’s job is just to create it and return it to you.