Ted Romanus
Ted Romanus

Reputation: 582

UI Switch in Unity

I'm working on cross-platform mobile Unity application. I want add a switch on my screen allowing user turn on and off some functionality (like this: Android Material Switch).

As I know there is no native implementation of UI Switches in Unity. I found only this asset (Switch UI element) in Unity Asset Store, but it has really poor design.

So should I manually implement the Material Switch? Or is there anything in the web I can use in this case?

Thanks for response.

Upvotes: 1

Views: 4768

Answers (2)

Olivér Raisz
Olivér Raisz

Reputation: 516

Probably I'm a bit late, but for anyone who is viewing this question, I found a fairly good (free) Asset called Lean GUI with switches and stuff.

Hope it'll help someone.

Upvotes: 2

Umair M
Umair M

Reputation: 10750

You can use slider as switch.

Here are simple steps:

  1. Create a slider by going to GameObject->UI->Slider
  2. Check whole numbers chech-box in slider component's inspector.
  3. set min value to 0 and max value to 1.
  4. Use whatever graphics you want (even from material design)
  5. Register "OnValueChange" method to handle change in value:

    public void SliderValueChanged(float value)
    {
        if(value == 0)
            // off
        else 
            // on
    }
    

Upvotes: 7

Related Questions