Making an object transparent,

Hey there, im trying to make an object half transparent by reducing its alpha channel by 0.5 with this code i get error " Assets/Scripts/transparent.cs(10,17): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer"

Also are there any other ways to fill an area with color so player can detect there is a zone there ? right now im trying to make a field when players enters will be forced to go in one direction but i want that fields size to be clear.

using UnityEngine;
using System.Collections;

public class transparent : MonoBehaviour {

	// Use this for initialization
	void Start () {


		GetComponent<Renderer.material.color.a>()=0.5f;
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

Two things:

  1. You are passing an incorrect type into the generic GetComponent<>() call. The part between the <> expects a class, and you are trying to supply members of an instance of a class. You need to use:

    Color oldColor = GetComponent ().material.color;

  2. You aren’t able to modify alpha directly, but you can set the entire material color:

    Color oldColor = GetComponent ().material.color;
    Color newColor = new Color (oldColor.r, oldColor.g, oldColor.b, 0.5f);
    GetComponent ().material.color = newColor;

Your calling GetComponent wrong, the “material.color.a” bit needs to come right after the parentheses, like this:

GetComponent<Renderer>().material.color.a = 0.5f;