BGJ-2022.1/Assets/Scripts/Movement/EnemyVerticalMovement.cs

30 lines
680 B
C#

using UnityEngine;
namespace Movement
{
public class EnemyVerticalMovement : EnemyMovement
{
protected Vector2 gravityForce = Vector2.right;
protected override void Awake()
{
base.Awake();
_rigidbody2D.gravityScale = 0f;
gravityForce *= -Physics2D.gravity.y * _rigidbody2D.mass;
}
protected override void FixedUpdate()
{
_rigidbody2D.AddRelativeForce(gravityForce);
if (IsPaused)
return;
Vector2 velocity = _rigidbody2D.velocity;
velocity.y = moveValue;
_rigidbody2D.velocity = velocity;
}
}
}