“SCRIPTABLE OBJECTS in Unity” Dropdown and prefab selection

Updated on September 11, 2018 in [A] Tutorials
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
3 on August 29, 2018

Hi Guys,

im working on a TCG (trading card game) and want to clean up my method to create new cards.

 

Now i want to know, how to select a prefab from a bool..

It should look like this:

 

If boolean == true -> use the 1. Prefab

else -> use the 2. Prefab

 

In this case the prefabs are different card layouts.

Or maybe even better, there is a way to integrate a “dropdown menu” to the inspector like:

Warrior == 1

Paladin == 2

Mage == 3

and so on…

 

And i could use this information of the current selected “class” to call a function.

 

Im sorry realy sorry for my bad english. If you dont understand something just ask and i’ll try to explain it.

 

 

  • Liked by
Reply
0 on August 29, 2018

enum

 

  • Liked by
Reply
Cancel
0 on August 29, 2018
  • Liked by
Reply
Cancel
0 on September 11, 2018

Did you end up getting this to work? I’m just curious because you wrote the answer to your own question in your first post, all you were missing was the variable.

bool newCard_1 = false;

bool newCard_2 = false;

void PickCard()
{
    if (newCard_1 == true)
    {
        //code to get prefab 1
    }
    else if (newCard_2 == true)
    {

        //code to get prefab 2
    }else
    {

        //code to get maybe a default prefab? Or just return to exit the loop
    }
}

You can do as many “else if”‘s as you want, enum might be better but it depends on your method and what exactly you’re doing with it.

  • Liked by
Reply
Cancel