- Home /
Foreach loop inside FileStream
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?
Answer by Khudere · Aug 22, 2017 at 10:37 PM
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);
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Logic question, unique path finding system 2 Answers
Checking an array variable in C# vs JavaScript 3 Answers
Foreach loop doesn't run 2 Answers