Collsions during animations
Hello there im new in unity and i had a problem. I putted an attack animation to a character and id does the animation properly when y press the specified button. The problem is that i have a sword attached to a hand and it moves with the hand during the animation but this sword (with a box collider) doesnt detect any collision. I have a script in that sword so when i attack the other objet looses 1 point of life.
public class AtaqueArma : MonoBehaviour { public GameObject enemigo; public float daño = 1; // Use this for initialization void Start () {
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter(Collision objeto){
enemigo = objeto.gameObject;
enemigo.GetComponent<MovEnemigo>().vida -= daño ;
}
}
The variables are in spanish ( vida is life, and daño is damage)
@maximum.870 I would definitely put this in -
void OnCollisionEnter(Collision objeto){
enemigo = objeto.gameObject;
enemigo.GetComponent<$$anonymous$$ovEnemigo>().vida -= daño ;
Debug.Log("Hit");
This way it will print out in the console to tell you if your OnCollisionEnter is working on the particular object. Next, I would recommend you put an enemy next to the sword and let your player keep hitting the enemy in play test, and see if there is anything missing in the Unity editor itself. Perhaps a collider is missing on the enemy?
Your answer
Follow this Question
Related Questions
Check for collision while animating 0 Answers
Rigid Body and Collision 1 Answer
Play Animation OnTriggerEnter2D 1 Answer
Free Look Camera Rig Changing Rotation 1 Answer
Use a string to call a class 2 Answers