몬스터 프리팹, 몬스터 스킬 프리팹 누락된 컴포넌트 추가 및 수정
This commit is contained in:
@@ -9,19 +9,13 @@ namespace TON
|
||||
[SerializeField]
|
||||
private MonsterBase _monsterBase;
|
||||
// private bool _isDetect;
|
||||
private GameObject skill;
|
||||
private GameObject skillPrefab;
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
skill = _monsterBase.smallFirePrefab;
|
||||
GameObject newSkill = Instantiate<GameObject>(skill);
|
||||
newSkill.transform.position = other.transform.position;
|
||||
// newSkill.GetComponent<skill>().Direction = new Vector2(1, 0);
|
||||
// _monsterBase.SetTransition(new AttackState());
|
||||
|
||||
|
||||
_monsterBase.SetTransition(new MonsterSkillState());
|
||||
// 플레이어 감지하면 따라가기
|
||||
// _monsterBase.SetTransition(new ChasingState());
|
||||
Debug.Log("감지됨");
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace TON
|
||||
public int level;
|
||||
public float currentHP = 100; // 몬스터의 현재 체력
|
||||
public int attackPower; // 공격력
|
||||
public int defensePower;
|
||||
public float defencePower; // 몬스터의 방어력
|
||||
public int monsterSkillID;
|
||||
public float patrolRange;
|
||||
public float detectionRange;
|
||||
@@ -46,8 +46,6 @@ namespace TON
|
||||
|
||||
[SerializeField] private Collider2D _collider; // 몬스터의 콜라이더
|
||||
|
||||
public float defencePower; // 몬스터의 방어력
|
||||
|
||||
// 애니메이션 관련 선언
|
||||
private string currentAnimationState; // 현재 애니메이션 상태
|
||||
|
||||
@@ -70,7 +68,18 @@ namespace TON
|
||||
public string animationName; // 스킬 애니메이션 이름
|
||||
|
||||
public GameObject smallFirePrefab;
|
||||
|
||||
public GameObject DragonBreathPrefab;
|
||||
public GameObject IceBlastPrefab;
|
||||
public GameObject PumpkinCrashPrefab;
|
||||
public GameObject TrollChargePrefab;
|
||||
public GameObject TrollCrashPrefab;
|
||||
public GameObject TrollThundePrefab;
|
||||
public GameObject WolfEnergyWavePrefab;
|
||||
public GameObject WolfPunchPrefab;
|
||||
public GameObject DragonShockWavePrefab;
|
||||
public GameObject FireImpactPrefab;
|
||||
public GameObject DropObjectPrefab;
|
||||
|
||||
// 첫 번째 프레임 전에 호출됩니다.
|
||||
private void Start()
|
||||
{
|
||||
@@ -105,7 +114,6 @@ namespace TON
|
||||
monsterName = monsterData.name;
|
||||
level = monsterData.level;
|
||||
currentHP = monsterData.hp;
|
||||
attackPower = monsterData.attackPower;
|
||||
defencePower = monsterData.defencePower;
|
||||
monsterSkillID = monsterData.monsterSkillID;;
|
||||
patrolRange = monsterData.patrolRange;
|
||||
@@ -243,5 +251,15 @@ namespace TON
|
||||
{
|
||||
_stateMachine.SetTransition(state);
|
||||
}
|
||||
|
||||
public void MonsterSkillLaunch()
|
||||
{
|
||||
var target = GameObject.FindGameObjectWithTag("Player");
|
||||
_spriteRenderer.flipX = target.transform.position.x < transform.position.x;
|
||||
|
||||
GameObject newSkill = Instantiate(smallFirePrefab);
|
||||
newSkill.transform.position = transform.position + new Vector3(0, 1f, 0);
|
||||
newSkill.GetComponent<MonsterSkill>().Direction = new Vector2(0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace TON
|
||||
{
|
||||
public class MonsterSkill : MonoBehaviour
|
||||
{
|
||||
public float speed = 3;
|
||||
public float speed = 5f;
|
||||
public float damage = 1;
|
||||
|
||||
Vector2 direction;
|
||||
|
||||
@@ -203,24 +203,48 @@ namespace TON
|
||||
public class MonsterSkillState : State
|
||||
{
|
||||
private const string AniAttack = "Attack"; // 공격 애니메이션
|
||||
public GameObject smallFirePrefab;
|
||||
private const string AniIdle = "Idle"; // 대기 애니메이션
|
||||
private MonsterBase _monsterBase;
|
||||
private float _skillAttackAnimationDuration = 0.5f; // 공격 애니메이션 지속 시간
|
||||
private float _skillAttackDelayTime = 2f; // 공격 딜레이 시간
|
||||
private float _lastSkillAttackTime; // 마지막 공격 시간
|
||||
|
||||
private bool _isSkillAttacking;
|
||||
|
||||
public void Enter(MonsterBase monsterBase)
|
||||
{
|
||||
smallFirePrefab = _monsterBase.smallFirePrefab;
|
||||
|
||||
_monsterBase = monsterBase;
|
||||
_lastSkillAttackTime = -_skillAttackDelayTime; // 처음 진입시 바로 공격하도록 설정
|
||||
SkillAttack();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
// 현재 공격 중이 아니고, 쿨다운이 지났다면 공격
|
||||
if (!_isSkillAttacking && Time.time >= _lastSkillAttackTime + _skillAttackDelayTime)
|
||||
{
|
||||
SkillAttack();
|
||||
}
|
||||
|
||||
// 공격 애니메이션 종료 체크
|
||||
if (_isSkillAttacking && Time.time >= _lastSkillAttackTime + _skillAttackAnimationDuration)
|
||||
{
|
||||
_isSkillAttacking = false;
|
||||
_monsterBase.ChangeAnimationState(AniIdle);
|
||||
}
|
||||
}
|
||||
|
||||
private void SkillAttack()
|
||||
{
|
||||
_monsterBase.ChangeAnimationState(AniAttack);
|
||||
|
||||
_monsterBase.MonsterSkillLaunch();
|
||||
_lastSkillAttackTime = Time.time;
|
||||
_isSkillAttacking = true;
|
||||
}
|
||||
|
||||
public void Exit()
|
||||
{
|
||||
|
||||
_isSkillAttacking = false;
|
||||
}
|
||||
|
||||
public void CheckTransition()
|
||||
|
||||
Reference in New Issue
Block a user