private IEnumerator Explosive(float time) { // Prepare explosive Skeleton.loop = true; Skeleton.AnimationName = EnemyAnimationName.Attack; IsAlive = false; yield return(new WaitForSeconds(time)); // Explosive RaycastHit2D[] hits = Physics2D.CircleCastAll(Collider.bounds.center, _radiusExplosive, Vector2.zero); foreach (var hit in hits) { if (hit.transform.CompareTag(ObjectTag.Player) || hit.transform.CompareTag(ObjectTag.Enemy)) { IAttackedable character = hit.transform.GetComponent <IAttackedable>(); if (character != null) { character.Attacked(AttackType.Hit); } } else if (hit.transform.CompareTag(ObjectTag.TileBlock)) { IGoreable g = hit.transform.GetComponent <IGoreable>(); if (g != null) { g.Gore(); } } } Destroy(); }
/// <summary> /// Create raycast to check is character stand on block /// </summary> public virtual void CheckObjectStand() { Vector2 boxSize = Collider.bounds.size; boxSize.y = .1f; Vector2 position = new Vector2(Collider.bounds.center.x, Collider.bounds.min.y - boxSize.y); RaycastHit2D[] hits = Physics2D.BoxCastAll(position, boxSize, 0f, Vector2.zero); bool[] itemBlock = new bool[TileBlockStand.Count]; for (int i = 0; i < itemBlock.Length; i++) { itemBlock[i] = false; } foreach (var hit in hits) { if (hit.transform.CompareTag(ObjectTag.TileBlock)) { IGoreable t = hit.transform.GetComponent <IGoreable>(); int indexTile = TileBlockStand.IndexOf(t); if (t != null && indexTile == -1) { t.Gored += Attacked; TileBlockStand.Add(t); } else if (indexTile != -1) { itemBlock[indexTile] = true; } } else if (hit.transform.CompareTag(ObjectTag.Platform)) { if (_platform) { continue; } Debug.Log("Stand on platform"); _platform = hit.transform.GetComponent <Platform>(); _oldPlatformPosition = _platform.Trans.position; } } for (int i = itemBlock.Length - 1; 0 <= i; i--) { if (!itemBlock[i]) { TileBlockStand[i].Gored -= Attacked; TileBlockStand.RemoveAt(i); } } }
/// <summary> /// Create damage when role /// </summary> protected void RoleDamage() { Vector2 size = Collider.bounds.size; Vector2 position = Collider.bounds.center; size.y *= .2f; size.x *= .8f; position.x += IsRight ? size.x / 4 : -size.x / 4; RaycastHit2D[] hits = Physics2D.BoxCastAll(position, size, 0, Vector2.zero); bool changeDirection = false; foreach (var hit in hits) { if (hit.transform.CompareTag(ObjectTag.Player)) { IAttackedable character = hit.transform.GetComponent <IAttackedable>(); character.Attacked(AttackType.Reflect, this); } else if (hit.transform.CompareTag(ObjectTag.Enemy)) { if (hit.transform.name == Trans.name) { continue; } IAttackedable character = hit.transform.GetComponent <IAttackedable>(); character.Attacked(AttackType.Reflect); } else if (hit.transform.CompareTag(ObjectTag.TileBlock)) { changeDirection = true; IGoreable tile = hit.transform.GetComponent <IGoreable>(); tile.Gore(); } else if (hit.transform.CompareTag(ObjectTag.Ground)) { changeDirection = true; } } if (changeDirection) { IsRight = !IsRight; } }