public void DamageEnemy(int damage) { stats.Health -= damage; if (stats.Health <= 0) { WrathMaster.KillEnemy(this); } }
void OnCollisionEnter2D(Collision2D coll) { if (coll.gameObject.tag == "Enemy") { WrathEnemy enemy = coll.gameObject.GetComponent <WrathEnemy> (); GameObject body = GetComponent <Collider2D> ().gameObject; GameObject bodyParent = body.transform.parent.gameObject; bodyParent.GetComponent <WrathCharacter> ().DamagePlayer(Damage); Debug.Log("Player took" + "34" + "damage."); WrathMaster.KillEnemy(enemy); } }
void Update() { if (player == null) { WrathMaster.KillEnemy(this); } Vector2 difference = player.position - transform.position; //subtracting the position of the player from the mouse position float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg; // find the angle in degrees transform.rotation = Quaternion.Euler(0f, 0f, rotZ + rotationOffset); transform.position += transform.up * stats.moveSpeed * Time.deltaTime; if (isShooter) { if (Time.time > timeToFire) { timeToFire = Time.time + 1 / stats.fireRate; Shoot(); } } }