private void OnTriggerEnter(Collider other) { if (!isHit) { int otherLayer = other.gameObject.layer; if (otherLayer == GlobalVariables.ENEMY_LAYER || otherLayer == GlobalVariables.PLAYER_LAYER) { IHealth otherHealth = other.GetComponent <IHealth>(); if (otherHealth == null) { otherHealth = other.GetComponentInParent <IHealth>(); } otherHealth.DecreaseHealth(DamageAmount, DamageType); OnHit(); } else if (otherLayer == GlobalVariables.PLAYER_MELEE_LAYER) { gameObject.layer = GlobalVariables.PLAYER_PROJECTILE_LAYER; transform.rotation = GameMan.Instance.PlayerT.rotation; projectileVerticalSpeed = projectileLaunchVerticalSpeed; StartCoroutine(DmgChange()); } else { OnHit(); } } }
private void OnTriggerEnter(Collider other) { IHealth otherHealth = other.GetComponent <IHealth>(); if (otherHealth == null) { otherHealth = other.GetComponentInParent <IHealth>(); } otherHealth.DecreaseHealth(999999, DamageType.KillTrigger); }
public virtual bool TakeDamage(int amount) { bool died = Health.DecreaseHealth(amount); if (died && !_dead) { _dead = true; Die(); } return(died); }
private void OnTriggerEnter(Collider other) { if (!isHit) { /* * string otherTag = other.gameObject.tag; * if (otherTag.Equals(GlobalVariables.ENEMY_TAG)) * { * other.GetComponent<IHealth>().DecreaseHealth(DamageAmount, DamageType); * OnHit(); * } * else if (otherTag.Equals(GlobalVariables.MELEE_WEAPON_TAG)) * { * transform.rotation = other.gameObject.transform.rotation; * } * else * { * OnHit(); * } */ int otherLayer = other.gameObject.layer; if (otherLayer == GlobalVariables.ENEMY_LAYER) { IHealth otherHealth = other.GetComponent <IHealth>(); if (otherHealth == null) { otherHealth = other.GetComponentInParent <IHealth>(); } otherHealth.DecreaseHealth(DamageAmount, DamageType); OnHit(); hitBox.enabled = false; } /* * else if (otherLayer == GlobalVariables.PLAYER_MELEE_LAYER) * { * gameObject.layer = GlobalVariables.PLAYER_PROJECTILE_LAYER; * transform.rotation = GameMan.Instance.PlayerT.rotation; * DamageAmount *= 5; * } */ else { OnHit(); hitBox.enabled = false; } } }
private void AreaDamageTick() { Collider[] units = Physics.OverlapSphere(transform.position, hitBox.radius, areaDmgLayerMask); for (int i = 0; i < units.Length; i++) { IHealth otherHealth = units[i].GetComponent <IHealth>(); if (otherHealth == null) { otherHealth = units[i].GetComponentInParent <IHealth>(); } otherHealth.DecreaseHealth(areaDamage, areaDamageType); } areaDamageIntervalTimer.Run(); }
// ANIMATION EVENTS private void MeleeAttackAnimEvent() { if (currentBehaviour != EnemyBehaviours.Dead && currentBehaviour != EnemyBehaviours.FleeFromPlayer && currentBehaviour != EnemyBehaviours.Knockback) { if (Physics.Raycast(transform.position + transform.up, transform.forward, out RaycastHit hit, meleeAttackRangeRealUnits, playerLayerMask)) { ParticleEffectBase hitParticles = (ParticleEffectBase)GameMan.Instance.ObjPoolMan.GetObjectFromPool(ObjectPoolType.MeleeHitParticles); hitParticles.Activate(hit.point, Quaternion.identity); //playerT.gameObject.GetComponent<IHealth>().DecreaseHealth(meleeDamageAmount, meleeAttackDmgType); IHealth otherHealth = playerT.GetComponent <IHealth>(); if (otherHealth == null) { otherHealth = playerT.GetComponentInParent <IHealth>(); } otherHealth.DecreaseHealth(meleeDamageAmount, meleeAttackDmgType); } } }
private void ShootLaser() { Vector3 transPos = transform.position; Vector3 lookRot = Quaternion.LookRotation(playerT.position - transPos, Vector3.up).eulerAngles; Vector3 ogRot = transform.rotation.eulerAngles; transform.rotation = Quaternion.Euler(lookRot.x, ogRot.y, ogRot.z); RaycastHit hit; if (Physics.Raycast(transPos, transform.forward, out hit, rayMaxDistance, raycastMask)) { if (!isHit) { GameObject hitGO = hit.collider.gameObject; if (hitGO.layer == GlobalVariables.PLAYER_LAYER) { IHealth otherHealth = hitGO.GetComponent <IHealth>(); if (otherHealth == null) { otherHealth = hitGO.GetComponentInParent <IHealth>(); } otherHealth.DecreaseHealth(dmgAmount, dmgType); isHit = true; } } ParticleEffectBase hitParticles = (ParticleEffectBase)GameMan.Instance.ObjPoolMan.GetObjectFromPool(ObjectPoolType.MeleeHitParticles); hitParticles.Activate(hit.point, Quaternion.identity); float hitDistance = hit.distance; //AfterRay(transPos, hit.point, wasHit: true); //Debug.DrawLine(transform.position, hit.point, Color.red, 1.0f, false); lineRenderer.SetPosition(1, new Vector3(0f, 0f, hitDistance)); } else { //AfterRay(transPos, transPos + transform.forward * rayMaxDistance, wasHit: false); //Debug.DrawLine(transform.position, transform.position + (transform.forward * rayMaxDistance), Color.green, 1f, false); lineRenderer.SetPosition(1, new Vector3(0f, 0f, rayMaxDistance)); } }
private void OnTriggerEnter(Collider other) { if (!TreeBoss.hasMeleeHit) { if (other.gameObject.layer == GlobalVariables.PLAYER_LAYER) { IHealth otherHealth = other.GetComponent <IHealth>(); if (otherHealth == null) { otherHealth = other.GetComponentInParent <IHealth>(); } otherHealth.DecreaseHealth(currentAttackDmg, attackDmgType); TreeBoss.hasMeleeHit = true; ParticleEffectBase hitParticles = (ParticleEffectBase)GameMan.Instance.ObjPoolMan.GetObjectFromPool(ObjectPoolType.MeleeHitParticles); hitParticles.Activate(GameMan.Instance.PlayerT.position, Quaternion.identity); } } }
private void OnTriggerEnter(Collider other) { int otherLayer = other.gameObject.layer; if (otherLayer == GlobalVariables.ENEMY_LAYER) { if (!hitColliders.Contains(other)) { hitColliders.Add(other); IHealth otherHealth = other.GetComponent <IHealth>(); if (otherHealth == null) { otherHealth = other.GetComponentInParent <IHealth>(); } otherHealth.DecreaseHealth(DamageAmount, DamageType); } } }
private void OnTriggerEnter(Collider other) { if (canHit) { int otherLayer = other.gameObject.layer; if (otherLayer == GlobalVariables.PLAYER_LAYER) { IHealth otherHealth = other.GetComponent <IHealth>(); if (otherHealth == null) { otherHealth = other.GetComponentInParent <IHealth>(); } otherHealth.DecreaseHealth(damageAmount, damageType); canHit = false; } ParticleEffectBase hitParticles = (ParticleEffectBase)GameMan.Instance.ObjPoolMan.GetObjectFromPool(ObjectPoolType.MeleeHitParticles); hitParticles.Activate(playerT.position, Quaternion.identity); } }
private void OnTriggerEnter(Collider other) { if (!hitColliders.Contains(other)) { hitColliders.Add(other); int otherLayer = other.gameObject.layer; if (otherLayer == GlobalVariables.ENEMY_LAYER) { ParticleEffectBase hitParticles = (ParticleEffectBase)GameMan.Instance.ObjPoolMan.GetObjectFromPool(ObjectPoolType.MeleeHitParticles); hitParticles.Activate(transform.position, Quaternion.identity); IHealth otherHealth = other.GetComponent <IHealth>(); if (otherHealth == null) { otherHealth = other.GetComponentInParent <IHealth>(); } otherHealth.DecreaseHealth(damageAmount, damageType); } } }
private void DoRayCast() { RaycastHit hit; Vector3 transPos = transform.position; if (Physics.Raycast(transPos, transform.forward, out hit, rayMaxDistance, raycastMask)) { if (IsHoldingType && !IsHoldRayIntervalRunning) { IsHoldRayIntervalRunning = true; GameObject hitGO = hit.collider.gameObject; if (hitGO.layer == GlobalVariables.ENEMY_LAYER) { IHealth otherHealth = hitGO.GetComponent <IHealth>(); if (otherHealth == null) { otherHealth = hitGO.GetComponentInParent <IHealth>(); } otherHealth.DecreaseHealth(DamageAmount, DamageType); } /* * if (hit.collider.gameObject.CompareTag(GlobalVariables.ENEMY_TAG)) * { * hit.collider.gameObject.GetComponent<IHealth>().DecreaseHealth(DamageAmount, DamageType); * } */ // TODO: MAKE GLOBAL ENUM FOR AUDIOEFFECTS AND MAKE VARIABLE OUT OF THAT AND DO SWITCH CHECK HERE WHICH AUDIO TO PLAY! //if (!audioSource.isPlaying) //{ // Settings.Instance.Audio.PlayEffect(audioSource, Data.AudioContainer.PlayerSFX.MagicBeam); //} holdRayTimer.Run(); } else if (!IsHoldingType) { /* * if (hit.collider.gameObject.CompareTag(GlobalVariables.ENEMY_TAG)) * { * hit.collider.gameObject.GetComponent<IHealth>().DecreaseHealth(DamageAmount, DamageType); * } */ GameObject hitGO = hit.collider.gameObject; if (hitGO.layer == GlobalVariables.ENEMY_LAYER) { IHealth otherHealth = hitGO.GetComponent <IHealth>(); if (otherHealth == null) { otherHealth = hitGO.GetComponentInParent <IHealth>(); } otherHealth.DecreaseHealth(DamageAmount, DamageType); } else if (hitGO.layer == GlobalVariables.ENEMY_PROJECTILE_LAYER) { hitGO.GetComponent <ProjectileBase>().OnHit(); } // TODO: MAKE GLOBAL ENUM FOR AUDIOEFFECTS AND MAKE VARIABLE OUT OF THAT AND DO SWITCH CHECK HERE WHICH AUDIO TO PLAY! //Settings.Instance.Audio.PlayEffect(audioSource, Data.AudioContainer.PlayerSFX.IceRay); } float hitDistance = hit.distance; AfterRay(transPos, hit.point, wasHit: true); //Debug.DrawLine(transform.position, hit.point, Color.red, 1.0f, false); lineRenderer.SetPosition(1, new Vector3(0f, 0f, hitDistance)); } else { AfterRay(transPos, transPos + transform.forward * rayMaxDistance, wasHit: false); //Debug.DrawLine(transform.position, transform.position + (transform.forward * rayMaxDistance), Color.green, 1f, false); lineRenderer.SetPosition(1, new Vector3(0f, 0f, rayMaxDistance)); } }