void Attack() { isAttackPressed = true; Collider2D target = Physics2D.OverlapCircle(attackPoint.position, attackRange, enemyLayers); EnemyHP enemy = null; try { enemy = target.GetComponent <EnemyHP>(); } catch { } if (enemy != null) { enemy.GetComponent <EnemyHP>().TakeDamage(damage); DamageIndicator.Create(enemy.transform.position, damage); int attackIndex = Random.Range(1, 4); string soundClip = string.Concat("Swidle", attackIndex.ToString()); FindObjectOfType <AudioManager>().Play(soundClip); } else { int attackIndex = Random.Range(1, 4); string soundClip = string.Concat("Swidle", attackIndex.ToString()); FindObjectOfType <AudioManager>().Play(soundClip); } }
void Attack() { isAttackPressed = true; Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, enemyLayers); foreach (Collider2D enemy in hitEnemies) { if (enemy.GetComponent <EnemyHP>()) { Instantiate(slashEffect, enemy.transform.position, enemy.transform.rotation, enemy.transform); enemy.GetComponent <EnemyHP>().TakeDamage(damage); DamageIndicator.Create(enemy.transform.position, damage); } else if (enemy.GetComponent <EnemyBullet>()) { Instantiate(slashEffect, enemy.transform.position, transform.rotation); FindObjectOfType <AudioManager>().Play("Deflect"); enemy.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0); enemy.GetComponent <Rigidbody2D>().AddForce(attackPoint.right * enemy.GetComponent <EnemyBullet>().bulletSpeed * 2); EnemyBullet enemyBullet = enemy.GetComponent <EnemyBullet>(); enemyBullet.deflected = true; enemyBullet.bulletDamage = (int)damage; } } // Sound int attackIndex = Random.Range(1, 4); string soundClip = string.Concat("Blade", attackIndex.ToString()); FindObjectOfType <AudioManager>().Play(soundClip); }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.transform.tag == "Player") { Rigidbody2D rb = collision.GetComponent <Rigidbody2D>(); rb.drag = 30f; } //takingDamage = true; if (collision) { if (collision.tag == "enemy") { if (collision.GetComponent <EnemyHP>()) { EnemyHP enemy = collision.GetComponent <EnemyHP>(); enemy.repeatingDamageAmount = lavaDamageEnemy; enemy.damageRate = .5f; enemy.takingDamage = true; DamageIndicator.Create(collision.transform.position, lavaDamageEnemy); } } StartCoroutine(DealDamage(collision.gameObject)); } Instantiate(splash, collision.transform.position, Quaternion.Euler(-90, 0, 0)); }
private void FixedUpdate() { if (dashing) { box.enabled = false; capsule.enabled = true; if (hitEnemies.Length > 0) { foreach (RaycastHit2D enemy in hitEnemies) { if (enemy.transform.tag != "enemy") { break; } else if (Vector2.Distance(transform.position, enemy.transform.position) <= Vector2.Distance(transform.position, closesetTarget)) { enemy.transform.GetComponent <EnemyHP>().TakeDamage(dashDamage); DamageIndicator.Create(enemy.transform.position, dashDamage); } } } onCooldown = true; dashing = false; } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.layer != 13 && collision.gameObject.layer != 14 && collision.gameObject.layer != 17 && collision.gameObject.layer != 21) { GetComponent <CircleCollider2D>().enabled = false; rb.velocity = Vector2.zero; transform.parent = collision.transform; hasHit = true; rb.isKinematic = true; gameObject.layer = 14; GetComponent <TrailRenderer>().emitting = false; } EnemyHP enemy = collision.GetComponent <EnemyHP>(); if (enemy != null) { enemy.TakeDamage(damage); DamageIndicator.Create(enemy.transform.position, damage); FindObjectOfType <AudioManager>().Play("ArrowIn"); } }
// Update is called once per frame void Update() { landingSmoke.transform.position = playerController.groundCheck.position + new Vector3(0, 1.4f, 0); if (Input.GetKeyDown(KeyCode.LeftShift)) { playerController.GetComponent <Rigidbody2D>().velocity = new Vector2(0, playerController.GetComponent <Rigidbody2D>().velocity.y); } if (playerController.grounded) { if (!landed) { if (jumpForce > jumpChargeToStun) { Collider2D[] enemies = Physics2D.OverlapAreaAll(new Vector2(transform.position.x - stunRadius, transform.position.y), new Vector2(transform.position.x + stunRadius, transform.position.y - transform.localScale.y / 2), playerController.enemyMask); foreach (Collider2D enemy in enemies) { enemy.GetComponent <Rigidbody2D>().AddForce(Vector2.up * stunHeight); enemy.GetComponent <EnemyHP>().TakeDamage(stunDamage); DamageIndicator.Create(enemy.transform.position, stunDamage); } landingSmoke.Play(); FindObjectOfType <AudioManager>().Play("FallHard"); try { CameraShaker.Instance.ShakeOnce(player.magnitude * 3, player.roughness, player.fadein, player.fadeout); } catch { } } jumpForce = 0; landed = true; } } else { landed = false; } if (Input.GetButtonDown("Jump")) { chargingJump = true; } if (Input.GetButtonUp("Jump")) { jumpForce = jumpCharge; dustPS.Play(); jumpCharge = 0; chargingJump = false; playerController.zoomMagnifier = 0; } playerController.jumpMultiplier = jumpCharge; jumpChargeController.SetHeight(jumpCharge); }
void OnTriggerEnter2D(Collider2D other) { if (other.name != "Player") { EnemyHP enemy = other.GetComponent <EnemyHP>(); if (enemy != null) { enemy.TakeDamage(damage); DamageIndicator.Create(enemy.transform.position, damage); } Instantiate(destroyEffect, transform.position, transform.rotation); if (Time.time > timeToDestroy) { timeToDestroy = Time.time + 10; Destroy(gameObject); } } }
private void OnCollisionEnter2D(Collision2D collision) { if (collision != null) { if (collision.transform.tag != "Player") { rb.velocity = Vector2.zero; collided = true; } if (collision.transform.tag == "enemy" && transform.childCount <= 1) { enemyHooked = true; enemy = collision.transform; enemy.transform.position = transform.position; collision.transform.GetComponent <EnemyHP>().TakeDamage(hookDamage); DamageIndicator.Create(collision.transform.position, hookDamage); } Physics2D.IgnoreCollision(GetComponent <BoxCollider2D>(), collision.collider); } }
void OnTriggerEnter2D(Collider2D other) { if (!deflected) { Player character = other.GetComponent <Player>(); try { character.TakeDamage(bulletDamage); } catch { } } else { EnemyHP character = other.GetComponent <EnemyHP>(); try { character.TakeDamage(bulletDamage); DamageIndicator.Create(character.transform.position, bulletDamage); } catch { } } Instantiate(destroyParticles, transform.position, Quaternion.identity); Destroy(gameObject); }