How to check when a bool changes value?

Hi,
I’ve written a script that allows my character to fly if not grounded (kind of like a double jump) as long as the “w” key is held down and the “flytime” variable is above zero, which works exactly how i’d like. The one problem is that as long as flytime is above zero, the player can press “w” any amount of times and cause the function to do its thing. I’d like it only to be able to be pressed once, but I just can’t figure out the logic. heres the code (I’ve omitted all the particle effects, audio and physics commands):

void FixedUpdate ()
		{
			if (Input.GetKey (KeyCode.W) && flytime > 0f && !IsGrounded) 
			{
				HandleFlyTime ();
				IsFlying = true;
			} 
			else 
			{
				IsFlying = false;
			}
		} 

		void HandleFlyTime ()
		{
			flytime -= 2.5f * Time.deltaTime;
        }

Thanks!!!

The best thing you should use is a bool property. This allows you to do checks and run functions when you change its value.

private bool _isFlying = false;

public bool IsFlying
{
 get {return _isFlying;}
 set 
 {
  if (_isFlying != value)
   {
      _isFlying = value;
      // Run some function or event here
   }
 } 
}

In your code you can use the IsFlying property the same way syntaxtically as you would use a regular boolean. Properties are very powerful and can be used for any variable type.