Game Development Reference
In-Depth Information
Braces Define Scope
When thinking about variables and scope, it's easy to think in terms of global variables living
application-wide, class variables as being class-wide, local variables as being function-wide, and
block variables as existing inside loops and if statements. But the braces symbols { } can be used
inside any function on their own, without the presence of a surrounding loop or if statement in order
to control variable scope, if required (see Listing 10-22).
Listing 10-22. Unconventional Block Scope
void Start()
{
{
//Scope inside braces
string Name = "Bob";
Debug.Log(Name);
}
//Variable not accessible here - will generate a compile error
Name = "John";
Debug.Log(Name);
}
Summary
So now we've reached the end of this intensive C# course in professional game development
with the Unity engine. We've covered a lot of ground. CMOD is completed, and having read this
chapter, you're now better positioned to make potential improvements and refinements, such as
adding more levels and refining the event system using either interfaces or delegates. In addition,
you've seen potential tips and tricks to keep in mind when using C# that can really help boost
your productivity.
Now, although there's lots more to see and learn (as there always will be), you can still use
and reuse the concepts here, with practically limitless potential. Using only the code and ideas
presented in this topic, you can produce amazing results. And I hope that this topic brings you
game-development success. So with that said, let me congratulate you on completing the topic
and creating a cartoon first-person shooter that rests on solid code—with the potential to be
expanded even further. This is Alan Thorn, signing off.
But before I do so, let's recap what this chapter has offered. After completing this chapter, you
should be able to do the following:
Understand ways in which CMOD can be expanded
Know how to load new levels with Application.LoadLevel
Load levels asynchronously and additively
Improve the event system with interfaces
 
Search WWH ::




Custom Search