- Home /
Help with Playerprefs to saving colors of buttons.
I am trying to save my colors of 12 different buttons with using Playerprefs, but for some reason the script is not working.
When I exit the play mode and restart the play mode in Unity, the buttons revert back to their original colors and not the new selected colors.
This is the code that I am currently using
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SaveLoadColors : MonoBehaviour {
public static void SaveColor (Color color, string key)
{
string col = color.ToString ();
col = col.Replace ("RGBA)", "");
col = col.Replace (")", "");
PlayerPrefs.SetString (key, col);
}
public static Color GetSaveColor (string key)
{
string col = PlayerPrefs.GetString (key);
Debug.Log (col);
if (col == "") {
return Color.white;
}
string[] strings = col.Split (',');
Color output = new Color ();
for (int i = 0; i < 4; i++) {
output [i] = System.Single.Parse (strings [i]);
}
return output;
}
Comment
Your answer
Follow this Question
Related Questions
How to add a gray scale to a buttons color? 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers