c# - How can I use Unity toggles and toggle groups to save a selected toggle in a toggle group as player prefs? -
i have scene input fields , toggle groups want save player input in playerprefs reusing in consecutive game sessions. text label of toggle selected in toggle group. here code far. have compiler error says cannot convert guitext string. think have inputfield strings saved fine toggle groups tricky.
using unityengine; using system.collections; using unityengine.ui; public class createholder : monobehaviour { public inputfield input1; public inputfield input2; public inputfield input3; public inputfield input4; public togglegroup discount; public togglegroup params; public togglegroup time; public void grabdata() { playerprefs.setstring("offername", input1.text); if (playerprefs.haskey("offername") == true) { debug.log("something has saved"); debug.log(playerprefs.getstring("input1").tostring()); } playerprefs.setstring("offerdesc", input2.text); playerprefs.setstring("offeramount", input3.text); playerprefs.setstring("offerpercent", input4.text); playerprefs.setstring("tog1", discount.getcomponent<guitext>()); playerprefs.setstring("tog2", params.getcomponent<guitext>()); playerprefs.setstring("tog3", time.getcomponent<guitext>()); } }
try code:
using unityengine; using system.collections; using unityengine.ui; public class createholder : monobehaviour { public inputfield input1; public inputfield input2; public inputfield input3; public inputfield input4; public togglegroup discount; public togglegroup params; public togglegroup time; public void grabdata() { playerprefs.setstring("offername", input1.text); if (playerprefs.haskey("offername") == true) { debug.log("something has saved"); debug.log(playerprefs.getstring("input1")); } playerprefs.setstring("offerdesc", input2.text); playerprefs.setstring("offeramount", input3.text); playerprefs.setstring("offerpercent", input4.text); playerprefs.setstring("tog1", discount.getcomponent<guitext>().text); playerprefs.setstring("tog2", params.getcomponent<guitext>().text); playerprefs.setstring("tog3", time.getcomponent<guitext>().text); } }
Comments
Post a Comment