Files
MobileShooter/Assets/Darkmatter/Code/Presentation/Enemies/EnemyMotor.cs
2025-12-31 17:14:20 -08:00

66 lines
1.7 KiB
C#

using Darkmatter.Core;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using VContainer;
namespace Darkmatter.Presentation
{
public class EnemyMotor : MonoBehaviour, IEnemyPawn
{
[SerializeField] private NavMeshAgent enemyAI;
[SerializeField] private Transform playerTransform;
[SerializeField] private List<Transform> patrolPoints = new List<Transform>();
[Inject] private EnemyConfigSO enemyConfig;
public Transform PlayerTarget => playerTransform;
public NavMeshAgent EnemyAI => enemyAI;
public List<Transform> PatrolPoints => patrolPoints;
public float Health { get; set; } = 100;
public bool isDead { get; set; } = false;
public event Action<float> OnHealthDecreased;
public void Die()
{
isDead = true;
enemyAI.enabled = false;
Invoke(nameof(Hide), 8f);
}
private void Hide()
{
this.gameObject.SetActive(false);
}
public Vector3 ReturnMyPos()
{
return this.transform.position;
}
public void SetDestination(Vector3 destination)
{
enemyAI.SetDestination(destination);
}
public void TakeDamage(float damage)
{
Health -= damage;
OnHealthDecreased?.Invoke(Health);
}
private void OnDrawGizmos()
{
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere(transform.position, enemyConfig.visionRange);
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(transform.position, enemyConfig.attackRange);
}
}
}