[FIX]
I fixed it by changing line 2 from “private” to “public” then dragged in the player into the inspector.
EDIT: I fixed it. I found out what the problem was. I put the fix on top of the post in bold.
Not sure why that fixed it but it did.
Each enemy is not only set up the exact same, but the same script is on each one. Yet, one enemy refuses to follow you when you are in range of it, the other three follows you.
So the script is: enemy follows you when you are in range.
public float speed; // how fast enemy runs at player
private Transform target; //variable that holds the game object the enemy is chasing, in this case, Player 1
private void Start()
{
target = GameObject.Find("Player1").GetComponent<Transform>();
}
private void Update()
{
if (Vector2.Distance(transform.position, target.position) < 5)
transform.position = Vector2.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
}