Quantcast
Channel: Questions in topic: "loops"
Viewing all articles
Browse latest Browse all 184

Dynamically create variable name from a loop

$
0
0
Let's say I have a list of hats as children in a UI panel, Each hat has a correct name of what it is, such as Tophat, Cowboy, Fedora, etc. Whether or not their unlocked is stored in bools named boughtHatTophat, etc How can I make a simple loop to check each variable without individually checking each one? I would like it to run something like this, in how you can combine strings together with + foreach (Transform child in hatList) { if (boughtHat + child.name == true) { child.gameObject.SetActive(true); } else { child.gameObject.SetActive(false); } }

Viewing all articles
Browse latest Browse all 184

Trending Articles