One button interaction

So I’m working on an “interact” button system, and I’m completely new to Unity and I decided to go with the UniScript/Java since it’s the closest scripting language I’ve ever worked with.

The way I’m planning to do it is to have the game send out a ray that when collides with the first object it sees returning an array consisting of two values ObjectClass and Distance. This way a player can start a dialog scene from a short distance, but can only run up a fence by being adjacent to it, all with the use of one button.

However, this is where my unfamiliarity with Unity comes in. I have found several ray classes that measure distance, but I haven’t found any that can return a variable from a GameObject. If this is not possible to do in the method I described earlier, could anyone suggest a different method? If not, could someone point me out to a ray class that can return data from a GameObject?

A ray will never return data from a gameObject, you will have to identify the gameObject through its collider, rigidbody, or transform which is accessible from the RaycastHit.

Ah, thank you very much.

That should help you, I forgot to put it last time.