JoeyBerger
JoeyBerger

Reputation: 1

Controlling the unity ui slider via script

I have a simple question: how does one go about controlling the UI Slider in Unity via code? I can control a GUI slider quite easily, but I'd prefer to work with the UI slider that can be assigned in the hierarchy.

I have a few scripts that control volume and audio timeline scrubbing (moving the slider to a certain point in an audio track) that work great, but I want to assign these scripts to a Unity UI slider.

I think I am missing something pretty easy, but have spent too much time trying to get this right. Any help would be greatly appreciated!

Upvotes: 0

Views: 4885

Answers (1)

malle
malle

Reputation: 334

Have you had a look at the Tutorial for Sliders yet? And the Scripting API?

http://docs.unity3d.com/ScriptReference/UI.Slider.html http://unity3d.com/learn/tutorials/modules/beginner/ui/ui-slider

The Slider has a OnValueChange eventHandler and there you can for example directly drag in your AudioListener (attached to the main Camera) or the script you want to call. Screenshot To add more calls just press the + ;)

Good Luck, hope that helps.

Upvotes: 1

Related Questions