Search Unity

Bug Color changing its value on its own in the Inspector and odd behavior in the Inspector

Discussion in 'Scripting' started by Only4gamers, Apr 20, 2022.

  1. Only4gamers

    Only4gamers

    Joined:
    Nov 8, 2019
    Posts:
    327
    Hello everyone,
    I am setting color of an UI element from the script:

    Code (CSharp):
    1. private Image arrowImage;
    2.     private Color red = new Color(255, 0, 0);
    3.     private Color yellow = new Color(255, 189, 0);
    4.     private Color green = new Color(0, 255, 141);
    5.  
    6. void Start()
    7.     {
    8.         arrow = transform.GetChild(0).gameObject;
    9.         arrowImage = arrow.GetComponent<Image>();
    10.  
    11.         if(parentTransform.tag != "Player")
    12.         {
    13.             if(EnemyAllyList.playerEnemies.Contains(parentTransform.tag))
    14.             {
    15.                 arrowImage.color = red;
    16.             }
    17.             else if(EnemyAllyList.playerAllies.Contains(parentTransform.tag))
    18.             {
    19.                 arrowImage.color = green;
    20.                 Debug.Log(green);
    21.             }
    22.             else if(EnemyAllyList.playerNeutrals.Contains(parentTransform.tag))
    23.             {
    24.                 arrowImage.color = yellow;
    25.             }
    26.         }
    27.     }
    So what happening is:
    Colors showing different values in the inspector and in the scene then the value set in the script. Like green color value is (0, 255, 141) becoming (0, 191, 109) in the inspector on runtime. But in the debug.log it's showing that color value didn't changed at all.

    Outside playmode (0, 191, 109) is looking greenish so I don't have much problem but inside the playmode the same value looking blue.

    What is happening? is this a bug?

    My unity editor version 2020.3.6f1
     
  2. SourGummi

    SourGummi

    Joined:
    Nov 14, 2021
    Posts:
    96
    Only4gamers likes this.