28 lines
728 B
C#
28 lines
728 B
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.Splines;
|
||
|
|
||
|
namespace BITKit.Entities.Movement
|
||
|
{
|
||
|
public class UnitySplineMovementComponent : EntityBehavior
|
||
|
{
|
||
|
[SerializeField] private float speed;
|
||
|
[SerializeField] private SplineContainer spline;
|
||
|
|
||
|
[Inject] private IHealth _health;
|
||
|
[Inject] private IEntityMovement _movement;
|
||
|
|
||
|
private float _currentDistance;
|
||
|
public override void OnFixedUpdate(float deltaTime)
|
||
|
{
|
||
|
base.OnFixedUpdate(deltaTime);
|
||
|
if (_health.IsAlive is false) return;
|
||
|
var position = spline.EvaluatePosition(_currentDistance+=speed*deltaTime);
|
||
|
|
||
|
_movement.Position = spline.transform.rotation * position + spline.transform.position;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|