Since currentAge was declared as a variable on line 7, the value it stores can be changed. The updated value will then trickle down to wherever the variable is used in code; let's see this in action:
- Stop the game by clicking the Play button if the scene is still running.
- Change Current Age to 18 in the Inspector panel and play the scene again, looking at the new output in the Console panel:
The first output will still be 31, but the second output is now 19 because we changed the value of our variable.Â
The goal here wasn't to go over variable syntax but to show how variables act as containers that can be created once and referenced elsewhere. We'll go into more detail in Chapter 3, Diving into Variables, Types, and Methods.
Now that we know how to create variables in C# and assign them values, we're ready to dive into the next important programming building block: methods!