How to access a Unity's TextMesh Pro Dropdown component via code?

Viewed 14725

I'm trying to access a TextMesh Pro Dropdown via code, as if I was using a regular Dropdown from Unity, but I'm not sure how to.

What I intend to do in the end is something like this (that is working, using a normal Dropdown):

using UnityEngine;
using UnityEngine.UI;

public class SettingsMenu : MonoBehaviour
{
    public Dropdown resolutionDropdown;
}

But, instead of using Unity's native Dropdown, use TextMesh Pro's Dropdown.

I'm already using TextMesh Pro in this project (been using it for text), so the package is already in the project itself.

What I'm having difficulties is with accessing the Dropdown component of a TextMesh Pro's Dropdown.

1 Answers

You need to access the TMPro namespace.

So, in this example, you'd do:

using UnityEngine;

public class SettingsMenu : MonoBehaviour
{
    public TMPro.TMP_Dropdown resolutionDropdown;
}

and in Unity, you'll be able to drag the TextMesh Pro's Dropdown into the Inspector, no problem!

Thank you to Jorge Carvalho who answered me this on twitter.

Related