Platformer example started
This commit is contained in:
1 parent
efcfaae647
commit
9f026b76d6
325 files changed
+23540
-270
No files matched your search
@@ -0,0 +1,32 @@
|
||||
using Code.Infrastructure.Configs;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Example.Platformer.Entity.Enemies
|
||||
{
|
||||
public class Snail : Entity
|
||||
{
|
||||
[SerializeField] private Vector2 groundLeft;
|
||||
[SerializeField] private Vector2 groundRight;
|
||||
[SerializeField] private bool _directionRight;
|
||||
|
||||
protected override void Move()
|
||||
{
|
||||
CheckupDirection();
|
||||
rigidbody2D.linearVelocityX = _directionRight ? 0.5f : -0.5f;
|
||||
}
|
||||
protected override void HandleFlipX() => spriteRenderer.flipX = rigidbody2D.linearVelocity.x > -0.01f;
|
||||
|
||||
private void CheckupDirection()
|
||||
{
|
||||
if (_directionRight)
|
||||
{
|
||||
if (!Physics2D.OverlapPoint((Vector2)transform.position + groundRight,
|
||||
LayerMasks.Masks[LayerMaskType.PlatformerGround]))
|
||||
_directionRight = false;
|
||||
}
|
||||
else if (!Physics2D.OverlapPoint((Vector2)transform.position + groundLeft,
|
||||
LayerMasks.Masks[LayerMaskType.PlatformerGround]))
|
||||
_directionRight = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user