Raycast to determine certain game objects?

I want to use a raycast to determine different game objects. So far I have a script which uses a raycast. When it hits and object and the left mouse button is pressed it changes a boolean to true. In a separate script, it checks if the variable is true and enables some GUI. I want to know how to determine what object the raycast hits and change what GUI appear because of it.

I’ll answer your original question, about raycasting. The GUI topic should be a separate question. Here’s a simple C# example on how to get the name of an object the ray is hitting. This uses a ray from mouse position from the main camera’s perspective.

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour
{
    RaycastHit hit;
    Ray ray;

    void Update()
    {
        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if(Physics.Raycast(ray, out hit))
        {
            Debug.Log(hit.collider.gameObject.name);
        }
    }
}