full playable game
This commit is contained in:
1 parent
afcd8761e6
commit
1869fa7584
56 files changed
+7581
-37
No files matched your search
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user