public void CheckCollision(ITakeDamage _currentView, int damageValue) { if (_currentView.GetName() == "EnemyView") { GameApplication.Instance.GetService <IEnemyService>().SetDamagingPlayerID(GetID()); _currentView.TakeDamage(damageValue); } else if (_currentView.GetName() == "PlayerView" && isFriendlyFire) { _currentView.TakeDamage(damageValue); } }
private void DoingDamageLogic() { if (_targetEnemy == null) { return; } _attackTimer -= GameTime.DeltaTime; if (_attackTimer > 0) { return; //keep waiting... } //ready to attack... _attackTimer = AttackSpeed; //deal ranged or melee damage if close enough & clear to attack... if (DistanceSquaredFromNearestEnemyUnit < Reach * Reach /*&& GetLineOfSightClear(TargetEnemy)*/) { //SetUpWeapon(true, UnitWeapon.WeaponClasses.Ranged); _targetEnemy.TakeDamage(Damage); WeaponMgr.Lightning.FireBeamAmmo(transform, Vector3.up * HeightFromPivotToTop, _targetEnemy.transform, _targetEnemy.GetCenterOfMassOffset()); //CurrentWeapon.GetComponent<WeaponMeleeMotion>()?.StartStabMotion(); //DEBUG if (LINE_DEBUG_ENABLED) { Debug.DrawLine(transform.position + Vector3.up * HeightFromPivotToTop, _targetEnemy.transform.position + _targetEnemy.GetCenterOfMassOffset(), Color.red, 0.02f); } } }
public void Shoot() { ShotEffectPlay(); for (int i = 0; i < gunPattern.BulletsCount; i++) { Vector3 shotInacurracyVector = new Vector3(Random.Range(-gunPattern.ShotInacurracy, gunPattern.ShotInacurracy), Random.Range(-gunPattern.ShotInacurracy, gunPattern.ShotInacurracy), Random.Range(-gunPattern.ShotInacurracy, gunPattern.ShotInacurracy)); Vector3 direction = raycastFrom.forward * gunPattern.Range + shotInacurracyVector; if (Physics.Raycast(raycastFrom.position, direction, out RaycastHit hitInfo, gunPattern.Range)) { if (hitInfo.rigidbody != null) { hitInfo.rigidbody.AddForce(-hitInfo.normal * gunPattern.ImpactForce / gunPattern.BulletsCount); } SpawnImpactEffect(hitInfo); ITakeDamage hittedObject = hitInfo.transform.GetComponent <ITakeDamage> (); if (hittedObject != null && !hitInfo.transform.CompareTag("Player")) { hittedObject.TakeDamage(gunPattern.Damage / gunPattern.BulletsCount); } } } }
protected virtual void OnCollideTakeDamage(Collider2D other, ITakeDamage takeDamage) { //Debug.Log("TAKE DAMAGE"); takeDamage.TakeDamage(damage, gameObject); DestroyBall(); }
private void DealDamage() { ITakeDamage _takeDamage = collision.GetComponent <ITakeDamage>(); // I don't think there was any point casting. _takeDamage.TakeDamage(Damage); }
protected virtual void OnTriggerStay2D(Collider2D collision) { //if (collision.gameObject.tag != "Player") //{ // Destroy(this.gameObject); //} if (collision.gameObject.layer != LayerMask.NameToLayer("TriggerArea") && collision.gameObject.name != fireingCharacterName && collision.name != "ProjectilePrefab(Clone)") { if (active) { Debug.Log(name + " OnTriggerStay collided with " + collision.name); //GameObject newImpactFX = Instantiate(impactParticlesPrefab, this.transform); //newImpactFX.transform.SetParent(null); //Destroy(newImpactFX, 1f); ObjectPoolManager.Instance.SpawnFromPool("Sparkles", transform.position); ITakeDamage takeDamageInterface = collision.gameObject.GetComponent <ITakeDamage>(); if (takeDamageInterface != null) { takeDamageInterface.TakeDamage(projectileDamage + weaponDamage); } //Destroy(this.gameObject); ObjectPoolManager.Instance.ReturnObjectHome(this.gameObject); } } }
void OnCollisionEnter(Collision other) { if (other.collider.CompareTag("Projectile") == false && other.collider.CompareTag("Player") == false) { GameObject Splash; Splash = Instantiate(splashEffect); Splash.transform.position = this.transform.position; Destroy(this.gameObject); Destroy(Splash, 0.05f); ITakeDamage damagable = other.collider.GetComponent <ITakeDamage>(); if (damagable != null) { damagable.TakeDamage(damage); GameObject Effect; //Effect = Instantiate(effect, other.transform.position, Quaternion.identity, // other.transform); // Effect.transform.position = other.transform.position; //Effect.transform.parent = other.transform; } } }
void OnTriggerEnter(Collider other) { if (targetList == (targetList | (1 << other.gameObject.layer))) { soundPlayer.StopSoundEvent("Fireball"); ITakeDamage hittedObject = other.GetComponent <ITakeDamage> (); if (hittedObject != null) { hittedObject.TakeDamage(damage); } foreach (RaycastHit hit in Physics.SphereCastAll(transform.position, 10f, transform.forward)) { Rigidbody rb = hit.collider.gameObject.GetComponent <Rigidbody> (); if (rb != null) { rb.AddExplosionForce(explosionForce, transform.position, 5f); } } GameObject explosion = Instantiate(explosionVFX, transform.position, transform.rotation); explosion.GetComponent <VisualEffect> ().Play(); StartCoroutine(LateExplosionSound(explosion.GetComponent <SoundPlayer> ())); Destroy(explosion, 3f); Destroy(gameObject, .1f); } }
public void AttackAble(bool isbool) { if (isbool) { // player attack _take.TakeDamage(_enemy.statusbug, _player.statusplayer); if (_enemy.statusbug.hp <= 0) { ExpTalet(); NewEnemy(); } } else { //Bug attack _take.TakeDamage(_player.statusplayer, _enemy.statusbug); } }
protected virtual void OnCollisionEnter2D(Collision2D collision) { ITakeDamage takeDamage = collision.gameObject.GetComponent <ITakeDamage>(); if (takeDamage != null) { takeDamage.TakeDamage(damage); } }
private void OnCollisionEnter(Collision collision) { ITakeDamage damagable = collision.gameObject.GetComponent <ITakeDamage>(); if (damagable != null) { damagable.TakeDamage(damageAmount); } }
private void OnTriggerEnter(Collider other) { ITakeDamage damagable = other.GetComponent <ITakeDamage>(); if (damagable != null) { damagable.TakeDamage(1); } }
protected virtual void OnCollideTakeDamage(Collider2D other, ITakeDamage takeDamage) { //Debug.Log("TAKE DAMAGE"); takeDamage.TakeDamage(damage, gameObject); DestroyZombie(); //Debug.Log(other.gameObject.name + "Poop "); }
private void OnTriggerEnter2D(Collider2D collision) { ITakeDamage damagableObj = collision.GetComponent <ITakeDamage>(); if (damagableObj != null) { damagableObj.TakeDamage(_damage); hit?.Invoke(); } }
private void OnTriggerEnter2D(Collider2D collision) { ITakeDamage takeDamage = collision.gameObject.GetComponent <ITakeDamage>(); if (takeDamage != null) { takeDamage.TakeDamage(explosionDamage); Destroy(gameObject); } }
public void OnTriggerEnter(Collider other) { ITakeDamage damagable = other.GetComponent <ITakeDamage>(); if (damagable != null) { damagable.TakeDamage(damage); } Destroy(gameObject); }
private void OnTriggerEnter2D(Collider2D collision) { ITakeDamage damagable = collision.GetComponent <ITakeDamage>(); if (damagable != null) { damagable.TakeDamage(attackPower); pool.ReturnToPool(this.gameObject); } }
protected override void OnCollideOwner(Collider2D other, ITakeDamage takeDamage) { if (IsDeflected) { //Destroy(Owner); //Owner.transform.position = new Vector3(44,5,5); takeDamage.TakeDamage(Damage, gameObject); //GameManager.Instance.AddPoints(1); DestroyProjectile(); } }
public void OnCollisionEnter(Collision collision) { ITakeDamage damageable = collision.gameObject.GetComponentInParent <ITakeDamage>(); if (damageable != null) { damageable.TakeDamage(damage, this.gameObject); } Destroy(this.gameObject); }
private void OnTriggerEnter2D(Collider2D target) { if (target.tag == "Bullet") { meteorDamage.TakeDamage(meteorDamage.damage); target.GetComponentInParent <IPoolable>().SetOff(); } else if (target.tag == "Player") { playerDamage.TakeDamage(playerDamage.damage); } }
protected override void OnCollideTakeDamage(Collider2D other, ITakeDamage takeDamage) { takeDamage.TakeDamage(Damage, gameObject); var controller = other.gameObject.GetComponent<CharacterController2D>(); if (controller != null) { HandleKnockback(controller); } DestroyProjectile(); }
private void OnTriggerEnter2D(Collider2D collider) { if (((1 << collider.gameObject.layer) & targetLayerMask) == 0) { return; } ITakeDamage obj = collider.GetComponent <ITakeDamage>(); if (obj != null) { obj.TakeDamage(); } }
public virtual void AttackTarget(Collider col) { float randomX = UnityEngine.Random.Range(0f, 0.5f); float randomY = UnityEngine.Random.Range(0f, 0.5f); if (hittingEffect != null) { Instantiate(hittingEffect, col.transform.position + new Vector3(randomX, 0f, randomY), Quaternion.Euler(90f, 0f, 0f), col.transform); } ITakeDamage target = col.GetComponent <ITakeDamage>(); target?.TakeDamage(Damage); Destroy(gameObject); }
public void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { GameObject Splash; Splash = Instantiate(splashEffect); Splash.transform.position = this.transform.position; ITakeDamage damagable = other.GetComponent <ITakeDamage>(); if (damagable != null) { damagable.TakeDamage(damage); } Destroy(this.gameObject); Destroy(Splash, 0.05f); } }
private void OnTriggerEnter2D(Collider2D collision) { Debug.Log("Hit"); if (collision.CompareTag(enemyTag)) { ITakeDamage _takeDamage = collision.GetComponent <ITakeDamage>(); if (_takeDamage is ITakeDamage) { _takeDamage.TakeDamage(Damage); } Die(); } }
private void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.name.Contains("Bottom")) { //to code health reduce Destroy(this.gameObject); } if (damageable != null && other.gameObject.name.Contains("Bullet")) { //to code health reduce Destroy(other.gameObject); damageable.TakeDamage(1); //Debug.Log("Score: " + GameData.Score); } }
void Update() { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { ITakeDamage damageable = hit.collider.GetComponent <ITakeDamage>(); if (damageable != null) { damageable.TakeDamage(1); } } } }
void Shoot() { RaycastHit hit; shootParticle.Play(); if (Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out hit, range)) { ITakeDamage damagable = hit.collider.GetComponent <ITakeDamage>(); if (damagable != null) { Rigidbody damagablerb = hit.collider.GetComponent <Rigidbody>(); Vector3 newVector = hit.point - playerCamera.transform.position; damagablerb.AddForce(newVector * 100); damagable.TakeDamage(damage); } } }
private void OnTriggerEnter(Collider info) { ITakeDamage damagable = info.GetComponent <ITakeDamage>(); // Damageable is anything with the ITakeDamage interface // If hammer is moving fast enough and it hit a mole if (speedPerSec > speedWhenRegistered && damagable != null) { // Play hit particle system hitParticle = info.GetComponentInChildren <ParticleSystem>(); hitParticle.Play(); // Add damage to the mole that was hit damagable.TakeDamage(1.0f); } if (speedPerSec > speedWhenRegistered && damagable == null) { // Remove time from timer on miss //timerScript.timer -= removeTimeOnMiss; } }
public void DealDamage() { Collider2D[] hit = Physics2D.OverlapCircleAll(attackPoint.position, swordRange, LayerMask.GetMask("Enemies")); foreach (Collider2D e in hit) { if (hit != null) { IEnemyCombat enemy = e.GetComponent <IEnemyCombat>(); if (attacking && !enemy.blocking) { ITakeDamage damaging = e.GetComponent <ITakeDamage>(); damaging.TakeDamage(attackDamage, gameObject.GetComponent <Character_Controller>().flipSide, push); } else if (attacking && enemy.blocking) { gameObject.GetComponent <Rigidbody2D>().AddForce(Vector2.left * 2.5f * push, ForceMode2D.Impulse); Instantiate(blockFlash, attackPoint.position, Quaternion.identity); } } } }
/* * @param other, the other GameObject * @param takeDamage, the amount of damage that the other GameObject receives * On collision, the other GameObject takes damage */ protected override void OnCollideTakeDamage(Collider2D other, ITakeDamage takeDamage) { // Handles what happens when the enemy is frozen if (other.GetComponent <EnemyAI>() != null && CanFreeze == true) { Enemy.Status = EnemyAI.EnemyStatus.Frozen; Enemy.MovementSpeed = 0f; Enemy.SpriteColor.color = Color.cyan; Enemy.StartCoroutine(Enemy.CountdownDebuff()); } // Handles what happens when the enemy is confused if (other.GetComponent <EnemyAI>() != null && CanConfuse == true) { Enemy.Status = EnemyAI.EnemyStatus.Confused; Enemy.StartCoroutine(Enemy.CountdownDebuff()); Enemy.Reverse(); Enemy.SpriteColor.color = Color.red; } // Handles what happens when the enemy is disabled if (other.GetComponent <EnemyAI>() != null && CanPoison == true) { Enemy.Status = EnemyAI.EnemyStatus.Poisoned; Enemy.StartCoroutine(Enemy.CountdownDebuff()); Enemy.SpriteColor.color = Color.green; } // Handles what happens when the enemy is paralyzed if (other.GetComponent <EnemyAI>() != null && CanParalyze == true) { Enemy.Status = EnemyAI.EnemyStatus.Paraylyzed; Enemy.StartCoroutine(Enemy.CountdownDebuff()); Enemy.CanFireProjectiles = false; Enemy.SpriteColor.color = Color.yellow; } takeDamage.TakeDamage(Damage, gameObject); DestroyProjectile(); // destroys the projectile }
protected override void OnCollideTakeDamage (Collider2D other, ITakeDamage takeDamage) { takeDamage.TakeDamage (Damage, gameObject); DestroyProjectile (); }