Dropdown menu buttons, dialog on click

0 votes
asked Jul 30, 2017 in Help by danve93 (160 points)

I'm having trouble setting up the dropdown menù buttons with a dialog.

The behaviour I'm trying to get is this one:
> Click on dropdown menù
> Click on one of the three buttons
> For every button I should get a different dialog 

I'm currently using this code, I wrote using the video tutorial from Youtube:


using UnityEngine;
using MaterialUI;

public class DialogScript : MonoBehaviour {

    [SerializeField] private MaterialDropdown m_Dropdown;
    [SerializeField] private Sprite[] m_IconSpriteArray;

    public void SelectedItem(int index = 0)
    {
        DialogManager.ShowAlert("statement 1", "title 1", MaterialIconHelper.GetIcon("mood"));
    }

    public void SelectedItem2(int index = 1)
    {
        DialogManager.ShowAlert("statement 2", "title 2", MaterialIconHelper.GetIcon("insert_drive_file"));
    }

    public void SelectedItem3(int index = 2)
    {
        DialogManager.ShowAlert("statement 3", "title 3", MaterialIconHelper.GetIcon("free_breakfast"));
    }

}

 

The int index = 0 should represent the option from the dropdown menù (at least in my mind), but with this written when I click on one button it opens 3 dialogs at the same time, could you please lead me?

 

1 Answer

+1 vote
answered Aug 30, 2017 by admin (31,720 points)
selected Aug 30, 2017 by danve93
 
Best answer

Hello!

Just use one method like that:

public void SelectedItem(int index)
{
    if (index == 0)
    {
    }
    else if (index == 1)
    {
    }
    else if (index == 2)
    {
    }
}
Welcome to MaterialUI support! Ask us anything :)
...