I got a problem, I want a block to change its texture when my players head(cube) looks at a block. This is my code so far.

Var range : float = Mathf.IsInfinity;
Var hit : RaycastHit;

Function HighlightBlock()
{

If (SeeBlock())
{

(Here it is. What goes here to make the texture change. I’ve tried a lot of things but none work. Btw this part ain’t in my script)

}

}

Function SeeBlock() : boolean
{
return physics.raycast (transform.position, transform.forward, hit, range)
}

Get the texture you want to change to in as a public variable

public var texture;

If the raycast hits a block then you can access the material using

var BlockMaterial = hit.collider.GetComponent.<Renderer>().material;
BlockMaterial.mainTexture = texture;