代码仓库
原视频地址
武器item
[CreateAssetMenu(menuName = "Item/Weapon Item")]
public class WeaponItem : Item
{
public GameObject modelPrefab;
public bool isUnarmed;
[Header("One Handed Attack Animations")]
public string OH_Light_Attack_1;
public string OH_Heavy_Attack_1;
}
新加了一个轻攻击的动画名称和一个重攻击的动画名称。
攻击组件和输入组件
public class PlayerAttacker : MonoBehaviour
{
AnimatorHandler animatorHandler;
private void Awake()
{
animatorHandler = GetComponentInChildren<AnimatorHandler>();
}
public void HandleLigthAttack(WeaponItem weapon)
{
animatorHandler.PlayTargetAnimation(weapon.OH_Light_Attack_1, true);
}
public void HandleHeavyAttack(WeaponItem weapon)
{
animatorHandler.PlayTargetAnimation(weapon.OH_Heavy_Attack_1, true);
}
这个Attacker类负责播放相应的动画
InputHandler里面负责接收输入,然后从Inventory中拿取玩家的武器,随后播放相应的攻击动画。
private void HandleAttackInput(float delta)
{
inputActions.PlayerActions.RB.performed += i => rb_Input = true;
inputActions.PlayerActions.RT.performed += i => rt_Input = true;
if (rb_Input)
{
playerAttacker.HandleLigthAttack(playerInventory.rightWeapon);
}
if (rt_Input)
{
playerAttacker.HandleHeavyAttack(playerInventory.rightWeapon);
}
}
别忘了最后在PlayerManager里面把rt_Input和rb_Input设置为false