- Unity - Using the Asset Store
- Unity - The Particle System
- Unity - Materials and Shaders
- Unity - The Slider
- Unity - Text Element
- Unity - The Button
- Unity - Starting with UI
- Unity - Introduction to Audio
- Unity - The Console
- Unity - Coroutines
- Unity - GameObject Destruction
- Understanding Prefabs and Instantiation
- Unity - Custom Collision Boundaries
- Unity - Rigidbodies and Physics
- Unity - Understanding Collisions
- Unity - Basic Movement Scripting
- Unity - Saving and Loading Scenes
- Unity - Internal Assets
- Transforms and Object Parenting
- Unity - Modifying Sprites
- Unity - Creating Sprites
- Unity - Installation and Setting Up
- Unity - Introduction
- Unity - Home
Unity Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Unity - The Console
The Console is where we will be reading the Developer outputs. These outputs can be used to quickly test bits of code without having to give added functionapty for testing.
There are three types of messages that appear in the default console. These messages can be related to most of the compiler standards −
Errors
Warnings
Messages
Errors
Errors are issues or exceptions that will prevent the code from running at all.
Warnings
Warnings are issues that will not stop your code from running, but may pose issues during runtime.
Messages
Messages are outputs that convey something to the user; they do not usually highpght issues.
We can even have the Console output our own messages, warnings and errors. To do so, we will use the Debug class. The Debug class is a part of MonoBehaviour, which gives us methods to write messages to the Console, quite similar to how you would create normal output messages in your starter programs.
You can find the Console in the labelled tab above the Assets region.
The outputs of the console are more useful to the programmer, not the end user or player.
Let us try writing a simple message to the Console. This will notify us when the Space key was pressed. For this, we will use the Log method, which takes in an Object as a parameter, which we will use a string in.
You can start with a fresh script or modify an existing one.
void Update() { if (Input.GetKeyDown(KeyCode.Space)) Debug.Log(“Space key was pressed!”); }
Saving, compipng and running this code (by attaching it to a GameObject, of course), try to hit the spacebar.
Note − Observe that the message shows up at the bottom of the editor.
If you cpck on the Console tab, you will find your message printed out.
Similarly, you can also output warnings by using the LogWarning method and errors with the LogError method. These will prove to be useful for testing small bits of code without actually having to implement them, as you will see later on.
Advertisements