Hello everyone,
I want to save and load RGB color (not A) of my directionnal light with unity PlayerPrefs.
Example: if I leave the game with directionnal light color egal to 230 / 150 / 50, when I load the 3 int I have this number 1 / 1 / 0.
I think my problem is in the “load code” because I load the int before convert the int32 to byte… But I don’t know how to do that.
- This is my load code:
DirectionalLightColorR = PlayerPrefs.GetInt("DirectionalLightColorR", DirectionalLightColorR);
DirectionalLightColorG = PlayerPrefs.GetInt("DirectionalLightColorG", DirectionalLightColorG);
DirectionalLightColorB = PlayerPrefs.GetInt("DirectionalLightColorB", DirectionalLightColorB);
NightAndDayCycleScript.DirectionalLight.color = new Color32(Convert.ToByte(DirectionalLightColorR), Convert.ToByte(DirectionalLightColorG), Convert.ToByte(DirectionalLightColorB), 255);
- This is my save code:
DirectionalLightColorR = Convert.ToInt32(NightAndDayCycleScript.DirectionalLight.color.r);
DirectionalLightColorG = Convert.ToInt32(NightAndDayCycleScript.DirectionalLight.color.g);
DirectionalLightColorB = Convert.ToInt32(NightAndDayCycleScript.DirectionalLight.color.b);
PlayerPrefs.SetInt ("DirectionalLightColorR", DirectionalLightColorR);
PlayerPrefs.SetInt ("DirectionalLightColorG", DirectionalLightColorG);
PlayerPrefs.SetInt ("DirectionalLightColorB", DirectionalLightColorB);
Thank you in advance for your help.
Best regards,
Alexandre.