What would be the best (or preferably easiest)way to save the state of a custom script. for example, I have a generic custom crafting script that enables and disables game objects if conditions are met (first is checks the local bool (isStageComplete), if it's false it then checks the players inventory (UIS) if they have the appropriate items in their inventory, if they do then it runs a Unity event to enable and disable assigned game objects and it then sets isStageComplete to true. The next time the player interacts with this object it moves on to the next.
Can you think of a way to save the isStageComplete value with the save system? I am able to save all of the game object states with the MultiActiveSaver component but I need to be able to save the state of the script itsself. I was thinking I could run a check once the game objects states are set to then determine what state the crafting scipt is at and set it then, but I feel like there might be a better way to achieve this.
Here's the code incase the above is a bit confusing.
Code: Select all
public void Interact(GameObject character)
{
int arrayCount = 0;
int arrayLength = constructorClass.Length;
Inventory playerInv = character.GetComponent<Inventory>();
foreach (VSBuildableClass constructor in constructorClass)
{
arrayCount = arrayCount + 1;
if (constructor.stageCompleted == false)
{
//if no item is required in the player's inventory
if (constructor.itemDefinition == null)
{
constructor.stageCompleted = true;
constructor._event.Invoke();
break;
}
if (playerInv.GetItemAmount(constructor.itemDefinition) >= constructor.amountRequired)
{
playerInv.RemoveItem(constructor.itemDefinition, constructor.amountRequired);
constructor._event.Invoke();
constructor.stageCompleted = true;
}
else
{
int amountNeeded = constructor.amountRequired - playerInv.GetItemAmount(constructor.itemDefinition);
string message = "You need to gather" + amountNeeded + " " + constructor.itemDefinition.name.ToString();
DialogueManager.ShowAlert(message);
}
break;
}
}
}
Code: Select all
public class VSBuildableClass
{
public ItemDefinition itemDefinition;
public int amountRequired;
public bool stageCompleted = false;
public UnityEvent _event;
}
I hope this isn't too convoluted. Thank you.
Nathan