Setting, and getting "Global" UI/GameObject bool

I didn’t think I was this dumb. People told me C++ was difficult, clunky, and hard to use, and yet I write it more fluently then I speak English as a native Canadian sometimes. I thought, with something as “archaic as C++”, that using C# would be easier, and I’ve had like 20 people tell me so.

So I don’t understand why I’m struggling so hard to create systems that would be done in the flick of a wrist with C++, in C#.

Is there anyone able to enlighten my C# deficient brain please?

I’ve set up UI buttons in a menu at the beginning of my game. The player selects a choice, and the choice would basically set a boolean to true. Then, when the player is interacting with other characters in the game, the script is supposed to “run a check” to see if that bool is set to true, and if so, gives the player more options.

So like this - You can choose between male and female. If you chose male, all the girl characters you can talk to in the game will have a “flirt” option made available. And the male characters will not have this option available.

For C++ it was easy. You set up a Callback, then in the call back you SetGlobalVarInt(“newstringname”, number variable) and then you call the “if/else” in a void string statement. I have no idea why I’m stuck here for what is apparently supposed to be a superior coding language, haha. Every attempt to do it, gives me a “you assigned the value but never used it” warning, and doesn’t work, so now I’m at a standstill, and all the tutorials I’ve looked for haven’t helped!

I would attach some data (via properties on your own monobehaviour) to your “people” game objects. A monobehaviour with all the measurable person attributes. You can then check that component for the individual (player or npc) when they interact (collider triggers on enter, exit, stay etc).

If you want a global property, than statics are a useful singleton approach. That is, you might have a static enum or bool on your person monobehaviour called perhaps “MenuSelectedGender”. It’s static so will be addressed via the class type Person.MenuSelectedGender.

This feels a bit of kludge to me though. If you ever get in to multiplayer, globals /statics may not help.

Anyway, hope this helps.

You could set up a class to save all this data. Like a class PlayerChoices and then you have the variables setup inside and set and get them with a reference to your PlayerChoices instance and the dot accessor.

//define class
class PlayerChoices{
bool isMale;
bool isTall;
}
//create instance
PlayerChoices playerChoices=new PlayerChoices();

//set values
public void ButtonChooseMale(){
playerChoices.isMale=true;
}
public void ButtonChooseFemale(){
playerChoices.isMale=false;
}

//get values
if(playerChoices.isMale==true){
//do stuff
}