Hello, i am making a kind of a tower defence game and i would like know how can i save my turret tags e.g Laser Turret and then the turret position, and then load the turret on the exact same position which it was.
I recommend using XML as it is builtin feature in .net.
First you need to create descriptor classes:
public class worldContainerDescriptor{
public List<TowerDescriptor> towers=new List<TowerDescriptor>();
}
public class TowerDescriptor{
public float px,py,pz;
public float rx,ry,rz,rw;
public float int upgradeStep;
}
Then you need to instantiate worldContainerDescriptor and populate its list with TowerDescriptor instances mimicing your towers. After that you can serialize this thingie:
string persistancePath = "pathtofile"+".xml";
StreamWriter streamer = new StreamWriter (persistancePath);
XmlSerializer serializer = new XmlSerializer (typeof(worldContainerDescriptor), "SaveRoot");
serializer.Serialize(streamer,myContainerClassInstance);
streamer.Flush ();
streamer.Close ();
For additional tricks check XmlSerializer .net manual: XmlSerializer Class (System.Xml.Serialization) | Microsoft Learn
Actually instead of XML serializing/complex Serialization
(as it is very hard especially if you cant understand scripting well) you can use System.IO class and Write all Text comman to do this in a single lined statement you can find more details of this command at various sites…
I solved this by using unity serializer