Merged Wall and Ground Enemies into One
This commit is contained in:
@@ -6,6 +6,7 @@ namespace Movement
|
||||
public class EnemyMovement : MonoBehaviour, IMovement
|
||||
{
|
||||
protected Rigidbody2D _rigidbody2D = null;
|
||||
protected Vector2 gravityForce = Vector2.down;
|
||||
protected bool _isPaused = false;
|
||||
protected float moveValue = 0f;
|
||||
|
||||
@@ -13,16 +14,23 @@ namespace Movement
|
||||
public bool IsPaused => _isPaused;
|
||||
|
||||
protected virtual void Awake()
|
||||
=> _rigidbody2D = GetComponent<Rigidbody2D>();
|
||||
{
|
||||
_rigidbody2D = GetComponent<Rigidbody2D>();
|
||||
|
||||
_rigidbody2D.gravityScale = 0f;
|
||||
gravityForce *= -Physics2D.gravity.y * _rigidbody2D.mass;
|
||||
}
|
||||
|
||||
protected virtual void FixedUpdate()
|
||||
{
|
||||
_rigidbody2D.AddRelativeForce(gravityForce);
|
||||
|
||||
if (IsPaused)
|
||||
return;
|
||||
|
||||
Vector2 velocity = _rigidbody2D.velocity;
|
||||
Vector2 velocity = transform.InverseTransformDirection(_rigidbody2D.velocity);
|
||||
velocity.x = moveValue;
|
||||
_rigidbody2D.velocity = velocity;
|
||||
_rigidbody2D.velocity = transform.TransformDirection(velocity);
|
||||
}
|
||||
|
||||
public void Move(float value)
|
||||
|
@@ -1,29 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: adfb41bcf8c09e94ea1e95e22a4c7533
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user