- Home /
Question by
Rebnerod · Sep 04, 2013 at 05:49 PM ·
Melee Attack
I'm trying to make a melee attack so I put rigidbodies(iskinematic) to object and sword. I also added coliders but the problem is sword may touch the collider when the character moves a bit without waiting my hit command. What can i add to my code to wait for the animation to finish? Here is my code:
using UnityEngine;
using System.Collections;
public class Health : MonoBehaviour
{
public float health;
void Start()
{
health = 100;
}
void Update ()
{
if (health < 0)
{
Destroy(this.gameObject);
}
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Weapon")
{
health -= 10;
}
}
}
Comment
Best Answer
Answer by Rebnerod · Sep 04, 2013 at 11:04 PM
Ok. Find the answer.
First I added a gameObject called target
public GameObject target;
than set it's value
target = GameObject.FindGameObjectWithTag("Player");
than checked animation status with
if (target.animation.IsPlaying("attack01"))
Those 3 helped me to check animation and stop damages because of regular touches. I hope this helps you too.
Your answer
![](https://koobas.hobune.stream/wayback/20220613113600im_/https://answers.unity.com/themes/thub/images/avi.jpg)