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(); }
private void Start() { cameraTransform = Camera.main.transform; handAnim = transform.parent.GetComponent <Animator>(); magAmmo = stats.magazineSize; AmmoUI.UpdateAmmo(magAmmo); }
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> (); }
public void InitializeAmmoUI() { if (instance == null) { instance = this; } else { Destroy(this.gameObject); } }
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(); }
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(); } }
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); } } }
public void Reload() { nextFireTime = Time.time + stats.reloadTime; weaponStatus = WeaponStatus.Reloading; AmmoUI.SetReloading(nextFireTime); }
public void Update(WeaponSettings weaponSettings, AmmoUI ammoUI) { UpdateShootReset(weaponSettings); UpdateReload(weaponSettings, ammoUI); }
public void FinishReload() { weaponStatus = WeaponStatus.Normal; magAmmo = stats.magazineSize; AmmoUI.UpdateAmmo(magAmmo); }
// Start is called before the first frame update public override void Start() { amount = 100; ammoUI = GetComponent <AmmoUI>(); }
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; } }
protected virtual void OnInputDown(WeaponSettings weaponSettings, Transform weaponBarrel, LayerMask damageLayer, LayerMask firedByLayer, AmmoUI ammoUI) { if (initialized == false) { Init(weaponSettings); } }
// Awake is called when the script gets initialised private void Awake() { bullet = GetComponent <Bullet>(); ammoUI = GetComponent <AmmoUI>(); }
private void Awake() { Instance = this; ammoText = transform.Find("ammoText").GetComponent <TextMeshProUGUI>(); }
protected virtual void OnInputHeld(WeaponSettings weaponSettings, Transform weaponBarrel, LayerMask damageLayer, LayerMask firedByLayer, AmmoUI ammoUI) { }
private void Awake() { Instance = this; }
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(); } } }