public void Damage(GunHit gunHit) { health -= gunHit.damage; if (health <= 0) { this.gameObject.SetActive(false); } }
void Damage(GunHit gunHit) { if (gunHit.raycastHit.normal != Vector3.zero) { Instantiate(objectToSpawn, gunHit.raycastHit.point, Quaternion.LookRotation(gunHit.raycastHit.normal)); } }
public void TakeDamage(GunHit gunHit) { Instantiate(objectToSpawn, gunHit.raycastHit.point, Quaternion.LookRotation(gunHit.raycastHit.normal)); currentHealth -= gunHit.damage; if (currentHealth <= 0) { Destroy(gameObject); } }
void Update() { UpdateCrosshair(); Crosshair crosshair = this.gameObject.GetComponentInParent <Crosshair> (); screenPos = crosshair.getScreenPos(); if (Input.GetKey(KeyCode.Space) && readyToFire) { RaycastHit hit; if (Physics.Raycast(mainCamera.ScreenPointToRay(screenPos), out hit, hitDistance)) { GunHit gunHit = new GunHit(); gunHit.damage = damage; gunHit.raycastHit = hit; if (hit.collider.gameObject.GetComponent <Target>() != null) { GameObject hole = Instantiate(bulletHole, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)) as GameObject; hole.transform.parent = hit.collider.gameObject.transform; hit.collider.SendMessage("Damage", gunHit, SendMessageOptions.DontRequireReceiver); } else if (hit.collider.gameObject.GetComponentInParent <Target>() != null) { Target target = hit.collider.gameObject.GetComponentInParent <Target>(); target.Damage(gunHit); } else { GameObject hole = Instantiate(bulletHole, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)) as GameObject; hole.transform.parent = hit.collider.gameObject.transform; Destroy(hole, 5); } } AudioSource shot = gameObject.GetComponent <AudioSource>(); shot.PlayOneShot(bulletShot, 1); fire.SetActive(true); readyToFire = false; } if (!readyToFire) { timeElapsed += Time.deltaTime; if (timeElapsed > bulletDelay) { fire.SetActive(false); timeElapsed = 0; readyToFire = true; } } }
void Update() { if (Input.GetAxis(buttonName) > 0 && readyToFire) { RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit, Mathf.Infinity, layerMask)) { if (hit.collider.tag == "Enemy") { GunHit gunHit = new GunHit(); gunHit.damage = damage; gunHit.raycastHit = hit; hit.collider.SendMessage("Damage", gunHit, SendMessageOptions.DontRequireReceiver); } } } }
void Shoot() { MuzzleFlash.Play(); RaycastHit hit; if (Physics.Raycast(fpscam.transform.position, fpscam.transform.forward, out hit, range)) { Debug.Log(hit.transform.name); GunHit target = hit.transform.GetComponent <GunHit>(); if (target != null) { target.TakeDamage(damage); } Instantiate(ImpactEffect, hit.point, Quaternion.LookRotation(hit.normal)); } }
protected override void PrimaryFire() { for (int i = 0; i < shotFragments; i++) { RaycastHit hit; Quaternion fireRotation = Quaternion.LookRotation(transform.forward); Quaternion randomRotation = Random.rotation; fireRotation = Quaternion.RotateTowards(fireRotation, randomRotation, Random.Range(0.0f, spreadAngle)); if (Physics.Raycast(transform.position, fireRotation * Vector3.forward, out hit, Mathf.Infinity, layerMask)) { GunHit gunHit = new GunHit(); gunHit.damage = damage; gunHit.raycastHit = hit; hit.collider.SendMessage("Damage", gunHit, SendMessageOptions.DontRequireReceiver); } } }
protected override void PrimaryFire() { for(int i = 0; i < shotFragments; i++) { RaycastHit hit; Quaternion fireRotation = Quaternion.LookRotation(transform.forward); Quaternion randomRotation = Random.rotation; fireRotation = Quaternion.RotateTowards(fireRotation,randomRotation,Random.Range(0.0f,spreadAngle)); if(Physics.Raycast(transform.position,fireRotation*Vector3.forward,out hit,Mathf.Infinity,layerMask)) { GunHit gunHit = new GunHit(); gunHit.damage = damage; gunHit.raycastHit = hit; hit.collider.SendMessage("Damage",gunHit,SendMessageOptions.DontRequireReceiver); } } }
void Update() { UpdateCrosshair (); Crosshair crosshair = this.gameObject.GetComponentInParent<Crosshair> (); screenPos = crosshair.getScreenPos (); if (Input.GetKey (KeyCode.Space) && readyToFire) { RaycastHit hit; if(Physics.Raycast(mainCamera.ScreenPointToRay(screenPos), out hit, hitDistance)){ GunHit gunHit = new GunHit(); gunHit.damage = damage; gunHit.raycastHit = hit; if(hit.collider.gameObject.GetComponent<Target>() != null){ GameObject hole = Instantiate(bulletHole, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)) as GameObject; hole.transform.parent = hit.collider.gameObject.transform; hit.collider.SendMessage("Damage", gunHit, SendMessageOptions.DontRequireReceiver); } else if(hit.collider.gameObject.GetComponentInParent<Target>() != null){ Target target = hit.collider.gameObject.GetComponentInParent<Target>(); target.Damage(gunHit); } else{ GameObject hole = Instantiate(bulletHole, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal)) as GameObject; hole.transform.parent = hit.collider.gameObject.transform; Destroy(hole,5); } } AudioSource shot = gameObject.GetComponent<AudioSource>(); shot.PlayOneShot(bulletShot, 1); fire.SetActive(true); readyToFire = false; } if (!readyToFire) { timeElapsed += Time.deltaTime; if(timeElapsed > bulletDelay){ fire.SetActive(false); timeElapsed = 0; readyToFire = true; } } }
// Update is called once per frame void Update () { if(Input.GetButton(buttonName)) //GetButtonDown for semi-auto, GetButton for automatic fire { fireTime += Time.deltaTime; if(readyToFire) { RaycastHit hit; Vector3 fireDirection = transform.forward; Quaternion fireRotation = Quaternion.LookRotation(fireDirection); Quaternion randomRotation = Random.rotation; float currentSpread = bulletSpreadCurve.Evaluate(fireTime/timeTillMaxSpreadAngle)*maxBulletSpreadAngle; //float currentSpread = Mathf.Lerp(0.0f, maxBulletSpreadAngle, fireTime/timeTillMaxSpreadAngle); fireRotation = Quaternion.RotateTowards(fireRotation,randomRotation,Random.Range(0.0f,currentSpread)); if(Physics.Raycast(transform.position,fireRotation*Vector3.forward,out hit,Mathf.Infinity,layerMask)) { GunHit gunHit = new GunHit(); gunHit.damage = damage; gunHit.raycastHit = hit; hit.collider.SendMessage("Damage",gunHit,SendMessageOptions.DontRequireReceiver); readyToFire = false; Invoke("SetReadyToFire", fireDelay); } } } else { fireTime = 0.0f; } }
// Update is called once per frame void Update() { if (Input.GetButton(buttonName)) //GetButtonDown for semi-auto, GetButton for automatic fire { fireTime += Time.deltaTime; if (readyToFire) { RaycastHit hit; Vector3 fireDirection = transform.forward; Quaternion fireRotation = Quaternion.LookRotation(fireDirection); Quaternion randomRotation = Random.rotation; float currentSpread = bulletSpreadCurve.Evaluate(fireTime / timeTillMaxSpreadAngle) * maxBulletSpreadAngle; //float currentSpread = Mathf.Lerp(0.0f, maxBulletSpreadAngle, fireTime/timeTillMaxSpreadAngle); fireRotation = Quaternion.RotateTowards(fireRotation, randomRotation, Random.Range(0.0f, currentSpread)); if (Physics.Raycast(transform.position, fireRotation * Vector3.forward, out hit, Mathf.Infinity, layerMask)) { GunHit gunHit = new GunHit(); gunHit.damage = damage; gunHit.raycastHit = hit; hit.collider.SendMessage("Damage", gunHit, SendMessageOptions.DontRequireReceiver); readyToFire = false; Invoke("SetReadyToFire", fireDelay); } } } else { fireTime = 0.0f; } }
// Update is called once per frame void Update() { if (isActiveAndEnabled) { Ammo current = GetComponent <Ammo>(); Ammo.currentWeapon = "Shotgun"; hasammo = Ammo.shells; } if (Input.GetButton("Fire1") && Time.time > nextFire && isActiveAndEnabled && hasammo > 0) { nextFire = Time.time + fireRate; Ammo getammo = (Ammo)this.GetComponentInParent(typeof(Ammo)); myGun = Ammo.currentWeapon = "Shotgun"; getammo.UseAmmo(myGun); for (int i = 0; i < shellFragments; i++) { StartCoroutine(ShotEffect()); Vector3 rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0)); RaycastHit hit; Vector3 fireDirection = fpsCam.transform.forward; Quaternion fireRotation = Quaternion.LookRotation(fireDirection); Quaternion randomrotation = Random.rotation; fireRotation = Quaternion.RotateTowards(fireRotation, randomrotation, Random.Range(0.0f, spreadAngle)); if (Physics.Raycast(rayOrigin, fireRotation * Vector3.forward, out hit, weaponRange)) { GunHit gunHit = new GunHit(); gunHit.damage = Damage; gunHit.raycastHit = hit; CanShoot health = hit.collider.GetComponent <CanShoot>(); if (health == true) { } else { Instantiate(objectToSpawn, gunHit.raycastHit.point, Quaternion.LookRotation(gunHit.raycastHit.normal)); } if (health != null) { health.TakeDamage(gunHit); } if (hit.rigidbody != null) { hit.rigidbody.AddForce(-hit.normal * hitForce); } } else { //laserLine.SetPosition (1, rayOrigin + (fpsCam.transform.forward * weaponRange)); } } } }
void Damage(GunHit gunHit) { Instantiate(objectToSpawn,gunHit.raycastHit.point,Quaternion.LookRotation(gunHit.raycastHit.normal)); }
protected override void Moving() { this.neutlal = this.motion == Riveradar.MOTION.neutral; switch (this.motion) { case Riveradar.MOTION.neutral: if (this.moveflame) { for (int index = 0; index < this.target.Count; ++index) { if (this.target[index].ManualFrame < 2) { ++this.target[index].ManualFrame; if (this.target[index].ManualFrame == 2) { this.sound.PlaySE(SoundEffect.search); } } } this.animationpoint = this.AnimeNeutral(this.frame); if (this.frame >= 6) { if (this.target.Count < this.manytarget) { var newTarget = this.RandomPanel(this.UnionEnemy); var newTargetEffect = new RiveradarCrosshair(this.sound, this.parent, newTarget.X, newTarget.Y, this.picturename, this.version); this.target.Add(newTargetEffect); this.parent.effects.Add(newTargetEffect); } this.frame = 0; ++this.roopneutral; if (this.roopneutral >= 2 && this.parent.nowscene != SceneBattle.BATTLESCENE.end) { this.roopneutral = 0; if (this.target.Count == this.manytarget && this.target[this.manytarget - 1].ManualFrame >= 2 && !this.badstatus[4]) { this.speed = 4; this.motion = Riveradar.MOTION.attackStart; this.counterTiming = true; } else { this.motion = Riveradar.MOTION.move; } } } break; } break; case Riveradar.MOTION.move: ++this.roopmove; this.motion = Riveradar.MOTION.neutral; this.MoveRandom(false, false); if (this.position == this.positionre) { this.motion = Riveradar.MOTION.neutral; this.frame = 0; this.roopneutral = 0; break; } this.parent.effects.Add(new MoveEnemy(this.sound, this.parent, this.position.X, this.position.Y)); this.position = this.positionre; this.PositionDirectSet(); this.frame = 0; this.roopneutral = 0; break; case Riveradar.MOTION.attackStart: if (this.moveflame) { this.animationpoint = this.AnimeMove(this.frame); if (this.frame >= 2) { this.counterTiming = false; this.motion = Riveradar.MOTION.attack; this.frame = 0; } break; } break; case Riveradar.MOTION.attack: this.animationpoint.X = this.attackanimation ? 8 : 7; if (this.moveflame) { this.attackanimation = !this.attackanimation; if (this.attackanimation) { this.sound.PlaySE(SoundEffect.vulcan); List <AttackBase> attacks = this.parent.attacks; IAudioEngine sound1 = this.sound; SceneBattle parent1 = this.parent; Point point = this.target[0].position; int x1 = point.X; point = this.target[0].position; int y1 = point.Y; int union1 = (int)this.union; int power = this.Power; int speed = this.speed; int element = (int)this.element; BombAttack bombAttack = new BombAttack(sound1, parent1, x1, y1, (Panel.COLOR)union1, power, speed, (ChipBase.ELEMENT)element); attacks.Add(bombAttack); List <EffectBase> effects = this.parent.effects; IAudioEngine sound2 = this.sound; SceneBattle parent2 = this.parent; point = this.target[0].position; int x2 = point.X; point = this.target[0].position; int y2 = point.Y; int union2 = (int)this.union; GunHit gunHit = new GunHit(sound2, parent2, x2, y2, (Panel.COLOR)union2); effects.Add(gunHit); this.parent.effects.Add(new BulletShells(this.sound, this.parent, this.position, this.positionDirect.X - 8 * this.UnionRebirth, this.positionDirect.Y - 24f, 32, this.union, 20 + this.Random.Next(20), 2, 0)); this.target[0].flag = false; this.target.RemoveAt(0); } if (this.target.Count <= 0 && !this.attackanimation) { foreach (var crosshair in this.target) { crosshair.ManualFrame = 0; } this.frame = 0; this.roopmove = 0; this.roopneutral = 0; this.speed = this.nspeed; this.motion = Riveradar.MOTION.attackEnd; } break; } break; case Riveradar.MOTION.attackEnd: if (this.moveflame) { this.animationpoint = this.AnimeMoveEND(this.frame); if (this.frame >= 2) { this.motion = Riveradar.MOTION.neutral; this.frame = 0; this.speed = this.nspeed; } break; } break; } this.FlameControl(); this.MoveAftar(); }
void Automatic() { if (canFire) { if (Input.GetMouseButton(0)) { firing = true; if(Time.time > nextFire) { heat += overheat; nextFire = Time.time + fireRate; fireTime += Time.deltaTime; RaycastHit hit; Ray ray = camera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0f)); fireDirection = ray.direction; Quaternion fireRotation = Quaternion.LookRotation(fireDirection); Quaternion randomRotation = Random.rotation; float currentSpread = bulletSpreadCurve.Evaluate(fireTime / timeTillMaxSpreadAngle) * maxBulletSpreadAngle; fireRotation = Quaternion.RotateTowards(fireRotation, randomRotation, Random.Range(0.0f, currentSpread)); if (Physics.Raycast(transform.position, fireRotation * Vector3.forward, out hit, Mathf.Infinity, layerMask)) { GunHit gunHit = new GunHit(); gunHit.damage = damage; gunHit.raycastHit = hit; if (hit.collider.name.Contains("Geck")) { hit.collider.GetComponent<PhotonView>().RPC("Damage", PhotonTargets.All, gunHit.damage); } Instantiate(heatmark, gunHit.raycastHit.point, Quaternion.LookRotation(gunHit.raycastHit.normal)); } Debug.DrawRay(this.transform.position, fireRotation * Vector3.forward * range, Color.red, 0f, false); } } else { firing = false; } } if(!firing) { fireTime = 0.0f; heat -= cooldown; } if (heat >= 1) { canFire = false; firing = false; } else if (heat <= .2 && heat > 0) { canFire = true; } else if (heat <= 0) { heat = 0; canFire = true; } }
void FixedUpdate() { if(firing) { muzzleFlash1.SetActive (false); muzzleFlash2.SetActive (false); anim.SetTrigger("Shooting"); fireTime += Time.deltaTime; firing = false; RaycastHit hit; Vector3 fireDirection = bulletSpawn1.forward; Quaternion fireRotation = Quaternion.LookRotation(fireDirection); Quaternion randomRotation = Random.rotation; float currentSpread = Mathf.Lerp(0.0f, maxBulletSpreadAngle, fireTime/timeToSpread); fireRotation = Quaternion.RotateTowards(fireRotation, randomRotation, Random.Range(0.0f, currentSpread)); if (Physics.Raycast (bulletSpawn1.position, fireRotation * Vector3.forward, out hit)) { //Debug.Log(hit.collider); if (hit.collider.tag == "Head") { BlockCharacterLife causeDD = hit.transform.GetComponentInParent<BlockCharacterLife>(); if(causeDD != null) { GunHit gunHit = new GunHit(); gunHit.damage = damage; gunHit.raycastHit = hit; hit.collider.SendMessage("Damage", gunHit, SendMessageOptions.DontRequireReceiver); causeDD.shots += 25; } EnemyHealth1 enemyHealth = hit.collider.GetComponentInParent<EnemyHealth1> (); if (enemyHealth != null) { enemyHealth.TakeDamage (damage * attackBooster, hit.transform.position); //other.rigidbody.AddForceAtPosition(Vector3.forward * 10, other.transform.position); } } else if (hit.transform.tag == "Environment") { GunHit gunHit = new GunHit(); gunHit.damage = damageFloat; gunHit.raycastHit = hit; hit.collider.SendMessage("Damage", gunHit, SendMessageOptions.DontRequireReceiver); //HUDEnemyCounter.enemyCounter--; } else if (hit.collider.tag == "Body") { BlockCharacterLife causeDD = hit.transform.GetComponentInParent<BlockCharacterLife>(); if(causeDD != null) { GunHit gunHit = new GunHit(); gunHit.damage = damage; gunHit.raycastHit = hit; hit.collider.SendMessage("Damage", gunHit, SendMessageOptions.DontRequireReceiver); causeDD.shots += 15; EnemyHealth1 enemyHealth = hit.collider.GetComponentInParent<EnemyHealth1> (); if (enemyHealth != null) { enemyHealth.TakeDamage (damage * attackBooster, hit.transform.position); //other.rigidbody.AddForceAtPosition(Vector3.forward * 10, other.transform.position); } } } else if (hit.collider.tag == "Poppy") { PoppyLife poppyLife = hit.collider.GetComponent<PoppyLife> (); if(poppyLife != null) { GunHit gunHit = new GunHit(); gunHit.damage = damage; gunHit.raycastHit = hit; hit.collider.SendMessage("Damage", gunHit, SendMessageOptions.DontRequireReceiver); poppyLife.TakeDamage (2); //poppyLife.shots++; } } else if (hit.collider.tag == "Bobby") { PoppyLife poppyLife = hit.collider.GetComponent<PoppyLife> (); if(poppyLife != null) { GunHit gunHit = new GunHit(); gunHit.damage = damage; gunHit.raycastHit = hit; hit.collider.SendMessage("Damage", gunHit, SendMessageOptions.DontRequireReceiver); poppyLife.TakeDamage (150); //poppyLife.shots += 75; } } else if (hit.collider.tag == "Legs") { BlockCharacterLife causeDD = hit.transform.GetComponentInParent<BlockCharacterLife>(); if(causeDD != null) { GunHit gunHit = new GunHit(); gunHit.damage = damage; gunHit.raycastHit = hit; hit.collider.SendMessage("Damage", gunHit, SendMessageOptions.DontRequireReceiver); causeDD.shots += 10; EnemyHealth1 enemyHealth = hit.collider.GetComponentInParent<EnemyHealth1> (); if (enemyHealth != null) { enemyHealth.TakeDamage (damage * attackBooster, hit.transform.position); //other.rigidbody.AddForceAtPosition(Vector3.forward * 10, other.transform.position); } } } else if (hit.collider.tag == "Arms") { BlockCharacterLife causeDD = hit.transform.GetComponentInParent<BlockCharacterLife>(); if(causeDD != null) { GunHit gunHit = new GunHit(); gunHit.damage = damage; gunHit.raycastHit = hit; hit.collider.SendMessage("Damage", gunHit, SendMessageOptions.DontRequireReceiver); causeDD.shots += 10; EnemyHealth1 enemyHealth = hit.collider.GetComponentInParent<EnemyHealth1> (); if (enemyHealth != null) { enemyHealth.TakeDamage (damage * attackBooster, hit.transform.position); //other.rigidbody.AddForceAtPosition(Vector3.forward * 10, other.transform.position); } } } /*impacts[currentImpact].transform.position = hit.point; impacts[currentImpact].GetComponent<ParticleSystem>().Play(); if(++currentImpact >= maxImpacts) { currentImpact = 0; }*/ } } }