오늘은 플레이어의 원거리 투척물을 사용할 수 있도록 구현하는 것을 했다.
아직 완성은 못했지만 스테이트 확장과 직접 투척물을 꺼내는 작업까지 진행하였다.
PlayerAnimationData 수정
public class PlayerAnimationData
{
// 생략
[SerializeField] private string throwParameterName = "Throw";
// 생략
public int ThrowParameterHash { get; private set; }
// 생략
ThrowParameterHash = Animator.StringToHash(throwParameterName);
}
}
PlayerStateMachine 수정
public class PlayerStateMachine : StateMachine, IDamageable
{
// 생략
public PlayerThrowState ThrowState { get; }
public PlayerStateMachine(Player player)
{
// 생략
ThrowState = new PlayerThrowState(this);
}
}
PlayerGroundState 수정
protected override void OnThrowStarted(InputAction.CallbackContext context)
{
stateMachine.ChangeState(stateMachine.ThrowState);
}
PlayerBaseState 수정
protected virtual void AddInputActionsCallbacks()
{
// 생략
input.PlayerActions.Throw.started += OnThrowStarted;
}
protected virtual void RemoveInputActionsCallbacks()
{
// 생략
input.PlayerActions.Throw.started -= OnThrowStarted;
}
protected virtual void OnThrowStarted(InputAction.CallbackContext context)
{
}
Player 수정
public class Player : MonoBehaviour
{
// 생략
public GameObject[] grenades;
public int hasGrenades;
public GameObject grenadeObj;
public void Grenade()
{
if (hasGrenades == 0)
return;
GameObject instantGrenade = Instantiate(grenadeObj, transform.position, transform.rotation);
Rigidbody rigidGrenade = instantGrenade.GetComponent<Rigidbody>();
}
<PlayerThrowState>
public class PlayerThrowState : PlayerGroundState
{
public PlayerThrowState(PlayerStateMachine playerstateMachine) : base(playerstateMachine)
{
}
public override void Enter()
{
base.Enter();
isMovable = false;
StartAnimation(stateMachine.Player.AnimationData.ThrowParameterHash);
stateMachine.Player.Grenade();
}
public override void Exit()
{
base.Exit();
StopAnimation(stateMachine.Player.AnimationData.ThrowParameterHash);
}
public override void Update()
{
base.Update();
if (stateMachine.Player.Animator.GetCurrentAnimatorStateInfo(0).IsName("Throw") &&
stateMachine.Player.Animator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1.0f)
{
stateMachine.ChangeState(stateMachine.IdleState);
}
}
}
내일은 투척물을 직접 전방으로 던지는 로직과 투척물의 폭발에 대해서도 구현을 해볼 계획이다.
아직 이 스크립트만으로는 플레이어의 위치에 투척물을 생성하는 것밖에 안되기 때문에
플레이어전방으로 포물선을 그리며 날아가도록 구현을 할 예정이다.
'TIL (since 2023.08.07 ~ )' 카테고리의 다른 글
2023-11-20 TIL(Unity 최종 프로젝트 21일차) (0) | 2023.11.20 |
---|---|
2023-11-17 TIL(Unity 최종 프로젝트 20일차) (0) | 2023.11.17 |
2023-11-14 TIL(Unity 최종 프로젝트 17일차) (0) | 2023.11.14 |
2023-11-13 TIL(Unity 최종 프로젝트 16일차) (0) | 2023.11.13 |
2023-11-10 TIL(Unity 최종 프로젝트 15일차) (0) | 2023.11.10 |