Why is the button blinking in white

I am trying to get a button to blink in red and green (background color) but it blinks in red and white? The button image color is set to white in editor. I have changed colors in the editor but I do not get the blinking in the colors I need.

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

public class BlinkLock : MonoBehaviour
{
    private Button btn_Lock;
    private Color green = new Color(3, 65, 2, 255);

    void Start()
    {
        btn_Lock = gameObject.GetComponentInChildren<Button>();

        StartCoroutine(BlinkButton());
    }

    public IEnumerator BlinkButton()
    {
        while (true)
        {
            btn_Lock.image.color = Color.red;
            yield return new WaitForSeconds(.5f);

            btn_Lock.image.color = green;
            yield return new WaitForSeconds(.5f);
        }
    }
}

Color uses RGBA values in the range of 0 - 1, so new Color(3, 65, 2, 255); is being clamped to (1,1,1,1) which is white.

Hi,

Change it to:

private Color green = new Color(0.3f, 0.65f, 0.2f, 1);

J

1 Like

ahhh off course I knew that, I am an idiot, tx

If you want to use your byte values instead of floats, using Color32 is an option.

private Color green = new Color32(3, 65, 2, 255);