Hard question about saving and loading

Hello, Hope you are doing good.
I have a system for creating a fortress in my game, I have 8 Gameobjects, and inside those 8 GameObjects, I have like 23 more GameObjects inside each one, each one of these objects has a script that contains a variable called “Cubo” (Cube in Spanish).
I want to know a way of saving the value of “Cubo” in each one, and then, load them properly, but I cant figure out how, does anybody know how to do this?

Here is an image so you can see more crearly what is happening:

10257-jpeg.jpg

So, Here you can see the GameObjects “Fila1”, “Fila2”, etc go fro Up to Down, not from left to right.

So, anybody knows how yo do this?

For saving/loading you should look into Player Preferences, specifically, PlayerPrefs.SetString/GetString.

Sorry, the hyperlink button isn’t working on my browser.

I tested it and if I understand correctly this C# code should work:

using UnityEngine;
using System.Collections;

public class SaveLoad : MonoBehaviour {
	
	public string[] loadedData;
	public int convertBack;
	
	// Update is called once per frame
	void Update () 
	{
	
		// Easy way to test it press "S" in game to save and "L" to load
		
		if(Input.GetKeyDown("s"))
			SaveCubos();
		
		if(Input.GetKeyDown("l"))
			LoadCubos();
		
	}
	
	public void SaveCubos()
	{
		GameObject[] cubos = GameObject.FindGameObjectsWithTag("Cubos"); // If you create a new tag "Cubos" and tag all of the cubos with it
		string saveData = "";
		
		foreach(GameObject specificCubo in cubos)
		{
			EspacioCreacion cuboScript = specificCubo.GetComponent<EspacioCreacion>();
			
			saveData = saveData + cuboScript.cubo.ToString() + ","; // The additional comma is for splitting the string later
		}
		Debug.Log(saveData); // To display what information we actually saved
		PlayerPrefs.SetString("SaveData", saveData); // Actually save the information to PlayerPrefs
	}
	
	public void LoadCubos()
	{	
		string loadData = PlayerPrefs.GetString("SaveData"); // Retrieve the information we saved
		
		loadedData = loadData.Split(','); // Divides the information up based on the commas "," into a string array
		
		// To convert the information back into integers or floats you could use:
		convertBack = int.Parse(loadedData[0]);
	}
}

I guess it matters whether you want to assign the data back to a specific cube. If so you will probably need to save more information that associates the “cubos” with each specific cube. You will also need to tag each object with the “Cubos” tag.

I hope that answers your question.

Thanks, God bless!

Howey