private void OnCollisionEnter(Collision other) { if (other.transform.tag == "Player") { HealthManager _healthManager = other.gameObject.GetComponent <HealthManager>(); if (_healthManager) { _healthManager.ApplyDamage(Damage); } } if (other.transform.tag == "Damagable") { HealthManager _healthManager = other.gameObject.GetComponent <HealthManager>(); if (_healthManager) { _healthManager.ApplyDamage(Damage); } //Svaki put kada se dva neprijatelja s tagom Damagable sudare, player će dobiti 10 bodova /*if (other.transform.tag == "Damagable") * GameManager.GM.Collect(10); */ //Destroy(gameObject); } }
public void ApplyDamage(float damage) { if (IsDead) { return; } damage *= damageFactor; if (referer) { referer.ApplyDamage(damage); } else { health -= damage; if (health <= 0) { health = 0; } photonView.RPC("RPCSetHealth", PhotonTargets.Others, health); } }
public void ApplyDamage(float damage) { if (IsDead) { return; } damage *= damageFactor; if (referer) { referer.ApplyDamage(damage); } else { Health -= damage; if (Health <= 0) { Health = 0; if (animator) { animator.SetTrigger("Dead"); } if (removeColliderOnDeath) { RemoveColliders(GetComponents <Collider>()); RemoveColliders(GetComponentsInChildren <Collider>()); } } } }
void CheckAttack() { float distanceFromTarget = GetActualDistanceFromTarget(); Vector3 direction = target.transform.position - this.transform.position; float angle = Vector3.Angle(direction, this.transform.forward); if (!isAttacking && distanceFromTarget <= 2.0f && angle <= 60f) { isAttacking = true; shouldChase = false; origSpeed = agent.speed; agent.speed = 0; int index1 = Random.Range(0, attackSound.Length); attackClip = deathSound[index1]; audioSource.PlayOneShot(attackClip); animator.SetTrigger("Attack"); HealthManager targetHealthManager = target.GetComponent <HealthManager>(); if (targetHealthManager) { targetHealthManager.ApplyDamage(damage); } StartCoroutine(ResetAttacking()); } }
private void OnTriggerEnter(Collider other) { HealthManager collided = other.GetComponent <HealthManager>(); collided.ApplyDamage(1); Destroy(gameObject); }
void CheckAttack() { // Calculate actual distance from target float distanceFromTarget = GetActualDistanceFromTarget(); // Calculate direction is toward player Vector3 direction = target.transform.position - this.transform.position; float angle = Vector3.Angle(direction, this.transform.forward); if (!isAttacking && distanceFromTarget <= 2.0f && angle <= 60f) { isAttacking = true; shouldChase = false; origSpeed = agent.speed; agent.speed = 0; networkEnemy.TriggerAttackAnimation(); HealthManager targetHealthManager = target.GetComponent <HealthManager>(); if (targetHealthManager) { targetHealthManager.ApplyDamage(damage); } resetAttackCo = ResetAttacking(); StartCoroutine(resetAttackCo); } }
// Trigger može oduzimati živote i davati damage private void OnTriggerEnter(Collider other) { HealthManager healthManager = other.gameObject.GetComponent <HealthManager>(); if (damageOnCollision == false && damageOnTrigger == true) { if (healthManager != null) { healthManager.looseLife(numOfLivesOnTrigger); } else { Debug.Log(other.gameObject.name + "Does not contain HealtManager component"); } } else if (damageOnCollision == true && damageOnTrigger == false) { if (healthManager != null) { healthManager.ApplyDamage(DamageValue); } else { Debug.Log(other.gameObject.name + "Does not contain HealtManager component"); } } else { Debug.Log("GameObject: " + gameObject.name + " both checkboxes cannot be checked or unchecked"); } }
void CheckAttack() { // Calculate actual distance from target float distanceFromTarget = GetActualDistanceFromTarget(); // Calculate direction is toward player Vector3 direction = target.transform.position - this.transform.position; float angle = Vector3.Angle(direction, this.transform.forward); if (!isAttacking && distanceFromTarget <= 2.0f && angle <= 60f) { isAttacking = true; shouldChase = false; origSpeed = agent.speed; agent.speed = 0; audioSource.PlayOneShot(attackSound); animator.SetTrigger("Attack"); HealthManager targetHealthManager = target.GetComponent <HealthManager>(); if (targetHealthManager) { targetHealthManager.ApplyDamage(damage); } StartCoroutine(ResetAttacking()); } }
private void HandleHealthChanged(float percent, int bulletDamage) { foregroundImage.fillAmount = percent; HealthManager healthManager = GetComponentInParent <HealthManager>(); healthManager.ApplyDamage(bulletDamage); // StartCoroutine(ChangeToPercent(percent, bulletDamage)); }
void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Player")) { HealthManager healthManager = other.GetComponent <HealthManager> (); healthManager.ApplyDamage(Mathf.Infinity); } }
private void OnCollisionEnter(Collision other) { HealthManager healthManager = other.gameObject.GetComponent <HealthManager> (); if (healthManager != null) { healthManager.ApplyDamage(Damage); } }
void Fire() { if (fireTimer < fireRate) { return; } if (loadedBullets <= 0) { // When Ammo is out, make fire is not working for a moment StartCoroutine(DisableFire()); //soundManager.Play(drySound); return; } RaycastHit hit; for (int i = 0; i < pellets; i++) { if (Physics.Raycast(shootPoint.position, CalculateSpread(spread, shootPoint), out hit, range)) { HealthManager health = hit.transform.GetComponent <HealthManager>(); if (health) { health.ApplyDamage(GetWeaponDamage()); } else { CreateRicochet(hit.point, hit.normal); GameObject bulletHole = Instantiate(bulletImpact, hit.point, Quaternion.FromToRotation(Vector3.forward, hit.normal)); bulletHole.transform.SetParent(hit.transform); Destroy(bulletHole, 10f); } } } if (hasLastFire && loadedBullets <= 1) { animator.CrossFadeInFixedTime("FPSHand|FireLast", 0.01f); } else { animator.CrossFadeInFixedTime("FPSHand|Fire", 0.01f); } //GameObject gunSmokeEffect = Instantiate(gunSmoke, muzzlePoint.position, muzzlePoint.rotation); //Destroy(gunSmokeEffect, 5f); muzzleflash.Play(); //soundManager.Play(gunFireSound); loadedBullets--; fireTimer = 0.0f; }
void OnTriggerEnter(Collider other) { HealthManager healthManager = other.gameObject.GetComponent <HealthManager>(); if (healthManager != null) { healthManager.ApplyDamage(Damage); } }
void ApplyFallingDamage(float fallDistance) { hm.ApplyDamage(fallDistance * fallDamageMultiplier); if (state < 2) { StartCoroutine(footsteps.JumpLand()); } StartCoroutine(FallCamera(new Vector3(12, Random.Range(-2.0f, 2.0f), 0), new Vector3(4, Random.Range(-1.0f, 1.0f), 0), 0.1f)); }
void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Enemy") { Vector3 dir = -(player.transform.position - other.transform.position).normalized; other.GetComponent <Rigidbody>().AddForce(dir * 200); HealthManager hm = other.GetComponent <HealthManager>(); hm.ApplyDamage(CurrentDamge); } }
// Handle collisions void OnTriggerEnter(Collider col) { if (col.gameObject.tag == tagToDamage) { // Damage object with relevant tag HealthManager healthManager = col.gameObject.GetComponent <HealthManager>(); healthManager.ApplyDamage(); } // Destroy self Destroy(this.gameObject); }
void OnTriggerEnter(Collider col) { if (col.gameObject.tag == tagBeenHit) { gameObject.GetComponent <Animator>().Play("Run In Place"); } if (col.gameObject.tag == tagToDamage) { HealthManager healthManager = col.gameObject.GetComponent <HealthManager>(); healthManager.ApplyDamage(damageAmount); } }
void applyRandomPowerUp() { float randomNum = Random.value; Vector3 position; if (randomNum <= 0.1) { // Damage all enemies power up GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy"); foreach (GameObject enemy in enemies) { HealthManager healthManager = enemy.GetComponent <HealthManager>(); healthManager.ApplyDamage(200); } } else if (randomNum <= 0.4 && randomNum > 0.1) { // Infinite Ammo Power Up PlayerReload playerReload = GetComponent <PlayerReload>(); playerReload.maxAmmo = 300; playerReload.ReloadAction(300); fireRate = 1000000f; ParticleSystem infAmmoParticleSystem = this.transform.Find("InfAmmo").GetComponent <ParticleSystem>(); infAmmoParticleSystem.enableEmission = true; Invoke("normalReload", 5); } else if (randomNum <= 0.7 && randomNum > 0.4) { // Health Buff Power Up PlayerHealth playerHealth = this.gameObject.GetComponent <PlayerHealth>(); playerHealth.maxHealth = 10000; HealthManager healthManager = GetComponentInParent <HealthManager>(); healthManager.currentHealth = 10000; playerHealth.OnEnable(); playerHealth.ModifyHealth(0); GameObject forceField = this.transform.Find("ForceField").gameObject; forceField.SetActive(true); Invoke("normalHealth", 5); } else { // Score Multiplier Power Up ScoreManager.killValue *= 2; InGameController inGameController = GameObject.Find("InGameController").GetComponent <InGameController>(); inGameController.multiplier = true; Invoke("normalScore", 20); } }
// Interpolate damage dealt so heal decreases gradually private IEnumerator ChangeToPercent(float percent, int bulletDamage) { float preChangePercent = foregroundImage.fillAmount; float elapsed = 0f; while (elapsed < updateSpeedSeconds) { elapsed += Time.deltaTime; foregroundImage.fillAmount = Mathf.Lerp(preChangePercent, percent, elapsed / updateSpeedSeconds); yield return(null); } foregroundImage.fillAmount = percent; HealthManager healthManager = GetComponentInParent <HealthManager>(); healthManager.ApplyDamage(bulletDamage); }
void OnTriggerEnter(Collider col) { // Debug.Log(col.gameObject.tag); if (col.gameObject.tag == tagToDamage) { // Damage object with relevant tag HealthManager healthManager = col.gameObject.GetComponent <HealthManager>(); healthManager.ApplyDamage(damageAmount); // Destroy self Destroy(this.gameObject); } if (col.gameObject.tag == tagToScenery) { Destroy(this.gameObject); } }
private void OnTriggerStay(Collider other) { if (other.tag == "Player") { _theUFO.CanMove(false); _thePlayerHP = other.GetComponent <HealthManager>(); while (_canDealDamage) { _thePlayerHP.ApplyDamage(DamageToDeal); StartCoroutine(DealDamageCo()); if (_thePlayerHP.ReturnCurentHP() <= 0.0f) { _theUFO.CanMove(true); } } //playSFX } }
public void ApplyDamage(float damage) { if (IsDead) { return; } damage *= damageFactor; if (referer) { referer.ApplyDamage(damage); } else { health -= damage; if (isPlayer) { anim.SetTrigger("damage"); } if (isPlayer && health <= 40 && health > 0) { healthText.color = Color.red; } if (health <= 0) { health = 0; if (animator) { animator.SetTrigger("Dead"); } if (removeColliderOnDeath) { RemoveColliders(GetComponents <Collider>()); RemoveColliders(GetComponentsInChildren <Collider>()); } } } }
private void Fire() { if (fireTimer < fireRate || isReloading || isRunning) { return; } RaycastHit hit; if (Physics.Raycast(shootPoint.position, shootPoint.transform.forward + Random.onUnitSphere * accuracy, out hit, range)) { GameObject hitSpark = Instantiate(hitSparkPrefab, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)); hitSpark.transform.SetParent(hit.transform); Destroy(hitSpark, 0.5f); GameObject hitHole = Instantiate(hitHolePrefab, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)); hitHole.transform.SetParent(hit.transform); Destroy(hitHole, 5.0f); Recoil(); BulletEffect(); HealthManager healthManager = hit.transform.GetComponent <HealthManager>(); if (healthManager) { healthManager.ApplyDamage(damage); } EnemyManager enemyManager = hit.transform.GetComponentInParent <EnemyManager>(); if (enemyManager) { enemyManager.ApplyDamage(damage); } Rigidbody rigidbody = hit.transform.GetComponent <Rigidbody>(); if (rigidbody) { rigidbody.AddForceAtPosition(transform.forward * 5.0f * damage, transform.position); } } currentBullets--; fireTimer = 0.0f; audioSource.PlayOneShot(shootSound); anim.CrossFadeInFixedTime("Fire", 0.01f); muzzleFlash.Play(); bulletsText.text = currentBullets + " / " + bulletsTotal; }
void OnCollisionEnter2D(Collision2D collision) { if (collisionEnabled && GetComponent <Collider2D>().IsTouchingLayers(LayerMask.GetMask("Characters"))) { collision.otherRigidbody.AddForce(new Vector2(-600, 0)); lastVictim = collision.gameObject; HealthManager hm = lastVictim.GetComponent <HealthManager>(); if (hm && hm.IsDamageable() && !hm.IsVampireDead()) // If hm is not null { hm.ApplyDamage(damageAmount); hm.SetDamageable(false); collision.rigidbody.velocity = new Vector2(0, damageVelocityVertical); damageAudio.Play(); StartCoroutine(DamageTimer(hm)); } } }
// Handle collisions void OnTriggerEnter(Collider col) { if (col.gameObject.tag == tagToDamage) { // Damage object with relevant tag HealthManager healthManager = col.GetComponent <HealthManager>(); healthManager.ApplyDamage(damageAmount); if (tagToDamage == "Player") { col.gameObject.GetComponent <AudioSource>().Play(); } // Destroy self Destroy(this.gameObject); } else if (col.gameObject.tag == "Wall") { Destroy(this.gameObject); } }
public void ApplyDamage(float damage) { if (IsDead) { return; } damage *= damageFactor; if (referer) { referer.ApplyDamage(damage); } else { health -= damage; if (health <= 0) { health = 0; } } }
// Handle collisions public void OnTriggerEnter(Collider col) { if (col.gameObject.tag == tagToDamage) { // Damage object with relevant tag HealthManager healthManager = col.gameObject.GetComponent <HealthManager>(); healthManager.ApplyDamage(damageAmount); PlaySoundOneShot(bulletHitSound); flashWhenHit(col); } //cannot damage these enemys if (col.gameObject.tag == tagUntouchableEnemys) { PlaySoundOneShot(bulletHitUntouchableSound); } //cannot damage these enemys if (col.gameObject.tag == tagWallWhite) { PlaySoundOneShot(bulletHitSound); } //cannot damage these enemys if (col.gameObject.tag == tagWallGrey) { // Damage object with relevant tag HealthManager healthManager = col.gameObject.GetComponent <HealthManager>(); healthManager.ApplyDamage(damageAmount); PlaySoundOneShot(bulletHitSound); flashWhenHit(col); } }
void Fire() { if (fireTimer < fireRate || !isEnabled) { return; } if (loadedBullets <= 0) { StartCoroutine(DisableFire()); soundManager.Play(drySound); return; } RaycastHit hit; for (int i = 0; i < pellets; i++) { if (Physics.Raycast(shootPoint.position, CalculateSpread(spread, shootPoint), out hit, range)) { HealthManager health = hit.transform.GetComponent <HealthManager>(); if (health) { health.ApplyDamage(GetWeaponDamage()); if (health.IsDead) { KillReward killReward; if (health.referer) { killReward = health.referer.transform.GetComponent <KillReward>(); } else { killReward = hit.transform.GetComponent <KillReward>(); } if (killReward) { int exp = killReward.exp; int fund = killReward.fund; levelSystem.GiveExp(exp); fundSystem.AddFund(fund); rewardText.Show(exp, fund); } } EnemyType enemyType = hit.transform.GetComponent <EnemyType>(); if (enemyType) { if (enemyType.type == Type.BIO) { CreateBlood(hit.point, hit.normal); } } else { CreateRicochet(hit.point, hit.normal); } } else { CreateRicochet(hit.point, hit.normal); if (hit.transform.tag == "bounds") { Debug.Log("Hit Wall"); } if (hit.transform.tag == "wood") { CreateWood(hit.point, hit.normal); } if (hit.transform.tag == "metal") { CreateMetal(hit.point, hit.normal); } if (hit.transform.tag == "ground") { CreateSand(hit.point, hit.normal); } if (hit.transform.tag == "stone") { CreateStone(hit.point, hit.normal); } if (hit.transform.tag == "alien") { EasterEgg.counter += 1; print(EasterEgg.counter); hit.transform.gameObject.GetComponent <AlienScript>().deathAnim(); soundManager.Play(laugh); if (EasterEgg.isComplete) { print("Easter egg complete"); } } if (hit.transform.tag == "tank") { CreateWater(hit.point, hit.normal); GameObject bulletHole = Instantiate(bulletImpact, hit.point, Quaternion.FromToRotation(Vector3.forward, hit.normal)); bulletHole.transform.SetParent(hit.transform); Destroy(bulletHole, 10f); } } } } if (hasLastFire && loadedBullets <= 1) { animator.CrossFadeInFixedTime("FPSHand|FireLast", 0.01f); } else { animator.CrossFadeInFixedTime("FPSHand|Fire", 0.01f); } GameObject gunSmokeEffect = Instantiate(gunSmoke, muzzlePoint.position, muzzlePoint.rotation); Destroy(gunSmokeEffect, 5f); GiveRecoil(); muzzleflash.Play(); soundManager.Play(gunFireSound); loadedBullets--; UpdateAmmoText(); fireTimer = 0.0f; }
void Fire() { if (!canShoot) { return; } if (loadedBullets <= 0) { // When Ammo is out, make fire is not working for a moment StartCoroutine(DisableFire()); soundManager.Play(drySound); canShoot = false; StartCoroutine(CoResetShootable()); return; } RaycastHit hit; for (int i = 0; i < pellets; i++) { if (Physics.Raycast(shootPoint.position, CalculateSpread(spread, shootPoint), out hit, range)) { HealthManager health = hit.transform.GetComponent <HealthManager>(); if (hit.transform.tag == "Player") { CreateRicochet(hit.point, hit.normal); } else if (health) { bool wasDead = health.IsDead; health.ApplyDamage(GetWeaponDamage()); if (!wasDead && health.IsDead) { KillReward killReward; // Check it was head if (health.referer) { killReward = health.referer.transform.GetComponent <KillReward>(); } else { killReward = hit.transform.GetComponent <KillReward>(); } if (killReward) { int exp = killReward.exp; int fund = killReward.fund; fundSystem.AddFund(fund); rewardText.Show(exp, fund); } } EnemyType enemyType = hit.transform.GetComponent <EnemyType>(); if (enemyType) { if (enemyType.type == HitType.BIO) { CreateBlood(hit.point, hit.transform.rotation); } } else { CreateRicochet(hit.point, hit.normal); } } else { CreateRicochet(hit.point, hit.normal); CreateBulletHole(hit.point, hit.normal, hit.transform); } } } if (hasLastFire && loadedBullets <= 1) { animator.CrossFadeInFixedTime("FPSHand|FireLast", 0.01f); } else { animator.CrossFadeInFixedTime("FPSHand|Fire", 0.01f); } GameObject gunSmokeEffect = Instantiate(gunSmoke, muzzlePoint.position, muzzlePoint.rotation); Destroy(gunSmokeEffect, 5f); GiveRecoil(); muzzleflash.Play(); soundManager.Play(gunFireSound); loadedBullets--; UpdateAmmoText(); canShoot = false; StartCoroutine(CoResetShootable()); }
void Fire() { if (fireTimer < fireRate || !isEnabled) { return; } fireTimer = 0f; // Reset timer if (loadedBullets <= 0) { // When Ammo is out, make fire is not working for a moment StartCoroutine(DisableFire()); soundManager.Play(drySound); return; } RaycastHit hit; for (int i = 0; i < pellets; i++) { if (Physics.Raycast(shootPoint.position, CalculateSpread(spread, shootPoint), out hit, range)) { HealthManager health = hit.transform.GetComponent <HealthManager>(); if (hit.transform.tag == "Player") { CreateRicochet(hit.point, hit.normal); } else if (health) { bool wasDead = health.IsDead; health.ApplyDamage(GetWeaponDamage()); if (!wasDead && health.IsDead) { KillReward killReward; // Check it was head if (health.referer) { killReward = health.referer.transform.GetComponent <KillReward>(); } else { killReward = hit.transform.GetComponent <KillReward>(); } if (killReward) { int exp = killReward.exp; int fund = killReward.fund; int playerCount = PhotonNetwork.playerList.Length; float bonusExp = exp * 0.3f; float bonusFund = fund * 0.4f; exp += ((int)bonusExp * (playerCount - 1)); fund += ((int)bonusFund * (playerCount - 1)); levelSystem.GiveExp(exp); fundSystem.AddFund(fund); GameObject[] players = GameObject.FindGameObjectsWithTag("Player"); foreach (GameObject player in players) { if (player == gameObject.transform.root.gameObject) { continue; } player.GetComponent <FundSystem>().AddBonus((int)bonusExp, (int)bonusFund); } rewardText.Show(exp, fund); // Update player status string weaponName = transform.name; switch (weaponName) { case "Glock": playerStatus.killsGlock++; break; case "MP5K": playerStatus.killsMp5k++; break; case "UMP45": playerStatus.killsUmp45++; break; case "Python": playerStatus.killsPython++; break; case "M870": playerStatus.killsM870++; break; case "AKM": playerStatus.killsAkm++; break; } playerStatus.totalKills++; } } EnemyType enemyType = hit.transform.GetComponent <EnemyType>(); if (enemyType) { if (enemyType.type == HitType.BIO) { CreateBlood(hit.point, hit.transform.rotation); } } else { CreateRicochet(hit.point, hit.normal); } } else { CreateRicochet(hit.point, hit.normal); CreateBulletHole(hit.point, hit.normal, hit.transform); } } } if (hasLastFire && loadedBullets <= 1) { animator.CrossFadeInFixedTime("FPSHand|FireLast", 0.01f); } else { animator.CrossFadeInFixedTime("FPSHand|Fire", 0.01f); } networkPlayer.FireWeapon(); GameObject gunSmokeEffect = Instantiate(gunSmoke, muzzlePoint.position, muzzlePoint.rotation); Destroy(gunSmokeEffect, 5f); GiveRecoil(); muzzleflash.Play(); soundManager.Play(gunFireSound); loadedBullets--; UpdateAmmoText(); fireTimer = 0.0f; }