Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Material color;
- //public GameObject hole;
- public int[] bullets;
- public int[] apkaboje;
- public int[] talpa;
- private int gunid = 0;
- private bool canShot = true;
- private bool isReloading = false;
- public AudioClip reloadsound;
- private Vector3 poz;
- private Quaternion rot;
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- gunid = WeaponRotation.gunid;
- RaycastHit hit;
- Ray ray = Camera.main.ScreenPointToRay (new Vector3(Screen.width/2, Screen.height/2, 0));
- if (Input.GetKeyDown (KeyCode.R)) {
- if(!isReloading && apkaboje[gunid] != talpa[gunid]) Reload();
- }
- if (apkaboje [gunid] == 0 && isReloading == false) {
- Reload ();
- }
- else {
- if (Input.GetMouseButton (0) && canShot && !isReloading) {
- StartCoroutine (Wait ());
- CalculateBullets ();
- this.gameObject.transform.GetChild(0).SendMessage("PlaySound");
- if (Physics.Raycast (ray, out hit, 100)) {
- /*GameObject bullet = GameObject.CreatePrimitive(PrimitiveType.Sphere);
- bullet.transform.position = hit.point;
- bullet.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
- bullet.GetComponent<MeshRenderer>().material = color;*/
- //GameObject bullet = (GameObject)Instantiate(hole);
- //bullet.transform.position = hit.point;
- //hit.
- //bullet.transform.parent = hit.transform.gameObject.transform;
- if (hit.transform.gameObject.tag == "Enemy") {
- hit.transform.gameObject.SendMessage ("TakeDamage", 1);
- } else if (hit.transform.gameObject.tag == "Head") {
- hit.transform.parent.gameObject.SendMessage ("HeadShot");
- }
- }
- }
- }
- }
- void CalculateBullets() {
- apkaboje [gunid]--;
- GameObject bulltext = GameObject.Find ("Bullets");
- bulltext.GetComponent<Text> ().text = apkaboje [gunid] + "/" + bullets [gunid];
- }
- void UpdateBullets(int gID) {
- gunid = gID;
- GameObject bulltext = GameObject.Find ("Bullets");
- bulltext.GetComponent<Text> ().text = apkaboje [gID] + "/" + bullets [gID];
- }
- void Reload() {
- if (apkaboje [gunid] < talpa[gunid]) {
- int diff = talpa[gunid] - apkaboje[gunid];
- if(bullets [gunid] > 0) {
- if(diff < bullets[gunid]) {
- apkaboje[gunid] = talpa[gunid];
- bullets[gunid] -= diff;
- }
- else {
- apkaboje[gunid] = bullets[gunid];
- bullets[gunid] = 0;
- }
- GameObject bulltext = GameObject.Find ("Bullets");
- bulltext.GetComponent<Text> ().text = apkaboje [gunid] + "/" + bullets [gunid];
- GameObject gun = this.gameObject.transform.GetChild(0).gameObject;
- GameObject apkaba = gun.transform.GetChild(1).gameObject;
- poz = apkaba.transform.localPosition;
- rot = apkaba.transform.localRotation;
- StartCoroutine(Reloading(apkaba));
- AudioSource.PlayClipAtPoint(reloadsound, transform.position);
- }
- }
- }
- IEnumerator Wait() {
- canShot = false;
- yield return new WaitForSeconds (0.05f);
- canShot = true;
- }
- IEnumerator Reloading(GameObject apkaba) {
- apkaba.AddComponent<Rigidbody> ();
- isReloading = true;
- yield return new WaitForSeconds (2f);
- isReloading = false;
- Destroy (apkaba.GetComponent<Rigidbody> ());
- apkaba.transform.localPosition = poz;
- apkaba.transform.localRotation = rot;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement