Answer the question
In order to leave comments, you need to log in
Damage animation problem, how to solve it?
Good day, can you please help to implement the damage animation when in contact with the enemy, here is my CollisionDamage script:
public class CollisionDamage : MonoBehaviour
{
public int damage =10;
[SerializeField] private Animator animator;
private Health health;
[SerializeField] private SpriteRenderer spriteRenderer;
private float direction;
public float Direction
{
get{ return direction; }
}
private void OnCollisionEnter2D(Collision2D col)
{
if (GameManager.Instance.collisionContainer.ContainsKey(col.gameObject))
{
health = GameManager.Instance.collisionContainer[col.gameObject];
direction = (col.transform.position - transform.position).x;
animator.SetFloat("Direction", Mathf.Abs(direction));
}
}
public void SetDamage()
{
if (health!=null)
health.TakeHit(damage);
health =null;
direction = 0;
animator.SetFloat("Direction",0F);
}
}
animator.SetBool("isGrounded",groundDetection.isGrounded);
if(!isJumping && !groundDetection.isGrounded)
{
animator.SetTrigger("StartFall");
animator.SetBool("Damaged",false);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question