protected override void Update() { base.Update(); m_Timer += Time.deltaTime; if (m_DamagedTargets.Count > 0) { foreach (Transform target in m_DamagedTargets) { if (target == null) { continue; } //Determining the base target type and then deal the proper type of damage switch (TargetType) { case TargetMask.Enemy: AITakeDamageInterface ai = target.GetComponent <AITakeDamageInterface>(); ai.TakeDamage(OwnersID, DamagePerInterval, null, 1); break; case TargetMask.Player: Player player = target.GetComponent <Player>(); player.TakeDamage(DamagePerInterval, Vector3.zero, null); break; } } m_DamagedTargets.Clear(); } }
private void OnCollisionEnter(Collision collision) { if (m_LerpingToEnemy && collision.gameObject.tag != "Enemy") { return; } m_LerpingToEnemy = false; if (collision.gameObject.tag == "Enemy" && m_NumberOfEnemyBounces < 2) { AITakeDamageInterface enemy = collision.transform.root.GetComponent <AITakeDamageInterface>(); if (enemy != null) { if (m_LastHitEnemy != enemy) { m_LastHitEnemy = enemy; if (PhotonNetwork.isMasterClient) { enemy.TakeDamage(m_ProjectileOwner, Mathf.RoundToInt(m_Damage * m_DamageMultiplier), m_StatusEffects, AIUtilits.GetCritMultiplier(collision.gameObject)); } } else { //rigidbody.velocity = Vector3.zero; //rigidbody.AddForce(-collision.contacts[0].normal * ShotSpeed, ForceMode.VelocityChange); //return; } } m_NumberOfEnemyBounces++; if (m_NumberOfEnemyBounces < 2) { BounceTomahawk(collision); } else { ReturnToPlayer(); } } else if (collision.gameObject.tag != "Enemy" && m_NumberOfSurfaceBounces < 2) { m_NumberOfSurfaceBounces++; SoundManager.GetInstance().photonView.RPC("PlaySFXNetworked", PhotonTargets.All, "TomahawkImpact", collision.gameObject.transform.position); if (m_NumberOfSurfaceBounces < 2) { BounceTomahawk(collision); } else { ReturnToPlayer(); } } }
private void OnTriggerEnter(Collider other) { if (((1 << other.gameObject.layer) & m_LayerMask) != 0) //if the collided gameobject is on the layer provided { AITakeDamageInterface enemy = other.transform.root.GetComponent <AITakeDamageInterface>(); if (enemy != null) //if the collided gameobject has a health component { if (PhotonNetwork.isMasterClient) { enemy.TakeDamage(m_ProjectileOwner, m_Damage, null, AIUtilits.GetCritMultiplier(other.gameObject)); } } } }
public void OnTriggerEnter(Collider other) { //If the thing collided with is tagged as a player get the health Component if (other.gameObject.tag == "Enemy") { //Get the health component and deal the damage if a component is found AITakeDamageInterface enemy = other.transform.root.GetComponent <AITakeDamageInterface>(); if (PhotonNetwork.isMasterClient) { for (int i = 0; i < playerRef.NumOfAttacks; i++) { enemy.TakeDamage(playerRef.PlayerNumber, (playerRef.BoostedMeleeDamage + 2) * playerRef.NumOfAttacks, null, AIUtilits.GetCritMultiplier(other.gameObject)); } } } }
private void OnCollisionEnter(Collision collision) { if (!m_CanCollide) { return; } SoundManager.GetInstance().photonView.RPC("PlaySFXNetworked", PhotonTargets.All, "GrenadeExplosion", transform.position); //instantiate explosion render GameObject explosionRenderer = (GameObject)(Instantiate(Resources.Load("Effects/ExplosionRenderer"), gameObject.transform.position, Quaternion.identity)); ExplosionEffect explosionEffect = explosionRenderer.GetComponent <ExplosionEffect>(); explosionEffect.ActivateExplosion(Radius); m_CanCollide = false; gameObject.SetActive(false); //return object to pool Collider[] colliders; //stores all colliders that were hit m_EnemiesHit.Clear(); colliders = Physics.OverlapSphere(gameObject.transform.position, Radius, m_LayerMask); //if we collided with any objects of our specific target layer mask then they take damage for (int i = 0; i < colliders.Length; i++) { AITakeDamageInterface enemy = colliders[i].transform.root.GetComponent <AITakeDamageInterface>(); if (enemy != null && !m_EnemiesHit.Contains(enemy)) //if the collided object has a health component { m_EnemiesHit.Add(enemy); if (PhotonNetwork.isMasterClient) { enemy.TakeDamage(m_ProjectileOwner, m_Damage, null, AIUtilits.GetCritMultiplier(colliders[i].gameObject)); } } } }
protected void HandleHitLogic(RaycastHit hit, int targetMask, int damage, int owner, float range, Vector3 gunLocation, bool enemyShot = false) { if (((1 << hit.collider.gameObject.layer) & targetMask) != 0) //if the raycast hit an object on the specific layer { AITakeDamageInterface enemy = null; Player p = null; if (enemyShot) { p = hit.collider.transform.root.GetComponent <Player>(); } else { enemy = hit.collider.transform.root.GetComponent <AITakeDamageInterface>(); } if (enemy != null) //if the raycasted object has a health component { if (PhotonNetwork.isMasterClient) { //Get the distance from the hit and the gun float distance = Vector3.Distance(hit.point, gunLocation); int FinalDamage = MathFunc.CalculateDamageDropoff(damage, distance, range); enemy.TakeDamage(owner, FinalDamage, null, AIUtilits.GetCritMultiplier(hit.collider.gameObject)); } } else if (p != null) { if (p.photonView.isMine) { p.TakeDamage(damage, Vector3.zero, null); } } } }