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.