c# - Deserialization Error: InvalidCastException: Cannot cast from source type to destination type -
i have problem , i'm not sure how solve it... tried plenty of things , can't find similar online help.
note: scene uses script saving , using same .dat file, not sure if that's issue though.
public gameobject[] top10 = new gameobject[10]; [system.serializable] public class scoreentry { public string name; public int score; } // use initialization void start () { if (file.exists(application.persistentdatapath + "/hiscores.dat")) { binaryformatter b = new binaryformatter(); var f = file.open(application.persistentdatapath + "/hiscores.dat", filemode.open); list<scoreentry> hiscores = (list<scoreentry>)b.deserialize(f); f.close(); (int = 0; == hiscores.count; i++) top10[i].getcomponent<textmesh>().text += hiscores[i].name + " - " + hiscores[i].score; } } // update called once per frame void update () { }
it looks scoreentry
class using fields, not properties. believe serializer/deserializer requires properties. try this:
[system.serializable] public class scoreentry { public string name {get;set;} public int score {get;set;} }
Comments
Post a Comment