bonishadelnorte
bonishadelnorte

Reputation: 75

Getting Invalid normalized color error when changing image color in Unity

I want to change the background color of my canvas from the script. The following script is attached to the canvas:

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

public class CanvasController : MonoBehaviour {

    Color lightBlue = new Color(173, 222, 246);
    Color purple = new Color(107, 62, 143, 255);

    void Start () {
        Image img = transform.GetComponent<Image>();
        img.color = lightBlue;
    }

    void Update () {

    }
}

However, when I press play the color turns white and I get two errors:

Invalid normalized color: RGBA(107.000, 62.000, 143.000, 1.000), normalize value: 0
UnityEditor.DockArea:OnGUI()

Setting normalized color with a non-normalized color: RGBA(107.000,62.000,143.000,1.000)
UnityEditor.DockArea:OnGUI()

Upvotes: 0

Views: 1246

Answers (1)

I.B
I.B

Reputation: 2923

When you use Color you have to pass a value between 0 and 1.

You can use Color32 to pass values between 0 and 255.

Links to documentation for Color and Color32

Upvotes: 1

Related Questions