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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user