Detect If User Set Value And Not Code C#

Good Morning, I have 2 float feilds 1. x 2.y and one bool. If the bool = true then if x changes it changes y value to equal x likewise the other way around if y changes then x changes value to equal y. The problem is solving when the user is changing the value and not the code.

Please see the code bellow: The current code only checks for a changed value and does not check if the user changed it or the code changed it.

using UnityEngine;
using System.Collections;

public class Sample : MonoBehaviour {

public bool Uniform;
public float x;
public float y;

public float oldx;
public float oldy;

void Update() {
if (Uniform == true) {
if (x != oldx) 
y = x;
oldx = x;
}
else if (y != oldy) {
x = y;
oldy = y;
}
}
}
}

Something like this should work:

    public bool Uniform;
	private float x;
	public float X
	{
		get { return x; }
		set 
		{
			if(Uniform)
			{
				y = x = value;
			}
			else
				x = value;
		}
	}
	private float y;
	public float Y
	{
		get { return y; }
		set 
		{
			if(Uniform)
			{
				x = y = value;
			}
			else
				y = value;
		}
	}

when you need to change x or y from script, do it using the functions.

void ChangeX(){
//do whatever you want when you want to change x with a script
}

void ChangeY(){
do whatever you want when you need to change y via the script
}

also, you can use

        private bool x = false;  //don't expose x in the editor (we made it private)

        public bool x_seen_in_editor{   //instead we expose the getter / setter variable
         set{ //do whatever you want here (envoke any functions) and then assign the passed value to the "hidden", real x
               x = value;}
         get{ //do whatever you want here (envoke any functions) and then return the value of the "hidden", real x
               return x;}
        }