Changing Dropdown options at Runtime | Unity Game Engine


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

public class DropdownOperations : MonoBehaviour
{
    private Dropdown dropdown;

    void Awake()
    {
        dropdown = GetComponent<Dropdown>();
    }

    public void LoadFruitOptions()
    {
        dropdown.ClearOptions();
        var option1 = new Dropdown.OptionData("Apple");
        dropdown.options.Add(option1);
        var option2 = new Dropdown.OptionData("Mango");
        dropdown.options.Add(option2);
        dropdown.RefreshShownValue();
    }
    
    public void LoadDrinkOptions()
    {
        dropdown.ClearOptions();
        var option1 = new Dropdown.OptionData("Tea");
        dropdown.options.Add(option1);
        var option2 = new Dropdown.OptionData("Coffee");
        dropdown.options.Add(option2);
        dropdown.RefreshShownValue();
    }
}