Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Fade out not working

Discussion in 'Scripting' started by Shayke, Sep 10, 2019.

  1. Shayke

    Shayke

    Joined:
    Dec 8, 2017
    Posts:
    352
    Hi guys, i have a list of the Player's body parts and i want the alpha to go from 255 to 0.
    So at first i set all the parts to 255 and then i made a while loop to decrease the alpha step by step.
    Somehow it doesn't work, any ideas why? Thanks
    Code (CSharp):
    1.     public IEnumerator PlayerDisAppear(float Timer, float Speed)
    2.     {    
    3.         //initialize
    4.         for (int j = 0; j < BodyReferences.Count; j++)
    5.         {
    6.             Color tmp = BodyReferences[j].color;
    7.             tmp.a = 255f;
    8.             BodyReferences[j].color = tmp;
    9.         }
    10.      
    11.         while (Timer > 0)
    12.         {
    13.             for (int i = 0; i < BodyReferences.Count; i++)
    14.             {
    15.                 Color tmp = BodyReferences[i].color;
    16.                 tmp.a -= Speed;
    17.                 print(tmp.a);
    18.                 BodyReferences[i].color = tmp;              
    19.             }
    20.             yield return null;
    21.             Timer -= Time.deltaTime;
    22.         }
    23.     }
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,741
    The RGBA values in Color go from 0 to 1, not 0 to 255.
     
    Joe-Censored likes this.
  3. Shayke

    Shayke

    Joined:
    Dec 8, 2017
    Posts:
    352
    Haha oops!
    Thanks :D