43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
using Syntriax.Modules.Trigger;
|
|
using UnityEngine;
|
|
|
|
namespace Syntriax.Modules.Movement.Samples
|
|
{
|
|
[RequireComponent(typeof(Rigidbody2D))]
|
|
public class GroundMovement1D : MovementBase1D
|
|
{
|
|
protected override float moveValue { get; set; } = 0f;
|
|
protected IGroundTrigger groundTrigger = null;
|
|
protected Rigidbody2D rigid = null;
|
|
|
|
private void Awake() => CanTakeOver = true;
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
|
|
rigid = GetComponentInParent<Rigidbody2D>();
|
|
groundTrigger = GetComponentInChildren<IGroundTrigger>();
|
|
|
|
if (groundTrigger != null)
|
|
{
|
|
groundTrigger.OnTriggerStateChanged += OnGroundTrigger;
|
|
CanTakeOver = false;
|
|
}
|
|
}
|
|
|
|
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() { }
|
|
}
|
|
}
|