Hi, all
I wanted to make a code that makes distortion in shader start at 100 and then with each second it lowers by 10 and once the distortion gets to 0 it waits 2 seconds and then again sets it to 100.
Im having problem with getting access to distortion as i cant find any resources of the shader [im using the one from unity ‘‘FX/Glass/Stained BumpDistort’’]
Here is what i have written
var disto : Renderer;
function Start ()
{
disto = GetComponent(Renderer).Distortion;
disto = 100;
}
function Update () {
if(disto > 0)
{
disto : float = Time.time - 10;
}
if (disto <=0)
{
disto = 0;
yield WaitForSeconds(2);
disto = 100
}
}
I know its probably wrong but whats wrong with it :? are there any other ways to get what i want :?
Thanks!
Here’s the documentation on setting a material property through scripts.
As you are probably aware now, the Renderer component doesn’t contain a Distortion variable. You need to access the property value defined in the shader
Shader "FX/Glass/Stained BumpDistort" {
Properties {
_BumpAmt ("Distortion", range (0,128)) = 10
_MainTex ("Tint Color (RGB)", 2D) = "white" {}
_BumpMap ("Bumpmap (RGB)", 2D) = "bump" {}
}
Here you can see the Distortion property definition in the shader you are using. So, using the example from the docs on Material.SetFloat, you would do something like this:
GetComponent<Renderer>().material.SetFloat("_BumpAmt", disto);
Hi there, so this is what i have now
var distor : Renderer;
function Start ()
{
distor = GetComponent(Renderer).material.SetFloat("_BumpAmt", disto);
distor = 100;
}
function Update () {
if(distor > 0)
{
distor : float = Time.time - 10;
}
if (distor <=0)
{
distor = 0;
yield WaitForSeconds(2);
distor = 100;
}
}
and it gives me this error (16,63): BCE0005: Unknown identifier: ‘disto’.
I tried ‘Distortion’ and same thing 
In your original example you used the variable name “disto”, now you use “distor”. I was assuming “disto” was an integer value that you would obtain from the material using the GetFloat function. Then, when you wanted to change the amount of distortion, you would need to call SetFloat using the modified value of “disto”/“distor”/whatever…
1 Like
Ok thanks, it worked but unfortunately the effect is not as i want [ i wanted to make raindrops dropping down the screen but it doesnt look good cuz it blures everything because i made a plane with normal diffuse texture on top with normal map scrolling to the down but as i said if i turn it on the shadows and every effect that i have on camera is covered by effect of this plane which is blured a bit. But thanks for helping!