mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-26 22:10:17 +00:00
implement reloading time - all weapons have it set to 0, except rockets
This commit is contained in:
parent
00a95beb66
commit
9ee8f0dfac
4 changed files with 29 additions and 4 deletions
|
@ -128,6 +128,7 @@ MonoBehaviour:
|
|||
drawLineFromGun: 0
|
||||
projectilePrefab: {fileID: 8038540346792760480, guid: 858b1226127ef9f4e8d16c9610e691b6,
|
||||
type: 3}
|
||||
projectileReloadTime: 2.5
|
||||
--- !u!114 &114529712737653322
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
@ -369,7 +369,10 @@ namespace SanAndreasUnity.Behaviours
|
|||
|
||||
this.FiresProjectile = s_weaponsUsingProjectile.Contains(this.Data.modelId1);
|
||||
if (this.FiresProjectile)
|
||||
{
|
||||
this.ProjectilePrefab = WeaponsSettings.projectilePrefab;
|
||||
this.ReloadTime = WeaponsSettings.projectileReloadTime;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -524,6 +527,8 @@ namespace SanAndreasUnity.Behaviours
|
|||
|
||||
public GameObject ProjectilePrefab { get; set; }
|
||||
|
||||
public float ReloadTime { get; set; } = 0;
|
||||
|
||||
|
||||
// TODO: this function should be removed, and new one should be created: OnAnimsUpdated
|
||||
public virtual void UpdateAnimWhileHolding ()
|
||||
|
|
|
@ -110,6 +110,9 @@ namespace SanAndreasUnity.Behaviours {
|
|||
public bool rotatePlayerInDirectionOfAiming = true;
|
||||
|
||||
|
||||
private float m_timeSinceStartedReloading = 0;
|
||||
|
||||
|
||||
|
||||
void Awake () {
|
||||
|
||||
|
@ -161,17 +164,31 @@ namespace SanAndreasUnity.Behaviours {
|
|||
}
|
||||
|
||||
// reload weapon ammo clip
|
||||
|
||||
bool isReloadingNow = false;
|
||||
|
||||
if (NetStatus.IsServer)
|
||||
{
|
||||
if (CurrentWeapon != null) {
|
||||
if (CurrentWeapon.AmmoClipSize > 0 && CurrentWeapon.AmmoInClip <= 0) {
|
||||
int amountToRefill = Mathf.Min (CurrentWeapon.AmmoClipSize, CurrentWeapon.AmmoOutsideOfClip);
|
||||
CurrentWeapon.AmmoInClip = amountToRefill;
|
||||
CurrentWeapon.AmmoOutsideOfClip -= amountToRefill;
|
||||
if (CurrentWeapon.AmmoClipSize > 0 && CurrentWeapon.AmmoInClip <= 0 && CurrentWeapon.AmmoOutsideOfClip > 0)
|
||||
{
|
||||
isReloadingNow = true;
|
||||
m_timeSinceStartedReloading += Time.deltaTime;
|
||||
if (m_timeSinceStartedReloading >= CurrentWeapon.ReloadTime)
|
||||
{
|
||||
m_timeSinceStartedReloading = 0;
|
||||
|
||||
int amountToRefill = Mathf.Min(CurrentWeapon.AmmoClipSize, CurrentWeapon.AmmoOutsideOfClip);
|
||||
CurrentWeapon.AmmoInClip = amountToRefill;
|
||||
CurrentWeapon.AmmoOutsideOfClip -= amountToRefill;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isReloadingNow)
|
||||
m_timeSinceStartedReloading = 0;
|
||||
|
||||
}
|
||||
|
||||
void LateUpdate_jdghrjgjr()
|
||||
|
@ -304,6 +321,7 @@ namespace SanAndreasUnity.Behaviours {
|
|||
this.currentWeaponSlot = slotIndex;
|
||||
|
||||
m_frameWhenSwitchedWeapon = Time.frameCount;
|
||||
m_timeSinceStartedReloading = 0;
|
||||
|
||||
if (NetStatus.IsServer)
|
||||
m_ped.StopFiring ();
|
||||
|
|
|
@ -51,6 +51,7 @@ namespace SanAndreasUnity.Behaviours.Weapons
|
|||
public bool drawLineFromGun = false;
|
||||
|
||||
public GameObject projectilePrefab;
|
||||
public float projectileReloadTime = 3f;
|
||||
|
||||
|
||||
public static WeaponsManager Instance { get; private set; }
|
||||
|
|
Loading…
Reference in a new issue