Vishruti Faldu
Vishruti Faldu

Reputation: 1

[Unity]: Multiple UI Button Selection

can we select multiple UI buttons? Something like this : https://ibb.co/gSgDvqh

Upvotes: 0

Views: 2287

Answers (2)

Meisam Sabaghi
Meisam Sabaghi

Reputation: 826

if you want create button like image , you can get bool parameter for each button for manage is click or not like that :

bool btn1Selected=false;
bool btn2Selected=false;

than in UIManager script add button and when button clicked , change UI of the button to selected image button.

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

public class test : MonoBehaviour
{

    public bool btn1Selected;
    public bool btn2Selected;

    public Sprite selectedSprite;
    public Sprite notSelectedSprite;

    Button btn1, btn2;


    public void BtnClicked(int btnIndex)
    {
        if (btnIndex == 1)
        {
            if (btn1Selected)
                btn1.GetComponent<Button>().image.sprite = notSelectedSprite;
            else
                btn1.GetComponent<Button>().image.sprite = selectedSprite;

            btn1Selected = !btn1Selected;
        }
        else
        {
            if (btn2Selected)
                btn2.GetComponent<Button>().image.sprite = notSelectedSprite;
            else
                btn2.GetComponent<Button>().image.sprite = selectedSprite;

            btn2Selected = !btn2Selected;
        }
    }


}

Upvotes: 0

Morion
Morion

Reputation: 10860

Did you check ToggleGroup? If it is not what you needed, you can simply create your own control.

Upvotes: 1

Related Questions