Search Unity

Bug I can't change the "Normal Color" from a "Button" component.

Discussion in 'UGUI & TextMesh Pro' started by JohnnyConnor, Feb 23, 2022.

  1. JohnnyConnor

    JohnnyConnor

    Joined:
    Aug 10, 2020
    Posts:
    42
    I've been searching for an answer and found a solution that appears to work for everyone but me (didn't find anyone with this problem so far): It consists of creating a ColorBlock and assigning it to the ColorBlock of your button. Then, change the normalColor from that ColorBlock and attribute the variable to your Button's ColorBlock.
    The following script is attached to my button.
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3.  
    4. public class PlayButton : MonoBehaviour
    5. {
    6.  
    7.     private Button _button;
    8.     private Color _digitalGreen;
    9.     private ColorBlock _colorBlock;
    10.  
    11.     private void Start()
    12.     {
    13.         _digitalGreen = new Color(12,224,9);
    14.         _button = GetComponent<Button>();
    15.  
    16.         _colorBlock = _button.colors;
    17.         _colorBlock.normalColor = _digitalGreen;
    18.         _button.colors = _colorBlock;
    19.     }
    20.  
    21. }
    If that's wasn't odd enough, whenever I click to edit the normal color during runtime, the color it was supposed to change into appears as selected, but the actual color is still the default one. Other colors works normally:


    The button's color only updates if I move the color selector.
     
    Last edited: Feb 23, 2022