How to get updated variable from another script?

I can’t seem to get the updated variable “isInPosition” from another script to work on a different script.

ScriptA

using UnityEngine;

public class EnemyMovement : MonoBehaviour
{
    public InputManager input;

    float speed = 2f;

    Vector2 target;
    Vector2 position;

    // Start is called before the first frame update
    void Start()
    {
        target = new Vector2(1.66f, -1.762784f);
    }

    // Update is called once per frame
    void Update()
    {
        position = gameObject.transform.position;
        float step = speed * Time.deltaTime;

        transform.position = Vector2.MoveTowards(transform.position, target, step);
    }

    public bool isInPosition()
    {
        if (position == target)
        {
            return true;
        }
        return false;
    }
}

Script B

using UnityEngine;

public class InputManager : MonoBehaviour
{
    public EnemySpawnScript enemySpawn;
    public EnemyMovement enemyMove;

    void Update()
    {
        
        for (int i = 0; i < Input.touchCount; i++)
        {
            if (Input.GetTouch(i).phase == TouchPhase.Began)
            {
                Debug.Log("Working");
            } 
        }

        if (Input.GetKeyDown(KeyCode.Space) && enemyMove.isInPosition())
        {
            enemySpawn.EnemyKilled();
        }
        else if (Input.GetKeyDown(KeyCode.Space) && !enemyMove.isInPosition())
        {
            Debug.Log("You lose");
        }
    }
}

If I use a debug.log in the first script, it works as it should. But if I use a debug.log on the second script calling the same variable inside the update method, it’s always true even though on the first script, it is false first and then true.

I would like to understand why this Isn’t working and if there is a way I can make this work without using methods. Thank you.

since isInPosition is a method and not a variable you should include the brackets after the call. enemyMove.isInPosition should be enemyMove.isInPosition()

Try adding some tolerance to isInPosition
MoveTowards will take you closer to the point but not exactly to it

Something like

private const float Tolerance = 0.0001f;

public bool isInPosition()
{
if (Vector3.Distance(position, target) <= Tolerance)
{
return true;
}
return false;
}