Facebook
From Yep, 2 Weeks ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 160
  1. void ColorFade()
  2. {
  3.     fadeTimer += Time.deltaTime;
  4.  
  5.     if (fadeTimer > fadeTime)
  6.     {
  7.         currentColors = paintableTexture.GetPixels32();
  8.  
  9.         for (int x = 0; x <= 99; ++x)
  10.         {
  11.             for (int y = 0; y <= 99; ++y)
  12.             {
  13.                 // Need to transform x and y coordinates to flat coordinates of array
  14.                 int array_pos = y * (int)paintableSprite.rect.width + x;
  15.  
  16.                 // Check if this is a valid position
  17.                 if (array_pos >= currentColors.Length || array_pos < 0)
  18.                     return;
  19.  
  20.                 if (currentColors[array_pos].a > 0)
  21.                 {
  22.                     Color colorChange = new Color(currentColors[array_pos].r,
  23.                      currentColors[array_pos].g, currentColors[array_pos].b,
  24.                      currentColors[array_pos].a - fadeAmount);
  25.  
  26.                     currentColors[array_pos] = colorChange;
  27.  
  28.                     Debug.Log(currentColors[array_pos].a);
  29.                 }
  30.                 else
  31.                 {
  32.                     currentColors[array_pos] = new Color(currentColors[array_pos].r,
  33.                      currentColors[array_pos].g, currentColors[array_pos].b, 0);
  34.                 }
  35.             }
  36.         }
  37.  
  38.         paintableTexture.SetPixels32(currentColors);
  39.         paintableTexture.Apply();
  40.  
  41.         fadeTimer = 0;
  42.     }
  43. }