/// <summary> /// Start shooting lights. /// </summary> public void Launch() { try { if (Ammo > 0) { WeaponToLaunch.SetActive(true); onPlayerShoot.Invoke(); if (enableAmmo) { ammo.MinusLauncherAmmo(); // Minus one Ammo } } else { WeaponToLaunch.SetActive(false); } } catch (UnassignedReferenceException) { Debug.Log("No 'Weapon to launch' Attached!!"); } switch (cameraShakeType) { case ShakeType.none: break; case ShakeType.simpleShake: camShake.ShakeCamera(simpleShakeSettings.shakePower, simpleShakeSettings.shakeDuration); break; case ShakeType.sineShake: camShake.StartShake(sineShakeSettings); break; default: break; } }
/// <summary> /// Start Shooting!! /// </summary> public void Shoot() { if (Time.time > nextFire && Ammo > 0) { onPlayerShoot.Invoke(); nextFire = Time.time + fireRate; // add time for next fire if (enableAmmo) { ammo.MinusAmmo(); // Send Message to AmmoText GameObject that we spent one bullet } try { switch (cameraShakeType) { case ShakeType.none: break; case ShakeType.simpleShake: camShake.ShakeCamera(simpleShakeSettings.shakePower, simpleShakeSettings.shakeDuration); break; case ShakeType.sineShake: camShake.StartShake(sineShakeSettings); break; default: break; } } catch (NullReferenceException) { Debug.Log("There is no Active Camera in the Scene."); } Vector3 offset1 = transform.rotation * GrenadeOffset; // Vector3 Bullet Offset Vector2 tt = transform.up; // up direction. if (Recoil) { // a little bit of recoil. Vector3 recoilVect = new Vector3(GetComponentInParent <Transform>().rotation.x + recoilVector.x, GetComponentInParent <Transform>().rotation.y + recoilVector.y); player.transform.position = new Vector3(player.transform.position.x - recoilVect.x, player.transform.position.y - recoilVect.y, player.transform.position.z); } //Shoot!! try {// get grenade from pool and activate it and add force to it; GameObject grenade = GetPooledObject(ExtraGrenades, temp, GrenadePrefabs, GrenadePool); grenade.transform.SetPositionAndRotation(transform.position + offset1, transform.rotation); grenade.SetActive(true); grenade.GetComponent <Rigidbody2D>().AddForce(tt * force, ForceMode2D.Impulse); // Add Force to Grenade. } catch (UnassignedReferenceException) { Debug.Log("No Grenade Prefab Attached!"); } if (Poof) {// get poof and activate it; GameObject puf = GetPooledObject(extraPuff, temp, puffs, PuffPool); puf.transform.SetPositionAndRotation(transform.position, transform.rotation); puf.SetActive(true); } } }
public void Shoot() { if (Time.time > nextFire && Ammo > 0) { nextFire = Time.time + fireRate; // add time for next fire //readyToShoot = true; if (enableAmmo) { _ammo.MinusAmmo(); // Send Message to AmmoText GameObject that we spent one bullet } hit = Physics2D.Raycast(transform.position, transform.up, 1000, layers); onPlayerShoot.Invoke(); if (hit.collider != null) { switch (_target) { case target.enemies: if (hit.collider.CompareTag(enemyTag)) { hit.collider.GetComponent <HealthScore>().laserDamage(damage); } break; case target.player: if (hit.collider.CompareTag(playerTag)) { hit.collider.GetComponent <PlayerHealth>().laserDamage(damage); } break; default: break; } endPosition = hit.point - hit.normal; hitObj.transform.position = endPosition; } if (hit.collider == null) { endPosition = Vector3.up; } g = getLaser(); /// instantiate prefab. if (g == null) { return; } g.transform.SetPositionAndRotation(transform.position, transform.rotation); if (Poof) // if Poof is true,Activate Puff prefab { GameObject poff = getPuff(); // get shell from pool; if (poff == null) { return; } poff.transform.SetPositionAndRotation(g.transform.position, g.transform.rotation); poff.SetActive(true); } if (ImpactEffect) // if Poof is true,Activate Puff prefab { GameObject imp = getImpactEffect(); // get shell from pool; if (imp == null) { return; } imp.transform.SetPositionAndRotation(endPosition, Quaternion.identity); imp.SetActive(true); } Laser lase = g.GetComponent <Laser>(); lase.startposition = g.transform; lase.startWidth = startWidth; lase.hitCollider = hitObj.GetComponent <Collider2D>(); lase.lineDrawSpeed = lineDrawSpeed; lase.widthSpeed = widthSpeed; g.SetActive(true); switch (cameraShakeType) { case ShakeType.none: break; case ShakeType.simpleShake: camShake.ShakeCamera(simpleShakeSettings.shakePower, simpleShakeSettings.shakeDuration); break; case ShakeType.sineShake: camShake.StartShake(sineShakeSettings); break; default: break; } } }
/// <summary> /// shoot function. /// </summary> public void Shoot(int bullCount = 0) // Start Shooting!! { if (Time.time > nextFire) { if (Ammo > 0) { onPlayerStartShooting.Invoke(); nextFire = Time.time + fireRate; // add time for next fire if (enableAmmo) { ammo.MinusAmmo(); // Send Message to AmmoText GameObject that we spent one bullet } Vector3 Shelloffset1 = transform.rotation * ShellOffset; //Vector3 shell offset try { for (int i = 0; i < amountOfGuns; i++) { float spread = UnityEngine.Random.Range(bulletSprey.x, bulletSprey.y); Quaternion bulletRotation = Quaternion.Euler(new Vector3(0, 0, spread)); Vector3 offset3 = (transform.rotation * bulletRotation) * DegreeToVector2(90);; Vector3 offset1 = transform.rotation * bulletOffset; // Vector3 Bullet Offset Vector2 tt = offset3; GameObject bullet = getBullet(); // get bullet from pool; if (bullet == null) { return; } bullet.transform.SetPositionAndRotation(transform.position + offset1, transform.rotation); bullet.SetActive(true); if (bullet.GetComponent <Rigidbody2D>()) { bullet.GetComponent <Rigidbody2D>().AddForce(tt * force, forceMode); // Add Force to Grenade. } } if (Recoil) { // a little bit of recoil. Vector3 recoilVect = new Vector3(GetComponentInParent <Transform>().rotation.x + recoilVector.x, GetComponentInParent <Transform>().rotation.y + recoilVector.y); player.transform.position = new Vector3(player.transform.position.x - recoilVect.x, player.transform.position.y - recoilVect.y, player.transform.position.z); } if (ActivateShell) // if bool ActivateShell is true, Instantiate Shell Prefab { GameObject shell = getShell(); // get shell from pool; if (shell == null) { return; } shell.transform.SetPositionAndRotation(transform.position + Shelloffset1, transform.rotation); shell.GetComponent <BoxCollider2D>().enabled = true; shell.GetComponent <Rigidbody2D>().isKinematic = false; shell.GetComponent <Rigidbody2D>().freezeRotation = false; shell.SetActive(true); switch (shellDirection) { case direction.left: shellVector = transform.right - new Vector3(UnityEngine.Random.Range(0f, 2), 0); // Random Shell Direction break; case direction.right: shellVector = (transform.right - new Vector3(UnityEngine.Random.Range(0f, 2), 0)) * -1; // Random Shell Direction break; default: break; } Rigidbody2D ShellClone = shell.GetComponent <Rigidbody2D>(); ShellClone.AddForce(shellVector * UnityEngine.Random.Range(.2f, 4f), ForceMode2D.Force); // Add Force to Shell RigidBody2D } if (Poof) // if Poof is true,Activate Puff prefab { GameObject poff = getPuff(); // get shell from pool; if (poff == null) { return; } poff.transform.SetPositionAndRotation(transform.position, transform.rotation); poff.SetActive(true); } } catch (UnassignedReferenceException) { Debug.Log("Prefab Needed!"); } try { switch (cameraShakeType) { case ShakeType.none: break; case ShakeType.simpleShake: camShake.ShakeCamera(simpleShakeSettings.shakePower, simpleShakeSettings.shakeDuration); break; case ShakeType.sineShake: camShake.StartShake(sineShakeSettings); break; default: break; } } catch (NullReferenceException) { Debug.Log("No Active Camera or 'Camera Shake' Script doesn't attached to Camera! "); } onPlayerStopShooting.Invoke(); } else { onPlayerOutOfAmmo.Invoke(); } } }
// public void shot() { if (Time.time > nextFire && Ammo > 0) { nextFire = Time.time + fireRate; // add time for next fire //readyToShoot = true; if (enableAmmo) { _ammo.MinusAmmo(); // Send Message to AmmoText GameObject that we spent one bullet } onPlayerShoot.Invoke(); hit = Physics2D.Raycast(transform.position, transform.up, 200, layers); if (hit.collider != null) { switch (_target) { case target.enemies: if (hit.collider.CompareTag(enemyTag)) { hit.collider.GetComponent <HealthScore>().laserDamage(damage); } break; case target.player: if (hit.collider.CompareTag(enemyTag)) { hit.collider.GetComponent <PlayerHealth>().laserDamage(damage); } break; default: break; } } if (hit.collider != null) { for (int i = 0; i < NumToSpawn; i++) { // instantiate lightning prefabs. GameObject litGO = Instantiate(lightningPrefab, transform.position, Quaternion.identity); if (hit.collider != null) { hitPosition.y = hit.point.y - hit.normal.y; hitPosition.x = hit.point.x - hit.normal.x; tr.transform.position = hitPosition; litGO.GetComponent <Lightning>().EndPoint = tr.transform; } } } switch (cameraShakeType) { case ShakeType.none: break; case ShakeType.simpleShake: camShake.ShakeCamera(simpleShakeSettings.shakePower, simpleShakeSettings.shakeDuration); break; case ShakeType.sineShake: camShake.StartShake(sineShakeSettings); break; default: break; } if (Poof) // if Poof is true,Activate Puff prefab { GameObject poff = getPuff(); // get shell from pool; if (poff == null) { return; } poff.transform.SetPositionAndRotation(transform.position, transform.rotation); poff.SetActive(true); } if (ImpactEffect) // if Poof is true,Activate Puff prefab { if (hit) { GameObject imp = getImpactEffect(); // get shell from pool; if (imp == null) { return; } imp.transform.SetPositionAndRotation(hitPosition, hit.transform.rotation); imp.SetActive(true); } } if (_target == target.player) { shoot = false; } } }