// When colliding with another object private void OnTriggerEnter2D(Collider2D other) { ICanBeDamaged victim = other.gameObject.GetComponent <ICanBeDamaged>(); if (victim != null && !isColliding) { isColliding = true; victim.TakeDamage(baseDamage); } if (!isContinuous) { Destroy(gameObject); } }
public bool ExecuteAttack(Vector3 target) { Vector3 actorPos = actorPosition.position; Vector3 targetModified = target; targetModified.z = 0; Vector3 difference = (targetModified - actorPosition.position).normalized; Vector2 overlapSpawn = new Vector2(); Vector2 overlapSize = new Vector2(1.5f, 1f); int overlapDegrees = 0; // If pointing up if (difference.y > 0 && (difference.x <= midPoint && difference.x >= -midPoint)) { overlapSpawn = new Vector2(actorPos.x, actorPos.y + 0.5f); } // If pointing down else if (difference.y < 0 && ((difference.x <= midPoint && difference.x >= -midPoint))) { overlapSpawn = new Vector2(actorPos.x, actorPos.y - 1f); } // If pointing right else if (difference.x > 0 && (difference.y <= midPoint && difference.y >= -midPoint)) { overlapDegrees = 90; overlapSpawn = new Vector2(actorPos.x + 0.5f, actorPos.y); } // If pointing left else { overlapDegrees = 90; overlapSpawn = new Vector2(actorPos.x - 0.5f, actorPos.y); } bool gottaHit = false; // Get all actors in melee zone Collider2D[] victims = Physics2D.OverlapBoxAll(overlapSpawn, overlapSize, overlapDegrees, LayerMask.GetMask("Characters", "Player")); // If the actor isn't of same type as this actor, deal damage foreach (Collider2D collider in victims) { ICanBeDamaged victim = collider.GetComponent <ICanBeDamaged>(); if (victim != null && collider.gameObject.tag != actorPosition.gameObject.tag) { victim.TakeDamage(damageAugment.ModifiedDmg(this.damage)); gottaHit = true; } } return(gottaHit); }
public bool ExecuteAttack(Vector3 tileCoords, int dmgMod, int rangeMod) { Transform target = TileSystem.ObjectAtTile(tileCoords); if (target != null && TileSystem.TileDistance(target.position, actorPosition.position) <= (range + rangeMod)) { ICanBeDamaged victim = target.GetComponent <ICanBeDamaged>(); if (victim != null) { victim.TakeDamage(damage + dmgMod); return(true); } } return(false); }
public override bool ExecuteAttack(Vector3 tileCoords, int modifier) { Transform actorPosition = gameObject.transform; Transform target = TileSystem.ObjectAtTile(tileCoords); if (target != null && TileSystem.TileDistance(target.position, actorPosition.position) <= range) { ICanBeDamaged victim = target.GetComponent <ICanBeDamaged>(); if (victim != null) { victim.TakeDamage(damage * modifier); return(true); } } return(false); }
private void DealDamage() { Vector3 halfArea = new Vector3(areaSquare / 2, areaSquare / 2, 0); Collider2D[] hitColliders2d = new Collider2D[10]; ContactFilter2D layer = new ContactFilter2D(); layer.SetLayerMask(LayerMask.GetMask("Characters")); // Only detect Character objects int victims = Physics2D.OverlapBox(transform.position, halfArea, 0, layer, hitColliders2d); // Number of victims // For each victim, deal damage for (int i = 0; i < victims; i++) { ICanBeDamaged victim = hitColliders2d[i].gameObject.GetComponent <ICanBeDamaged>(); if (victim != null) { victim.TakeDamage(damagePerTick); } } }
public void BasicAttack(ICanBeDamaged target) { target.TakeDamage(attackPower); }