/// <summary> /// Triggered when the bullet collides with anything /// </summary> /// <param name="col">The object it collides with</param> void OnCollisionEnter(Collision col) { SystemLogger.write("Bullet collision"); // If it's an enemy if (col.gameObject.CompareTag(this.targetTag)) { // Try and find an EnemyHealth script on the gameobject hit. EnemyStats enemyHealth = col.gameObject.GetComponentInParent <EnemyStats>(); // if not in parent if (enemyHealth == null) { enemyHealth = col.gameObject.GetComponent <EnemyStats>(); } // If the EnemyHealth component exists... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage((int)this.damage); if (PowerUpManager.Instance.Powerups["DamageUp"].IsActive) { enemyHealth.TakeDamage((int)PowerUpManager.Instance.PowerIncrease); } } } }
/// <summary> /// Triggered when the bullet collides with anything /// </summary> /// <param name="obj"></param> void OnCollisionEnter(Collision obj) { SystemLogger.write("Rocket collision"); // Get all the objects in a <ExplosionRadius> radius from where the bullet collided Collider[] hitColliders = Physics.OverlapSphere(transform.position, ExplosionRadius); // Create Explosion object Instantiate(Explosion, transform.position, transform.rotation); // For every object in the explosion for (int i = 0; i < hitColliders.Length; ++i) { if (hitColliders[i]) { // Add an explosion force of <ExplosionForce> to them Rigidbody rb = hitColliders[i].gameObject.GetComponent <Rigidbody>(); if (rb) { rb.AddExplosionForce(ExplosionForce, transform.position, this.ExplosionRadius); } // Try and find an EnemyHealth script on the gameobject hit. EnemyStats enemyHealth = hitColliders[i].gameObject.GetComponentInParent <EnemyStats>(); if (hitColliders[i].CompareTag("Player")) { ScoreManager.Instance.DecreaseScore((int)this.GetComponent <Weapon>().damage); } else if (hitColliders[i].CompareTag("DestructableEnvironment")) { Destroy(hitColliders[i].gameObject); } // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage((int)this.GetComponent <Weapon>().damage); // If the damage up power up is active, do extra damage if (PowerUpManager.Instance.Powerups["DamageUp"].IsActive) { enemyHealth.TakeDamage((int)PowerUpManager.Instance.PowerIncrease); } } } } // Destroy the rocket Destroy(this.gameObject); }
/// <summary> /// Used to detect when this object has come into contact with another object /// </summary> /// <param name="collision"></param> public void OnCollisionEnter(Collision collision) { if (collision.transform.tag != "TestSpell" && stats.currentHealth >= 0) { if (this.GetComponent <Rigidbody>().velocity.magnitude > stats.armour.getValue()) { stats.TakeDamage(this.GetComponent <Rigidbody>().velocity.magnitude, collision.transform.tag); } else if (collision.transform.GetComponent <Rigidbody>().velocity.magnitude > stats.armour.getValue()) { stats.TakeDamage(collision.transform.GetComponent <Rigidbody>().velocity.magnitude, collision.transform.tag); } } }
// Update is called once per frame void Update() { //Debug.DrawLine(transform.position,new Vector2(transform.position.x + radius, transform.position.y)); if ((Input.GetKeyDown(attackKey) || Input.GetKeyDown(KeyCode.Joystick1Button3)) && Time.time > AOEstart + coolDown) { AOEstart = Time.time; nuke = Instantiate(prefab, new Vector2(transform.position.x + 1, transform.position.y), Quaternion.identity) as Rigidbody2D; nuke = Instantiate(prefab, new Vector2(transform.position.x - 1, transform.position.y), Quaternion.identity) as Rigidbody2D; nuke = Instantiate(prefab, new Vector2(transform.position.x, transform.position.y + 1), Quaternion.identity) as Rigidbody2D; nuke = Instantiate(prefab, new Vector2(transform.position.x, transform.position.y - 1), Quaternion.identity) as Rigidbody2D; nuke = Instantiate(prefab, new Vector2(transform.position.x + 1, transform.position.y + 1), Quaternion.identity) as Rigidbody2D; nuke = Instantiate(prefab, new Vector2(transform.position.x - 1, transform.position.y - 1), Quaternion.identity) as Rigidbody2D; nuke = Instantiate(prefab, new Vector2(transform.position.x - 1, transform.position.y + 1), Quaternion.identity) as Rigidbody2D; nuke = Instantiate(prefab, new Vector2(transform.position.x + 1, transform.position.y - 1), Quaternion.identity) as Rigidbody2D; Collider2D [] enemies = Physics2D.OverlapCircleAll(transform.position, radius); foreach (Collider2D enem in enemies) { if (enem.CompareTag("Enemy")) { EnemyStats eStats = enem.GetComponent <EnemyStats> (); eStats.TakeDamage(attackDamage); } } } }
void OnCollisionEnter(Collision col) { if (!isCollided) { isCollided = true; if (col.gameObject.tag != "Arrow") { // rb.isKinematic = true; // transform.parent = ArrowCollecter.transform; rb.constraints = RigidbodyConstraints.FreezeAll; Debug.Log("arrow hit"); } else { rb.useGravity = true; } if (col.gameObject.tag != "Enemy") { Object.Destroy(gameObject, 2.0f); } else { Object.Destroy(gameObject); } } if (col.gameObject.GetComponent <EnemyStats>()) { EnemyStats stats = col.gameObject.GetComponent <EnemyStats>(); stats.TakeDamage(damage); } }
public void OnTriggerEnter(Collider other) { if (other.tag == "Enemy") //si es enemigo { EnemyStats enemyStats = other.GetComponent <EnemyStats>(); //obtener clase EnemyStats del enemigo if (enemyStats != null) //si existe { if (explosion != null) { Instantiate(explosion, transform.position, Quaternion.identity); } enemyStats.TakeDamage(bulletDamage); //hacer danyo Destroy(gameObject); //Debug.Log("Bala destruida por colision contra enemigo"); } } if (maxCollisions - 1 == 0) { if (explosion != null) { Instantiate(explosion, transform.position, Quaternion.identity); } Destroy(gameObject); //Debug.Log("Bala destruida por colision"); } else { maxCollisions--; } }
void OnCollisionEnter(Collision other) { enemyStats = other.collider.GetComponent <EnemyStats> (); if (!other.collider.CompareTag("Player")) { if (enemyStats != null) { //deals damage to enemy enemyStats.TakeDamage(PlayerStats.stats.iceSpell.damage); //add ice particle affect around affected enemy GameObject clone = Instantiate(slowEffect, other.collider.transform.position, Quaternion.identity) as GameObject; clone.transform.SetParent(other.collider.transform); //add to slow duration enemyStats.slowTime = Time.time + 3f; } if (other.collider.GetComponent <UnityEngine.AI.NavMeshAgent>() != null && !enemyStats.isSlowed) { SlowTarget(other); } explosion.transform.SetParent(null); explosion.SetActive(true); Destroy(gameObject); } }
void DealDamage() { Collider[] enemies = Physics.OverlapSphere(centerPoint, spell.radius, 1 << 11); foreach (Collider enemy in enemies) { EnemyStats tarStats = enemy.gameObject.GetComponent <EnemyStats>(); bool isCrit = false; int damageDone; if (spell.school == 0) { damageDone = casterStats.PhysicalDamage * spell.damageValue; } else { damageDone = casterStats.MagicalDamage * spell.damageValue; } damageDone = GameVariables.RandomDamageRange(damageDone, .3f); float critChance = casterStats.CritChance / 100; float randomValue = (float)System.Math.Round(Random.Range(0f, 1f), 2); if (critChance >= randomValue) { isCrit = true; damageDone *= 2; } tarStats.TakeDamage(damageDone, isCrit); } }
/// <summary> /// Add the bomb pickup to the pickup array /// </summary> public void AddBombPickup() { template bomb = (obj) => { if (obj.gameObject.GetComponent <Shooting>() != null) { Instantiate(bombExplosion, obj.transform.position, obj.transform.rotation); // Get all the objects in a <ExplosionRadius> radius from where the bullet collided Collider[] hitColliders = Physics.OverlapSphere( transform.position, PowerUpManager.Instance.BombRadius, PowerUpManager.Instance.BombLayer); PopUpText.Instance.NewPopUp("Nuke!"); // For every object in the explosion for (int i = 0; i < hitColliders.Length; ++i) { if (hitColliders[i]) { // Try and find an EnemyHealth script on the gameobject hit. EnemyStats enemyHealth = hitColliders[i].gameObject.GetComponentInParent <EnemyStats>(); // If the EnemyHealth component exist... if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage((int)PowerUpManager.Instance.BombDamage); } } } } }; this.Type[6] = bomb; SystemLogger.write("Bomb Pickup Initialized"); }
// checks if the projectile collides with anyone private void OnTriggerEnter(Collider other) { // if the projectile aint hitting its owner then execute if (other.name != _attacker) { if (_buff != null) { EnemyStats EStats = other.GetComponent <EnemyStats>(); EStats.enemy.Buffs.Add(_buff); } if (_explodes == true) { GameObject obj = Instantiate(_prefab, gameObject.transform.position, Quaternion.identity); obj.GetComponent <Aoe>().RecieveParameters(_attacker, _damage, _meter, _aggro, _size, _buff); Destroy(this.gameObject); } else { EnemyStats EStats = other.GetComponent <EnemyStats>(); if (EStats == null) { return; } else { EStats.TakeDamage(_attacker, other.name, _damage, _aggro); Destroy(this.gameObject); } } } }
void OnTriggerEnter(Collider c) { GameObject other = c.gameObject; if (other.tag == "Enemy") { string damageType = "none"; float force = 5; if (augment != null) { augment.onHitEffect(other); damageType = augment.Element; if (augment.Element == "earth") { force = 20; } } //TODO: Add enemy Knockback Vector3 enemyPos = other.transform.position; Vector3 playerPos = transform.parent.position; other.GetComponent <Rigidbody>().AddForce((enemyPos - playerPos) * force, ForceMode.VelocityChange); EnemyStats enemyHP = other.GetComponent <EnemyStats> (); if (isSwinging) { enemyHP.TakeDamage(swordDamage, damageType); } } }
/** * Do damage on enemy on impact*/ private void DoDamage(Collider2D coll) { EnemyStats enemyStats = coll.GetComponent <EnemyStats>(); enemyStats.TakeDamage(attackDamage); GameObject.Destroy(gameObject); }
void ShootPrimary() { if (mana.mana < manaPrimary) { return; } mana.UseMana(manaPrimary); Vector2 shootPosition = Input.mousePosition; RaycastHit2D hit = Physics2D.Raycast(bulletSpawn.position, Camera.main.ScreenToWorldPoint(shootPosition) - bulletSpawn.position, 100, hitLayer); if (hit) { Zapp zappScript = Instantiate(zapp, bulletSpawn.position, Quaternion.identity).GetComponent <Zapp>(); zappScript.ZapTarget(hit.point); if (hit.collider.gameObject.CompareTag("Enemy")) { EnemyStats s = hit.collider.gameObject.GetComponent <EnemyStats>(); s.TakeDamage(damage); s.Flinch(transform.position, 2); } } else { Zapp zappScript = Instantiate(zapp, bulletSpawn.position, Quaternion.identity).GetComponent <Zapp>(); zappScript.ZapTarget(Camera.main.ScreenToWorldPoint(shootPosition)); } }
void Shoot() { int mask = (1 << LayerMask.NameToLayer("Enemies")) | (1 << LayerMask.NameToLayer("obstacles")); RaycastHit2D hit = Physics2D.Raycast(firePoint.position, firePoint.right, 100, mask); if (hit.collider != null) { if (hit.collider.gameObject.tag == "Enemy") { EnemyStats enemystats = hit.collider.gameObject.GetComponent <EnemyStats>(); enemystats.TakeDamage(damage); } else if (hit.collider.gameObject.tag == "Boss") { hit.collider.gameObject.GetComponent <bossController>().TakeDamage(damage); } Debug.Log(hit.collider.gameObject.name); lineRenderer.SetPosition(0, firePoint.position); lineRenderer.SetPosition(1, hit.point); } else { lineRenderer.SetPosition(0, firePoint.position); lineRenderer.SetPosition(1, firePoint.transform.right); } lineRenderer.enabled = true; }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.CompareTag("Enemy")) { EnemyStats enemy = other.GetComponent <EnemyStats>(); enemy.TakeDamage(damage); } }
/// <summary> /// Deal damage to enemy /// </summary> /// <param name="enemy">Transform enemy.</param> /// <param name="damageToDeal">An int amount of damage.</param> void DealDamage(Transform enemy, int damageToDeal) { EnemyStats enemyStats = enemy.GetComponent <EnemyStats> (); if (enemyStats != null) { enemyStats.TakeDamage(damageToDeal); } }
void Damage(Transform enemy) { EnemyStats e = enemy.GetComponent <EnemyStats>(); if (e != null) { e.TakeDamage(damage); } }
void OnTriggerEnter(Collider col) { if (enemyStats) { if (col.GetComponent <Weapon>()) { enemyStats.TakeDamage((int)col.gameObject.GetComponent <Weapon>().damage); } } }
private void Update() { Collider[] hitChecks = hitCheck(); if (hitChecks.Length > 0) { EnemyStats stats = hitChecks[0].transform.gameObject.GetComponent <EnemyStats>(); stats.TakeDamage(damage); Destroy(gameObject); } }
private void OnTriggerEnter(Collider other) { EnemyStats playerStats = other.GetComponent <EnemyStats>(); if (playerStats != null) { playerStats.TakeDamage(damage); Debug.Log("damage"); } }
private void Shoot() { if (!equippedWeapon || dead) { return; } fireDelays[equippedWeapon.ID] = Time.time + equippedWeapon.fireRate; m_Animator.SetTrigger("Fire"); AudioSource.PlayClipAtPoint(equippedWeapon.shotSounds[Random.Range(0, equippedWeapon.shotSounds.Length)], barrel.position); shotMuzzles.Stop(true); shotMuzzles.Play(true); //Get hit point and stuff RaycastHit hit; Vector3 shotOrigin = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0)); float acc = 1 - equippedWeapon.accuracy; Vector3 shotInaccuracy = new Vector3(Random.Range(-acc, acc), Random.Range(-acc, acc), Random.Range(-acc, acc)); if (!m_Grounded) { shotInaccuracy *= 1.5f; } Debug.DrawRay(barrel.position, Camera.main.transform.forward * equippedWeapon.range + shotInaccuracy, Color.yellow); if (Physics.Raycast(shotOrigin, Camera.main.transform.forward + shotInaccuracy, out hit, equippedWeapon.range, hitLayers, QueryTriggerInteraction.Ignore)) { Instantiate(equippedWeapon.impactParticles, hit.point, Quaternion.identity); if (hit.collider.CompareTag("Enemy")) { EnemyStats enemy = hit.collider.GetComponent <EnemyStats>(); enemy.TakeDamage(equippedWeapon.damage, hit.point, transform); } } //Make sure to alarm idle enemies around. They shouldn't be deaf. Collider[] enemies = Physics.OverlapSphere(barrel.position, 50, hitLayers); foreach (Collider col in enemies) { EnemyController controller = col.GetComponent <EnemyController>(); if (controller && controller.state == EnemyController.State.Idle) { controller.target = targetable; controller.TransitionTo(EnemyController.State.LostTarget); return; } if (controller && controller.suspicious) { controller.target = targetable; controller.TransitionTo(EnemyController.State.Chase); } } }
private void OnTriggerEnter(Collider other) { EnemyStats stats = other.GetComponent <EnemyStats>(); if (stats != null) { stats.TakeDamage(damage, DamageType.Fire); StopParticles(); Destroy(gameObject); } }
/// <summary> /// Executes the critical hit skill /// </summary> /// <param name="focus"></param> void CriticalHit(int focus) { EnemyStats enemy = FindEnemy(playerMovement.facingdirection + (Vector2)playerMovement.transform.position); if (enemy != null) { playerAnimator.SetAttackAnimationDirection(playerMovement.facingdirection); playerAnimator.AnimateAttack(); enemy.TakeDamage(Random.Range(playerStats.minAttack.GetIntValue() * 2, playerStats.maxAttack.GetIntValue() * 2 + 1)); playerStats.ChangeFocus(-focus); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Player")) { collision.GetComponent <PlayerStats>().TakeDamage(_damage); Destroy(gameObject); } else if (collision.CompareTag("Bullet")) { _enemyStats.TakeDamage(collision.GetComponent <BulletMovement>()._damage); } }
private void Laser() { if (!lineRenderer.enabled) { lineRenderer.enabled = true; } enemyStatsScript.TakeDamage(damageOverTime * Time.deltaTime); lineRenderer.SetPosition(0, firePoint.position); lineRenderer.SetPosition(1, target.position); }
IEnumerator AttackTarget() { agent.SetDestination(target.position); if (agent.remainingDistance <= 0.1f) { target = null; yield break; } SetAnimation(false, false, true); if (target == null) { yield break; } enemyStatsScript = target.GetComponent <EnemyStats>(); while (true) { if (enemyStatsScript == null) { target = null; SetAnimation(true, false, false); movingActivate = false; attackActivate = false; Debug.Log("nema enemya vise"); yield break; } else if (agent.remainingDistance >= statsOfThis.attackRange + 1f) { target = null; SetAnimation(true, false, false); movingActivate = false; attackActivate = false; Debug.Log("enemy je predaleko za napadanje"); yield break; } else if (agent.remainingDistance <= statsOfThis.attackRange + 1f) { SetAnimation(false, false, true); //Debug.Log("is attacking u while " + animator.GetBool("isAttacking")); enemyStatsScript.TakeDamage(statsOfThis.attackPower); yield return(new WaitForSeconds(1f)); } } }
void OnTriggerEnter2D(Collider2D other) { EnemyStats enemy = other.GetComponent <EnemyStats>(); if (enemy != null) { enemy.TakeDamage(Damage * pDamage); if (name != "boomerang(Clone)") { Destroy(gameObject); } } }
/// <summary> /// Used to handle collisions. Will do damage when the cylinder collider collides with /// an object matching the Target tag /// </summary> /// <param name="col">The collider the cylinder interacted with</param> void OnTriggerEnter(Collider col) { SystemLogger.write("Laser beam collision"); // If it's the right tag if (col.transform.gameObject.tag == this.Target) { // Create the "Got hit by laser" particle effect. GameObject.Instantiate(CollisionParticle, col.gameObject.transform.position, Quaternion.Euler(Vector3.zero)); if (this.Target == "Enemy") { // Get the enemy info EnemyStats enemyHealth = col.transform.gameObject.GetComponentInParent <EnemyStats>(); // If the EnemyStats component was found on the game object if (enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage((int)this.GetComponentInParent <Weapon>().damage); // If the damage increase power up is active, do additional damage if (PowerUpManager.Instance.Powerups["DamageUp"].IsActive) { enemyHealth.TakeDamage((int)PowerUpManager.Instance.PowerIncrease); } } } else if (this.Target == "Player") { ScoreManager.Instance.DecreaseScore((int)GetComponentInParent <Weapon>().damage); } } if (CantPassThrough == (CantPassThrough | (1 << col.gameObject.layer))) { // Stop growing the laser this.stopGrowing = true; } }
protected override void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.CompareTag("Enemy")) { EnemyStats enemy = other.GetComponent <EnemyStats>(); enemy.TakeDamage(damage); Destroy(gameObject); } else if (other.gameObject.CompareTag("Walls")) { Destroy(gameObject); } }
public void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Enemy") { EnemyStats enemy = other.gameObject.GetComponent <EnemyStats>(); // Check if enemy is dead if (!enemy.GetEnemyStatus()) { enemy.TakeDamage(bulletElement, bulletDamage); } } Destroy(this.gameObject); }
private void OnTriggerStay(Collider objectColliding) { if (objectColliding.CompareTag("Enemy")) { //Repeat each X amount of time. if (Time.time > m_Cooldown) { m_Cooldown = Time.time + m_AttackRate; //Take the enemy health and reduce it by X m_EnemyStatsScript = objectColliding.gameObject.transform.parent.GetComponent<EnemyStats>(); m_EnemyStatsScript.TakeDamage(m_Damage); } } }
void OnTriggerEnter(Collider hit) { if (hit.tag == "Enemy") { // add HP remover here instead of Destroyer. m_EnemyStatsScript = hit.gameObject.transform.parent.GetComponent<EnemyStats>(); m_EnemyStatsScript.TakeDamage(m_Damage); } if (hit.tag == "Isle") { Instantiate(FireExplosion, transform.position, transform.rotation); Destroy(gameObject); } if (hit.tag == "Water") { Instantiate(Splash, transform.position, transform.rotation); Destroy(gameObject); } if (hit.tag == "Untagged") return; }