Reputation: 75
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