Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGlen Hayes
5,798 PointsrestartTimer variable value is what?
At the risk of asking a possibly obvious and stoopid question, when and what does the restartTimer variable get instantiated to? The float is instantiated but is never given a value in the value other than itself + Time.deltaTime or am I missing something?
3 Answers
Tom Ku
3,049 PointsI also wondered about the possibility of using a variable before its initialization when I saw this code, being a newbie to C# and object oriented programming. Having run the code a number of times, it is obvious that this static int variable of a class is initialized to zero.
I believe that this implicit initialization of static variables of a class to zero is necessarily so, since there is no way for a user of the class (i.e. when instantiating an instance) to figure out if it is the first instance of the class. A quick Google search confirms that this is indeed defined in C# language specification (for example, in this discussion http://stackoverflow.com/questions/5949889/static-variables-initialization). Moreover, It is not just a C# feature, but also applies to java and C++.
Glen Hayes
5,798 Pointsyeah makes sense but if its set to zero and its not a serialized field, why not just make restartTimer = Time.deltaTime?
Tom Ku
3,049 PointsPerhaps this thread in Unity community addresses your question:http://answers.unity3d.com/questions/296336/timedeltatime.html, Glen.