Recently I've decided to drop playmaker just due to the lag it was causing on mobile devices. I'm learning how to code everything by hand now and have just gotten to the point where I need to set up ES2.
As of right now, my game can be thought of as a rpg. There are various characters, weapons, and items. Each of these have various stats, unlock/upgrade costs, etc. I've been toying with saving/loading these into a 2D array as shown on the documentation. While this works fine, I'm just not sure on my execution.
On my Weapon Loadout scene for example, I made an empty object that holds a script to load a saved 2d array and stores it into a public string array called UnlockStatus. The array is something like:
[Pistol] [Unlocked]
[Minigun] [Locked]
[Sword] [Locked]
The menu is made up of various sprites that needs to read the saved data and check if it is locked or unlocked to display the proper graphic.
Right now, in the code for each of my menu items I have it like this:
Code: Select all
public class WeaponCardUpdater : MonoBehaviour
{
private tk2dSprite mySprite;
public string Weapon;
//Default Value is Locked
private string UnlockStatus = "Locked";
public GameObject DataObject;
// Use this for initialization
void Start ()
{
mySprite = GetComponent<tk2dSprite>();
Weapon = DataObject.GetComponent<SaveLoadGameData>().stringArray[0,0];
UnlockStatus = DataObject.GetComponent<SaveLoadGameData>().stringArray[0,1];
}
// Update is called once per frame
void Update ()
{
mySprite.SetSprite(Weapon + " " + UnlockStatus);
}
}
I have no idea if this is how I should be going about doing this.
Is there a way to directly load a certain index of an array from a file, or do I have to load said array into a variable first, and then get the proper index from the variable.
Also is referencing another gameobject that is doing all the saving/loading correct? Another way I could think of doing this is having each object on the scene load the file in order to get that array, but then that would mean I would have 20+ objects all calling the load function at once. I'm not sure if that would be a good route to go.
Sorry for the newbish questions
Edit:
Another way I thought of is to just have each weapon object save and load individual variables all with different tags instead of using an array. Although that seems more wasteful maybe?