Unity - Scripting API: UI.Slider.onValueChanged (2024)

#pragma strict// Required when Using UI elements.public class Example {public var mainSlider;public function Start() {//Adds a listener to the main slider and invokes a method when the value changes.mainSlider.onValueChanged.AddListener(function() {ValueChangeCheck();});}// Invoked when the value of the slider changes.public function ValueChangeCheck() {Debug.Log(mainSlider.value);}}
using UnityEngine;using System.Collections;using UnityEngine.UI; // Required when Using UI elements.

public class Example : MonoBehaviour {public Slider mainSlider;public void Start(){//Adds a listener to the main slider and invokes a method when the value changes.mainSlider.onValueChanged.AddListener (delegate {ValueChangeCheck ();});}// Invoked when the value of the slider changes.public void ValueChangeCheck(){Debug.Log (mainSlider.value);}}

Unity - Scripting API: UI.Slider.onValueChanged (2024)
Top Articles
Latest Posts
Article information

Author: Lakeisha Bayer VM

Last Updated:

Views: 5366

Rating: 4.9 / 5 (69 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Lakeisha Bayer VM

Birthday: 1997-10-17

Address: Suite 835 34136 Adrian Mountains, Floydton, UT 81036

Phone: +3571527672278

Job: Manufacturing Agent

Hobby: Skimboarding, Photography, Roller skating, Knife making, Paintball, Embroidery, Gunsmithing

Introduction: My name is Lakeisha Bayer VM, I am a brainy, kind, enchanting, healthy, lovely, clean, witty person who loves writing and wants to share my knowledge and understanding with you.