full playable game
This commit is contained in:
1 parent
afcd8761e6
commit
1869fa7584
56 files changed
+7581
-37
No files matched your search
@@ -0,0 +1,16 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Gameplay.Character.Stats
|
||||
{
|
||||
public class HealthBuff : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private int healthBuff = 50;
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (!other.CompareTag("Player")) return;
|
||||
var health = other.GetComponent<HealthSystem>();
|
||||
health?.Heal(healthBuff);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0c628fd85b24cb1ad9748bba030feaa
|
||||
timeCreated: 1771912003
|
||||
@@ -10,6 +10,7 @@ namespace Code.Gameplay.Enemy
|
||||
{
|
||||
[SerializeField] private HealthSystem healthSystem;
|
||||
[SerializeField] private WeaponBase weapon;
|
||||
[SerializeField] private Transform weaponPoint;
|
||||
[SerializeField] private Transform firePoint;
|
||||
[SerializeField] private Transform target;
|
||||
|
||||
@@ -40,6 +41,15 @@ namespace Code.Gameplay.Enemy
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (weapon)
|
||||
{
|
||||
var weaponGo = Instantiate(weapon.gameObject, weaponPoint);
|
||||
weapon = weaponGo.GetComponent<WeaponBase>();
|
||||
weapon._firePoint = firePoint.transform;
|
||||
weapon.Reload();
|
||||
attackCooldown = weapon.FireRate + 0.01f;
|
||||
}
|
||||
|
||||
if (healthSystem != null)
|
||||
{
|
||||
healthSystem.OnDied += HandleDeath;
|
||||
@@ -110,17 +120,20 @@ namespace Code.Gameplay.Enemy
|
||||
if (!HasLineOfSight()) return;
|
||||
|
||||
lastAttackTime = Time.time;
|
||||
weapon.Shoot();
|
||||
if (weapon.CurrentAmmo <= 0)
|
||||
weapon.Reload();
|
||||
else
|
||||
weapon.StartShooting();
|
||||
}
|
||||
|
||||
private bool HasLineOfSight()
|
||||
{
|
||||
if (target == null) return false;
|
||||
|
||||
var direction = (target.position - firePoint.position).normalized;
|
||||
var distance = Vector3.Distance(firePoint.position, target.position);
|
||||
var direction = (target.position - weaponPoint.position).normalized;
|
||||
var distance = Vector3.Distance(weaponPoint.position, target.position);
|
||||
|
||||
if (Physics.Raycast(firePoint.position, direction, out var hit, distance, obstacleMask))
|
||||
if (Physics.Raycast(weaponPoint.position, direction, out var hit, distance, obstacleMask))
|
||||
{
|
||||
return hit.collider.transform == target;
|
||||
}
|
||||
@@ -131,8 +144,11 @@ namespace Code.Gameplay.Enemy
|
||||
private void HandleDeath()
|
||||
{
|
||||
enabled = false;
|
||||
|
||||
Destroy(gameObject, 2f);
|
||||
|
||||
var healthGo = Instantiate(Resources.Load<GameObject>("Prefabs/HealthBuff").gameObject);
|
||||
healthGo.transform.position = new Vector3(transform.position.x, transform.position.y - 1, transform.position.z);
|
||||
|
||||
Destroy(gameObject, 1);
|
||||
}
|
||||
|
||||
public void TakeDamage(float damage)
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Code.Gameplay.Weapons
|
||||
[SerializeField] protected float reloadTime = 1.5f;
|
||||
[SerializeField] protected float spreadAngle = 1f;
|
||||
|
||||
private Transform _firePoint;
|
||||
public Transform _firePoint;
|
||||
[SerializeField] protected GameObject bulletPrefab;
|
||||
[SerializeField] protected ParticleSystem muzzleFlash;
|
||||
[SerializeField] protected AudioClip shootSound;
|
||||
@@ -32,12 +32,15 @@ namespace Code.Gameplay.Weapons
|
||||
protected bool isShooting;
|
||||
protected bool isReloading;
|
||||
protected float lastShotTime;
|
||||
protected float lastShotTryTime;
|
||||
|
||||
public WeaponType Type => weaponType;
|
||||
public int CurrentAmmo => currentAmmo;
|
||||
public int ReserveAmmo => reserveAmmo;
|
||||
public int MagazineSize => magazineSize;
|
||||
public bool IsReloading => isReloading;
|
||||
public float FireRate => fireRate;
|
||||
public string WeaponName => weaponName;
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
@@ -50,21 +53,23 @@ namespace Code.Gameplay.Weapons
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
_firePoint = FindFirstObjectByType<CameraController>().transform;
|
||||
if (!_firePoint)
|
||||
_firePoint = FindFirstObjectByType<CameraController>().transform;
|
||||
}
|
||||
|
||||
public virtual void Shoot()
|
||||
{
|
||||
if (isReloading) return;
|
||||
|
||||
if (Time.time - lastShotTime < fireRate)
|
||||
return;
|
||||
|
||||
if (currentAmmo <= 0)
|
||||
{
|
||||
PlayEmptySound();
|
||||
return;
|
||||
}
|
||||
|
||||
if (Time.time - lastShotTime < fireRate)
|
||||
return;
|
||||
|
||||
switch (fireMode)
|
||||
{
|
||||
case FireMode.SemiAutomatic:
|
||||
@@ -160,6 +165,9 @@ namespace Code.Gameplay.Weapons
|
||||
|
||||
protected virtual void PlayEmptySound()
|
||||
{
|
||||
if (Time.time - lastShotTryTime < fireRate)
|
||||
return;
|
||||
lastShotTryTime = Time.time;
|
||||
if (emptySound != null)
|
||||
audioSource.PlayOneShot(emptySound);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Code.Gameplay.Character.Core;
|
||||
using Code.Gameplay.Character.Inventory;
|
||||
using Code.Gameplay.Character.Stats;
|
||||
|
||||
namespace Code.UI
|
||||
{
|
||||
public class GameUI : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text weaponNameText;
|
||||
[SerializeField] private TMP_Text healthText;
|
||||
[SerializeField] private TMP_Text ammoText;
|
||||
|
||||
[SerializeField] private string weaponNameFormat = "CURRENT WEAPON: {0}";
|
||||
[SerializeField] private string healthFormat = "HP: {0}/{1}";
|
||||
[SerializeField] private string ammoFormat = "AMMO: {0}/{1}";
|
||||
|
||||
private CharacterProvider _player;
|
||||
private HealthSystem _playerHealth;
|
||||
private WeaponInventory _weaponInventory;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_player = FindFirstObjectByType<CharacterProvider>();
|
||||
|
||||
if (_player != null)
|
||||
{
|
||||
_playerHealth = _player.GetComponent<HealthSystem>();
|
||||
_weaponInventory = _player.GetComponent<WeaponInventory>();
|
||||
}
|
||||
|
||||
if (_playerHealth != null)
|
||||
{
|
||||
_playerHealth.OnHealthChanged += UpdateHealth;
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
UpdateWeaponName();
|
||||
UpdateHealth();
|
||||
UpdateAmmo();
|
||||
}
|
||||
|
||||
private void UpdateWeaponName()
|
||||
{
|
||||
if (weaponNameText == null || _weaponInventory?.CurrentWeapon == null) return;
|
||||
|
||||
var weaponName = _weaponInventory.CurrentWeapon.WeaponName;
|
||||
weaponNameText.text = string.Format(weaponNameFormat, weaponName.ToUpper());
|
||||
}
|
||||
|
||||
private void UpdateHealth()
|
||||
{
|
||||
if (healthText == null || _playerHealth == null) return;
|
||||
|
||||
healthText.text = string.Format(healthFormat,
|
||||
_playerHealth.CurrentHealth,
|
||||
_playerHealth.MaxHealth);
|
||||
}
|
||||
|
||||
private void UpdateHealth(float current, float max)
|
||||
{
|
||||
if (healthText == null) return;
|
||||
healthText.text = string.Format(healthFormat, current, max);
|
||||
}
|
||||
|
||||
private void UpdateAmmo()
|
||||
{
|
||||
if (ammoText == null || _weaponInventory?.CurrentWeapon == null) return;
|
||||
|
||||
var weapon = _weaponInventory.CurrentWeapon;
|
||||
ammoText.text = string.Format(ammoFormat,
|
||||
weapon.CurrentAmmo,
|
||||
weapon.ReserveAmmo);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_playerHealth != null)
|
||||
{
|
||||
_playerHealth.OnHealthChanged -= UpdateHealth;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 178d0870793f4cee961b9e91b88f88ae
|
||||
timeCreated: 1771875966
|
||||
Reference in new issue
Block a user