2022-11-14 13:21:35 +03:00
|
|
|
using Syntriax.Modules.Trigger;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace Syntriax.Modules.Movement.Implementations
|
|
|
|
{
|
|
|
|
[RequireComponent(typeof(Rigidbody2D))]
|
|
|
|
public class GroundMovement1D : MovementBase1D
|
|
|
|
{
|
|
|
|
protected override float moveValue { get; set; } = 0f;
|
|
|
|
protected IGroundTrigger groundTrigger = null;
|
|
|
|
protected Rigidbody2D rigid = null;
|
|
|
|
|
|
|
|
protected override void Start()
|
|
|
|
{
|
|
|
|
base.Start();
|
|
|
|
|
|
|
|
rigid = GetComponent<Rigidbody2D>();
|
|
|
|
groundTrigger = GetComponentInChildren<IGroundTrigger>();
|
2022-11-15 14:30:08 +03:00
|
|
|
|
|
|
|
if (groundTrigger != null)
|
|
|
|
groundTrigger.OnTriggered += OnGroundTrigger;
|
|
|
|
else
|
|
|
|
CanTakeOver = true;
|
2022-11-14 13:21:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OnGroundTrigger(bool isGrounded)
|
|
|
|
=> CanTakeOver = isGrounded;
|
|
|
|
|
|
|
|
public override void ApplyMovement()
|
|
|
|
{
|
|
|
|
Vector2 velocity = rigid.velocity;
|
|
|
|
velocity.x = moveValue;
|
|
|
|
rigid.velocity = velocity;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnDeactivated() { }
|
|
|
|
protected override void OnActivated() { }
|
|
|
|
}
|
|
|
|
}
|