public int newSpeed = speed, hp = 3, wandBonus, swordBonus; //created newspeed variable and update this instead of speed var which should stay constant. void OnTriggerEnter(Collider collisionInfo) { if (collisionInfo.gameObject.name.Equals("Player")) { // print("hit"); changeDirection(); } if (collisionInfo.gameObject.CompareTag("Ground") || collisionInfo.gameObject.CompareTag("inGameWall")) { // print("wall"); changeDirection(); } if (collisionInfo.gameObject.CompareTag("Enemy")) { //changeDirection(); } if (collisionInfo.gameObject.CompareTag("Projectile")) { health.takeDamage(player.GetAttackPower() * player.spell + wandBonus); print("hurt"); } if (collisionInfo.gameObject.CompareTag("Freeze")) { health.takeDamage(player.GetAttackPower()); } /*print("Detected collision between " + gameObject.name + " and " + collisionInfo.collider.name); * print("There are " + collisionInfo.contacts.Length + " point(s) of contacts"); * print("Their relative velocity is " + collisionInfo.relativeVelocity);*/ }
void OnTriggerStay2D(Collider2D other) { if (!hit && other.CompareTag("Enemy")) { EnemyHealth enemyHealth = other.GetComponent <EnemyHealth>(); if (enemyHealth) { if (other.gameObject.layer != highDamageLayer) { enemyHealth.takeDamage((long)(damage * enemyHealth.defense)); } else { long highDamage = (long)(damage * highDamageMultiplier); highDamage = (long)(highDamage * enemyHealth.defense); enemyHealth.takeDamage(highDamage); } if (explosion) { Instantiate(explosion, transform.position, transform.rotation); } hit = true; Destroy(gameObject); } } }
/* * Collisions are damage stacking with fire rings so this is a work around. use handleAttack otherwise */ public virtual void HandleMercyAttack(float damage, BaseAttack.Element element) { if (mercyTimer > 0) { return; } mercyTimer = MercyTime; enemyHealth.takeDamage(damage, element); }
/* * // Start is called before the first frame update * void Start() * { * * } */ private void Shoot() { timer = 0f; gunAudio.Play(); gunLight.enabled = true; gunParticla.Stop(); gunParticla.Play(); gunLine.enabled = true; gunLine.SetPosition(0, transform.position); /* * transform.forward is object forward, but Vector3.forward is world forward. */ shootRay.origin = transform.position; shootRay.direction = transform.forward; if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { // 取得 EnemyHealth enemyhealth = shootHit.collider.GetComponent <EnemyHealth>(); enemyhealth.takeDamage(damageperShoot, shootHit.point); gunLine.SetPosition(1, shootHit.point); } else { gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } }
private void Shoot() { timer = 0f; gunAudio.Play(); gunLight.enabled = true; gunParticle.Stop(); gunParticle.Play(); gunLine.enabled = true; gunLine.SetPosition(0, transform.position); //element 0 = 自己的位置 element 1 = 敵人的位置 shootRay.origin = transform.position; //shootRay原點 shootRay.direction = transform.forward; //shootRay方向 transform=自身座標(才會跟著轉) Vector3=世界座標 if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) //Raycast(原點,終點,距離,layer) { gunLine.SetPosition(1, shootHit.point); //打到敵人不會穿過 EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>(); //取得打到的敵人 enemyHealth.takeDamage(damagePerShot, shootHit.point); //呼叫takeDamage並丟入參數(攻擊力, 擊中的位置) } else if (Physics.Raycast(shootRay, out shootHit, range, environmentMask)) { gunLine.SetPosition(1, shootHit.point);//打到環境不會穿過 } else { gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } }
private void OnCollisionEnter(Collision coll) { if (coll.gameObject.CompareTag("Player")) { PlayerHealth ph = coll.gameObject.GetComponent <PlayerHealth>(); if (ph != null) { ph.takeDMG(dmg); Destroy(gameObject); } } if (coll.gameObject.CompareTag("Enemy")) { EnemyHealth eh = coll.gameObject.GetComponent <EnemyHealth>(); if (eh != null) { eh.takeDamage(dmg); Destroy(gameObject); } } if (coll.gameObject.CompareTag("Walls")) { Destroy(gameObject); } }
void OnCollisionEnter2D(Collision2D Other) { Instantiate(Explostion, transform.position, Quaternion.identity); if (Other.gameObject.CompareTag("Enemy") && IsThisHero) { EnemyHealth eh = Other.gameObject.GetComponent <EnemyHealth> (); eh.takeDamage(DamageCreated); } else if (Other.gameObject.CompareTag("Player") && !IsThisHero) { PlayerHealth ph = Other.gameObject.GetComponent <PlayerHealth> (); ph.takeDamage(DamageCreated); } else if (Other.gameObject.CompareTag("GreenWall") && IsThisHero) { wall w = Other.gameObject.GetComponent <wall> (); w.DestroyWall(); } else if (Other.gameObject.CompareTag("EnemySlug") && IsThisHero) { EnemySlug eh = Other.gameObject.GetComponent <EnemySlug> (); eh.takeDamage(DamageCreated); } Destroy(gameObject); }
void OnTriggerEnter(Collider other) { if (other.tag == "Target") { Instantiate(explosion, other.transform.position, other.transform.rotation); EnemyHealth enemyHealth = other.GetComponent <EnemyHealth>(); enemyHealth.takeDamage(damage); Collider[] hitColliders = Physics.OverlapSphere(other.transform.position, 5f); int i = 0; while (i < hitColliders.Length) { if (hitColliders[i].tag == "Enemy" && Vector3.Distance(other.transform.position, hitColliders[i].transform.position) < 1.5f) { EnemyHealth colliderHealth = hitColliders[i].GetComponent <EnemyHealth>(); colliderHealth.takeDamage(damage); } if (hitColliders[i].tag == "Player" && Vector3.Distance(other.transform.position, hitColliders[i].transform.position) < 1.5f) { PlayerHealth playerHealth = hitColliders[i].GetComponent <PlayerHealth>(); playerHealth.takeDamage(damage); } i++; } Destroy(gameObject); } }
private void ProcessRayCast() { RaycastHit hit; if (Physics.Raycast(FPCamera.transform.position, FPCamera.transform.forward, out hit, range)) { if (hit.transform.tag == "Enemy") { GameObject impact = Instantiate(hitBlood, hit.point, Quaternion.LookRotation(hit.normal)); AudioSource.PlayClipAtPoint(hit.transform.gameObject.GetComponent <EnemyAI>().bulletImpact.clip, hit.transform.position, .1F); Destroy(impact, 3f); } else { CreateHitImpact(hit); } EnemyHealth target = hit.transform.GetComponent <EnemyHealth>(); if (target == null) { return; } target.takeDamage(damage); } else { return; } }
void Shoot() { timer = 0; BuletTrail.enabled = true; BuletTrail.SetPosition(0, transform.position); ShootRay.origin = transform.position; ShootRay.direction = transform.forward; if (Physics.Raycast(ShootRay, out Shoothit, range, shootMask)) { EnemyHealth enemyHealth = Shoothit.collider.GetComponent <EnemyHealth>(); if (enemyHealth != null) { enemyHealth.takeDamage(DamageShoot, Shoothit.point); } } else { BuletTrail.SetPosition(1, ShootRay.origin + ShootRay.direction * range); } }
public void getHit(Vector2 kb, int hitLag, int hitStun, int damage) { knockback = kb * .8f; hitstunCounter = hitStun; hitlagCounter = hitLag; inHitlag = true; sounds.getHit(damage); hp.takeDamage(damage); }
void Damage(Transform enemy) { EnemyHealth e = enemy.GetComponent <EnemyHealth>(); if (e != null) { e.takeDamage(damage); } }
void OnTriggerEnter(Collider other) { if (other.tag == "Enemy" && attackCac) { attackCac = false; EnemyHealth enemyHealth = other.GetComponent <EnemyHealth>(); enemyHealth.takeDamage(damage); } }
void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "arrow") { //Debug.Log("Body Shot @@@@@@"); //collision.gameObject.SendMessage("takeDamage", 10); enemyHealthScript.takeDamage(20); } }
void OnTriggerEnter(Collider other) { if (other.tag == "Target") { Instantiate(explosion, other.transform.position, other.transform.rotation); EnemyHealth enemyHealth = other.GetComponent <EnemyHealth>(); enemyHealth.takeDamage(damage); Destroy(gameObject, lifetime); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.CompareTag("Enemy") || collision.gameObject.CompareTag("Enemy1")) { Debug.Log("Bullet Hit"); enemyHealth = collision.GetComponent <EnemyHealth>(); enemyHealth.takeDamage(attackDamage); Destroy(gameObject); } }
private void OnTriggerStay2D(Collider2D collision) { if (collision.gameObject.tag != "Player") { if (collision.gameObject.GetComponent <EnemyHealth>() != null) { EnemyHealth enemyHealth = collision.gameObject.GetComponent <EnemyHealth>(); enemyHealth.takeDamage(3); } } }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.CompareTag("Player")) { //add animation event after animation to run a code playerNear = true; } if (other.gameObject.CompareTag("playerWeapon") && enemyHealth.health > 0) { enemyHealth.takeDamage(playerDamage); animator.SetTrigger("isAttacked"); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.CompareTag("Enemy") || collision.gameObject.CompareTag("Enemy1")) { enemyHealth = collision.GetComponent <EnemyHealth>(); if (enemyHealth.currentHealth > 0) { enemyHealth.swordHit = true; enemyHealth.takeDamage(attackDamage); enemyHealth.swordHit = false; } } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag != "Player" && collision.gameObject.tag != "SpawnPoint" && collision.gameObject.tag != "PlayerProjectile" && collision.gameObject.tag != "DoorTrigger") { Destroy(gameObject); } if (collision.gameObject.tag == "Enemy") { EnemyHealth enemyHealth = collision.gameObject.GetComponent <EnemyHealth>(); enemyHealth.takeDamage(2); Destroy(gameObject); } }
void Attack() { timer = 0f; anim.SetTrigger("Attack"); if (enemy != null) { EnemyHealth enemyHealth = enemy.GetComponent <EnemyHealth> (); if (enemyHealth != null) { enemyHealth.takeDamage(damagePerAttack); swordSound.Play(); } } }
void OnCollisionEnter(Collision collisionInfo) { if (collisionInfo.collider.name.Equals("Player")) { if (dirRight == true) { dirRight = false; } else if (dirRight == false) { dirRight = true; } } if (collisionInfo.collider.name.Equals("Projectile(Clone)")) { health.takeDamage(); print(hp); } /*print("Detected collision between " + gameObject.name + " and " + collisionInfo.collider.name); * print("There are " + collisionInfo.contacts.Length + " point(s) of contacts"); * print("Their relative velocity is " + collisionInfo.relativeVelocity);*/ }
void Update() { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Input.GetMouseButtonDown(0) && Physics.Raycast(ray, out hit, 20f, mask)) { EnemyHealth enemy = hit.transform.gameObject.GetComponent <EnemyHealth>(); if (enemy.health > 0) { enemy.takeDamage(damage); } } }
private void OnTriggerEnter(Collider other) { if (other.tag == "Enemy") { EnemyHealth enemyHealth = other.GetComponent <EnemyHealth>(); if (enemyHealth != null) { enemyHealth.takeDamage(damage); } } if (other.tag != "Player" && other.tag != "Bullet" && other.tag != "Bullet Pos") { SimplePool.Despawn(gameObject); } }
/// <summary> /// Behavior when the bullet collides with something. /// </summary> /// <param name="col">collision information</param> private void OnCollisionEnter(Collision col) { if (gameObject.tag != "Enemy Projectile" && (col.gameObject.tag == "Bullet" || col.gameObject.layer == LayerMask.NameToLayer("Player"))) { // Do nothing when these objects are hit return; } if (gameObject.tag == "Enemy Projectile") { if (col.gameObject.tag == "Bullet" || col.gameObject.tag == "Missile") // Allow player to disable enemy projectiles { hitSomething = true; } else { // If an enemy bullet has struck something, delete it (no ricochet) Destroy(gameObject); } return; } if (col.gameObject.layer == LayerMask.NameToLayer("Enemy")) { EnemyHealth eh = col.gameObject.GetComponentInChildren <EnemyHealth>() ?? col.gameObject.GetComponentInParent <EnemyHealth>(); eh.takeDamage(damage, 1); if (gameObject.tag == "Bullet") { eh.showDamageExplosion(eh.explosions, 0.4f); } else if (gameObject.tag == "Missile") { eh.showDamageExplosion(eh.bigExplosions, 0.65f); } } if (ricochetEnabled && !hitSomething) // ricochet just once { hitSomething = true; // Apply ricochet Vector3 norm = col.GetContact(0).normal; ricochetDirection = Vector3.Reflect(transform.position, norm * 20).normalized; target = null; } else if (!ricochetEnabled) { gameObject.SetActive(false); } }
private void OnTriggerEnter(Collider col) { EnemyHealth enemyHealth = col.gameObject.GetComponent <EnemyHealth>(); if (enemyHealth != null) { enemyHealth.takeDamage(damage); PlayerShotPool.Instance.ReturnToPool(this); } EnemyShot enemyShot = col.gameObject.GetComponent <EnemyShot>(); if (enemyShot != null) { PlayerShotPool.Instance.ReturnToPool(this); } }
void OnTriggerEnter2D(Collider2D collider) { if (collider.gameObject.tag == "Walls" || collider.gameObject.tag == "Floor") { // Destroy(gameObject); gameObject.SetActive(false); } if (collider.gameObject.tag == "Enemy") { EnemyHealth enemy = collider.GetComponent <EnemyHealth>(); enemy.takeDamage(damage); // Destroy(gameObject); gameObject.SetActive(false); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag != "Player" && collision.gameObject.tag != "SpawnPoint" && collision.gameObject.tag != "PlayerProjectile" && collision.gameObject.tag != "DoorTrigger") { // instantiate boom Instantiate(explosion, new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, 0), Quaternion.identity); Destroy(gameObject); } if (collision.gameObject.tag == "Enemy") { EnemyHealth enemyHealth = collision.gameObject.GetComponent <EnemyHealth>(); enemyHealth.takeDamage(2); Instantiate(explosion, new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, 0), Quaternion.identity); // instantiate boom Destroy(gameObject); } }
//on collision void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "AllyProjectile") //if the projectile is an ally projectile //find the projectiles data { ProjectileData hitData = other.gameObject.GetComponent <ProjectileData> (); //deal damage according to its data myHealthScript.takeDamage(hitData.getDamage()); //if the projectile is DestroyOnHit destroy the projectile if (hitData.getDestroyOnHit()) { Destroy(other.gameObject); } } }
public void OnCollisionEnter(Collision col) { //Debug.Log ("hit " + col.gameObject.tag); if (col.gameObject.tag.Equals("Enemy")) { Debug.Log("was an enemy"); EnemyHealth eh = col.gameObject.transform.root.GetComponent <EnemyHealth>(); eh.takeDamage(bulletDamage); Destroy(gameObject); //MonkeyHealth mh = col.gameObject.GetComponent<MonkeyHealth>(); //mh.damage(bulletDamage); //pl.numEnemies -= 1; } if (col.gameObject.tag == "player") { } }