- Home /
The question is answered, right answer was accepted
How can I make a Dropdown be activated by a Script?
I want to create a script that activates a dropdown UI when I select an option of another Dropdown UI and I already tried to create one but it doesn't work, I don't receive any compiler errors mesages,I used "if" and the Input.GetKey to see if it works but it doesn't. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class ActivatingByOptions : MonoBehaviour {
public Dropdown FirstDropdown;
public Dropdown SecondDropdown;
void Start()
{
if(FirstDropdown.onValueChanged.value)
{
SecondDropdown.gameObject.SetActive(true);
}
}
}
(After the Input.Getkey failed,I tried to use onValueChanged.value but the "value" event only applies to the Dropdown component in the if statement).
Answer by Hellium · Jul 26, 2020 at 02:41 PM
void Start()
{
FirstDropdown.onValueChanged.AddListener(OnFirstDropdownValueChanged);
}
void OnFirstDropdownValueChange(int value)
{
SecondDropdown.gameObject.SetActive(true);
}
Follow this Question
Related Questions
Making a blocker like dropdown menu for another gameobject. 0 Answers
Does anyone know how to make a Dropdown inside an element of another Dropdown? 0 Answers
how to keep dropdown's tempelate at the centre of the screen regarless of position of dropdown bar ? 1 Answer
Dropdown not showing after canvas set active 6 Answers
New dropdown menu sample 3 Answers