how to make a gameobject transparent unity code example

Example: unity transparent object

//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