Camera switches to white, not specified color

So I’m making a game kind of like a mini PC.
In the settings there is an option to change the background color, with 9 colors. But whenever I click any of the colors, it changes to just white, even though in code, all of the rgba colors are correct.

If anybody wants code, here:
BGColour.cs

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

public class BGColour : MonoBehaviour {

    public enum BGColourTypes
    {
        Orange_Default,
        Blue,
        Red,
        Green,
        Purple,
        Yellow,
        Black,
        White,
        Pink
    }

    public BGColourTypes BgColourTypes;
    public Camera desktop;

    public void BGColourChange()
    {
        string colour = PlayerPrefs.GetString("colour", "Orange");
        if (colour == "Orange")
        {
            BgColourTypes = BGColourTypes.Orange_Default;
            PlayerPrefs.SetString("colour", "Orange");
        } else if (colour == "Blue")
        {
            BgColourTypes = BGColourTypes.Blue;
            PlayerPrefs.SetString("colour", "Blue");
        } else if (colour == "Red")
        {
            BgColourTypes = BGColourTypes.Red;
            PlayerPrefs.SetString("colour", "Red");
        } else if (colour == "Green")
        {
            BgColourTypes = BGColourTypes.Green;
            PlayerPrefs.SetString("colour", "Green");
        } else if (colour == "Purple")
        {
            BgColourTypes = BGColourTypes.Purple;
            PlayerPrefs.SetString("colour", "Purple");
        } else if (colour == "Yellow")
        {
            BgColourTypes = BGColourTypes.Yellow;
            PlayerPrefs.SetString("colour", "Yellow");
        } else if (colour == "BLack")
        {
            BgColourTypes = BGColourTypes.Black;
            PlayerPrefs.SetString("colour", "Black");
        } else if (colour == "White")
        {
            BgColourTypes = BGColourTypes.White;
            PlayerPrefs.SetString("colour", "White");
        } else if (colour == "Pink")
        {
            BgColourTypes = BGColourTypes.Pink;
            PlayerPrefs.SetString("colour", "Pink");
        }
    }

    void Update()
    {
        if (BgColourTypes == BGColourTypes.Orange_Default)
        {
            desktop.backgroundColor = new Color(255, 179, 55, 255);
        }
        else if (BgColourTypes == BGColourTypes.Blue)
        {
            desktop.backgroundColor = new Color(55, 131, 255, 255);
        }
        else if (BgColourTypes == BGColourTypes.Red)
        {
            desktop.backgroundColor = new Color(255, 55, 55, 255);
        }
        else if (BgColourTypes == BGColourTypes.Green)
        {
            desktop.backgroundColor = new Color(0, 216, 10, 255);
        }
        else if (BgColourTypes == BGColourTypes.Purple)
        {
            desktop.backgroundColor = new Color(186, 55, 255, 255);
        }
        else if (BgColourTypes == BGColourTypes.Yellow)
        {
            desktop.backgroundColor = new Color(255, 241, 55, 255);
        }
        else if (BgColourTypes == BGColourTypes.Black)
        {
            desktop.backgroundColor = new Color(0, 0, 0, 255);
        }
        else if (BgColourTypes == BGColourTypes.White)
        {
            desktop.backgroundColor = new Color(255, 255, 255, 255);
        }
        else if (BgColourTypes == BGColourTypes.Pink)
        {
            desktop.backgroundColor = new Color(255, 120, 251, 255);
        }
    }
}

Thanks :slight_smile:

The issue you’re facing where the background color changes to white regardless of the selected color likely occurs because the values you’re passing to the Color constructor are outside the 0-1 range for RGB(A) color components. The Color constructor expects values between 0 and 1 for red, green, blue, and alpha components.

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

public class BGColour : MonoBehaviour
{
    public enum BGColourTypes
    {
        Orange_Default,
        Blue,
        Red,
        Green,
        Purple,
        Yellow,
        Black,
        White,
        Pink
    }

    public BGColourTypes BgColourTypes;
    public Camera desktop;

    public void BGColourChange()
    {
        string colour = PlayerPrefs.GetString("colour", "Orange");
        if (colour == "Orange")
        {
            BgColourTypes = BGColourTypes.Orange_Default;
            PlayerPrefs.SetString("colour", "Orange");
        }
        else if (colour == "Blue")
        {
            BgColourTypes = BGColourTypes.Blue;
            PlayerPrefs.SetString("colour", "Blue");
        }
        else if (colour == "Red")
        {
            BgColourTypes = BGColourTypes.Red;
            PlayerPrefs.SetString("colour", "Red");
        }
        else if (colour == "Green")
        {
            BgColourTypes = BGColourTypes.Green;
            PlayerPrefs.SetString("colour", "Green");
        }
        else if (colour == "Purple")
        {
            BgColourTypes = BGColourTypes.Purple;
            PlayerPrefs.SetString("colour", "Purple");
        }
        else if (colour == "Yellow")
        {
            BgColourTypes = BGColourTypes.Yellow;
            PlayerPrefs.SetString("colour", "Yellow");
        }
        else if (colour == "Black")
        {
            BgColourTypes = BGColourTypes.Black;
            PlayerPrefs.SetString("colour", "Black");
        }
        else if (colour == "White")
        {
            BgColourTypes = BGColourTypes.White;
            PlayerPrefs.SetString("colour", "White");
        }
        else if (colour == "Pink")
        {
            BgColourTypes = BGColourTypes.Pink;
            PlayerPrefs.SetString("colour", "Pink");
        }
    }

    void Update()
    {
        Color backgroundColor;

        switch (BgColourTypes)
        {
            case BGColourTypes.Orange_Default:
                backgroundColor = new Color(255f / 255f, 179f / 255f, 55f / 255f, 1f);
                break;
            case BGColourTypes.Blue:
                backgroundColor = new Color(55f / 255f, 131f / 255f, 255f / 255f, 1f);
                break;
            case BGColourTypes.Red:
                backgroundColor = new Color(255f / 255f, 55f / 255f, 55f / 255f, 1f);
                break;
            case BGColourTypes.Green:
                backgroundColor = new Color(0f / 255f, 216f / 255f, 10f / 255f, 1f);
                break;
            case BGColourTypes.Purple:
                backgroundColor = new Color(186f / 255f, 55f / 255f, 255f / 255f, 1f);
                break;
            case BGColourTypes.Yellow:
                backgroundColor = new Color(255f / 255f, 241f / 255f, 55f / 255f, 1f);
                break;
            case BGColourTypes.Black:
                backgroundColor = new Color(0f, 0f, 0f, 1f);
                break;
            case BGColourTypes.White:
                backgroundColor = new Color(1f, 1f, 1f, 1f);
                break;
            case BGColourTypes.Pink:
                backgroundColor = new Color(255f / 255f, 120f / 255f, 251f / 255f, 1f);
                break;
            default:
                backgroundColor = Color.white; // Default to white if none of the cases match.
                break;
        }

        desktop.backgroundColor = backgroundColor;
    }
}

@Marko2155 I think code you shared should be written like this:

public class BGColour : MonoBehaviour
{
	[SerializeField] EColor _backgroundColor;
	[SerializeField] Camera _camera;

	public void ReadColor ()
	{
		_backgroundColor = (EColor) PlayerPrefs.GetInt( "colour" , 0 );
		if( colorDefinitions.ContainsKey( _backgroundColor ) )
			_camera.backgroundColor = colorDefinitions[ _backgroundColor ];
		else Debug.LogError($"{nameof(colorDefinitions)} contains no definition for {_backgroundColor} yet. Add it asap!");
	}

	public void WriteColor ()
	{
		PlayerPrefs.SetInt( "colour" , (int)_backgroundColor );
	}

	public enum EColor { Orange, Blue, Red, Green, Purple, Yellow, Black, White, Pink }

	Dictionary<EColor,Color> colorDefinitions = new (){
		{ EColor.Orange , new Color32(255, 179, 55, 255) } ,
		{ EColor.Blue , new Color32(55, 131, 255, 255) } ,
		{ EColor.Red , new Color32(255, 55, 55, 255) } ,
		{ EColor.Green , new Color32(0, 216, 10, 255) } ,
		{ EColor.Purple , new Color32(186, 55, 255, 255) } ,
		{ EColor.Yellow , new Color32(255, 241, 55, 255) } ,
		{ EColor.Black , new Color32(0, 0, 0, 255) } ,
		{ EColor.White , new Color32(255, 255, 255, 255) } ,
		{ EColor.Pink , new Color32(255, 120, 251, 255) } ,
	};
}