Hi SpecialJstorm,
Yes, you are right. All variables declared in methods are temporary because they get destroyed after the method finished executing its code. These variables are also called local variables because they exist in the local scope of the method only. The opposite would be an instance variable, which exists during the lifetime of the instance/object of the class. And there are also static variables, which belong to the class. They exist as long as your program is running.
In most cases, we create local variables to make our code more readable. The two lines in your post would look like this without the temporary variable:
answerButtons[i].GetComponentInChildren().text = question.GetAnswer(i);
That one-liner is quite difficult to read and understand, isn’t it? Of course, we could decipher it but we usually don’t want to waste our time doing that.
Feel free to rewrite the code to explore your ideas and to improve your own coding skills. The compiler will complain if the code is invalid.
Did this help?
See also:
- Forum User Guides : How to mark a topic as solved