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

Dictionary creates copy, rather than references

$
0
0
I'm looking to create a dictionary to use strings to refer to bools reflecting whether or not an item is unlocked. I thought I could do this with: Dictionary hatDict = new Dictionary(); //the booleans I want to access already exist elsewhere. I just need a way to reference them from a string hatDict.Add("Cowboy", Variables.boughtHatCowboy); hatDict.Add("Cowgirl", Variables.boughtHatCowgirl); hatDict.Add("Fedora", Variables.boughtHatFedora); //Then I'd like to use a transforms.name as the key to check the bools of whether or not the item is purchased foreach (Transform child in hatList) { if (hatDict[child.name] == true) { child.gameObject.SetActive(true); } else { child.gameObject.SetActive(false); } } Only thing is when I set up the dictionary it seems to create it's own instance of the bool using the originals value, so when I change the value of the dictionary it doesn't update the original Any suggestions how to get the dictionary to refer to another var rather than just take the value from it upon declaring?

Viewing all articles
Browse latest Browse all 184

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>