2022-02-21 15:53:23 +03:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace Movement
|
|
|
|
{
|
|
|
|
[RequireComponent(typeof(Rigidbody2D))]
|
|
|
|
public class EnemyMovement : MonoBehaviour, IMovement
|
|
|
|
{
|
2022-02-21 19:30:46 +03:00
|
|
|
protected Rigidbody2D _rigidbody2D = null;
|
|
|
|
protected bool _isPaused = false;
|
|
|
|
protected float moveValue = 0f;
|
2022-02-21 15:53:23 +03:00
|
|
|
|
|
|
|
public float BaseSpeed { get; set; } = 1f;
|
|
|
|
public bool IsPaused => _isPaused;
|
|
|
|
|
2022-02-21 19:30:46 +03:00
|
|
|
protected virtual void Awake()
|
2022-02-21 15:53:23 +03:00
|
|
|
=> _rigidbody2D = GetComponent<Rigidbody2D>();
|
|
|
|
|
2022-02-21 19:30:46 +03:00
|
|
|
protected virtual void FixedUpdate()
|
2022-02-21 15:53:23 +03:00
|
|
|
{
|
|
|
|
if (IsPaused)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Vector2 velocity = _rigidbody2D.velocity;
|
|
|
|
velocity.x = moveValue;
|
|
|
|
_rigidbody2D.velocity = velocity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Move(float value)
|
|
|
|
=> moveValue = value * BaseSpeed;
|
|
|
|
|
|
|
|
public void Pause()
|
|
|
|
{
|
|
|
|
_isPaused = true;
|
|
|
|
UpdateRigidbody();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Resume()
|
|
|
|
{
|
|
|
|
_isPaused = false;
|
|
|
|
UpdateRigidbody();
|
|
|
|
}
|
|
|
|
|
2022-02-21 19:30:46 +03:00
|
|
|
protected void UpdateRigidbody()
|
2022-02-21 15:53:23 +03:00
|
|
|
=> _rigidbody2D.simulated = !_isPaused;
|
|
|
|
}
|
|
|
|
}
|