How can I make one variable affect others in custom inspector?

For example, I have a custom inspector like this

public override void OnInspectorGUI()
{ 
     a= EditorGUILayout.FloatField("A", a); 
     lock =EditorGUILayout.Toggle("Lock",lock); 
     b= EditorGUILayout.FloatField("B", b);
 }

How do I make adjusting a also change b and vice versa when lock is true?

Hello, maybe this will help

As you should know OnInspectorGUI runs fairly often, lets say every frame or so.
then you have two floats A and B? and a bool called lock. you require A & B to be adjusted at a given ratio when _lock true.

lock is a C# Keyword so you will need to rename it, _lock will do.

a= EditorGUILayout.FloatField("A", a); assisngs A to the return value of EditorGUILAyout.FloatFeild() This is the same with B. so basically all you need to do is check if lock is true then modify the return value of A so B remains the same.
To know how much they adjust by just make some temporary variable that store the old values of A and B to calculate how we should modify them

 public override void OnInspectorGUI()
 { 
     //Store unmodified values of A and B
      float old_a = a;
     float old_b = b;
     
       //Modify them using Editor Functions
      a= EditorGUILayout.FloatField("A", a); 
      lock =EditorGUILayout.Toggle("Lock",lock); 
      b= EditorGUILayout.FloatField("B", b);

     // Check if _lock is true
     if(_lock) {
          //if A was adjusted
          if(old_a != a) {
               //modify B based on A
               b = (old_b / old_a) * a
             }
        //if B was adjusted but not A
        else if(old_b != b) {
                  //Modify A based on B
                  a = (old_a / old_b) * b;
           }
     }
  }

This code firstly assigns two new variables , old_a and old_b. which are assigned to the original counterparts. then your original code runs, changing the values of a and b. Once this is done, an If Statement run if _lock is true, if it is true. two more If statements compare the values of a,b and old_a,old_b. if a or B has changed, we calculate a new value for the unchanged one.

Hope it Helps

DISCLAIMER!
the formulas used to modify A and B are ones i made on the spot. they will probably produce weird results.

Sources:

try this

 public override void OnInspectorGUI(){
 if(lock){
    a=b;
    b=a;
 }
}

this will change a to b and b to a when lock is true