Hey guys,
Ive managed to get a small prototype working where when the player enters a trigger then a animation is played. The issue im having is that once the animation has played the object should be destroyed but it doesnt seem to do that.
the code i have is:
private GameObject activationPortal;
Animator portalActivator;
// Use this for initialization
void Start () {
activationPortal = GameObject.Find("PortalActivate");
activationPortal.gameObject.SetActive(false);
portalActivator = activationPortal.GetComponent<Animator>();
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
Destroy(gameObject);
activationPortal.gameObject.SetActive(true);
portalActivator.Play("PortalActivation");
StartCoroutine(PortalAnim(portalActivator.GetCurrentAnimatorStateInfo(0).length));
}
}
public IEnumerator PortalAnim(float waitTime)
{
yield return new WaitForSeconds(waitTime);
Destroy(activationPortal);
}
For some reason the Destroy(activationPortal);
is never reached.
Unless ive done something wrong.
Any help will be appreciated.
Thanks!