34 lines
896 B
C#
34 lines
896 B
C#
using System;
|
|
using UnityEngine;
|
|
|
|
public class Enemy : AutoControlledEntity
|
|
{
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
Vector2 direction = new Vector2(0, stats.rb.linearVelocityY);
|
|
if (!stats.isStalled)
|
|
{
|
|
if (closestEntity && Vector3.Distance(closestEntity.transform.position, transform.position) < maxTargettingRange)
|
|
{
|
|
direction.x = (closestEntity.transform.position - transform.position).normalized.x * stats.speed;
|
|
if ((closestEntity.transform.position.y - transform.position.y > maxHeightDifference || (DetectWalls() && Vector3.Distance(closestEntity.transform.position, transform.position) > minTargetJumpDistance)) && stats.OnGround())
|
|
{
|
|
direction.y = stats.jumpPower;
|
|
}
|
|
}
|
|
FlipSprite(direction);
|
|
}
|
|
else
|
|
{
|
|
direction.x = 0;
|
|
}
|
|
stats.rb.linearVelocity = direction;
|
|
}
|
|
|
|
public override void OnDeath()
|
|
{
|
|
base.OnDeath();
|
|
Destroy(gameObject);
|
|
}
|
|
}
|