- Home /
Need help with animations & melee attack
So I have spent the past 3 hours trying to set up animations for moving and then animations for moving+attacking. I have 1 animator layer for basic movement stuff, and then a second animator layer for movement + attacking.
This is the code that I have in my MeleePlayerController that specifically deals with this:
if (currentGun) { //SHOOTING/ATTACKING
if (Input.GetButtonDown ("Shoot")) {
Melee.meleeAttacking = true;
anim.SetLayerWeight (0, 0);
anim.SetLayerWeight (1, 1);
} else {
anim.SetLayerWeight (0, 1);
anim.SetLayerWeight (1, 0);
}
}
And here is the 'Melee' script that it is referencing:
public float damage;
static public bool meleeAttacking;
public GameObject player;
private Animator playerAnimator;
void Start () {
meleeAttacking = false;
playerAnimator = player.GetComponent<Animator> ();
}
void Update () {
if(!playerAnimator.GetCurrentAnimatorStateInfo(1).IsName("Melee_Attack"))
{
meleeAttacking = false;
playerAnimator.SetLayerWeight (0, 1);
playerAnimator.SetLayerWeight (1, 0);
}
}
void OnTriggerEnter(Collider col)
{
if (meleeAttacking) {
if (col.gameObject.tag == "Enemy") {
col.GetComponent<BasicEnemy> ().TakeDamage (damage);
}
}
}
}
My issue so far is that
A) The animations on my second layer (layer 1) are not playing all the way through (i.e the melee attacking animation). B) No damage is being done to the enemy.
I have been trying to get this to work for hours with no luck and was wondering if I could get any pointers or help on this. Anything would be great!
Answer by Zoogyburger · Feb 16, 2016 at 05:22 PM
These tutorials might help you: https://www.youtube.com/watch?v=Pk3GCgaNVTY∈dex=1&list=PLiyfvmtjWC_X6e0EYLPczO9tNCkm2dzkm