TIL 0419 최종 프로젝트 - 20

강성원·2024년 5월 12일
0

TIL 오늘 배운 것

목록 보기
66/69

Drone 공중에 떠서 움직이지도, 죽지도 않음

문제

  • Ball이 아무런 행동도 취하지 않음

이유

처음에 코드를 간편하게 만든다고 Initialize (생성자에서 호출되는)에서 초기 상태로 들어가는 것을 호출하지 않았다.

public class DroneStateMachine : BaseStateMachine
{
    public DroneStateMachine(Entity entity) : base(entity)
    {
    }

    public override void Initialize()
    {
        Provider = new DroneStateProivder(this);
        
    }

    public override void Reset()
    {
        CurrentState = Provider.GetState(Minion_States.Alive);
        CurrentState.EnterState();
    }
}

해결

다시 코드를 추가해주니 정상으로 돌아왔음.

public class DroneStateMachine : BaseStateMachine
{
    public DroneStateMachine(Entity entity) : base(entity)
    {
    }

    public override void Initialize()
    {
        Provider = new DroneStateProivder(this);
        CurrentState = Provider.GetState(Minion_States.Alive);
        CurrentState.EnterState();
    }

    public override void Reset()
    {
        CurrentState = Provider.GetState(Minion_States.Alive);
        CurrentState.EnterState();
    }
}

Ball 폭발효과 및 공격로직 발동하지 않음

문제

기존에 Dead 상태로 진입하고 호출하는 Explosion 함수를 코루틴으로 구현했었음.

하지만 Explosion 함수가 끝나기 전에 Ball의 Active가 false가 돼서 중간에 함수가 멈춰버리는 등의 오류가 발생했다.

원인

예상대로 코루틴 함수의 진행 중에 Active가 변해버리는 문제가 있었음.

해결

코루틴 함수를 일반 함수의 형태로 바꿔서 호출해주었다.

기존에 코루틴 함수 내에서 1초 기다렸다가 로직 진행하던 것을 변경했다.

n초 측정 후에 폭발 함수를 호출한다.

public class Ball_DeadState : BaseState
{
    float explodeDelay = 1f;
    float passedTime;

    public Ball_DeadState(BaseStateMachine context, BaseStateProvider provider) : base(context, provider)
    {
        IsRootState = true;
    }

    public override void EnterState()
    {
        passedTime = 0f;
        
    }

    public override void UpdateState()
    {
        passedTime += Time.deltaTime;
        if(passedTime >= explodeDelay)
        {
            Explosion();
        }
    }  
,,,
    private void Explosion()
    {
        ,,,생략,,,
        
        Context.Entity.gameObject.SetActive(false);
    }
}

역시 기초적인 것으로 먼저 구현해보는게 최고인 것 같다.

profile
개발은삼순이발

0개의 댓글