Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- public class player_movement : MonoBehaviour {
- public float speed;
- public float health;
- public bool isOnFirstLevel;
- public GameObject pistolBullet;
- public GameObject shotgunBullet;
- public GameObject shotgunBullet2;
- public GameObject bullet;
- public GameObject bullet2;
- public GameObject bullet3;
- public GameObject ionBullet;
- public GameObject ionBullet2;
- public GameObject ionSounder;
- public GameObject grenade;
- public GameObject rocket;
- public GameObject healthdraw;
- public GameObject uziBullet;
- public GameObject rifleBullet;
- public GameObject explosion;
- public GameObject Mexplosion;
- public GameObject Trexplosion;
- public GameObject explosionSounder;
- public GameObject gunModel1;
- public GameObject gunModel2;
- public GameObject gunModel3;
- public GameObject gunRotate3;
- public GameObject gunRotate33;
- public GameObject gunModel4;
- public GameObject gunModel5;
- public GameObject gunRotate5;
- public GameObject gunModel6;
- public GameObject gunModel7;
- public GameObject gunModel8;
- public GameObject gunModel9;
- public float fireDelay;
- public bool death;
- public float gun1;
- public float gun2;
- public float gun3;
- public float gun4;
- public float gun5;
- public float gun6;
- public float gun7;
- public float gun8;
- public float gun9;
- public float equip;
- public int ammo1;
- public int ammo2;
- public int ammo3;
- public int ammo4;
- public int ammo5;
- public int ammo6;
- public int ammo7;
- public int ammo8;
- public int ammo9;
- public Transform shootPlace;
- public Transform shootPlace1;
- public Transform shootPlace2;
- public Transform shootPlace3;
- public Transform shootPlace4;
- public Transform shootPlace5;
- public Transform shootPlace6;
- public Transform shootPlace7;
- public Transform shootPlace8;
- public Transform shootPlace9;
- public Transform gunHand;
- public Rigidbody myBody;
- public Text healthText;
- public Text equipText;
- public Text weaponText1;
- public Text weaponText2;
- public Text weaponText3;
- public Text weaponText4;
- public Text weaponText5;
- public Text weaponText6;
- public Text weaponText7;
- public Text weaponText8;
- public Text weaponText9;
- public Text ammoText;
- private float nextFire;
- void Start(){
- health = 100;
- UpdateHealth ();
- equipText.text = "Handgun (1)";
- Instantiate (gunModel1, gunHand.position, gunHand.rotation);
- myBody = GetComponent<Rigidbody>();
- if (isOnFirstLevel.Equals(false)){
- gun1=PlayerPrefs.GetFloat("gun01", 1.0f);
- gun2=PlayerPrefs.GetFloat("gun02", 0.0f);
- gun3=PlayerPrefs.GetFloat("gun03", 0.0f);
- gun4=PlayerPrefs.GetFloat("gun04", 0.0f);
- gun5=PlayerPrefs.GetFloat("gun05", 0.0f);
- gun6=PlayerPrefs.GetFloat("gun06", 0.0f);
- gun7=PlayerPrefs.GetFloat("gun07", 0.0f);
- gun8=PlayerPrefs.GetFloat("gun08", 0.0f);
- gun9=PlayerPrefs.GetFloat("gun09", 0.0f);
- ammo1=PlayerPrefs.GetInt("ammo01", 34);
- ammo2=PlayerPrefs.GetInt("ammo02", 0);
- ammo3=PlayerPrefs.GetInt("ammo03", 0);
- ammo4=PlayerPrefs.GetInt("ammo04", 0);
- ammo5=PlayerPrefs.GetInt("ammo05", 0);
- ammo6=PlayerPrefs.GetInt("ammo06", 0);
- ammo7=PlayerPrefs.GetInt("ammo07", 0);
- ammo8=PlayerPrefs.GetInt("ammo08", 0);
- ammo9=PlayerPrefs.GetInt("ammo09", 0);
- }
- }
- void FixedUpdate()
- {
- //myBody.MovePosition(transform.position + (transform.forward * Time.deltaTime * speed));
- }
- void Update()
- {
- float axisX = Input.GetAxis ("Horizontal");
- float axisY = Input.GetAxis ("Vertical");
- if (gun1 == 1){
- weaponText1.text = "1";
- }
- if (gun2 == 1){
- weaponText2.text = "2";
- }
- if (gun3 == 1){
- weaponText3.text = "3";
- }
- if (gun4 == 1){
- weaponText4.text = "4";
- }
- if (gun5 == 1){
- weaponText5.text = "5";
- }
- if (gun6 == 1){
- weaponText6.text = "6";
- }
- if (gun7 == 1){
- weaponText7.text = "7";
- }
- if (gun8 == 1){
- weaponText8.text = "8";
- }
- if (gun9 == 1){
- weaponText9.text = "9";
- }
- if (death == false){
- //transform.Translate (new Vector3 (axisX, axisY) * Time.deltaTime * speed);
- myBody.velocity = new Vector3(axisX * speed, axisY * speed);
- }
- UpdateHealth ();
- if (death == false)
- {
- if (Input.GetKey (KeyCode.Q))
- transform.Rotate (Vector3.forward * 150 * Time.deltaTime);
- if (Input.GetKey (KeyCode.E))
- transform.Rotate (-Vector3.forward * 150 * Time.deltaTime);
- if (Input.GetKey ("1")) {
- if (gun1 == 1) {
- fireDelay = 0.12f;
- equip = 1;
- equipText.text = "Handgun (1)";
- ammoText.text = "Ammo: Infinity";
- Destroy (GameObject.FindWithTag("EquippedGun"));
- Instantiate (gunModel1, gunHand.position, gunHand.rotation);
- }
- }
- if (Input.GetKey ("2")) {
- if (gun2 == 1) {
- fireDelay = 0.66f;
- equip = 2;
- equipText.text = "Shotgun (2)";
- ammoText.text = "Ammo: " + ammo2;
- Destroy (GameObject.FindWithTag("EquippedGun"));
- Instantiate (gunModel2, gunHand.position, gunHand.rotation);
- }
- }
- if (Input.GetKey ("3")) {
- if (gun3 == 1) {
- fireDelay = 0.3f;
- equip = 3;
- equipText.text = "Grenade Launcher (3)";
- ammoText.text = "Ammo: " + ammo3;
- Destroy (GameObject.FindWithTag("EquippedGun"));
- Instantiate (gunModel3, gunHand.position, gunHand.rotation);
- }
- }
- if (Input.GetKey ("4")) {
- if (gun4 == 1) {
- fireDelay = 0.08f;
- equip = 4;
- equipText.text = "Minigun (4)";
- ammoText.text = "Ammo: " + ammo4;
- Destroy (GameObject.FindWithTag("EquippedGun"));
- Instantiate (gunModel4, gunHand.position, gunHand.rotation);
- }
- }
- if (Input.GetKey ("5")) {
- if (gun5 == 1) {
- fireDelay = 0.6f;
- equip = 5;
- equipText.text = "Rocket Launcher (5)";
- ammoText.text = "Ammo: " + ammo5;
- Destroy (GameObject.FindWithTag("EquippedGun"));
- Instantiate (gunModel5, gunHand.position, gunHand.rotation);
- }
- }
- if (Input.GetKey ("6")) {
- if (gun6 == 1) {
- fireDelay = 0.6f;
- equip = 6;
- equipText.text = "Ion Cannon (6)";
- ammoText.text = "Ammo: " + ammo6;
- Destroy (GameObject.FindWithTag("EquippedGun"));
- Instantiate (gunModel6, gunHand.position, gunHand.rotation);
- }
- }
- if (Input.GetKey ("7")) {
- if (gun7 == 1) {
- fireDelay = 0.8f;
- equip = 7;
- equipText.text = "Plasma Cannon (7)";
- ammoText.text = "Ammo: " + ammo7;
- Destroy (GameObject.FindWithTag("EquippedGun"));
- Instantiate (gunModel7, gunHand.position, gunHand.rotation);
- }
- }
- if (Input.GetKey ("8")) {
- if (gun8 == 1) {
- fireDelay = 0.05f;
- equip = 8;
- equipText.text = "Minigun (8)";
- }
- }
- if (Input.GetKey ("9")) {
- if (gun9 == 1) {
- fireDelay = 0.15f;
- equip = 9;
- equipText.text = "Death Cannon (9)";
- }
- }
- if (health <= 0) {
- speed = 0;
- Invoke("Respawning", 8.0f);
- death = true;
- }
- if (Input.GetMouseButtonDown(0) && Time.time > nextFire) {
- {
- if (equip == 1) {
- FireHandgun ();
- Instantiate (pistolBullet, shootPlace.position, shootPlace.rotation);
- nextFire = Time.time + fireDelay;
- }
- if ((equip == 2) && (ammo2 > 0)) {
- FireShotgun ();
- ammo2 -= 1;
- Instantiate (shotgunBullet, shootPlace.position, shootPlace.rotation);
- nextFire = Time.time + fireDelay;
- ammoText.text = "Ammo: " + ammo2;
- }
- if ((equip == 3) && (ammo3 > 0)) {
- Instantiate (grenade, shootPlace.position, shootPlace.rotation);
- ammo3 -= 1;
- Invoke("GrenadeFirstRotation", 0.1f);
- Invoke("GrenadeNextRotation", 0.2f);
- Invoke("GrenadeLastRotation", 0.3f);
- nextFire = Time.time + fireDelay;
- Instantiate (uziBullet, shootPlace.position, shootPlace.rotation);
- ammoText.text = "Ammo: " + ammo3;
- }
- if ((equip == 6) && (ammo6 > 0)) {
- FireIon ();
- ammo6 -= 1;
- Instantiate (ionSounder, shootPlace3.position, shootPlace3.rotation);
- nextFire = Time.time + fireDelay;
- ammoText.text = "Ammo: " + ammo6;
- }
- if ((equip == 5) && (ammo5 > 0)) {
- FireRocket ();
- ammo5 -= 1;
- nextFire = Time.time + fireDelay;
- Instantiate (uziBullet, shootPlace2.position, shootPlace2.rotation);
- Destroy (GameObject.FindWithTag("EquippedGun"));
- Instantiate (gunRotate5, gunHand.position, gunHand.rotation);
- Invoke("RocketRotation", 0.65f);
- ammoText.text = "Ammo: " + ammo5;
- }
- if ((equip == 7) && (ammo7 > 0)) {
- FirePlasma ();
- ammo7 -= 1;
- Instantiate (ionSounder, shootPlace3.position, shootPlace3.rotation);
- nextFire = Time.time + fireDelay;
- ammoText.text = "Ammo: " + ammo7;
- }
- if (equip == 8) {
- Instantiate(bullet3, shootPlace.position, shootPlace.rotation);
- Instantiate (rifleBullet, shootPlace.position, shootPlace.rotation);
- nextFire = Time.time + fireDelay;
- }
- if (equip == 9) {
- Instantiate (ionBullet, shootPlace.position, shootPlace.rotation);
- Instantiate (ionSounder, shootPlace.position, shootPlace.rotation);
- nextFire = Time.time + fireDelay;
- }
- }
- }
- if (Input.GetMouseButton(0) && Time.time > nextFire) {
- {
- nextFire = Time.time + fireDelay;
- if ((equip == 4) && (ammo4 > 0)) {
- MachineGun ();
- ammo4 -= 1;
- Instantiate (rifleBullet, shootPlace3.position, shootPlace3.rotation);
- ammoText.text = "Ammo: " + ammo4;
- }
- }
- }
- }
- }
- void FireHandgun ()
- {
- for(var i = 0; i<1; i++){
- var pistolbulletRot = shootPlace.transform.rotation;
- pistolbulletRot.x += Random.Range(-0.04f, 0.04f);
- pistolbulletRot.y += Random.Range(-0.04f, 0.04f);
- pistolbulletRot.z += Random.Range(-0.04f, 0.04f);
- Instantiate(bullet, shootPlace.transform.position, pistolbulletRot);
- }
- }
- void FireShotgun ()
- {
- for(var i = 0; i<10; i++){
- var pelletRot = shootPlace2.transform.rotation;
- pelletRot.x += Random.Range(-0.14f, 0.14f);
- pelletRot.y += Random.Range(-0.14f, 0.14f);
- pelletRot.z += Random.Range(-0.14f, 0.14f);
- Instantiate(bullet2, shootPlace2.transform.position, pelletRot);
- }
- }
- void MachineGun ()
- {
- for(var i = 0; i<1; i++){
- var machinebulletRot = shootPlace3.transform.rotation;
- machinebulletRot.x += Random.Range(-0.06f, 0.06f);
- machinebulletRot.y += Random.Range(-0.06f, 0.06f);
- machinebulletRot.z += Random.Range(-0.06f, 0.06f);
- Instantiate(bullet3, shootPlace3.transform.position, machinebulletRot);
- }
- }
- void FireRocket ()
- {
- for(var i = 0; i<1; i++){
- var rocketRot = shootPlace.transform.rotation;
- rocketRot.x += Random.Range(-0.02f, 0.02f);
- rocketRot.y += Random.Range(-0.02f, 0.02f);
- rocketRot.z += Random.Range(-0.02f, 0.02f);
- Instantiate(rocket, shootPlace.transform.position, rocketRot);
- }
- }
- void FireIon ()
- {
- for(var i = 0; i<1; i++){
- var dicebulletRot = shootPlace.transform.rotation;
- dicebulletRot.x += Random.Range(-0.02f, 0.02f);
- dicebulletRot.y += Random.Range(-0.02f, 0.02f);
- dicebulletRot.z += Random.Range(-0.02f, 0.02f);
- Instantiate(ionBullet, shootPlace.transform.position, dicebulletRot);
- }
- }
- void FirePlasma ()
- {
- for(var i = 0; i<1; i++){
- var dicebulletRot = shootPlace.transform.rotation;
- dicebulletRot.x += Random.Range(-0.02f, 0.02f);
- dicebulletRot.y += Random.Range(-0.02f, 0.02f);
- dicebulletRot.z += Random.Range(-0.02f, 0.02f);
- Instantiate(ionBullet2, shootPlace.transform.position, dicebulletRot);
- }
- }
- void GrenadeFirstRotation ()
- {
- Destroy (GameObject.FindWithTag("EquippedGun"));
- Instantiate (gunRotate3, gunHand.position, gunHand.rotation);
- }
- void GrenadeNextRotation ()
- {
- Destroy (GameObject.FindWithTag("EquippedGun"));
- Instantiate (gunRotate33, gunHand.position, gunHand.rotation);
- }
- void GrenadeLastRotation ()
- {
- Destroy (GameObject.FindWithTag("EquippedGun"));
- Instantiate (gunModel3, gunHand.position, gunHand.rotation);
- }
- void RocketRotation ()
- {
- Destroy (GameObject.FindWithTag("EquippedGun"));
- Instantiate (gunModel5, gunHand.position, gunHand.rotation);
- }
- void UpdateHealth ()
- {
- if (death == false){
- healthText.text = "Health: " + health;
- }
- else
- {
- healthText.text = "GAME OVER!!!!!!";
- }
- }
- void Respawning () {
- SceneManager.LoadScene(SceneManager.GetActiveScene().name);
- }
- void OnTriggerEnter(Collider other)
- {
- if (other.tag == "Gun 2") {
- Destroy (other.gameObject);
- ammo2 += 6;
- gun2 = 1;
- if (equip == 2){
- ammoText.text = "Ammo: " + ammo2;
- }
- if (equip < 2) {
- fireDelay = 0.66f;
- equip = 2;
- equipText.text = "Shotgun (2)";
- ammoText.text = "Ammo: " + ammo2;
- Destroy (GameObject.FindWithTag("EquippedGun"));
- Instantiate (gunModel2, gunHand.position, gunHand.rotation);
- }
- }
- if (other.tag == "Gun 3") {
- Destroy (other.gameObject);
- ammo3 += 6;
- gun3 = 1;
- if (equip == 3){
- ammoText.text = "Ammo: " + ammo3;
- }
- if (equip < 3) {
- fireDelay = 0.3f;
- equip = 3;
- equipText.text = "Grenade Launcher (3)";
- ammoText.text = "Ammo: " + ammo3;
- Destroy (GameObject.FindWithTag("EquippedGun"));
- Instantiate (gunModel3, gunHand.position, gunHand.rotation);
- }
- }
- if (other.tag == "Gun 4")
- {
- Destroy(other.gameObject);
- ammo4 += 100;
- gun4 = 1;
- if (equip == 4){
- ammoText.text = "Ammo: " + ammo4;
- }
- if (equip < 4) {
- fireDelay = 0.08f;
- equip = 4;
- equipText.text = "Machine Gun (4)";
- ammoText.text = "Ammo: " + ammo4;
- Destroy (GameObject.FindWithTag("EquippedGun"));
- Instantiate (gunModel4, gunHand.position, gunHand.rotation);
- }
- }
- if (other.tag == "Gun 5")
- {
- Destroy(other.gameObject);
- ammo5 += 1;
- gun5 = 1;
- if (equip == 5){
- ammoText.text = "Ammo: " + ammo5;
- }
- if (equip < 5) {
- fireDelay = 0.6f;
- equip = 5;
- equipText.text = "Rocket Launcher (5)";
- ammoText.text = "Ammo: " + ammo5;
- Destroy (GameObject.FindWithTag("EquippedGun"));
- Instantiate (gunModel5, gunHand.position, gunHand.rotation);
- }
- }
- if (other.tag == "Gun 6")
- {
- Destroy(other.gameObject);
- gun6 = 1;
- if (equip == 6){
- ammoText.text = "Ammo: " + ammo6;
- }
- if (equip < 6) {
- fireDelay = 0.6f;
- equip = 6;
- equipText.text = "Ion Cannon (6)";
- ammoText.text = "Ammo: " + ammo6;
- Destroy (GameObject.FindWithTag("EquippedGun"));
- Instantiate (gunModel6, gunHand.position, gunHand.rotation);
- }
- }
- if (other.tag == "Gun 7")
- {
- Destroy(other.gameObject);
- gun7 = 1;
- if (equip == 7){
- ammoText.text = "Ammo: " + ammo7;
- }
- if (equip < 7) {
- fireDelay = 0.8f;
- equip = 7;
- equipText.text = "Plasma Cannon (7)";
- ammoText.text = "Ammo: " + ammo7;
- Destroy (GameObject.FindWithTag("EquippedGun"));
- Instantiate (gunModel7, gunHand.position, gunHand.rotation);
- }
- }
- if (other.tag == "Gun 8")
- {
- Destroy(other.gameObject);
- gun8 = 1;
- }
- if (other.tag == "Shell") {
- Destroy (other.gameObject);
- ammo2 += 1;
- if (equip == 2){
- ammoText.text = "Ammo: " + ammo2;
- }
- }
- if (other.tag == "Shells") {
- Destroy (other.gameObject);
- ammo2 += 4;
- if (equip == 2){
- ammoText.text = "Ammo: " + ammo2;
- }
- }
- if (other.tag == "Grenade") {
- Destroy (other.gameObject);
- ammo3 += 1;
- if (equip == 3){
- ammoText.text = "Ammo: " + ammo3;
- }
- }
- if (other.tag == "Grenades") {
- Destroy (other.gameObject);
- ammo3 += 4;
- if (equip == 3){
- ammoText.text = "Ammo: " + ammo3;
- }
- }
- if (other.tag == "Ammo Box") {
- Destroy (other.gameObject);
- ammo4 += 100;
- if (equip == 4){
- ammoText.text = "Ammo: " + ammo4;
- }
- }
- if (other.tag == "Rockets") {
- Destroy (other.gameObject);
- ammo5 += 1;
- if (equip == 5){
- ammoText.text = "Ammo: " + ammo5;
- }
- }
- if (other.tag == "Batteries") {
- Destroy (other.gameObject);
- ammo6 += 4;
- if (equip == 6){
- ammoText.text = "Ammo: " + ammo6;
- }
- }
- if (other.tag == "Plasma Shells") {
- Destroy (other.gameObject);
- ammo7 += 3;
- if (equip == 7){
- ammoText.text = "Ammo: " + ammo7;
- }
- }
- if (other.tag == "Spider Attack") {
- health -= 2;
- Instantiate (Trexplosion, other.transform.position, other.transform.rotation);
- }
- if (other.tag == "Cockroach Attack") {
- health -= 4;
- Instantiate (Trexplosion, other.transform.position, other.transform.rotation);
- }
- if (other.tag == "Beetle Attack") {
- health -= 5;
- Instantiate (Trexplosion, other.transform.position, other.transform.rotation);
- }
- if (other.tag == "EnemyPulse") {
- health -= 4;
- Instantiate (Trexplosion, other.transform.position, other.transform.rotation);
- Destroy(other.gameObject);
- }
- if (other.tag == "Tarantula Attack") {
- Instantiate (explosion, other.transform.position, other.transform.rotation);
- Instantiate (explosionSounder, other.transform.position, other.transform.rotation);
- health -= 20;
- }
- if (other.tag == "Mealworm Attack") {
- Instantiate (Mexplosion, other.transform.position, other.transform.rotation);
- Instantiate (shotgunBullet, other.transform.position, other.transform.rotation);
- health -= 14;
- }
- if (other.tag == "EnemyRocket") {
- Destroy (other.gameObject);
- }
- if (other.tag == "EnemyExplosion") {
- health -= 7;
- }
- if (other.tag == "Tarantula Explosion") {
- health -= 20;
- }
- if (other.tag == "Mealworm Explosion") {
- health -= 14;
- }
- if (other.tag == "Barrier") {
- Destroy (other.gameObject);
- }
- if (GameObject.FindGameObjectsWithTag("Boss").Length < 1)
- {
- if (other.tag == "StartGame") {
- health = 100;
- SceneManager.LoadScene ("Mission 1");
- }
- if (other.tag == "NextLevel") {
- CompleteLevel();
- health = 100;
- SceneManager.LoadScene ("Mission 2");
- }
- if (other.tag == "NextLevel2") {
- CompleteLevel();
- health = 100;
- SceneManager.LoadScene ("Mission 3");
- }
- if (other.tag == "NextLevel3") {
- CompleteLevel();
- SceneManager.LoadScene("Mission 4");
- health = 100;
- }
- if (other.tag == "NextLevel4") {
- CompleteLevel();
- SceneManager.LoadScene("Mission 5");
- health = 100;
- }
- if (other.tag == "NextLevel5") {
- CompleteLevel();
- SceneManager.LoadScene("Mission 6");
- health = 100;
- }
- if (other.tag == "NextLevel6") {
- CompleteLevel();
- SceneManager.LoadScene("Mission 7");
- health = 100;
- }
- if (other.tag == "NextLevel7") {
- CompleteLevel();
- SceneManager.LoadScene("Mission 8");
- health = 100;
- }
- if (other.tag == "NextLevel8") {
- CompleteLevel();
- SceneManager.LoadScene("Mission 9");
- health = 100;
- }
- if (other.tag == "NextLevel9") {
- CompleteLevel();
- SceneManager.LoadScene("Mission 10");
- health = 100;
- }
- }
- }
- void CompleteLevel(){
- PlayerPrefs.SetFloat("gun01",gun1);
- PlayerPrefs.SetFloat("gun02",gun2);
- PlayerPrefs.SetFloat("gun03",gun3);
- PlayerPrefs.SetFloat("gun04",gun4);
- PlayerPrefs.SetFloat("gun05",gun5);
- PlayerPrefs.SetFloat("gun06",gun6);
- PlayerPrefs.SetFloat("gun07",gun7);
- PlayerPrefs.SetFloat("gun08",gun8);
- PlayerPrefs.SetFloat("gun09",gun9);
- PlayerPrefs.SetInt("ammo01",ammo1);
- PlayerPrefs.SetInt("ammo02",ammo2);
- PlayerPrefs.SetInt("ammo03",ammo3);
- PlayerPrefs.SetInt("ammo04",ammo4);
- PlayerPrefs.SetInt("ammo05",ammo5);
- PlayerPrefs.SetInt("ammo06",ammo6);
- PlayerPrefs.SetInt("ammo07",ammo7);
- PlayerPrefs.SetInt("ammo08",ammo8);
- PlayerPrefs.SetInt("ammo09",ammo9);
- PlayerPrefs.Save();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment