Could anybody help me with a camera script that fades out object when they are close to the camera. If the object is close/in front of the camera the opacity is set to 50% ....... Any hints/help ???????
ok, Nice it worked out after a bit of truble .... I realized that I had to use the transparent shader (But I want to use the Toon shader) How could I make a Toon shaded object transparent ? I used this script Code (csharp): if (Camera.main.WorldToViewportPoint(transform.position).z < 5) renderer.material.color.a = 0.5;
Instead of Code (csharp): if (Camera.main.WorldToViewportPoint(transform.position).z < 5) use Code (csharp): (Camera.main.transform.position - transform.position).magnitude It tells you how far away something is. Toon shaders are just like diffuse shaders, and also can use renderer.material.color.a.
ok, thanks. But the Code (csharp): renderer.material.color.a didn't work with toon shaders ( I have to use the transparent shaders )
That script seems like just what I need, but I get an error on line 125 stating that there is already a local variable with the name ‘newMaterial’.
Why not do this in a shader? Arguably a lot more optimized and the standard way of doing this. Seeing the camera is already being parsed to the shader, and ofcourse the vertex positions, it's should be no issue to calculate the distance and go from there.