Hi. I'm trying to reference an instance or object of a class in another script (using Unity). My problem is, when I execute the code, I want to change which object I am referencing based on a string variable that changes.
string y = otherScript.User1.name;
string y will then become "Bob", from the object I made in the otherScript. But I want to be able to change which "object I reference. For Example:
string x; // This string will change, could be User1, User2 etc...
The above line, will return an error. It will look instead for a name variable attached to the string I made in THIS script. Is there a way to use a string variable where the x is, that will just change the object I'm referencing?
What I have tried:
I've tried passing the string through a function written in the script containing the object, and even then it won't work. Or putting the string in brackets.