public void Shoot() { RaycastHit hit; float distance = 5f; Vector3 direction = transform.forward; Vector3 spread = new Vector3(); spread = spread + (transform.right * Random.Range(-1f, 1f)); direction += spread.normalized * Random.Range(0f, 0.2f); //Vector3 fwd = transform.TransformDirection(Vector3.forward * 10); Ray DetectionRay = new Ray(transform.position, direction); if (Physics.Raycast(DetectionRay, out hit, distance)) { Debug.DrawLine(transform.position, hit.point, Color.green, 1f); if (hit.collider.tag == "Zombie") { //If Zombie is hit, destroy that specific GameObject, and decrease # of zombies Debug.Log("Hit!"); //Checks the zombie health script. ZombieAI health = hit.collider.GetComponent <ZombieAI>(); //this sets how much damage a zombie will take. See why this may not work if its attached to every gun? 1 damage isnt going to cut it if we're using miniguns or shotguns, etc. health.TakeDamage(1, hit.point); if (health != null) { health.TakeDamage(0, hit.point); Debug.Log("Zombie Health: " + health.currentHealth); } //Need health.takedamage(1,hit.point) } //A repeat of above, except with EL DIABLO!! if (hit.collider.tag == "Devil") { DevilScript health = hit.collider.GetComponent <DevilScript>(); //If Zombie is hit, destroy that specific GameObject, and decrease # of zombies Debug.Log("Hit!"); if (health != null) { health.TakeDamage(1, hit.point); Debug.Log("Devil health = " + health.currentHealth); } } } else { Debug.DrawRay(this.transform.position, direction, Color.red, 0.2f); } }
public void gotShot() { fwd = transform.TransformDirection(Vector3.forward * 10); Ray DetectionRay = new Ray(transform.position, fwd); //Physics capsule cast //Gotta figure this out later if (Physics.CapsuleCast(transform.position, fwd, 1.5f, Vector3.forward, out hit, distance)) { if (hit.collider.tag == "Zombie") { Debug.Log("Capsule hit!"); } } if (Physics.Raycast(DetectionRay, out hit, distance)) { //Ray Debugger Debug.DrawRay(transform.position, fwd, Color.green); if (hit.collider.tag == "Zombie") { //If Zombie is hit, destroy that specific GameObject, and decrease # of zombies Debug.Log("Hit!"); //Checks the zombie health script. ZombieAI health = hit.collider.GetComponent <ZombieAI>(); //this sets how much damage a zombie will take. See why this may not work if its attached to every gun? 1 damage isnt going to cut it if we're using miniguns or shotguns, etc. health.TakeDamage(1, hit.point); if (health != null) { health.TakeDamage(0, hit.point); Debug.Log("Zombie Health: " + health.currentHealth); } //Need health.takedamage(1,hit.point) Debug.Log(Zoomzoom.numEnemy); } //A repeat of above, except with EL DIABLO!! if (hit.collider.tag == "Devil") { DevilScript health = hit.collider.GetComponent <DevilScript>(); //If Zombie is hit, destroy that specific GameObject, and decrease # of zombies Debug.Log("Hit!"); if (health != null) { health.TakeDamage(1, hit.point); Debug.Log("Devil health = " + health.currentHealth); } } } }
// Update is called once per frame void Update() { //Checks the forward Facing Direction & raycasts fwd = transform.TransformDirection(Vector3.forward * 10); Ray DetectionRay = new Ray(transform.position, fwd); //Fire by MB1 or Spacebar if (Input.GetMouseButtonDown(0) || Input.GetKeyDown("space")) { //Ray Debugger Debug.DrawRay(transform.position, fwd, Color.cyan); if (Physics.Raycast(DetectionRay, out hit, distance)) { if (hit.collider.tag == "Zombie") { //If Zombie is hit, destroy that specific GameObject, and decrease # of zombies Debug.Log("Hit!"); //Checks the zombie health script. ZombieAI health = hit.collider.GetComponent <ZombieAI>(); //this sets how much damage a zombie will take. See why this may not work if its attached to every gun? 1 damage isnt going to cut it if we're using miniguns or shotguns, etc. health.TakeDamage(damage, hit.point); if (health != null) { health.TakeDamage(0, hit.point); Debug.Log("Zombie Health: " + health.currentHealth); } //Need health.takedamage(1,hit.point) } //A repeat of above, except with EL DIABLO!! if (hit.collider.tag == "Devil") { DevilScript health = hit.collider.GetComponent <DevilScript>(); //If Zombie is hit, destroy that specific GameObject, and decrease # of zombies Debug.Log("Hit!"); if (health != null) { health.TakeDamage(damage, hit.point); Debug.Log("Devil health = " + health.currentHealth); } } } } }
private void OnTriggerStay2D(Collider2D collision) { if (collision.tag == "Enemy") { EyeScript es = collision.GetComponent <EyeScript>(); if (es != null) { if (this.prestige < es.prestige) { waiting = true; } } else { ImpScript im = collision.GetComponent <ImpScript>(); if (im != null) { if (this.prestige < im.prestige) { waiting = true; } } else { DevilScript ds = collision.GetComponent <DevilScript>(); if (ds != null) { if (this.prestige < ds.prestige) { waiting = true; } } else { DarkAngelScript da = collision.GetComponent <DarkAngelScript>(); if (da != null) { waiting = true; } } } } } }
// This may need to be moved onto something else later. Perhaps a damager script? private void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag == "Fireball") { devilGO = GameObject.FindGameObjectWithTag("Devil"); devil = devilGO.GetComponent <DevilScript>(); Debug.Log("FUEGO!!!"); Destroy(collision.gameObject); TakeDamage(devil.fireballDamage); } else if (collision.gameObject.tag == "Zombie") { zombieGO = GameObject.FindGameObjectWithTag("Zombie"); zombie = zombieGO.GetComponent <ZombieAI>(); TakeDamage(zombie.zombieDamage); } }
public void Shoot() { RaycastHit hit; List <Ray> rays = new List <Ray>(); float distance = 4f; int numberOfRaysToShoot = 4; Vector3 fwd = transform.TransformDirection(Vector3.forward * 10); Ray DetectionRay = new Ray(transform.position, fwd); Ray NewDetectRay; Vector3 direction = transform.forward; Vector3 spread = new Vector3(); for (int i = 0; i < numberOfRaysToShoot; i++) { spread = spread + (transform.right * Random.Range(-1f, 1f)); direction += spread.normalized * Random.Range(0f, 0.2f); //rays.Add(Camera.main.ViewportPointToRay(new Vector3(Random.value, 0f, Random.value))); //fwd = transform.TransformDirection(new Vector3(0,0,0)); rays.Add(NewDetectRay = new Ray(direction, fwd)); } foreach (Ray ray in rays) { if (Physics.Raycast(ray, out hit, distance)) { Debug.DrawLine(transform.position, hit.point, Color.green, 1f); if (hit.collider.tag == "Zombie") { //If Zombie is hit, destroy that specific GameObject, and decrease # of zombies Debug.Log("Hit!"); //Checks the zombie health script. ZombieAI health = hit.collider.GetComponent <ZombieAI>(); //this sets how much damage a zombie will take. See why this may not work if its attached to every gun? 1 damage isnt going to cut it if we're using miniguns or shotguns, etc. health.TakeDamage(1, hit.point); if (health != null) { health.TakeDamage(0, hit.point); Debug.Log("Zombie Health: " + health.currentHealth); } //Need health.takedamage(1,hit.point) } //A repeat of above, except with EL DIABLO!! if (hit.collider.tag == "Devil") { DevilScript health = hit.collider.GetComponent <DevilScript>(); //If Zombie is hit, destroy that specific GameObject, and decrease # of zombies Debug.Log("Hit!"); if (health != null) { health.TakeDamage(1, hit.point); Debug.Log("Devil health = " + health.currentHealth); } } } else { Debug.DrawRay(this.transform.position, direction, Color.red, 0.2f); } } }