C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Unity ConsoleThe console is used to see the output of code. These outputs can be used to quickly test a line of code without having to give added functionality for testing. Three types of messages usually appear in the default console. These messages can be related to most of the compiler standards:
Errors: errors are exceptions or issues that will prevent the code from running at all. Warnings: warnings are also issues, but this will not stop your code from running but may pose issues during runtime. Messages: messages are outputs that convey something to the user, but they do not usually cause an issue. Even we can have the console output our messages, errors, and warnings. To do that, 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. These methods are:
To open the console from the main menu of Unity Editor, select Windows -> General -> Console or press ctrl + shift + C. By default console window is at the bottom and next to the Project tab of the Unity editor. The outputs of the console are more useful to the programmer, not much more useful for the end-user or player. Let's create a script for displaying a simple message, warning, and Error to the console. These will notify us when the space key, escape key, and delete key was pressed. For this, we will use the Debug class methods, which take in an object as a parameter, which we use a string in. using System.Collections; using System.Collections.Generic; using UnityEngine; public class ConsoleOutput : MonoBehaviour { void Update() { if (Input.GetKeyDown(KeyCode.Space)) Debug.Log("Message!! Space key was pressed!"); if (Input.GetKeyDown(KeyCode.Escape)) Debug.LogWarning("Warning!! Escape key was pressed!"); if (Input.GetKeyDown(KeyCode.Delete)) Debug.LogError("Error!! Delete key was pressed!"); } } Output:
Next TopicUnity Sound
|