// Update is called once per frame void Update() { Collider2D[] firsHit = new Collider2D[1]; col.OverlapCollider(new ContactFilter2D(), firsHit); if (firsHit[0] != null) { if (baddieProjectile) { if (firsHit[0].gameObject.tag.Equals("Player")) { // Object.Destroy(firsHit[0].gameObject); mainChar b = firsHit[0].GetComponent <mainChar>(); b.takeDamage(damage); Object.Destroy(gameObject); } if (!firsHit[0].gameObject.tag.Equals("Baddie")) { Object.Destroy(gameObject); } } else { if (firsHit[0].gameObject.tag.Equals("Baddie")) { // Object.Destroy(firsHit[0].gameObject); Baddie b = firsHit[0].GetComponent <Baddie>(); if (b.hp - damage < 0) { int newdamage = damage - b.hp; b.takeDamg(damage); damage = newdamage; } else { b.takeDamg(damage); hits = peirce; } hits++; } if (!firsHit[0].gameObject.tag.Equals("Player") && hits > peirce || firsHit[0].gameObject.tag.Equals("Wall")) { Object.Destroy(gameObject); } } } transform.Translate(new Vector3(Time.deltaTime * speed * 50, 0, 0)); if (!render.isVisible) { Object.Destroy(gameObject); } }
public bool Attack(Vector2 position, float angle) { bool attacked = false; if (timeSinceLastAttack > attackSpeed * attackSpeedMod) { attacked = true; timeSinceLastAttack = 0; //Move to same place transform.position = position; if (angle >= -45 && angle < 45) { // Debug.Log("Right"); transform.position = new Vector3(transform.position.x + attackOffSet.x, transform.position.y, transform.position.z); transform.rotation = Quaternion.Euler(0, 0, 0); } if (angle >= 45 && angle < 135) { //Debug.Log("Up"); transform.position = new Vector3(transform.position.x, transform.position.y + attackOffSet.y, transform.position.z); transform.rotation = Quaternion.Euler(0, 0, 90); } if (angle >= 135 || angle < -135) { /// Debug.Log("Left"); transform.position = new Vector3(transform.position.x - attackOffSet.x, transform.position.y, transform.position.z); transform.rotation = Quaternion.Euler(0, 0, 180); } if (angle >= -135 && angle < -45) { // Debug.Log("Down"); transform.position = new Vector3(transform.position.x, transform.position.y - attackOffSet.y, transform.position.z); transform.rotation = Quaternion.Euler(0, 0, 270); } Collider2D[] results = new Collider2D[cleaveNumber]; col.OverlapCollider(new ContactFilter2D(), results); int hit = 0; for (int i = 0; i < results.Length; i++) { if (results[i] != null && !results[i].gameObject.tag.Equals("Player")) { hit++; if (results[i].gameObject.tag.Equals("Baddie")) { //Object.Destroy(results[i].gameObject); Baddie b = results[i].GetComponent <Baddie>(); b.takeDamg(attackDamage); } } } } return(attacked); }