I’m having difficulty asking this question, please bear with my ignorance of such things.
Basically, I want to do this. I know it’s wrong, but hopefully you can see what I mean.
I have a variable “RoomNum” which is the number of the room for this case of the script. I have the script on all of the rooms, and each example of the script already knows what it’s RoomNum is (int between 1-15). There’s 15 different room objects, each of which have a unique corresponding script, titled “Room” followed by their room number, and that script has unique information in it (cost, description, etc). So, suppose my script knows that it is room number 12 (RoomNum = 12). It then wants to find the room with the script “Room12”, and pull information from it, like the cost and description. I could do this by having a huge wall of if statements, like this
if (RoomNum == 1)
{Cost = FindObjectOfType<Room1>().GetComponent<RoomStats>().cost}
And I would have to do that for all 15 types. But, wouldn’t it be soooo much easier, if in the FindObjectOfType I could have the reference be variable? For example, something like this…
FindObjectOfType<“Room”+RoomNum>().GetComponent().cost}
I would only have to do this in ONE line, rather than like 60. I’ve had tons of moments when coding where I wish I could do this. Is there a way to let the <> know it’s contents are going to be variable?
Another way of asking this, is there a way for the CONTENTS of a variable to be what’s being used, rather than the name of the variable? We can do that easily in string, like this “Room”+RoomNum knows that it’s the word “Room” followed by the contents of the variable RoomNum. It seems so stupidly simple to me, but I can’t make it do it.
Is it impossible? Or am I just ignorant of the method? Hopefully this makes at least some sense. Thanks for any help you can provide/[/code]