[solved]Setting background color doent work

i have a scene where you can put rgb codes in to set a back ground color and it saves it
the script for that is:

using UnityEngine;
using UnityEngine.UI;

public class setColor : MonoBehaviour
{
    public InputField r;
    public InputField g;
    public InputField b;

    void Start()
    {

    }

    void Update()
    {
        if (float.Parse(r.text) >= 245)
        {
            r.text = "244";
        }
        if (float.Parse(g.text) >= 245)
        {
            g.text = "244";
        }
        if (float.Parse(b.text) >= 245)
        {
            b.text = "244";
        }
        if (string.IsNullOrEmpty(r.text) || string.IsNullOrEmpty(g.text) || string.IsNullOrEmpty(b.text))
        {
            PlayerPrefs.SetFloat("r", float.Parse(70.ToString()));
            PlayerPrefs.SetFloat("g", float.Parse(134.ToString()));
            PlayerPrefs.SetFloat("b", float.Parse(159.ToString()));
        }
        else
        {
            PlayerPrefs.SetFloat("r", float.Parse(r.text));
            PlayerPrefs.SetFloat("g", float.Parse(g.text));
            PlayerPrefs.SetFloat("b", float.Parse(b.text));
           
        }
    }
}

and the script to get that rgb code is:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class getColor : MonoBehaviour
{

    void Update()
    {
        float r = PlayerPrefs.GetFloat("r");
        float g = PlayerPrefs.GetFloat("g");
        float b = PlayerPrefs.GetFloat("b");
        Debug.Log(r + ", " + g + ", " + b);
        Color color = new Vector4(r, g, b, 244);
        Debug.Log(color);
        Camera.main.backgroundColor = color;
    }
}

but when the backround color changes it is always white but it saves ir right because the debug.log shows the saved values.

anyone know?

How does this even compile?

Color color = new Vector4(r, g, b, 244);

i dont know, it doent trow an error

Interesting…I’m surprised at that, but I guess it makes sense, a color is similar to a vector4…

Color color = new Color(r, g, b, a);
However, I’m use to just doing color like this. Keep in mind, this takes a value from 0 - 1, which may be why your code isn’t working.

To get your values, take value/255 in color picker. So if red is 150, then your r value should be 150/255 or .588

1 Like

thank you it worked with value/255