- Home /
need help with armor customization
Hi, I'm working on a Fan made halo game called Project BackBurn. And I'm wondering how I would handle armor customization for the Spartan's. I have all the armor pieces attached to the under suit that is rigged. So would I have a button that sets each armor piece active using "Set Active" and the same for disabling armor pieces? But how would that effect it in the actual game? Ughhh I need help.
Hello.
Your question is unclear... If you know you can make buttons that "active or unactive" the object, where is the problem?
and what you mean with effect it in the actual game?
Ok so say I have a several buttons for each armor set. If I customize my armor to whatever I want how would I have the game change the armor in the custom games or matchmaking?
Answer by akaBase · Jul 11, 2019 at 02:44 PM
You need to brake it down into different parts.
First have a script on each Armor Piece parent with some info about it and the ability to change the Armour pieces active status, example below.
public class ArmorPiece : MonoBehaviour
{
public string id;
public GameObject armorPiece;
public bool isActive;
public void ToggleActiveState()
{
isActive = !isActive;
armorPiece.SetActive(isActive);
}
}
And then some sort of Manager for all ArmorPieces, example below.
public class ArmorManager : MonoBehaviour
{
public GameObject[] armorGameObjects;
public Dictionary<string, ArmorPiece> armorPieces;
private void Start()
{
armorPieces = new Dictionary<string, ArmorPiece>();
foreach (GameObject armorGameObject in armorGameObjects)
{
ArmorPiece armorPiece = armorGameObject.GetComponent<ArmorPiece>();
if (armorPiece != null)
{
armorPieces.Add(armorPiece.id, armorPiece);
}
}
}
public void ToggleArmorStatus(string armorID)
{
if (armorPieces.ContainsKey(armorID))
{
armorPieces[armorID].ToggleActiveState();
}
}
}
And then to toggle Armor pieces create buttons with the that onclick point to ToggleArmorStatus
with the id of that buttons Armor Piece as the value.
That is just pseudo code but gives you more than enough to go on, and gives an idea on how to brake things down into the different parts needed to accomplish something a little more complex.
now how would it be saved for my profile for say and it show up in the custom game?
Not entirely sure what you mean by my profile and custom game but if you wish for the settings to persist between games you could turn the ArmorPieces Dictionary into a json and save that resulting string with PlayerPrefs (Due to JsonUitlity limitations you will need to create a struct to hold the dictionary for serialization)