Default color issue

I currently have a struct named Colors. Here’s its code:-

using UnityEngine;

struct Colors
{
    public Color defBtnDisabledColor
    {
        get
        {
            return Color32(32, 32, 32, 128);
        }
    }
}

So, what happens is when I set any color to Colors.defBtnDisabledColor, it always set it to #1A1A1A with 26, 26, 26, 128 RGBA values. I expect it to have #202020 with 128 alpha as it is the color hex.

if anyone knows why is it happening, what could be causing this, please let me know.
Thanks in advance.

EDIT: This issue is only occurring when the color is having alpha less than 255. I have other colors too and I am setting their values just like this only except they have 255 alpha. They are working just fine.

Maybe you have a different property that you are reading by mistake.

I created a unit test to verify that your code works.

using NUnit.Framework;
using UnityEngine;

namespace Tests
{
    struct Colors
    {
        public static Color defBtnDisabledColor
        {
            get
            {
                return new Color32(32, 32, 32, 128);
            }
        }
    }

    public class ColorTests
    {
        [Test]
        public void defBtnDisabledColorShouldBe_20202080()
        {
            Color color = Colors.defBtnDisabledColor;
            string actual = ColorUtility.ToHtmlStringRGBA(color);

            // Passes test
            Assert.AreEqual("20202080", actual);
        }
    }
}

Hi @HitarthPadaliya , I hope this code will help you, also your cod should work as I understand it but anyway there two other way to do it: one is Using Hex name and another one is by using color struct instead of color32 which seems alright. I did test this and it worked smoothly, let me know if you had any problem. good luck, cheers. :slight_smile:

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



public static class _Color
{
    #region ColorGeneral
    public static Color Red
    {
        get
        {
            Color redColor = new Color(0.8f, 0.03f, 0f, 1f);
            return redColor;
        }
    }
public static Color BeginnerButtonColor
    {
        get
        {
            Color BpurpleColor;
            if (ColorUtility.TryParseHtmlString("#FF8ACB", out BpurpleColor))
            {
                //return BpurpleColor;
            }
            return BpurpleColor;
        }
    }
   
    #endregion

    #region Favorite Colors

// using HEXName is much easier.
    public static Color SetNewColor(string colorHEXName)
    {
        Color SuperDarkColor;
        if (ColorUtility.TryParseHtmlString(colorHEXName, out SuperDarkColor))
        {
        }
        return SuperDarkColor;
    }
    #endregion









}//EndClasssss