//For 2D sprites :
public GameObject myObject;
public void makeTransparent()
{
var col = myObjetc.GetComponent<SpriteRenderer>().color;
col.a = 0.5f; //Change the value of transparency here (with 0 = totally transparent and 1 = not transparent at all)
myObjetc.GetComponent<SpriteRenderer>().color = col;
}
//For 3D gameObjects :
I think you have to use shaders there are a lot of youtube videos it is not only with a script
GameObject g;
// 50% Transparency.
g.renderer.material.color.a = 0.5f; // a is the alpha value.
// 100% Transparency.
g.renderer.material.color.a = 1.0f;