void Update() { if (scene.name == "Level1") { if (WayPoints.arrived && !crossHairEnabled) { crossHair = Instantiate(crossHairPrefab, new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y), transform.rotation) as Transform; foreach (Renderer r in GetComponentsInChildren <Renderer>()) { r.enabled = true; } isDead = false; canMove = true; canShoot = true; crossHairEnabled = true; } } else if (!crossHairEnabled) { crossHair = Instantiate(crossHairPrefab, new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y), transform.rotation) as Transform; crossHairEnabled = true; } if (!isDead) { if (!footstepSoundEnabled) { StartCoroutine(cycleFootsteps()); footstepSoundEnabled = true; } GameMaster.slot1type = slot1type; GameMaster.slot2type = slot2type; GameMaster.slot3type = slot3type; GameMaster.grenadeCount = grenadeCount; if (slot [0] != null) { GameMaster.slot1ammo = slot [0].GetComponent <Weapon> ().ammo; GameMaster.slot1MaxAmmo = slot [0].GetComponent <Weapon> ().maxAmmo; } if (slot [1] != null) { GameMaster.slot2ammo = slot [1].GetComponent <Weapon> ().ammo; GameMaster.slot2MaxAmmo = slot [1].GetComponent <Weapon> ().maxAmmo; } if (Input.GetButtonDown("Grenade") || Input.GetButtonDown("AltGrenade")) { Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position; difference.Normalize(); float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg; if (grenadeCount > 0) { GameMaster.CreateGrenade(grenadePrefab, transform.position, rotZ - 90, 100, 20, 70, false, true); grenadeCount--; } else { //play no bullet sound PickUpLog.noGrenadeLog = true; } } weaponslist = GameObject.FindGameObjectsWithTag("Pickup"); float minDist = Mathf.Infinity; GameObject closestWeapon = null; foreach (GameObject weapon in weaponslist) { float dist = Vector3.Distance(transform.position, weapon.transform.position); if (dist < minDist) { minDist = dist; closestWeapon = weapon; } } foreach (GameObject weapon in weaponslist) { weapon.GetComponent <PickupPrefab>().HideStars(); } if (closestWeapon != null) { PickupPrefab pk = closestWeapon.GetComponent <PickupPrefab>(); if (minDist < 2) { pk.DisplayStars(); if (Input.GetButtonDown("Pickup") && pk.type != WeaponType.golddeserteagle) { ChangeWeapon(pk.type, pk, closestWeapon); PlayHitSound(noBulletSound, this.transform.position); } } } if (Input.GetButtonDown("SwapSlot") || Input.GetAxis("Mouse ScrollWheel") < 0) { PlayHitSound(noBulletSound, this.transform.position); slotActive = (slotActive + 1) % 3; while (slot [slotActive] == null) { slotActive = (slotActive + 1) % 3; } } if (Input.GetAxis("Mouse ScrollWheel") > 0) { PlayHitSound(noBulletSound, this.transform.position); slotActive = (slotActive + 2) % 3; while (slot [slotActive] == null) { slotActive = (slotActive + 2) % 3; } } if (Input.GetButtonDown("Slot1") && slot [0] != null) { PlayHitSound(noBulletSound, this.transform.position); slotActive = 0; } if (Input.GetButtonDown("Slot2") && slot [1] != null) { PlayHitSound(noBulletSound, this.transform.position); slotActive = 1; } if (Input.GetButtonDown("Slot3")) { PlayHitSound(noBulletSound, this.transform.position); slotActive = 2; } slot [slotActive].SetActive(true); if (slot [(slotActive + 1) % 3] != null) { slot [(slotActive + 1) % 3].SetActive(false); } if (slot [(slotActive + 2) % 3] != null) { slot [(slotActive + 2) % 3].SetActive(false); } if (!isInvulnerable) { foreach (Renderer r in GetComponentsInChildren <Renderer>()) { if (r.gameObject.tag != "MuzzelFlash") { Color c = r.material.color; c.a = 1f; r.material.color = c; } } } else { foreach (Renderer r in GetComponentsInChildren <Renderer>()) { if (r.gameObject.tag != "MuzzelFlash") { Color c = r.material.color; c.a = 0.3f; r.material.color = c; } } } } if (crossHairEnabled) { crossHair.position = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y); } if (Time.timeScale != 0 && !gameOver) { Cursor.visible = false; } else if (Time.timeScale == 0 || gameOver) { Cursor.visible = true; } }
public void ChangeWeapon(WeaponType type, PickupPrefab pickup, GameObject pickupObject) { int pickupAmmo = pickup.ammo; GameObject.Find("Canvas").GetComponent <HUDManager>().ResetStars(); if (slot [0] != null && slot [1] != null) { if (slotActive == 0) { pickup.ChangeType(slot1type, slot [0].GetComponent <Weapon> ().ammo); Destroy(slot [0]); slot [0] = Instantiate(weaponsprefabs [(int)type], transform.position + weaponsprefabs [(int)type].transform.position, new Quaternion(0, 0, 0, 0), this.transform); slot1type = type; if (pickupAmmo != -1) { slot [0].GetComponent <Weapon> ().ammo = pickupAmmo; } } if (slotActive == 1) { pickup.ChangeType(slot2type, slot [1].GetComponent <Weapon> ().ammo); Destroy(slot [1]); slot [1] = Instantiate(weaponsprefabs [(int)type], transform.position + weaponsprefabs [(int)type].transform.position, new Quaternion(0, 0, 0, 0), this.transform); slot2type = type; if (pickupAmmo != -1) { slot [1].GetComponent <Weapon> ().ammo = pickupAmmo; } } if (slotActive == 2) { pickup.ChangeType(slot1type, slot [0].GetComponent <Weapon> ().ammo); Destroy(slot [0]); slot [0] = Instantiate(weaponsprefabs [(int)type], transform.position + weaponsprefabs [(int)type].transform.position, new Quaternion(0, 0, 0, 0), this.transform); slot1type = type; if (pickupAmmo != -1) { slot [0].GetComponent <Weapon> ().ammo = pickupAmmo; } slotActive = 0; } } else if (slot [0] == null) { slot [0] = Instantiate(weaponsprefabs[(int)type], transform.position + weaponsprefabs[(int)type].transform.position, new Quaternion(0, 0, 0, 0), this.transform); slot1type = type; Destroy(pickupObject); if (pickupAmmo != -1) { slot [0].GetComponent <Weapon> ().ammo = pickupAmmo; } slotActive = 0; } else if (slot [1] == null) { slot [1] = Instantiate(weaponsprefabs[(int)type], transform.position + weaponsprefabs[(int)type].transform.position, new Quaternion(0, 0, 0, 0), this.transform); slot2type = type; Destroy(pickupObject); if (pickupAmmo != -1) { slot [1].GetComponent <Weapon> ().ammo = pickupAmmo; } slotActive = 1; } }
void pickAGun() { GameObject gun = Instantiate(pickup, transform.position, transform.rotation); PickupPrefab pickupPrefab = gun.GetComponent <PickupPrefab>(); bool arrayEmpty = true; int [] array = null; while (arrayEmpty) { float chance = Random.value; if (chance <= 0.3) { if (isTier1) { array = tier1rare1; } else if (isTier2) { array = tier2rare1; } else { array = tier3rare1; } } if (chance > 0.3 && chance <= 0.55) { if (isTier1) { array = tier1rare2; } else if (isTier2) { array = tier2rare2; } else { array = tier3rare2; } } if (chance > 0.55 && chance <= 0.75) { if (isTier1) { array = tier1rare3; } else if (isTier2) { array = tier2rare3; } else { array = tier3rare3; } } if (chance > 0.75 && chance <= 0.9) { if (isTier1) { array = tier1rare4; } else if (isTier2) { array = tier2rare4; } else { array = tier3rare4; } } if (chance > 0.9) { if (isTier1) { array = tier1rare5; } else if (isTier2) { array = tier2rare5; } else { array = tier3rare5; } } if (array.Length > 0) { arrayEmpty = false; } } int pick = Random.Range(0, array.Length); pickupPrefab.type = (Player.WeaponType)array[pick]; }