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?