Enemy Movement and BasicPatrollingEnemyAI has added
This commit is contained in:
46
Assets/Scripts/Movement/EnemyMovement.cs
Normal file
46
Assets/Scripts/Movement/EnemyMovement.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Movement
|
||||
{
|
||||
[RequireComponent(typeof(Rigidbody2D))]
|
||||
public class EnemyMovement : MonoBehaviour, IMovement
|
||||
{
|
||||
private Rigidbody2D _rigidbody2D = null;
|
||||
private bool _isPaused = false;
|
||||
private float moveValue = 0f;
|
||||
|
||||
public float BaseSpeed { get; set; } = 1f;
|
||||
public bool IsPaused => _isPaused;
|
||||
|
||||
private void Awake()
|
||||
=> _rigidbody2D = GetComponent<Rigidbody2D>();
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
private void UpdateRigidbody()
|
||||
=> _rigidbody2D.simulated = !_isPaused;
|
||||
}
|
||||
}
|
11
Assets/Scripts/Movement/EnemyMovement.cs.meta
Normal file
11
Assets/Scripts/Movement/EnemyMovement.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ae10931055aaa44d8c518e9efa3d034
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user