Answers for "unity dropdown variable"

C#
0

unity dropdown variable

//Use an enum to get editor dropdown variables.

//Define the enum
    public enum Foods
    {
        apple,
        pie,
        hamburger
    };

//Create the variable field
	[SerializeField] public Foods m_foods;

//Get value and do stuff with it
    string favouriteFood()
    {
        switch (m_foods) //Switch is like if but in cleaner.
        {               //We use it so we arent yandereDev.
            case Foods.apple:
                return "apple";
            case Foods.pie:
                return "pie";
            case Foods.hamburger:
                return "hamburger";
        }

        return "Error"; //Triggered if selected value not found in list.
    }
Posted by: Guest on June-13-2021

Code answers related to "unity dropdown variable"

C# Answers by Framework

Browse Popular Code Answers by Language