D
D
Dmitry Korolev2016-03-29 01:08:07
C++ / C#
Dmitry Korolev, 2016-03-29 01:08:07

Where can a unit appear in a variable back?

The Clip variable returns its value. how to exclude it?

using UnityEngine;
using System.Collections;
using System;

public class Shooting : MonoBehaviour {
    public Transform bullet;
    public GUISkin MySkin;
    public int BulletForce = 5000;
    public static int AmmoCount = 30;
    public int ammo;
    public int MaxAmmoCount = 30;
    public int Clip;
    public static int Cli;
    public int MaxClip = 9;
    public AudioClip Fire;
    public AudioClip Reload;
    public AudioClip Discharge;
    public int AmmoBoxWidth = 200;
    public int AmmoBoxHeight = 100;
    public float ReloadTimer = 1f;
  void Start () {

    }
    void Update()
    {
        ammo = AmmoCount;
        Clip = SaveSystem.Clipp;
        Clip = Clip1.clip1 + Clip2.clip2 + Clip3.clip3 + Clip4.clip4 + Clip5.clip5 + Clip6.clip6 + Clip7.clip7 + Clip8.clip8 + Clip9.clip9 + Clip10.clip10 + Clip11.clip11 + Clip12.clip12 + Clip13.clip13 + Clip14.clip14 + Clip15.clip15 + Clip16.clip16 + Clip17.clip17 + Clip18.clip18 + Clip19.clip19 + Clip20.clip20 + Clip21.clip21 + Clip22.clip22 + Clip23.clip23 + Clip24.clip24 + Clip25.clip25 + Clip26.clip26 + Clip27.clip27 + Clip28.clip28 + Clip29.clip29 + Clip30.clip30 + Clip31.clip31 + Clip32.clip32 + Clip33.clip33 + Clip34.clip34 + Clip35.clip35 + Clip36.clip36 + Clip37.clip37 + Clip38.clip38 + Clip39.clip39 + Clip40.clip40 + Clip41.clip41 + Clip42.clip42 + Clip43.clip43 + Clip44.clip44 + Clip45.clip45 + Clip46.clip46 + Clip47.clip47 + Clip48.clip48 + Clip49.clip49 + Clip50.clip50 + Clip51.clip51 + Clip52.clip52 + Clip53.clip53 + Clip54.clip54 + Clip55.clip55 + Clip56.clip56 + Clip57.clip57 + Clip58.clip58 + Clip59.clip59 + Clip60.clip60 + Clip61.clip61 + Clip62.clip62 + Clip63.clip63 + Clip64.clip64 + Clip65.clip65 + Clip66.clip66 + Clip67.clip67 + Clip68.clip68 + Clip69.clip69 + Clip70.clip70 + Clip71.clip71 + Clip72.clip72 + Clip73.clip73 + Clip74.clip74 + Clip75.clip75 + Clip76.clip76 + Clip77.clip77 + Clip78.clip78 + Clip79.clip79 + Clip80.clip80 + Clip81.clip81;
        Cli = Clip;
        if (Input.GetMouseButtonDown(0) & SaveSystem.Ammo > 0 & ReloadTimer <= 0)
            {
                Shoot();
            }
        if (Input.GetButtonDown("Reload Weapon") && Clip > 0)
        {
            ReloadTimer = 1.0f;
            Clip = Clip - 1;
            SaveSystem.Ammo = 30;
            GetComponent<AudioSource>().PlayOneShot(Reload);
        }
        if (Clip > MaxClip)
        {
            Clip = MaxClip;
        }
        if (Input.GetButtonDown("Discharge Weapon"))
        {
            SaveSystem.Ammo = 0;
            GetComponent<AudioSource>().PlayOneShot(Discharge);
        }
        if (ReloadTimer>0.0f)
        {
            ReloadTimer -= Time.deltaTime;
        }
    }
    void Shoot()
    {
            SaveSystem.Ammo = AmmoCount;
            Transform BulletInstance = (Transform)Instantiate(bullet, GameObject.Find("BulletSpawnPoint").transform.position, Quaternion.identity);
            BulletInstance.GetComponent<Rigidbody>().AddForce(transform.forward * BulletForce);
            SaveSystem.Ammo = SaveSystem.Ammo - 1;
            GetComponent<AudioSource>().PlayOneShot(Fire);
    }
    void OnGUI()
    {
        GUI.skin = MySkin;
        GUI.Box(new Rect(Screen.width - AmmoBoxWidth, 0, AmmoBoxWidth, AmmoBoxHeight), "Патронов: " + SaveSystem.Ammo + "/" + MaxAmmoCount);
        GUI.Label(new Rect(Screen.width - AmmoBoxWidth, 0, AmmoBoxWidth, AmmoBoxHeight), "Обойм: " + Clip + "/" + MaxClip);
    }
}

using UnityEngine;

public class SaveSystem : MonoBehaviour {
    public Transform TransformPos;
    public static int Count = 0;
    public static int Ammo = 30;
    public static int Clipp = 0;
    public void Update()
    {
        ScoreControl.score = Count;
        Shooting.AmmoCount = Ammo;
        Shooting.Cli = Clipp;
    }
    public void SaveSlot1()
    {
        {
            var x = transform.position.x;
            var y = transform.position.y;
            var z = transform.position.z;
            PlayerPrefs.SetFloat("PosX1", x);
            PlayerPrefs.SetFloat("PosY1", y);
            PlayerPrefs.SetFloat("PosZ1", z);
            PlayerPrefs.SetInt("Count1", Count);
            PlayerPrefs.SetInt("Ammo1", Ammo);
            PlayerPrefs.SetInt("Clip1", Clipp);
            print("Data 1 save");
        }
    }
    public void SaveSlot2()
    {
        {
            var x = transform.position.x;
            var y = transform.position.y;
            var z = transform.position.z;
            PlayerPrefs.SetFloat("PosX2", x);
            PlayerPrefs.SetFloat("PosY2", y);
            PlayerPrefs.SetFloat("PosZ2", z);
            PlayerPrefs.SetInt("Count2", Count);
            PlayerPrefs.SetInt("Ammo2", Ammo);
            PlayerPrefs.SetInt("Clip2", Clipp);
            print("Data 2 save");
        }
    }
    public void SaveSlot3()
    {
        {
            var x = transform.position.x;
            var y = transform.position.y;
            var z = transform.position.z;
            PlayerPrefs.SetFloat("PosX3", x);
            PlayerPrefs.SetFloat("PosY3", y);
            PlayerPrefs.SetFloat("PosZ3", z);
            PlayerPrefs.SetInt("Count3", Count);
            PlayerPrefs.SetInt("Ammo3", Ammo);
            PlayerPrefs.SetInt("Clip3", Clipp);
            print("Data 3 save");
        }
    }
    public void LoadSlot1()
    {
        {
            transform.position = new Vector3(PlayerPrefs.GetFloat("PosX1"), PlayerPrefs.GetFloat("PosY1"), PlayerPrefs.GetFloat("PosZ1"));
            Count = PlayerPrefs.GetInt("Count1");
            Ammo = PlayerPrefs.GetInt("Ammo1");
            Clipp = PlayerPrefs.GetInt("Clip1");
            print("Data 2 load");
        }
    }
    public void LoadSlot2()
    {
        {
            transform.position = new Vector3(PlayerPrefs.GetFloat("PosX2"), PlayerPrefs.GetFloat("PosY2"), PlayerPrefs.GetFloat("PosZ2"));
            Count = PlayerPrefs.GetInt("Count2");
            Ammo = PlayerPrefs.GetInt("Ammo2");
            Clipp = PlayerPrefs.GetInt("Clip2");
            print("Data 2 load");
        }
    }
    public void LoadSlot3()
    {
        {
            transform.position = new Vector3(PlayerPrefs.GetFloat("PosX3"), PlayerPrefs.GetFloat("PosY3"), PlayerPrefs.GetFloat("PosZ3"));
            Count = PlayerPrefs.GetInt("Count3");
            Ammo = PlayerPrefs.GetInt("Ammo3");
            Clipp = PlayerPrefs.GetInt("Clip3");
            print("Data 3 load");
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Korolev, 2016-03-29
@adressmoeistranici

if (Input.GetButtonDown("Reload Weapon") && Clip > 0) in this condition

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question