I'm trying to determine if the distance between my player and enemy is greater than the minimum distance. Then I'm moving the enemy toward the player. However the code i'm using in the if statement to check the distance keeps throwing an error. It says object reference not set to an instance of an object.
If anyone could help that would be awesome!
Here's the code:
if (Vector2.Distance(transform.position,player.transform.position) >= minDistance)
{
//moves enemy towards enemy//
transform.position = Vector2.MoveTowards(transform.position, player.transform.position, speed * Time.deltaTime);
}
↧