OneShotOneKill/Assets/Script/InGame/Actor/MobActor.cs

79 lines
1.7 KiB
C#
Raw Normal View History

2026-01-12 22:13:54 +00:00
using UnityEngine;
2026-01-12 22:47:31 +00:00
public enum eMobState { Move, Attack }
2026-01-12 22:13:54 +00:00
public class MobActor : MonoBehaviour
{
2026-01-12 22:47:31 +00:00
MonsterTableData m_Data;
float FenceY, m_attackTimer;
eMobState m_State = eMobState.Move;
2026-01-12 22:13:54 +00:00
private void Awake()
{
var srs = GetComponentsInChildren<SpriteRenderer>(true);
for (int i = 0; i < srs.Length; i++)
srs[i].sortingOrder -= 5;
}
private void Update()
{
2026-01-12 22:47:31 +00:00
float distToFence = transform.position.y - FenceY;
switch (m_State)
{
case eMobState.Move:
if (distToFence <= m_Data.f_AttackRange)
{
m_State = eMobState.Attack;
OnEnterAttack();
}
else
{
Move();
}
break;
case eMobState.Attack:
Attack();
break;
}
}
public void Set(MonsterTableData data, float fenceY)
{
m_Data = data;
FenceY = fenceY;
m_attackTimer = m_Data.f_AttackDelay;
}
void Move()
{
transform.position += Vector3.down * Time.deltaTime * m_Data.f_MoveSpeed;
}
void OnEnterAttack()
{
// 이동 정지 시점 보정 (너무 파고들지 않게)
Vector3 pos = transform.position;
pos.y = FenceY + m_Data.f_AttackRange;
transform.position = pos;
// 애니메이션, 공격 쿨타임 초기화 등
}
void Attack()
{
m_attackTimer -= Time.deltaTime;
if (m_attackTimer > 0f)
return;
m_attackTimer = m_Data.f_AttackDelay;
// 철책 or 플레이어 공격
AttackFence();
}
void AttackFence()
{
2026-01-12 22:13:54 +00:00
}
}