RayCast Hit

I have a script that I am using for a game. I want it to change a cubes (a cube will be referenced as a block from here) texture when it is clicked with the left mouse button. There are multiple blocks on the screen and I want only one. Here is the code:-

var hit : RaycastHit;
var BlockTexture : Texture;

function Update () {
	if(Input.GetMouseButtonDown(1))
	{
		TextureBlock();
	}
}

function TextureBlock()
{
	if(HitBlock())
	{
		cube.renderer.material.mainTexture = BlockTexture;
	}
}

function HitBlock() : boolean
{
	return Physics.Raycast(transform.position, transform.forward, hit, range);
}

Where am I going wrong. I cannot figure out where I am going wrong. The errors I am getting are:-

Assets/CraftingTest/RayCastHit.js(15,17): BCE0005: Unknown identifier: ‘cube’.

And

Assets/CraftingTest/RayCastHit.js(21,31): BCE0023: No appropriate version of ‘UnityEngine.Physics.Raycast’ for the argument list ‘(UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.RaycastHit, function(int): System.Collections.Generic.IEnumerable.)’ was found.

Answers are appreciated.

Well one is that cube is an unknown variable. Assuming that your gameobject is named cube, you can remove it, or change it to this

renderer.material.mainTexture = BlockTexture;
or
this.renderer.material.mainTexture = BlockTexture;

Second, have you defined “range”? I looks like you haven’t and the compiler thinks you are trying to call a method. Try changing range to a number like 1000.

Turns out that I was doing it all wrong… Here is the code I used and it worked:-

function OnMouseDown () {
	this.gameObject.renderer.material.color = Color.red;
}