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.
//////////////////////////////////////////////////////////////////////////////////////////////
if(Input.GetKeyDown(KeyCode.Y)){
animator.Play ("ycat");
Instantiate (prefabY);
Instantiate (Yak);
audio.PlayOneShot (ySound);
}
if(Input.GetKeyDown(KeyCode.Z)){
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.