change material on raycast hit

using basic raycasting, how can i change an object’s material, based on what did the cast hit. can anyone point me to some references or sort of help - thanks

public class MaterialChanger : MonoBehaviour {
public override void OnRaycastTouch() {
renderer.material = someNewMaterialYouNeedToWriteLogicFor;
}
}

Then do a GetComponent< MaterialChanger >() on the game objects that the raycast hits and call OnRaycastHit on them (it sounds like you know how to do the raycast?). You could expand to pass extra information about the hit if needed, or use a superclass/interface if you need similar behaviour from other classes

Attach this to an empty game object, then drag and drop a material onto the ‘material’ variable of this script in the Inspector. Any object you click on will get that material. Depending on your game you may want to consider changing just the texture instead of the material.

#pragma strict

var material : Material;

function Update() {
	if (Input.GetMouseButtonDown(0)) {
		var hit : RaycastHit;
		var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		if (Physics.Raycast(ray, hit)) {
			hit.collider.renderer.material = material;
		}
	}
}