Image Color doesnt change !!!!

Hey , i wanna change the image.color but i have a problem.


when i hit the play,

the color stay yellow, doesnt go back red ??? G increases but color doesnt change ??? by the way, sorry about my english :),

This is my code;

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

public class ChangingColorRGB : MonoBehaviour {

    float G = 75;

    Image imgcolor;

    // Use this for initialization
    void Start () {
        imgcolor = this.GetComponent<Image>();

    }
  
    // Update is called once per frame
    void FixedUpdate () {
        Changing();
    }

    void Changing()
    {
        if(G < 255)
        {
            if(G == 254)
            {
                G = 75;
            }
            G += 1;
          
            imgcolor.color = new Color (255, G, 0, 255);
            print(G);
          
        }

      
    }
}

I’ve hit this “issue” myself, too :slight_smile:
There are ‘2’ kinds of Color variables in Unity. Color and Color32. Color is in the range 0…1 and is a float. the syntax you’re using is for Color32. So, you can choose to alter it how you’d like so it works :wink:

1 Like

Just as an aside, the benefit of Color in the range (0…1) is that it can represent a position on a gradient. I use this to flicker softly between yellows and oranges for flames. Color32 uses (0-255) values for RGBA.

And to add, you can simply divide your value by 255 to get the float you want.

So if G = 75, just do G/255.

1 Like