TheDeveloperBlog.com

Home | Contact Us

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

Unity UI Text

Unity UI Text 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 UI Text

The UI text element displays a non-interactive piece of text to the user. Text elements can be used to provide captions or labels for other GUI controls or to display instructions or other text. For example printing the current score of the player to the screen requires the numeric value of the score to be converted to a string, generally through the .toString() method, before it is displayed.

To insert a Text UI element in Unity, right-click on the Scene Hierarchy, then select GameObject -> UI -> Text.

Unity UI Text

There are many properties of the Text element. In which Text Field is the most important property. You can type out what you want the text box to show in that field.

Unity UI Text

You can change the font of the text; you must first import the font file from your system into Unity as an Asset.

We can also accept the Text element through the scripting; this is where the importance of dynamic UI comes in.

Let's see one simple example, instead of the console, which is printing how many times the button has been pressed, as in the previous chapter; let's print it out on the game screen trough the Text element. To do so, open your previous script file (ButtonAction.cs) and make some changes to it:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ButtonAction : MonoBehaviour
{
    int n;
    public Text myText;
    public void OnButtonPress(){
      n++;
      myText.text = "Button clicked " + n + " times.";
    }
}

Here, we added a public Text variable, where we can drag and drop our Text UI element.

Save your script and go to the ButtonGameObject, and you will now see the new slot for the Text UI element. Drag and drop your Text GameObject on to the slot.

Unity UI Text

Now hit the play button.

Unity UI Text
Next Topic#




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