Book Image

Learning C# 7 By Developing Games with Unity 2017 - Third Edition

Book Image

Learning C# 7 By Developing Games with Unity 2017 - Third Edition

Overview of this book

Do you want to learn C# programming by creating fun and interactive games using the latest Unity 2017 platform? If so, look no further; this is the right book for you. Get started with programming C# so you can create 2D and 3D games in Unity. We will walk you through the basics to get you started with C# 7 and its latest features. Then, explore the use of C# 7 and its latest functional programming capabilities to create amazing games with Unity 2017. You will create your first C# script for Unity, add objects into it, and learn how to create game elements with it. Work with the latest functional programming features of C# and leverage them for great game scripting. Throughout the book, you will learn to use the new Unity 2017 2D tool set and create an interactive 2D game with it. You will make enemies appear to challenge your player, and discover some optimization techniques for great game performance. At the end, you will learn how to transform a 2D game into 3D, and you will be able to skill up to become a pro C# programmer with Unity 2017!
Table of Contents (23 chapters)
Title Page
Credits
About the Authors
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Hiding and showing the Canvas


We have decided that the UI in our game will be made up of three simple views:

  • MenuView
  • InGameView
  • GameOverView

We have created most of the MenuView. I am using two terms here, View and Canvas. In our simple game, both of them will mean the same thing. MenuCanvas is just the visible part of MenuView. Keep that in mind.

The simplest way to toggle the view's visibility is by enabling and disabling the Canvas component. Let's test how it works without the code for now:

  1. Press Play in Unity.
  2. Select the MenuCanvas game object in the Hierarchy window.
  3. Disable the Canvas element, marked here:
  1. As the Canvas component is responsible for rendering the UI in the scene, disabling it will hide the content of all UI elements within the canvas.

Note

Note once again that disabling the Canvas component will hide all UI elements within the canvas. It will also disable all events handled by the Event System.

It's been a while since we wrote some code. Let's implement the same behavior in the...