How to Instantiate an object one at a time when button down?

Hello Unity community! I need help please. Please look at the following lines of code and I will explain what I’m trying to do.



		animator.Play ("ycat");
		Instantiate (prefabY);
		Instantiate (Yak);
		audio.PlayOneShot (ySound);

		animator.Play ("ccat");
		Instantiate (prefabZ);
		Instantiate (Zebra);
		audio.PlayOneShot (zSound);



Okay, If I press the Z Key a zebra will instantiate. If I press the Y Key a Yak will instantiate. I want it to be that if Z is pressed instantiate the zebra for 2 seconds then destroy then allow any animal to instantiate to its corresponding key. Right now every animal pops up as many times as I press on keys. Does that make any sense? Any help is appreciated please.

You could create a boolean flag that becomes true everytime a key is pressed. Then create a new void , under which you could make that boolean become false. So now everytime you press a key, that boolean is now becoming true. Now give an Invoke command with the time interval to be 2 secs. Also, you will need to add an if statement inside every key press code that will check if the boolean is true or not, and if it is true, it wont instantiate the animals else, it will. Hope it is not hard to understand.