public works but if private with Get/Set doesn't work

I’m working on tools for my game. Everything was working fine till i decide to put some variables of my Spawn script to private and add GetSet function.

I cleaned the scripts to make it easy to understand

(Doesn’t work)Trying to script this way:

public class SpawnTool : EditorWindow
{
	void OnGUI ()
	{
		Spawn target = Selection.activeGameObject.GetComponent ("Spawn") as Spawn;
		
		target.GetSetWaitTime = EditorGUILayout.Slider ("Wait Time", target.GetSetWaitTime, 0.0f, 30.0f);
	}
 }

 public class Spawn : MonoBehaviour
{
	private float waitTime;

    public float GetSetWaitTime {
	   get {
		   return waitTime;
	   }
	   set {
		   waitTime = value;
	   }
   }
}

(Work very well)Working way:

public class SpawnTool : EditorWindow
{
	void OnGUI ()
	{
		Spawn target = Selection.activeGameObject.GetComponent ("Spawn") as Spawn;
		
		target.waitTime = EditorGUILayout.Slider ("Wait Time", target.waitTime, 0.0f, 30.0f);
	}
 }

public class Spawn : MonoBehaviour
{
	public float waitTime;

}

When i set the slider with my SpawnTool, it set the waitTime value in Spawn Script. But when i do play the waitTime jump to 0 if my waitTime is private. While my waitTime is public (as you can see we my working script), everything is working well.

With my Get/Set, it suppose to do the same as if my waitTime variable was public no?

I’m really not a pro in programmation and in english :S. But I wanna know what i’m doing wrong. I use Get/Set on other script and it works well.

Thank you in advance for your help.
If it’s too hard to understand my question let me know please.

Your Get/Set is working fine (but most people would name the property waitTime and the private var _waitTime.)

Unity only perma-saves public or [serializable] things – not regular private vars. Making waitTime public would fix it (but defeat the purpose of the getter/setter.) It’s a real pain and there are some hacks if you search for serializable. It’s actually .NET weirdness, not just Unity.