45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
|
|
using UnityEngine;
|
||
|
|
using UVC.Core;
|
||
|
|
|
||
|
|
namespace Sample
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// 런타임에 Instantiate로 생성되는 오브젝트
|
||
|
|
/// 생성 후 수동으로 Inject 호출 필요
|
||
|
|
/// </summary>
|
||
|
|
public class InjectorSampleEnemy : MonoBehaviour
|
||
|
|
{
|
||
|
|
[Header("Enemy Settings")]
|
||
|
|
[SerializeField] private int baseHealth = 100;
|
||
|
|
|
||
|
|
[Inject] private ILogService _logger;
|
||
|
|
[Inject(Optional = true)] private ISceneConfig _sceneConfig;
|
||
|
|
|
||
|
|
public int Health { get; private set; }
|
||
|
|
|
||
|
|
private void Start()
|
||
|
|
{
|
||
|
|
var difficulty = _sceneConfig?.Difficulty ?? 1.0f;
|
||
|
|
Health = (int)(baseHealth * difficulty);
|
||
|
|
_logger?.Log($"Enemy spawned with {Health} HP");
|
||
|
|
}
|
||
|
|
|
||
|
|
public void TakeDamage(int damage)
|
||
|
|
{
|
||
|
|
Health -= damage;
|
||
|
|
_logger?.Log($"Enemy took {damage} damage. HP: {Health}");
|
||
|
|
|
||
|
|
if (Health <= 0)
|
||
|
|
{
|
||
|
|
Die();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void Die()
|
||
|
|
{
|
||
|
|
_logger?.Log("Enemy died");
|
||
|
|
Destroy(gameObject);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|