Skip to content

Instantly share code, notes, and snippets.

@DomDomHaas
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DomDomHaas/f73cb01c03c9ee23bf41 to your computer and use it in GitHub Desktop.
Save DomDomHaas/f73cb01c03c9ee23bf41 to your computer and use it in GitHub Desktop.
AnimationEvents in Unity
using UnityEngine;
using System.Collections;
public class EnemyAnimationControl : MonoBehaviour
{
private Animator animControl;
private GameObject attackCollider;
private GameObject checkCollider;
private EnemyControl enemyCont;
void Awake ()
{
animControl = GetComponent<Animator> ();
enemyCont = this.gameObject.transform.parent.GetComponent<EnemyControl> ();
attackCollider = UnityShortcuts.getFirstChildWithTag (this.gameObject.transform.parent.gameObject, "AttackCollider");
checkCollider = UnityShortcuts.getFirstChildWithTag (this.gameObject.transform.parent.gameObject, "CheckAttack");
if (this.enabled) {
// use the collider because of the BossPoolManager
//attackCollider.SetActive (false);
attackCollider.collider.enabled = false;
}
}
void Start ()
{
StartCoroutine (UnityShortcuts.MinimalMoveToRetrigger (this.attackCollider));
}
void Update ()
{
if (this.enemyCont.isDead && this.enemyCont.attackAbility) {
if (this.attackCollider.collider.enabled || this.checkCollider.collider.enabled) {
attackCollider.collider.enabled = false;
checkCollider.collider.enabled = false;
//attackCollider.GetComponent<Killable> ().attackPoints.selfValue = 0;
//attackCollider.GetComponent<Killable> ().enabled = false;
}
}
}
void OnAttackStart ()
{
//attackCollider.SetActive (true);
attackCollider.collider.enabled = true;
MasterAudio.PlaySound3DFollowTransform ("Enemy_Attack", this.enemyCont.transform);
}
void OnAttackEnd ()
{
//attackCollider.SetActive (false);
attackCollider.collider.enabled = false;
}
void OnAttackAnimationEnd ()
{
this.animControl.SetBool ("isAttacking", false);
// go back to following
enemyCont.doFollow ();
}
void OnFootstepEnemy ()
{
MasterAudio.PlaySound3DFollowTransform ("Enemy_Footstep", this.enemyCont.transform);
}
void OnEnemyDie ()
{
MasterAudio.PlaySound3DFollowTransform ("Enemy_Die", this.enemyCont.transform);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment