- Home /
[SOLVED] How to make a mesh with mobile/bumped diffuse shader transparent?
Hello devs,
I have been looking out on this for a while, but I have not found a right solution. I have a mesh which at times comes right in the middle of the camera and the player, hence I would like to make it transparent. The mesh has a in-built mobile/Bumped diffuse shader.
Could you guys please help me on this?
Target : iPad devices (except iPad1)
Thank you,
Karsnen.
Answer by Karsnen_2 · Nov 22, 2012 at 08:40 PM
SOLVED :
So the point was, I was able to make it transparent if it has transparent shader. So whatever shader I had, I just switched it and reduced it's alpha. If I want the transparency to be back, then all I have to do is to switch it back to normal (original) shader.
Downside : Though while switching the shader, it is lightly obvious that the shader did change.
CODE :
using UnityEngine;
using System.Collections;
public class FadeOut : MonoBehaviour
{
Color TempColor;
Shader OriginalShader, TempShader;
void Start ()
{
TempColor = Color.white;
OriginalShader = Shader.Find("Mobile/Bumped Diffuse");
TempShader = Shader.Find("Transparent/Diffuse");
}
//Shifts the shader and makes it transparent.
//One time call.
public void TransparencyON()
{
TempColor.a = 0.1f;
this.renderer.material.shader = TempShader;
// The next line is an extension from PRIME31's GoKit. You could just replace it by assigning the color to that particular material.color.
this.transform.renderer.material.colorTo(0.4f,TempColor,MaterialColorType.Color);
}
//Replaces the original shader and makes it to normal again.
//One time call.
public void TransparencyOFF()
{
TempColor.a = 1f;
this.renderer.material.shader = OriginalShader;
this.renderer.material.color = TempColor;
}
}