Note: This edition is for people who plan to use Visual Studio to develop their C# Unity scripts and stand-alone programs. If you plan to use MonoDevelop, you should buy the MonoDevelop edition instead.
Welcome to the wonderful world of programming! In this book you’ll learn the basics of programming using the C# programming language. While we admit we love to code (another word for program) just about anything, developing games is one of the coolest things of all. Most of the examples in this book are related to game development using Unity. So you’ll learn how to program properly and you’ll learn how to write C# scripts in Unity.
It's important to note that the Unity focus in this book is on the actual C# scripting you do to build Unity games. The book doesn't cover the full gamut of how to build Unity games from scratch (though we do build a complete game in Chapter 20); instead, we use just enough “Unity stuff” to build interesting pieces of game functionality so we can concentrate on learning C#. Don't worry, there are plenty of other books and resources for learning the rest of Unity! If you really just want to learn all the nuts and bolts of Unity, you should buy one of those books instead.
You’ll notice we said “learn how to program properly” above, not “whack together games that seem to work.” This is a book that focuses on the correct way to write game software (and software in general), so there’s lots of discussion about our motivations for the particular design and coding decisions we make throughout the book.
The book assumes that you’ve never programmed before, so all the material starts at the most basic level. That means that anyone should be able to pick up the book and work their way through it without any prior knowledge. That’s the good news.
The bad news is that programming is hard work, especially at first. If you truly want to learn how to program, you’ll need to write programs yourself and struggle through some rough spots before some topics really click for you. Just as you can’t learn how to ride a bicycle by reading about it – you have to actually do it, probably with some spills along the way – you can’t learn to program just by reading about it. If you were hoping to read a book to learn how to program without doing any programming yourself, it’s not going to happen. If you aspire to be a professional game programmer – whether as an indie game developer or in a large game company – and you're willing to put in the work, though, this book will give you a solid foundation for starting on that path.
Table of Contents
Chapter 1. Introduction
Chapter 2. Starting to Code
Chapter 3. Data Types, Variables, and Constants
Chapter 4. Classes and Objects
Chapter 5. Strings
Chapter 6. Unity 2D Basics
Chapter 7. Selection
Chapter 8. Unity Mice, Keyboards, and Gamepads
Chapter 9. Arrays and Collection Classes
Chapter 10. Iteration: For and Foreach Loops
Chapter 11. Iteration: While Loops
Chapter 12. Class Design and Implementation
Chapter 13. More Class Design and Methods
Chapter 14. Unity Text IO
Chapter 15. Unity Audio
Chapter 16. Inheritance and Polymorphism
Chapter 17. Delegates and Event Handling
Chapter 18. Exceptions, Equality, and Hash Codes
Chapter 19. File IO
Chapter 20. Putting It All Together
Appendix: Setting Up Your Development Environment