C# Save color prefab

Hi!
I have problem with save prefab.

This is the code to change the color but do not know how to save it to a prefab , I tried to string convert but without consequences ;/.

 using UnityEngine;
 using System.Collections;
 public class ChangeColor : MonoBehaviour {
  public Color myColor;
  public Material BallMaterial;
  void OnGUI ()
  {
  myColor = RGBSlider (new Rect (10, 425, 200, 20), myColor);
  }
  Color RGBSlider(Rect screenRect, Color rgb)
  {
  rgb.r = SliderTest.LabelSlider (screenRect, rgb.r, 1.0f, "Red");
  screenRect.y += 20;
  rgb.g = SliderTest.LabelSlider (screenRect, rgb.g, 1.0f, "Green");
  screenRect.y += 20;
  rgb.b = SliderTest.LabelSlider (screenRect, rgb.b, 1.0f, "Blue");
  return rgb;
   
  }
  void Update() {
  BallMaterial.color = myColor;
  }
 }

Hi,

What do you mean save it to a prefab?
Are you trying to save the color at runtime, prefabs are a editor thing, you don’t create them at runtime.
If you are looking for a way to save the color at runtime then strings are fine but you need to make sure they are in a format you understand and put them somewhere you can get to later.

For example you could use player prefs to save the color although you could also use xml, text files, binary files etc.

This example uses PlayerPrefs, its probably not going to solve your problem but it will give you some ideas on converting between(hopefully!).

    void SaveColor(Color col)
    {
        // Save floats
        PlayerPrefs.SetFloat("red", col.r);
        PlayerPrefs.SetFloat("green", col.g);
        PlayerPrefs.SetFloat("blue", col.b);
        PlayerPrefs.SetFloat("alpha", col.a);

        // Save as a string
        PlayerPrefs.SetString("myColor", col.r + " " + col.g + " " + col.g + " " + col.b + " " + col.a );
    }

    Color LoadColor()
    {
        // As float
        float r = PlayerPrefs.GetFloat("red");
        float b = PlayerPrefs.GetFloat("green");
        float g = PlayerPrefs.GetFloat("blue");
        float a = PlayerPrefs.GetFloat("alpha");
        var col = new Color(r, g, b, a);
        return col;

        // As string
        string colString = PlayerPrefs.GetString("myColor");
        var split = colString.Split(' ');
        float r = float.parse(split[0]);
        float g = float.parse(split[1]);
        float b = float.parse(split[2]);
        float a = float.parse(split[3]);
        var col = new Color(r, g, b, a);
        return col;
    }