// Use this for initialization void Start() { facingRight = true; myRigidbody = GetComponent <Rigidbody2D>(); myAnimator = GetComponent <Animator>(); myHealth = GetComponent <Health_Lv1>(); swapWeapon(defaultWeapon); //starting weapon currentLifes = lifes; }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag != "Player") { Health_Lv1 enemyHealth = collision.gameObject.GetComponent <Health_Lv1>(); if (enemyHealth != null) { enemyHealth.TakeDamage(damage); } Destroy(gameObject); return; } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.name == "Walls") { Flip(); } if (collision.tag == "Player") { Health_Lv1 playerHealth = collision.gameObject.GetComponent <Health_Lv1>(); if (playerHealth != null) { playerHealth.TakeDamage(damage); collision.GetComponent <Player_Lv1>().KnockBack(transform); collision.GetComponent <Rigidbody2D>().AddForce(Vector2.left); } } }