Search Unity

Bug Animator prevents color.alpha level

Discussion in 'UGUI & TextMesh Pro' started by halbenhb1, Feb 10, 2021.

  1. halbenhb1

    halbenhb1

    Joined:
    Sep 10, 2020
    Posts:
    5
    I have an UI Image named YouDiedImage which is the child of a panel named YouDiedPanel. When YouDiedPanel activated, animator inside it works and animate YouDiedImage's scale and color(transparency). After animation end, I want to change the transparancy of image whenever the pointer enter the image panel. So, i add an Event System and code a basic transition. However, if animatior component of Panel is enabled (loop is not active and I set a transition to an empty State), my code is not working for alpha. R,G,B components are perfectly changing but alpha level stays same.

    This is my code:
    Code (CSharp):
    1.     public bool TransperencyOn, OpaqueOn;
    2.     [SerializeField]
    3.     private Color FirstColor;
    4.     [SerializeField]
    5.     private Color SecondColor;
    6.     [SerializeField] float lerpTime;  
    7.  
    8.  
    9.     // Start is called before the first frame update
    10.     void Start()
    11.     {
    12.         TransperencyOn= false;
    13.         OpaqueOn= false;
    14.  
    15.     }
    16.  
    17.     // Update is called once per frame
    18.     void Update()
    19.     {
    20.         if (lerpTime < 1)
    21.         {
    22.             lerpTime += Mathf.Lerp(0, 1, 0.01f);
    23.         }
    24.  
    25.         if (TransperencyOn)
    26.         {
    27.             gameObject.GetComponent<UnityEngine.UI.Image>().color = new Color(FirstColor.r, FirstColor.g, FirstColor.b, 1-lerpTime);
    28.         }
    29.         if (OpaqueOn)
    30.         {
    31.             gameObject.GetComponent<UnityEngine.UI.Image>().color = new Color(SecondColor.r, SecondColor.g, SecondColor.b, lerpTime);
    32.         }
    33.     }
    34.  
    35.     public void Transperency()
    36.     {
    37.         lerpTime = 0;
    38.         TransperencyOn= false;
    39.         OpaqueOn= true;
    40.     }
    41.     public void Opaque()
    42.     {
    43.         lerpTime = 0;
    44.         TransperencyOn= false;
    45.         OpaqueOn= true;
    46.     }