I am playing around with the save and load features of FileStream and was hoping there may be a way to do a foreach loop for the save/load with FileStream?
Right now I’m using :
Save:
binaryformatter.Serialize(fs,
GameObject.Find(“WT1_0002_options”).GetComponent().internal_won);
Load:
GameObject.Find (“WT1_0002_options”).GetComponent
().internal_won =
(bool)binaryFormatter.Deserialize(fs);
I was thinking of somehow doing a foreach loop with tags instead of manually entering the Find GameObject each time? Is this possible?
Actually after some more thinking i figured this out myself, just put the entire thing into a forloop worked
Save:
GameObject[] objs ;
objs = GameObject.FindGameObjectsWithTag("selection_tile");
foreach(GameObject tile in objs) {
binaryformatter.Serialize(fs, tile.GetComponent<singleton_attached_script>().internal_won);
}
Load:
GameObject[] objs ;
objs = GameObject.FindGameObjectsWithTag("selection_tile");
foreach(GameObject tile in objs) {
tile.GetComponent<singleton_attached_script> ().internal_won = (bool)binaryFormatter.Deserialize(fs);
}