Skip to content

Instantly share code, notes, and snippets.

@ygjb
Created October 8, 2015 15:28
Show Gist options
  • Save ygjb/3095332b2107bc6489eb to your computer and use it in GitHub Desktop.
Save ygjb/3095332b2107bc6489eb to your computer and use it in GitHub Desktop.
void ClearField()
{
GameObject[] targets = GameObject.FindGameObjectsWithTag("Target");
foreach (GameObject target in targets)
{
target.GetComponent<TargetExit>().Exit();
}
}
public void Exit()
{
if (this.GetComponent<Animator>() == null)
// no Animator so just destroy right away
KillTarget();
else if (!startDestroy)
{
// set startDestroy to true so this code will not run a second time
startDestroy = true;
// trigger the Animator to make the "Exit" transition
this.GetComponent<Animator>().SetTrigger("Exit");
// Call KillTarget function after exitAnimationSeconds to give time for animation to play
Invoke("KillTarget", exitAnimationSeconds);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment