Hide objects blocking character view

Similar to diablo where an object will fade out when blocking the view of the character. I know how to use raycasts and change models alpha channel so it fades out but am not sure how to direct a raycast at the player and fade out an object with using as less code as possible.

Raycast from the camera to de player hips, them if something collides fade it to the alpha value you want.

Edit1:
What the following code does: Cast a ray to the player, if it collides with something store the GameObject and fades it down, them if the ray collide with something else and has collided with something previously fades up the last collided object and fades down the current.
(The script uses iTween to fade the objects)

I know it’s a little confuse, any question please comment.

Pastebin http://pastebin.com/dZcZB9fp

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
 
public class CameraOpacity : MonoBehaviour {
       
        public GameObject player;
        public Shader shaderDifuse;
    public Shader shaderTransparent;
        public float targetAlpha;
        public float time;
        public GameObject o;
        public bool mustFadeBack = false;
       
        // Use this for initialization
        void Start ()
        {      
                player = GameObject.FindGameObjectWithTag("Player");
                shaderDifuse      = Shader.Find("Diffuse");
            shaderTransparent = Shader.Find("Transparent/Diffuse");
        }
       
        // Update is called once per frame
        void Update ()
        {
                RaycastHit hit;
                if(Physics.Raycast(transform.position, player.transform.position - transform.position, out hit, 30))
                {
                        if(hit.collider.gameObject.layer == LayerMask.NameToLayer("CanHide"))
                        {      
                                mustFadeBack = true;
                               
                                if(hit.collider.gameObject != o && o != null)
                                {
                                        FadeUp(o);
                                }
 
                                o = hit.collider.gameObject;
 
                                if(o.renderer.material.shader != shaderTransparent)
                                {
                                        o.renderer.material.shader = shaderTransparent;
                                        Color k = o.renderer.material.color;
                                        k.a = 0.5f;
                                        o.renderer.material.color = k;
                                }
                               
                                FadeDown(o);
                        }
                        else
                        {
                                if(mustFadeBack)
                                {
                                        mustFadeBack = false;
                                        FadeUp(o);
                                }
                        }
                }
        }
       
        void FadeUp(GameObject f)
        {
                //iTween.Stop(f);
                iTween.FadeTo(f, iTween.Hash("alpha", 1, "time", time, "oncomplete", "SetDifuseShading", "oncompletetarget", this.gameObject, "oncompleteparams", f));
        }
       
        void FadeDown(GameObject f)
        {
                //iTween.Stop(f);
                iTween.FadeTo(f, iTween.Hash("alpha", targetAlpha, "time", time));
        }
       
        void SetDifuseShading(GameObject f)
        {
                if(f.renderer.material.color.a == 1)
                {
                        f.renderer.material.shader = shaderDifuse;
                }
        }
       
        void OnDrawGizmos()
        {
                Gizmos.color = Color.red;
                Gizmos.DrawRay(transform.position, player.transform.position - transform.position);
        }
}

Work in Unity3d V5

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class CameraOpacity : MonoBehaviour
{

    public GameObject player;
    public Shader shaderDifuse;
    public Shader shaderTransparent;
    public float targetAlpha;
    public float time;
    public GameObject o;
    public bool mustFadeBack = false;

    // Use this for initialization
    void Start()
    {
        player = GameObject.FindGameObjectWithTag("Player");
        shaderDifuse = Shader.Find("Diffuse");
        shaderTransparent = Shader.Find("Transparent/Diffuse");
    }

    // Update is called once per frame
    void Update()
    {
        RaycastHit hit;
        if (Physics.Raycast(transform.position, player.transform.position - transform.position, out hit, 30))
        {
            if (hit.collider.gameObject.layer == LayerMask.NameToLayer("CanHide"))
            {
                mustFadeBack = true;

                if (hit.collider.gameObject != o && o != null)
                {
                    FadeUp(o);
                }

                o = hit.collider.gameObject;

                if (o.GetComponent<Renderer>().material.shader != shaderTransparent)
                {
                    o.GetComponent<Renderer>().material.shader = shaderTransparent;
                    Color k = o.GetComponent<Renderer>().material.color;
                    k.a = 0.5f;
                    o.GetComponent<Renderer>().material.color = k;
                }

                FadeDown(o);
            }
            else
            {
                if (mustFadeBack)
                {
                    mustFadeBack = false;
                    FadeUp(o);
                }
            }
        }
    }

    void FadeUp(GameObject f)
    {
        //iTween.Stop(f);
        iTween.FadeTo(f, iTween.Hash("alpha", 1, "time", time, "oncomplete", "SetDifuseShading", "oncompletetarget", this.gameObject, "oncompleteparams", f));
    }

    void FadeDown(GameObject f)
    {
        //iTween.Stop(f);
        iTween.FadeTo(f, iTween.Hash("alpha", targetAlpha, "time", time));
    }

    void SetDifuseShading(GameObject f)
    {
        if (f.GetComponent<Renderer>().material.color.a == 1)
        {
            f.GetComponent<Renderer>().material.shader = shaderDifuse;
        }
    }

    void OnDrawGizmos()
    {
        Gizmos.color = Color.red;
        Gizmos.DrawRay(transform.position, player.transform.position - transform.position);
    }
}