Adjust Trees transparency/Opaque/Alpha value

I’ve made the following script that determines if something is blocking the cameras view of the player

if (Physics.Raycast(player.position, targetMove - player.position, out hit, Vector3.Distance(player.position, targetMove)))

    {
        //if the last raycast hit is not the same as the new one (E.g. Monster to rock) set Monster to 100% transparency (can see)
        if (hit.transform.gameObject.tag != "Terrain")
        {
            if (oldGameobject.name != hit.transform.gameObject.name)
            {
                oldGameobject = hit.transform.gameObject;
                color.a = 1;
            }

            //Get render of the Gameobject
            render = hit.transform.gameObject.GetComponentInChildren<Renderer>();
            mat = render.material;
            color = mat.color;

            //If alpha value is greater then subtract
            if (color.a > 0.7f)
            {
                color.a -= 0.1f;
            }
            mat.color = color;
            //targetMoveUse = Vector3.Lerp(hit.point, player.position, rayHitMoveInFront);
        }

Now this works on one of my monster characters using a custom shader, (Textures don’t allow adjusting the opaque/alpha value by default) As you can see Below the monster is slightly Transparent (you can see the players legs)

84083-effect.png

Now here is the tree which isn’t transparent, any help would be greatly appreciated

(I got the Idea from a game called Titan Quest)

I’ve figured it out. All ownership of the code goes to Panthesilea, Unity Tree transparency - Questions & Answers - Unity Discussions

Here is the code that made it work but it requires editing unity’s default trees. i deleted the LODs in the tree and picked one of the trees (child of the tree and made it the parent), I then created a raycast from the camera to the player and determined if something was in front of the camera and if the tag was equal to a tree I then ran the following code.

private void SetTransparent(GameObject g)
     {
         for (int i = 0; i < g.renderer.materials.Length; i++)
         {
             g.renderer.materials*.shader = Shader.Find("Transparent/Diffuse");*

g.renderer.materials*.SetColor("Color", new Color(1, 1, 1, 0.1f));
_
}*

for (int i = 0; i < g.transform.childCount; i++)
SetTransparent(g.transform.GetChild(i).gameObject);
}

I’m having trouble with mobile, the same one described by @Panthesilea. My trees are all turning purple when I try to restore them to opaque after having made them transparent. He mentions using a Resources folder, but I don’t follow – and his post is pretty old. Did you have to solve that problem, @JaredHD?