Using the information from the dropdown selection

Now that our Dropdown looks the way we want it and is functioning properly, we can access the player's selection with code. We'll use the player's selection to update the player character image in the top-left corner of the screen.

To swap the player character image with the selection from the Dropdown, complete the following steps:

  1. Create a new C# script in your Assets/Scripts folder named PlayerCharacterSwap.cs.
  2. For us to access UI variable types, add the UnityEngine.UI namespace to the top of the script with the following line:
using UnityEngine.UI;
  1. We only need two variables, one to represent the Image that will be swapped with the selection from the Dropdown menu and one to represent ...

Get Mastering UI Development with Unity now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.