TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Unity Console

Unity Console with Introduction, Installing, GameObject, First Unity Project, Unity 2D, Sprite Unity, Loops, If Statement, Data Types, Swith Statements, Unity UI, Unity Asset Store etc.

<< Back to UNITY

Unity Console

The 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
  • Warnings
  • Messages

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:

  • Debug.Log
  • Debug.LogWarning
  • Debug.LogError

To open the console from the main menu of Unity Editor, select Windows -> General -> Console or press ctrl + shift + C.

Unity Console

By default console window is at the bottom and next to the Project tab of the Unity editor.

Unity Console

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:

Unity Console
Next TopicUnity Sound




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf