Convert String Name to Variable Name?

Total newbie - not sure if this is possible, but really hoping it is. Apologies for if the question is confusing, I’m struggling with the vocab of programming.

I am using a multi dimensional array. I would like to use the value returned from a Raycast.hit (which will be “left”, “middle”, or “right”) in place of an index numbers. I have integer variables defined with the same words like this.

static public var left = 0;
static public var middle = 1;
static public var right = 2;

The function looks like this:

function clickHandler ()
	var hit : RaycastHit;
    Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hit);
	for(var i = 0; i < numberOfControls; i++) 
    	if (masterControlTable[currentState][hit,i] == 1)
  			print(hit+ " triggered the ClickHandler in state " + currentState);
  		else if (currentState < numberOfControls && masterControlTable[currentState][0,i] == 0)
  			print("nothing to see here");

Is there any way to take the value of hit and use it as the value of the variable with the same name? That is, can I somehow make the string of “hit” call the variable?

I’m not sure if I got your question. You probably look for an enum?

enum Values { left, middle, right}

var myValues : Values = Values.left;

If you want to associate values with strings you may want to use a dictionary.

After compiling, variable names are not known at runtime. It also makes no sense to do this, you can use arrays and array-like types.

Hope this helps

E: could you give a bit more detail on what you want to do. I don’t think the code like you have it now is working?