Movement/2D/OneWay2DGroundMovement.cs

29 lines
811 B
C#
Raw Normal View History

using Syntriax.Modules.Movement.ColliderTrigger;
using UnityEngine;
namespace Syntriax.Modules.Movement
{
public class OneWay2DGroundMovement : OneWay2DMovementBase
{
protected override float moveValue { get; set; } = 0f;
protected IGroundTrigger groundTrigger = null;
protected override void Start()
{
base.Start();
groundTrigger = GetComponentInChildren<IGroundTrigger>();
groundTrigger.OnTriggered.AddListener(OnGroundTrigger);
}
private void OnGroundTrigger(bool isGrounded)
=> CanTakeOver = isGrounded;
public override void ApplyMovement()
{
Vector2 velocity = rigid.velocity;
velocity.x = moveValue;
rigid.velocity = velocity;
}
}
}