Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning C# by Developing Games with Unity - Seventh Edition

You're reading from  Learning C# by Developing Games with Unity - Seventh Edition

Product type Book
Published in Nov 2022
Publisher Packt
ISBN-13 9781837636877
Pages 466 pages
Edition 7th Edition
Languages
Author (1):
Harrison Ferrone Harrison Ferrone
Profile icon Harrison Ferrone

Table of Contents (18) Chapters

Preface 1. Getting to Know Your Environment 2. The Building Blocks of Programming 3. Diving into Variables, Types, and Methods 4. Control Flow and Collection Types 5. Working with Classes, Structs, and OOP 6. Getting Your Hands Dirty with Unity 7. Movement, Camera Controls, and Collisions 8. Scripting Game Mechanics 9. Basic AI and Enemy Behavior 10. Revisiting Types, Methods, and Classes 11. Specialized Collection Types and LINQ 12. Saving, Loading, and Serializing Data 13. Exploring Generics, Delegates, and Beyond 14. The Journey Continues 15. Pop Quiz Answers
16. Other Books You May Enjoy
17. Index

Defining classes

Back in Chapter 2, The Building Blocks of Programming, we talked briefly about how classes are blueprints for objects and mentioned that they can be treated as custom variable types. We also learned that the LearningCurve script is a class, but a special one that Unity can attach to objects in the scene. The main thing to remember with classes is that they are reference types—that is, when they are assigned or passed to another variable, the original object is referenced, not a new copy. We'll get into this after we discuss structs. However, before any of that, we need to understand the basics of creating classes.

For now, we're going to set aside how classes and scripts work in Unity and focus on how they are created and used in C#. Classes are created using the class keyword, as follows:

accessModifier class UniqueName
{
    Variables 
    Constructors
    Methods
}

Any variables or methods declared inside a class belong to that class and are accessed...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at AU $19.99/month. Cancel anytime}