Enemy Movement and BasicPatrollingEnemyAI has added

This commit is contained in:
2022-02-21 15:53:23 +03:00
parent 87f0652ce1
commit 4cfbf23960
6 changed files with 301 additions and 0 deletions

View 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;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4ae10931055aaa44d8c518e9efa3d034
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: