Is there any way to reference the object that a raycast hits

Basically, i have a reticle that shows where the player is looking. if the player sees the object, i want to change the material color. Originally, i had this setup in the script whose material is changing, the problem was that all of the other materials colors were changing as well (i have multiple objects the player can look at that all have the same script attached). So i tried setting this up in the script for the reticle. However, it seems that i am not able to actually reference propertys of the other object through a raycast? Heres my code

using UnityEngine;
using System.Collections;

public class reticleScript : MonoBehaviour {
	public Camera cameraFacing;

	// Use this for initialization
	void Start () {
	// Update is called once per frame
	void Update () {
		transform.LookAt (cameraFacing.transform.position);
		transform.Rotate (0.0f, 180.0f, 0.0f);
		RaycastHit hit;
		if (Physics.Raycast (transform.position, Vector3.forward, 10, out hit)) {
			Orbit.isSelected = true;
		/*****This is where im having trobule*/

hit.collider.gameObject.mat = Resources.Load("mat_Orange",
    typeof(Material)) as Material;
	gameObject.GetComponent<Renderer>().material = mat;


Is what im trying to do impossible? if so, is there a better way i should be going about this?

Found an old post

Once you have determined that your raycast actually hit something, you can query your ‘hit’ object for many different properties.

For the gameObject’s name:;

For the object’s tag:


And there are many others - see the RaycastHit manual page.

Because “collider” is a component, you can use “GetComponent” on the hit.collider result, to get access to any other component on the gameObject - including your own script.

You would use something like this (inside your , assuming your script is called “BoomScript” and it has a function in it called “Boom”:

if (Physics.Raycast (ray, hit, 1000)) {
    var boomScript : BoomScript = hit.collider.GetComponent(BoomScript);
    if (boomScript != null) {