diff --git a/Scripts/Damageable.cs b/Scripts/Damageable.cs index 01b754e..1bdceaf 100644 --- a/Scripts/Damageable.cs +++ b/Scripts/Damageable.cs @@ -29,7 +29,12 @@ namespace GameDev.CoreSystems public void ModifyHealth(int healthChange) { if (IsInvulnerable) return; + CurrentHealth += healthChange; + + if (CurrentHealth >= 0) return; + + print($"{transform.parent.parent.name} died"); } #endregion diff --git a/Scripts/Targetable.cs b/Scripts/Targetable.cs index bbd8b89..de72aec 100644 --- a/Scripts/Targetable.cs +++ b/Scripts/Targetable.cs @@ -14,6 +14,9 @@ namespace GameDev.CoreSystems [SerializeField] private Transform _centerPosition; [SerializeField] private Transform _basePosition; + [field: Header("Collider")] + [field: SerializeField] public Collider Collider { get; private set; } + private void OnEnable() { _activeTargetableRuntimeSet._list.Add(this); diff --git a/Scripts/Weapon.cs b/Scripts/Weapon.cs new file mode 100644 index 0000000..ae60495 --- /dev/null +++ b/Scripts/Weapon.cs @@ -0,0 +1,75 @@ +using System; +using UnityEngine; + +namespace GameDev.CoreSystems +{ + public class Weapon : MonoBehaviour, IWeapon + { + [field: Header("RigConnections")] + [field: SerializeField] public Transform PivotPoint { get; private set; } + [field: SerializeField] public Transform BarrelEndPoint { get; private set; } + + [field: Header("Config")] + [field: SerializeField] public float FireRate { get; set; } + [field: SerializeField] public float Damage { get; set; } + + [field: Header("State")] + [field: SerializeField] public bool FireWeapon { get; set; } + [field: SerializeField] private float _timeUntilFire; + + private Vector3 _start; + private Vector3 _direction; + // private bool drawGizmo; + // private Vector3 start; + // private Vector3 end; + // + // private void OnEnable() + // { + // start = BarrelEndPoint.position; + // end = BarrelEndPoint.position; + // } + // + // private void OnDrawGizmos() + // { + // if (drawGizmo) + // { + // Gizmos.DrawLine(start, end); + // } + // } + + private void Update() + { + if (FireWeapon) + { + // drawGizmo = true; + // start = BarrelEndPoint.position; + // end = start + Vector3.forward * 5; + _timeUntilFire -= Time.deltaTime; + + if (!(_timeUntilFire <= 0)) return; + + // _start = BarrelEndPoint.position; + //_direction = BarrelEndPoint.forward; + + var ray = new Ray(BarrelEndPoint.position, BarrelEndPoint.forward); + Debug.DrawRay(BarrelEndPoint.position, BarrelEndPoint.forward * 10, Color.green); + + if (Physics.Raycast(ray, out RaycastHit hitInfo)) + { + if (hitInfo.transform.TryGetComponent(out Targetable target)) + { + print("pew"); + target.Damageable.ModifyHealth(Mathf.RoundToInt(-Damage)); + } + } + + _timeUntilFire = FireRate; + } + else + { + // drawGizmo = false; + _timeUntilFire = 0; + } + } + } +} \ No newline at end of file diff --git a/Scripts/Weapon.cs.meta b/Scripts/Weapon.cs.meta new file mode 100644 index 0000000..c749410 --- /dev/null +++ b/Scripts/Weapon.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 86bd9978589203b4db636cf6248e263b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: