How to choose which int to modify from the other class using inspector?

Hello!
I’m not a programmer, so I’m really sorry if my questions are silly. I just desperately need help.

I have some public variables in a certain class, e.g. class named “General attributes”.
I need to pick some of them from the other class and manipulate them.
Here is the example to make it clear:
Say, I have variables named Srenght, Dexterity, Health and Willpower.
In inspector I choose Dexterity from a dropdown list and then choose “Modify” from another dropdown list (containing Modify, Make Equal to, etc…) and set the number to modify my variable, e.g +7 or -2.

So, when game runs and that method is activated (e.g. on button click) the public variable “Dexterity” gets +7 (or -2, or any other change we determined previously in inspector).

Is it possible?

It’s not possible to do that directly, although it’s possible to make a class that looks like that in the inspector (by doing a bunch of work under the covers to translate the inspector fields into actual code instructions).

The most basic way to get a dropdown in the inspector is to define an enum containing the things you want to have show up in that dropdown, and then make a public variable of that enumerated type. (Tip: Unity saves the numerical value of enums, NOT the name, so it’s good practice to explicitly assign a number to each value in your enum, and don’t change those numbers even if you add or remove values later.)

e.g. you could have an enum like

public enum
{
    Strength = 0,
    Dexterity = 1,
    Health = 2,
    Willpower = 3
}

(Once you’ve got that, you may find it is also helpful to get rid of the idea of separate variables named “strength”, “dexterity”, etc. and instead put all those attributes into an array or a dictionary, so that you can easily access them using the corresponding enumerated value.)

Then you could also make an enum with values like “Modify”, “SetEqualTo”, etc. and write some function with a switch statement that executes different code depending on which of those things was selected.

For the drop down you can use enums in your inspector like this:

//enum in your code
enum Properties
{
    Willpower,
    Strength,
    etc...
};

enum currMode
{
Modify,
Equal,
etc...
};

//Inspector dropdown
var currentProperty = Properties.Willpower;

var currentMode = currMode.Modify;

For your button I assume you have a separate object to host your button functions.

public GameObject player;

public int EditProperty(GeneralVariables obj)
{
    switch(obj.currentMode)
    {
        case obj.currMode.Modify:
            switch(obj.currentProperty)
            case obj.Propterties.Willpower:
    player.GetComponent<PlayerScriptWithVariables>().willpower += obj.amount;
                break;
    }
}

Do this for all your variables. I don’t know if it works but it should, if not let me know and I will try to help.

Thanks. I’ll try it.

If you change a public variable in play mode, it will revert back to the original value when you stop play mode. If this is OK (you’re just testing things and you want to see the values in the Inspector as you do), then no worries. If you want them to persist, you’ll have to change how things are set up.