Run Code Once... is there an error with this code?

void Update()
{
if (Input.GetKeyDown (KeyCode.A))
{
if (!_woot)
{
_woot = true;
Debug.Log (_woot);
StartCoroutine(derp());
}
}
}

	IEnumerator derp()
	{
		yield return new WaitForSeconds(Time.deltaTime);
		_woot = false;
	}

This seems like it should be running once, but my Debug.Log is ticking twice.

Does anyone know why?

That’s not possible for multiple reasons. First Input.GetKeyDown will only be true for the frame the keypress happens, so it runs naturally only once. Your “_woot” variable in addition ensures that it only runs that code one time. The variable is quite useless since you set it back to false the next frame (or the one after depending on FPS fluctuations).

The only reason why your Debug.Log executes two times is:

“You have attached this script two times, either to the same or to different gameobjects”.

Each instance of the script has it’s own “_woot” variable and since both instances will process Update each frame, both will react to GetKeyDown.