• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by EntropicJoey · May 29, 2012 at 04:19 PM · c#playerprefs

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!!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image EntropicJoey · May 29, 2012 at 05:41 PM 0
Share

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..
avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image EntropicJoey · May 29, 2012 at 05:07 PM 0
Share

thank you both kindly

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Saving final score and displaying on main menu 1 Answer

Distribute terrain in zones 3 Answers

How To Add PlayerPrefs Scores? 1 Answer

Multiple Cars not working 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges