- Home /
variable before (dot)
I have a bunch of variables, RT1-36 (standing for RawText) In a Switch I want to change their Color with RT1.color = Color. Red. But can I exchange the RT1 with a variable so i can change it dynamicly? (The numbers behind rt)
Answer by fffMalzbier · Jan 22, 2016 at 01:32 PM
Why not add all the variable to a array and iterate with a for loop over all the variables? (or use a array for your raw text components from the start)
Answer by cjdev · Jan 23, 2016 at 06:02 AM
The language isn't really designed to do that but you can use a Dictionary as an alternative. If you haven't seen them before, they basically let you store your variables in one column and use another variable type in the other column to access them.
// A collection with the type on the left indexing the type on the right
Dictionary<int, TextAsset> rawTexts = new Dictionary<int, TextAsset>();
rawTexts.Add(1, RT1);
rawTexts.Add(2, RT2);
rawTexts[1] // This is RT1
Here the int is used as the key, the index, and that's what you can use to access the value, your variable. You could just as easily have used strings and made "RT1" as an index too. Note that in the example I'm assuming your RT objects are of type TextAsset.
Your answer
Follow this Question
Related Questions
Tranferring Color from a script to a Gui Box? 1 Answer
How to render a colored 2D rectangle. 6 Answers
Labels aren't colored properly 1 Answer
Change GUI.Label text while it's active? 1 Answer
Colored 3d Text? 1 Answer