Ejemplo n.º 1
0
    protected virtual void UpdateReload(WeaponSettings weaponSettings, AmmoUI ammoUI)
    {
        if (reloading == false)
        {
            return;
        }

        if (reloadCount < weaponSettings.weaponInfo.reloadTime)
        {
            reloadCount += Time.deltaTime;
            return;
        }

        reloading   = false;
        reloadCount = 0f;
        canShoot    = true;

        if (currentAmmo < ammoPerClip && maxAmmo != 0)
        {
            currentClip = currentAmmo;
        }
        else
        {
            currentClip = ammoPerClip;
        }

        ammoUI.Reloaded();
    }
Ejemplo n.º 2
0
 private void Start()
 {
     cameraTransform = Camera.main.transform;
     handAnim        = transform.parent.GetComponent <Animator>();
     magAmmo         = stats.magazineSize;
     AmmoUI.UpdateAmmo(magAmmo);
 }
Ejemplo n.º 3
0
 public override void Load()
 {
     if (Main.dedServ)
     {
         customResources = new UserInterface();
         ammoUI          = new AmmoUI();
         AmmoUI.visible  = true;
         customResources.SetState(ammoUI);
     }
 }
    void Awake()
    {
        GameObject ammoUIObject = GameObject.Find("Ammo");

        if (ammoUIObject != null)
        {
            ammoUI = ammoUIObject.GetComponent <AmmoUI> ();
        }
        anim = GetComponent <Animator> ();
    }
Ejemplo n.º 5
0
 public void InitializeAmmoUI()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Destroy(this.gameObject);
     }
 }
Ejemplo n.º 6
0
    public void Init(Transform weapon, int startingWeaponId, LayerMask damageLayer, AmmoUI ammoUI)
    {
        this.weapon      = weapon;
        weaponBarrel     = weapon.GetChild(0);
        weaponSprite     = weapon.GetComponent <SpriteRenderer>();
        this.damageLayer = damageLayer;

        this.ammoUI = ammoUI;
        ammoUI.Init();

        fireModeFactory = new FireModeFactory();

        GiveNewWeaponById(startingWeaponId);
        UpdateCurrnetWeapon();
    }
Ejemplo n.º 7
0
    public void Fire()
    {
        handAnim.Play("Fire");
        for (int i = 0; i < stats.bulletCount; i++)
        {
            Vector3 forwardVector = Vector3.forward;
            float   deviation     = UnityEngine.Random.Range(0f, stats.spread);
            float   angle         = UnityEngine.Random.Range(0f, 360f);
            forwardVector = Quaternion.AngleAxis(deviation, Vector3.up) * forwardVector;
            forwardVector = Quaternion.AngleAxis(angle, Vector3.forward) * forwardVector;
            forwardVector = cameraTransform.transform.rotation * forwardVector;

            Physics.Raycast(cameraTransform.position, forwardVector, out RaycastHit hit, 200f, layerMask); // change to projectile?
            if (hit.transform)
            {
                IHitReceiver hittable = hit.transform.GetComponent <IHitReceiver>();
                if (hittable != null)
                {
                    hittable.Hit(15.0f);
                }
                else
                {
                    //DrawDecals;
                }
                Transform dec = Instantiate(decal, hit.transform).transform;
                dec.position = hit.point;
            }
        }
        magAmmo--;

        nextFireTime = Time.time + stats.fireTime;
        AmmoUI.UpdateAmmo(magAmmo);

        recoilObject.recoil += stats.recoilTime;

        if (magAmmo == 0)
        {
            Reload();
        }
    }
Ejemplo n.º 8
0
    protected override void OnInputHeld(WeaponSettings weaponSettings, Transform weaponBarrel, LayerMask damageLayer, LayerMask firedByLayer, AmmoUI ammoUI)
    {
        if (shouldReset == true)
        {
            return;
        }

        if (shootCount < weaponSettings.weaponInfo.fireRateAuto)
        {
            shootCount += Time.deltaTime;
            return;
        }

        shootCount = 0f;

        // If we have ammo or if we are using a weapon with unlimited ammo
        if (currentAmmo > 0 || currentAmmo >= 0 && maxAmmo == 0)
        {
            if (currentClip > 0)
            {
                canShoot = false;

                currentClip--;

                if (currentAmmo > 0)
                {
                    currentAmmo--;
                }

                ammoUI.UpdateCurrentAmmo(currentClip);
                SpawnProjectile(weaponSettings, weaponBarrel, damageLayer, firedByLayer);
            }
        }
    }
Ejemplo n.º 9
0
 public void Reload()
 {
     nextFireTime = Time.time + stats.reloadTime;
     weaponStatus = WeaponStatus.Reloading;
     AmmoUI.SetReloading(nextFireTime);
 }
Ejemplo n.º 10
0
 public void Update(WeaponSettings weaponSettings, AmmoUI ammoUI)
 {
     UpdateShootReset(weaponSettings);
     UpdateReload(weaponSettings, ammoUI);
 }
Ejemplo n.º 11
0
 public void FinishReload()
 {
     weaponStatus = WeaponStatus.Normal;
     magAmmo      = stats.magazineSize;
     AmmoUI.UpdateAmmo(magAmmo);
 }
Ejemplo n.º 12
0
 // Start is called before the first frame update
 public override void Start()
 {
     amount = 100;
     ammoUI = GetComponent <AmmoUI>();
 }
Ejemplo n.º 13
0
    public void Shoot(WeaponSettings weaponSettings, Transform weaponBarrel, LayerMask damageLayer, LayerMask firedByLayer, KeyInputType inputType, AmmoUI ammoUI)
    {
        switch (inputType)
        {
        case KeyInputType.Down:
            OnInputDown(weaponSettings, weaponBarrel, damageLayer, firedByLayer, ammoUI);
            break;

        case KeyInputType.Held:
            OnInputHeld(weaponSettings, weaponBarrel, damageLayer, firedByLayer, ammoUI);
            break;

        case KeyInputType.Up:
            OnInputUp(weaponSettings);
            break;

        default:
            break;
        }
    }
Ejemplo n.º 14
0
 protected virtual void OnInputDown(WeaponSettings weaponSettings, Transform weaponBarrel, LayerMask damageLayer, LayerMask firedByLayer, AmmoUI ammoUI)
 {
     if (initialized == false)
     {
         Init(weaponSettings);
     }
 }
Ejemplo n.º 15
0
 // Awake is called when the script gets initialised
 private void Awake()
 {
     bullet = GetComponent <Bullet>();
     ammoUI = GetComponent <AmmoUI>();
 }
Ejemplo n.º 16
0
    private void Awake()
    {
        Instance = this;

        ammoText = transform.Find("ammoText").GetComponent <TextMeshProUGUI>();
    }
Ejemplo n.º 17
0
 protected virtual void OnInputHeld(WeaponSettings weaponSettings, Transform weaponBarrel, LayerMask damageLayer, LayerMask firedByLayer, AmmoUI ammoUI)
 {
 }
Ejemplo n.º 18
0
 private void Awake()
 {
     Instance = this;
 }
Ejemplo n.º 19
0
    protected override void OnInputDown(WeaponSettings weaponSettings, Transform weaponBarrel, LayerMask damageLayer, LayerMask firedByLayer, AmmoUI ammoUI)
    {
        base.OnInputDown(weaponSettings, weaponBarrel, damageLayer, firedByLayer, ammoUI);
        if (canShoot == false)
        {
            return;
        }

        if (weaponSettings.weaponInfo.projectile == null)
        {
            Debug.LogWarning("Trying to shoot a weapon with no projectile!");
            return;
        }

        // If we have ammo or if we are using a weapon with unlimited ammo
        if (currentAmmo > 0 || currentAmmo >= 0 && maxAmmo == 0)
        {
            if (currentClip > 0)
            {
                canShoot = false;

                currentClip--;

                if (currentAmmo > 0)
                {
                    currentAmmo--;
                }

                ammoUI.UpdateCurrentAmmo(currentClip);
                SpawnProjectile(weaponSettings, weaponBarrel, damageLayer, firedByLayer);
            }
            else
            {
                Reload();
            }
        }
    }