This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class Weapon : MonoBehaviour | |
{ | |
[SerializeField] | |
private WeaponSettings _weaponSettings; | |
[SerializeField] | |
private Transform _muzzlePoint; | |
private SteamVR_TrackedController _controller; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class WeaponAmmo | |
{ | |
private int _ammoNotInClip; | |
private int _ammoInClip; | |
private int _maxAmmoPerClip; | |
private bool HasAmmoReady { get { return _ammoInClip > 0; } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal interface ITakeDamage | |
{ | |
void TakeDamage(int damage); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
[CreateAssetMenu(menuName = "Weapons/WeaponSettings")] | |
public class WeaponSettings : ScriptableObject | |
{ | |
[SerializeField] | |
[Tooltip("Time required between trigger clicks to fire.")] | |
[Range(0, 2f)] | |
private float _fireDelay = 0.25f; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public WeaponAmmo(WeaponSettings weaponSettings) | |
{ | |
_ammoNotInClip = weaponSettings.StartingAmmo; | |
_maxAmmoPerClip = weaponSettings.AmmoPerClip; | |
Reload(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Reload() | |
{ | |
int spaceRemaining = _maxAmmoPerClip - _ammoInClip; | |
int desiredAmmoToMove = Math.Min(_maxAmmoPerClip, spaceRemaining); | |
int amountToMove = Math.Min(desiredAmmoToMove, _ammoNotInClip); | |
if (amountToMove > 0) | |
{ | |
_ammoNotInClip -= amountToMove; | |
_ammoInClip += amountToMove; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public bool TryTakeBullet() | |
{ | |
if (HasAmmoReady == false) | |
return false; | |
_ammoInClip--; | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CreateAssetMenu(menuName = "Weapons/WeaponSettings")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[SerializeField] | |
private WeaponSettings _weaponSettings; | |
[SerializeField] | |
private Transform _muzzlePoint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private SteamVR_TrackedController _controller; | |
private WeaponAmmo _weaponAmmo; | |
private float _nextFireTime; | |
private bool CanFire { get { return Time.time >= _nextFireTime; } } |
OlderNewer