Search Unity

How do I use shader graph for a fading white effect?

Discussion in '2D' started by samdaman93, May 31, 2020.

  1. samdaman93

    samdaman93

    Joined:
    Oct 3, 2015
    Posts:
    37
    Hello,

    I'm struggling to get a white flash effect from the shader material I setup. This is my first time using shaders so I'm not too sure why this isn't working, in fact I'm new to all of this so the problem is probably really obvious.

    I have a coroutine which is called when the player takes damage, for a certain period, the player will be invulnerable. I want there to be a fading white flash over this period. I've linked the shader graph below for review. I've also linked the code. Can anyone see the problem?

    Cheers,

    Shader Graph
    https://imgur.com/a/tmeE6Ov

    Code (CSharp):
    1.  public IEnumerator iFrame()
    2.     {
    3.         float iFrameTimer = 0f;
    4.         canTakeDamage = false;
    5.  
    6.  
    7.  
    8.         while (iFrameTimer<iFrameDuration)
    9.         {
    10.          
    11.             alpha = ((iFrameDuration-iFrameTimer)/iFrameDuration);
    12.             iFrameShader.SetColor("_Tint", new Color(255, 255, 255, alpha));
    13.             iFrameTimer += Time.deltaTime;
    14.             yield return null;
    15.         }
    16.  
    17.         iFrameShader.SetColor("_Tint", new Color(255, 255, 255, 0));
    18.  
    19.         if (!isDead)
    20.         {
    21.             canTakeDamage = true;
    22.         }
    23.         else
    24.         {
    25.             canTakeDamage = false;
    26.         }
    27.  
    28.         yield return null;
    29.     }