Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Game Development with Unity for .NET Developers

You're reading from   Game Development with Unity for .NET Developers The ultimate guide to creating games with Unity and Microsoft Game Stack

Arrow left icon
Product type Paperback
Published in May 2022
Publisher Packt
ISBN-13 9781801078078
Length 584 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Jiadong Chen Jiadong Chen
Author Profile Icon Jiadong Chen
Jiadong Chen
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Preface 1. Part 1: Basic Unity Concepts
2. Chapter 1: Hello Unity FREE CHAPTER 3. Chapter 2: Scripting Concepts in Unity 4. Part 2: Using C# Scripts to Work with Unity's Built-In Modules
5. Chapter 3: Developing UI with the Unity UI System 6. Chapter 4: Creating Animations with the Unity Animation System 7. Chapter 5: Working with the Unity Physics System 8. Chapter 6: Integrating Audio and Video in a Unity Project 9. Part 3: Advanced Scripting in Unity
10. Chapter 7: Understanding the Mathematics of Computer Graphics in Unity 11. Chapter 8: The Scriptable Render Pipeline in Unity 12. Chapter 9: The Data-Oriented Technology Stack in Unity 13. Chapter 10: Serialization System and Assets Management in Unity and Azure 14. Chapter 11: Working with Microsoft Game Dev, Azure Cloud, PlayFab, and Unity 15. Other Books You May Enjoy

Building Unity games with Visual Studio

Before you start writing any code, it is important to choose suitable development tools. Microsoft's Visual Studio is not only a widely used IDE but also the development environment that is installed by default when you install Unity on Windows or macOS:

Figure 1.52 – Visual Studio Installer

While installing Visual Studio, Visual Studio Tools for Unity will also be installed. It is a free extension that provides support for writing and debugging C# in Unity.

If you do not install Visual Studio through the Unity Hub, please make sure you installed this extension. You can check it in the Visual Studio Installer:

Figure 1.53 – Installing Visual Studio Tools for Unity

After installing the Unity Editor and Visual Studio Community 2019, you can check the External Script Editor settings in the Preferences window of the Unity Editor:

Figure 1.54 – The External Script Editor settings

In addition, you can also select other script editors by modifying this setting, such as Visual Studio Code and JetBrains Rider.

Then, we can create a new C# script file named NewBehaviourScript in the Unity Editor and double-click to open it in Visual Studio:

Figure 1.55 – IntelliSense for the Unity APIs

As you can see in the preceding screenshot, there are two built-in methods in the script file by default, namely Start and Update. Visual Studio supports IntelliSense for Unity APIs, so we can write code quickly:

Figure 1.56 – Debugging your code

It is also very easy to debug your code in Visual Studio. In the preceding screenshot, I set a breakpoint inside the Start method and clicked the Attach to Unity button in Visual Studio:

Figure 1.57 – Clicking the Attach to Unity button

In order to run this code, I attach this script to a GameObject in the Scene and click on the Play button in the Unity Editor to run the game in the Game view.

Figure 1.58 – The debugger stopping at the breakpoint

Then, the debugger will stop at the breakpoint, and you can look at the current state of the game.

You have been reading a chapter from
Game Development with Unity for .NET Developers
Published in: May 2022
Publisher: Packt
ISBN-13: 9781801078078
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 $19.99/month. Cancel anytime