I'm trying to make AI for enemies in my game. I applied a pathfinding (A*) script to my enemy sprite, after which the sprite began to follow the player. But when the enemy approaches the player, the enemy gradually disappears. This only happens in the Game section but in the Stage section the enemy does not disappear. And when the enemy is to the left of the player, he disappears altogether. How can this be fixed?
Here is the enemy script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Pathfinding;
public class EnemyGFX : MonoBehaviour
{
public AIPath aiPath;
void Update()
{
if (aiPath.desiredVelocity.x >= 0.01f)
{
transform.localScale = new Vector3(-1f, 1f, 1f);
} else if (aiPath.desiredVelocity.x <= -0.01f)
{
transform.localScale = new Vector3(1f, 1f, 1f);
}
}
}




