private void KillAllEnnemies() { int maxLifeEnnemies = 100; GameObject[] ennemies = GameObject.FindGameObjectsWithTag("Ennemi"); foreach (GameObject ennemi in ennemies) { iDamageable ennemiToKill = ennemi.GetComponent <iDamageable>(); ennemiToKill.TakeDammageInt(maxLifeEnnemies); } }
void ShootGun() { RaycastHit raycastHit; bool hit = UpdateViserHitLocation(out raycastHit); if (hit) { iDamageable ennemi = null; if (raycastHit.collider.GetComponent <Personnage>() == null) { ennemi = raycastHit.collider.gameObject.GetComponent <iDamageable>(); } if (ennemi != null) { ennemi.TakeDammageInt(DamageAmount); } } IncreaseGunBar(); }
public void VerifyIfBulletHit() { Ray sight = new Ray(); sight.origin = new Vector3(transform.position.x, transform.position.y + 6.5f, transform.position.z); sight.direction = transform.forward; RaycastHit objectHit; Vector3 fwd = transform.TransformDirection(Vector3.forward); if (Physics.Raycast(sight, out objectHit)) { Debug.DrawLine(sight.origin, objectHit.point, Color.red, 10); ShootLaserFromTargetPosition(sight.origin); if (objectHit.collider.tag == "Player") { iDamageable playerDamage = objectHit.collider.gameObject.GetComponent <iDamageable>(); playerDamage.TakeDammageInt(DamageAmount); } } }
protected bool MeleeHitCheck() { bool hitDetected = false; RaycastHit objectHit; Physics.Raycast(raycastObject.transform.position, gameObject.transform.forward, out objectHit, 7); if (Physics.Raycast(RaycastObject.transform.position + new Vector3(0, 5, 0), gameObject.transform.forward, out objectHit, 3)) { iDamageable ennemi = objectHit.collider.gameObject.GetComponent <iDamageable>(); if (ennemi != null) { ennemi.TakeDammageInt(10); } hitDetected = true; } else { hitDetected = false; } return(hitDetected); }
public void GiveDammage() { iDamageable dammagePlayer = playerTarget.GetComponent <iDamageable>(); dammagePlayer.TakeDammageInt(DamageAmount); }