44 lines
798 B
C#
44 lines
798 B
C#
using System;
|
|
using UnityEngine;
|
|
|
|
public class Entity : MonoBehaviour
|
|
{
|
|
[Header("Sprite")]
|
|
public SpriteRenderer sprite;
|
|
[Header("Movement")]
|
|
public float speed;
|
|
[SerializeField] protected Rigidbody2D rb;
|
|
public Vector3 moveDirection;
|
|
public bool stalled;
|
|
public bool isFacingRight;
|
|
protected void FlipSprite(Vector2 lookDirection)
|
|
{
|
|
if (lookDirection.x > 0f && isFacingRight)
|
|
{
|
|
sprite.flipX = true;
|
|
isFacingRight = !isFacingRight;
|
|
}
|
|
else if (lookDirection.x < 0f && !isFacingRight)
|
|
{
|
|
sprite.flipX = false;
|
|
isFacingRight = !isFacingRight;
|
|
}
|
|
}
|
|
protected virtual void Movement()
|
|
{
|
|
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
if (!stalled)
|
|
{
|
|
Movement();
|
|
rb.linearVelocity = moveDirection * speed;
|
|
}
|
|
else
|
|
{
|
|
rb.linearVelocity = Vector2.zero;
|
|
}
|
|
}
|
|
}
|