TheDeveloperBlog.com

Home | Contact Us

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

Unity UI Slider

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

The Slider UI element is commonly used where a certain value should be set between a minimum and maximum value pair. One of the most common usages of this is for audio volume, screen brightness, or for doing zoom.

To create a slider UI, right-click on the scene hierarchy and select GameObject -> UI -> Slider. A new slider element will display on your scene.

Unity UI Slider
Unity UI Slider

Now, select the slider and go to the Inspector tab.

Unity UI Slider

Let's try to make a volume slider. For this open the ButtonAction script which we previously created and did some changes on it:

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

public class ButtonAction : MonoBehaviour
{
    public Text myText;
    public Slider mySlider;
    void Update() {
      myText.text = "Current Volume: " + mySlider.value;
   }
}

Attach this script to the ButtonGameObject (which we previously created). Now, you will get a new slot for slider in the Inspector tab of ButtonGameObject.

Drag the slider from the Hierarchy tab to the newly created slot (My Slider) of ButtonGameObject.

Unity UI Slider

Change the slider's maximum value to 100. And check mark for Whole Numbers.

Unity UI Slider
Unity UI Slider

Here, I changed the color of Text to green from its properties, so that it will be more visible.

Now press the play button and slide the slider.

Unity UI Slider
Next TopicUnity UI Text




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