public ActionPanelPickUpHealthCrate(BattleMap Map, HealthCrate Owner, Squad ActiveSquad) : base(PanelName, Map.ListActionMenuChoice, null, false) { this.Map = Map; this.Owner = Owner; this.ActiveSquad = ActiveSquad; }
// check for collision void OnTriggerEnter(Collider otherCollider) { if (otherCollider.GetComponent <AmmoCrate>() != null) { // collect ammoCreate. AmmoCrate ammoCrate = otherCollider.GetComponent <AmmoCrate>(); ammo += ammoCrate.ammo; Destroy(ammoCrate.gameObject); } else if (otherCollider.GetComponent <HealthCrate>() != null) { // collect healthCreate. HealthCrate healthCrate = otherCollider.GetComponent <HealthCrate>(); health += healthCrate.health; Destroy(healthCrate.gameObject); } if (!isHurt) { GameObject hazard = null; if (otherCollider.GetComponent <Enemy>() != null) { Enemy enemy = otherCollider.GetComponent <Enemy>(); if (enemy.kill == false) { hazard = enemy.gameObject; health -= enemy.damage; } } else if (otherCollider.GetComponent <Bullet>() != null) { Bullet bullet = otherCollider.GetComponent <Bullet>(); if (bullet.ShotByPlayer == false) { hazard = bullet.gameObject; health -= bullet.damage; bullet.gameObject.SetActive(false); } } if (hazard != null) { isHurt = true; // knock back effect Vector3 hurtDirection = (transform.position - hazard.transform.position).normalized; Vector3 knockbackDirection = (hurtDirection + Vector3.up).normalized; GetComponent <ForceReceiver>().AddForce(knockbackDirection, knockBackForce); GetComponent <Rigidbody>().AddForce(knockbackDirection * knockBackForce); StartCoroutine(HurtRoutine()); } if (health <= 0) { if (killed == false) { killed = true; OnKill(); } } } }
public override void Update(GameTime gameTime) { int PosX = RandomHelper.Random.Next(Map.MapSize.X); int PosY = RandomHelper.Random.Next(Map.MapSize.Y); HealthCrate NewCrate = new HealthCrate(new Vector3(5, 10, 0), Map); NewCrate.Load(Map.Content); Map.LayerManager[0].ListProp.Add(NewCrate); IsEnded = true; }
void ShootBullet() { muzzleFlash.Play(); gunSound.Play(); RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, bulletRange) && hit.collider.tag == "Zombie") { GameObject impactObject = Instantiate(impactEffect, hit.point, Quaternion.identity); Destroy(impactObject, 3f); hit.collider.GetComponent <ZombieHealth>().TakeDamage(bulletDamage); } if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, bulletRange) && hit.collider.tag == "HealthCrate") { HealthCrate crate = hit.collider.GetComponent <HealthCrate>(); crate.TakeDamage(1); } }
void OnTriggerEnter(Collider otherCollider) { if (otherCollider.GetComponent <AmmoCrate>() != null) { AmmoCrate ammoCrate = otherCollider.GetComponent <AmmoCrate>(); ammo += ammoCrate.ammo; Destroy(ammoCrate.gameObject); } else if (otherCollider.GetComponent <HealthCrate>() != null) { HealthCrate healthCrate = otherCollider.GetComponent <HealthCrate>(); health += healthCrate.health; Destroy(healthCrate.gameObject); } if (!isHurt) { GameObject hazard = null; if (otherCollider.GetComponent <Enemy>() != null) { Debug.Log("Collide with enemy"); Enemy enemy = otherCollider.GetComponent <Enemy>(); if (!enemy.Killed) { hazard = enemy.gameObject; health -= enemy.damage; } } else if (otherCollider.GetComponent <Bullet>() != null) { Bullet bullet = otherCollider.GetComponent <Bullet>(); if (!bullet.ShotByPlayer) { Debug.Log("Collide with bullet"); hazard = bullet.gameObject; health -= bullet.damage; bullet.gameObject.SetActive(false); } } if (hazard != null) { isHurt = true; Vector3 hurtDirection = (transform.position - hazard.transform.position).normalized; Vector3 knockbackDirection = (hurtDirection + Vector3.up).normalized; GetComponent <ForceReceiver>().AddForce(knockbackDirection, knockbackForce); StartCoroutine(HurtRoutine()); } } if (health <= 0 && !killed) { killed = true; OnKill(); } }
public virtual void Update() { // Update gun looking gun.transform.LookAt(leftHand); // Find the nearest control point float bestDistance = Mathf.Infinity; ControlPoint closestPoint = null; foreach (ControlPoint point in FindObjectsOfType <ControlPoint>()) { if (point.ownership != ControlPoint.Ownership.RED && point.influence < 4) { float distance = Vector3.Distance(point.transform.position, transform.position); if (distance < bestDistance) { bestDistance = distance; closestPoint = point; } } } // Find the nearest health pickup float bestHealthDistance = Mathf.Infinity; HealthCrate closestHealth = null; foreach (HealthCrate healthCrate in FindObjectsOfType <HealthCrate>()) { float distance = Vector3.Distance(healthCrate.transform.position, transform.position); if (distance < bestHealthDistance) { bestHealthDistance = distance; closestHealth = healthCrate; } } // Get if there's a player if (player == null) { if (FindObjectOfType <GunManager>() != null) { player = FindObjectOfType <GunManager>().transform; } else { return; } } if (health > 20) { if (CheckIfInSights(player, transform.position)) { state = States.ATTACKING; } else { if (bestDistance > closestPoint.captureDistance) { state = States.ATTACKING_POINT; } else { state = States.DEFENDING_POINT; } } } else { state = States.RETREATING; } // Act on state switch (state) { case States.ATTACKING: agent.isStopped = true; transform.LookAt(player); transform.eulerAngles = new Vector3(0, transform.eulerAngles.y + 8.039f, 0); // Rotate Y-Axis of shooting pos Transform shootingPos = gun.GetComponent <GunObject>().shootingPos; shootingPos.LookAt(player); anim.SetBool("Shooting", true); // Shoot at the player GunObject gunProp = gun.GetComponent <GunObject>(); if (gunProp.CanShoot()) { gunProp.Shoot(); } if (gunProp.ammoInClip <= 0 && !gunProp.isReloading) { gunProp.StartCoroutine(gunProp.Reload()); gunProp.ammoTotal += gunProp.gun.ammoPerMagazine; } break; case States.DEFENDING_POINT: // Defend agent.SetDestination(randomDefencePoint + closestPoint.transform.position); anim.SetBool("Shooting", agent.remainingDistance < 1); break; case States.RETREATING: // Go to nearest health crate agent.isStopped = false; if (closestHealth != null) { agent.SetDestination(closestHealth.transform.position); anim.SetBool("Shooting", false); } else { Debug.Log("No health points found!"); state = States.DEFENDING_POINT; } break; case States.ATTACKING_POINT: if (closestPoint != null) { agent.isStopped = false; if (Vector3.Distance(transform.position, closestPoint.transform.position) >= 15) { agent.SetDestination(closestPoint.transform.position); anim.SetBool("Shooting", false); } else { anim.SetBool("Shooting", false); state = States.DEFENDING_POINT; } } break; } }
//check for collision void OnTriggerEnter(Collider otherCollider) { if (otherCollider.GetComponent <Ammocrate>() != null) { //collect ammo crate Ammocrate ammocrate = otherCollider.GetComponent <Ammocrate>(); ammo += ammocrate.ammo; Destroy(ammocrate.gameObject); } else if (otherCollider.GetComponent <HealthCrate>() != null) { //collect health crate HealthCrate healthCrate = otherCollider.GetComponent <HealthCrate>(); health += healthCrate.health; Destroy(healthCrate.gameObject); } if (isHurt == false) { //gameObject hazard = null; if (otherCollider.GetComponent <Enemy>() != null) { //Touching enemies Enemy enemy = otherCollider.GetComponent <Enemy>(); if (enemy.Killed == false) { //hazard = enemy.gameObject; health -= enemy.damage; isHurt = true; Vector3 hurtDirection = (transform.position - enemy.transform.position).normalized; Vector3 knockbackDirection = (hurtDirection + Vector3.up).normalized; GetComponent <Rigidbody>().AddForce(knockbackDirection * knockbackForce); StartCoroutine(HurtRoutine()); } } else if (otherCollider.GetComponent <Bullet>() != null) { Bullet bullet = otherCollider.GetComponent <Bullet>(); if (bullet.ShotByPlayer == false) { //hazard = bullet.gameObject; health -= bullet.damage; isHurt = true; bullet.gameObject.SetActive(false); Vector3 hurtDirection = (transform.position - bullet.transform.position).normalized; Vector3 knockbackDirection = (hurtDirection + Vector3.up).normalized; GetComponent <Rigidbody>().AddForce(knockbackDirection * knockbackForce); StartCoroutine(HurtRoutine()); } } /*if (hazard != null) * { * isHurt = true; * Vector3 hurtDirection = (transform.position - hazard.transform.position).normalized; * Vector3 knockbackDirection = (hurtDirection + Vector3.up).normalized; * GetComponent<Rigidbody>().AddForce(knockbackDirection * knockbackForce); * StartCoroutine(HurtRoutine()); * * }*/ if (health <= 0) { if (killed == false) { killed = true; OnKill(); } } } }