Search Unity

Changing properties during runtime

Discussion in 'Shaders' started by CoffeeConundrum, Mar 5, 2014.

  1. CoffeeConundrum

    CoffeeConundrum

    Joined:
    Dec 30, 2013
    Posts:
    46
    I'm new to shaders and found this code online to help with blending between two textures
    Code (csharp):
    1. Shader "Fading" {
    2. Properties {
    3.     _Blend ("Blend", Range (0, 1) ) = 0.0
    4.     _BaseTexture ("Base Texture", 2D) = "" {}
    5.     _OverlayTexture ("Texture 2 with alpha", 2D) = "" {}
    6.  
    7. }
    8. SubShader {
    9.        Pass {
    10.          SetTexture[_BaseTexture]
    11.          SetTexture[_OverlayTexture] {
    12.           ConstantColor (0,0,0, [_Blend])
    13.           combine texture Lerp(constant) previous
    14.          }
    15.        }
    16.     }
    17. }
    Which works fine with the use of the slider in the editor however, I'm wondering if I can change the Blend property during runtime so that it fades slowly over time. I've had a look into the SetFloat function in my script however nothing has appeared on screen.

    Many thanks!
     
  2. Duney

    Duney

    Joined:
    Aug 19, 2013
    Posts:
    170
    You'll need to look at renderer.SharedMaterial.SetFloat( "_Blend", value ); with the script attached to the object you want to have fade in/out.