- Home /
bza, Saving color to player prefs
here is the colorpicker code i am using,
if (GUI.RepeatButton(new Rect(xxx, yyy, xxx, yyy), colorPicker, GUI.skin.GetStyle("ColorPickerStyle"))) {
Vector2 pickpos = Event.current.mousePosition;
Vector2 coords = new Vector2((pickpos.x - xxx) / xxx, -(pickpos.y - yyy) / yyy);
Color color = colorPicker.GetPixelBilinear(coords.x, coords.y);
_headMaterial.SetColor ("_Color",col);
}
and use GameSettings2.SaveColor( col );
and this is what i am trying to do to save
and load from gamesettings script,
public static String SaveColor( string col ) {
PlayerPrefs.SetString( "col", Color );
}
public static String LoadColor() {
return PlayerPrefs.GetString( "col", Color );
}
and my error, currently anyways, is
Assets/_Scripts/_Items/GameSettings2.cs(87,37): error CS0161: `GameSettings2.SaveColor(string)': not all code paths return a value so what am i doing wrong? cause i am failing to truly understand what i am really doing lool i cant seem to get it to work, though choosing the color etc, works fine, i might not have fully translated java to c#? any help or straight forward fix would be grand, thank you!!
Answer by Statement · May 29, 2012 at 04:48 PM
// "not all code paths return a value"
// ||
// vvvvvv
public static String SaveColor( string col ) {
// ^^^^^^
PlayerPrefs.SetString( "col", Color );
}
Your code expets SaveColor to return a string, but you aren't returning anything there. Either remove String from the signature or return a string.
how do i return a string, it seems the color picker is a string, unless i am wrong ive tried floats and ints and they give me the same error, and right now i have error like this Assets/_Scripts/_Items/GameSettings2.cs(88,50): error CS0119: Expression denotes a type', where a variable', value' or method group' was expected
and this is what i tried
public static void SaveColor( string col ) {
PlayerPrefs.SetString( "_Color", Color );
}
public static string LoadColor() {
return PlayerPrefs.GetString( "_Color", 1 );
}
playerprefsX is something i never heard of therefore i believe its not something i should try to wrap my head around just yet..
Answer by Eric5h5 · May 29, 2012 at 04:49 PM
You can't save a Color as a string; they are different types. Use ArrayPrefs2, then you can just do PlayerPrefsX.SetColor/GetColor and save yourself a lot of bother.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Saving final score and displaying on main menu 1 Answer
How To Add PlayerPrefs Scores? 1 Answer
Multiple Cars not working 1 Answer
A node in a childnode? 1 Answer