protected void OnTriggerEnter(Collider other) { TargetProjectile targetProj = other.GetComponentInChildren <TargetProjectile>(); if (targetProj != null) { Vector3 dir = targetProj.transform.position - Player.Instance.transform.position; dir.y = 0.0f; dir = dir.normalized; targetProj.Hit(Player.Instance.gameObject, dir * Knockback); return; } if (!enemiesHit.Contains(other.gameObject)) { Enemy enemy = other.GetComponentInChildren <Enemy>(); if (enemy == null) { enemy = other.GetComponentInParent <Enemy>(); } if (enemy != null) { enemiesHit.Add(other.gameObject); float damage = enemy.health.TakeDamage(this.Type, this.Damage); bool isDead = enemy.health.IsDead(); if (damage > 0) { if (isDead) { Vector3 forward = Player.Instance.camera.transform.forward; //forward = forward.normalized; enemy.Explode(forward * RigidbodyKnockback, Player.Instance.camera.transform.position); } else { Vector3 forward = Player.Instance.camera.transform.forward; forward.y = 0.0f; forward = forward.normalized; enemy.Knockback(forward * Knockback, KnockbackDuration); } } } else { Rigidbody rb = other.GetComponentInChildren <Rigidbody>(); if (rb == null) { rb = other.GetComponentInParent <Rigidbody>(); } if (rb != null) { Vector3 forward = Player.Instance.camera.transform.forward; //forward = forward.normalized; rb.AddForce(forward * RigidbodyKnockback, ForceMode.Impulse); } } } }
private void ReceiveTarget(TargetReceiver receiver, GameObject meteor) { if (currProjectile == null) { return; } print("Received " + meteor.name); if (ReceiveCount == 0) { currProjectile.OnHit -= HitTarget; currProjectile.OnMiss -= MissTarget; currProjectile = null; GameObject shield = Shields[0]; Shields.RemoveAt(0); Destroy(shield.gameObject); Destroy(meteor.gameObject); if (Shields.Count == 0) { Aura.SetActive(false); stateMachine.ChangeState("Boss4_MeteorShower"); } else { StartCoroutine(SpawnProjectileDelay()); } } else { ReceiveCount--; Vector3 dir = Vector3.up; dir *= ProjectileImpulse; //currProjectile.SpeedOverTime -= .01f; currProjectile.Hit(this.gameObject, dir); } }
private void SlamAttack() { Player.Instance.CanWalk = true; Player.Instance.velocity.y = PlayerJump; DustEffect.Play(); AudioManager.Instance.PlaySoundWithParent("hammer", ESoundChannel.SFX, gameObject); int layermask = PhysicsCollisionMatrix.Instance.MaskForLayer(this.gameObject.layer); Collider[] colliders = Physics.OverlapSphere(Player.Instance.transform.position, SlamRadius, layermask); //Collider[] colliders = Physics.OverlapSphere(SlamCenter.position, SlamRadius, layermask); foreach (Collider c in colliders) { TargetProjectile targetProj = c.GetComponentInChildren <TargetProjectile>(); if (targetProj != null) { Vector3 dir = targetProj.transform.position - Player.Instance.transform.position; dir.y = 0.0f; dir = dir.normalized; targetProj.Hit(Player.Instance.gameObject, dir * Knockback); continue; } Enemy enemy = c.GetComponentInChildren <Enemy>(); if (enemy == null) { enemy = c.GetComponentInParent <Enemy>(); } if (enemy != null) { // Damage float damage = enemy.health.TakeDamage(this.Type, this.Damage); bool isDead = enemy.health.IsDead(); // Knockback if (damage > 0) { if (isDead) { //Vector3 dir = c.transform.position - SlamCenter.position; Vector3 dir = c.transform.position - Player.Instance.transform.position; //dir.y = 0.0f; dir = dir.normalized; enemy.Explode(dir * RigidbodyKnockback, SlamCenter.position); } else { //Vector3 dir = c.transform.position - SlamCenter.position; Vector3 dir = c.transform.position - Player.Instance.transform.position; dir.y = 0.0f; dir = dir.normalized; enemy.Knockback(dir * Knockback, KnockbackDuration); } } } else { Rigidbody rb = c.GetComponentInChildren <Rigidbody>(); if (rb == null) { rb = c.GetComponentInParent <Rigidbody>(); } if (rb != null) { //Vector3 dir = c.transform.position - SlamCenter.position; Vector3 dir = c.transform.position - Player.Instance.transform.position; //dir.y = 0.0f; dir = dir.normalized; rb.AddForceAtPosition(dir * RigidbodyKnockback, SlamCenter.position, ForceMode.Impulse); } } } }