You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/Plugins/Animancer/Examples/06 State Machines/06 Platformer/Creature States/AdvancedJumpState.cs

51 lines
1.9 KiB
C#

3 months ago
// Animancer // Copyright 2020 Kybernetik //
#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value.
using UnityEngine;
namespace Animancer.Examples.StateMachines.Platformer
{
/// <summary>
/// A more complex <see cref="JumpState"/> that allows you to hold the button down to jump higher.
/// </summary>
[AddComponentMenu(Strings.MenuPrefix + "Examples/Platformer - Advanced Jump State")]
[HelpURL(Strings.APIDocumentationURL + ".Examples.StateMachines.Platformer/AdvancedJumpState")]
public sealed class AdvancedJumpState : JumpState
{
/************************************************************************************************************************/
[SerializeField] private float _HoldForce = 20;
[SerializeField] private float _HoldDuration = 0.25f;
public bool IsHolding { get; set; }
/************************************************************************************************************************/
protected override void OnEnable()
{
base.OnEnable();
IsHolding = true;
}
/************************************************************************************************************************/
private void OnDisable()
{
IsHolding = false;
}
/************************************************************************************************************************/
protected override void FixedUpdate()
{
base.FixedUpdate();
if (IsHolding && AnimancerState.Time <= _HoldDuration)
Creature.Rigidbody.velocity += new Vector2(0, _HoldForce * Time.deltaTime);
}
/************************************************************************************************************************/
}
}