Detecting a game object when reaching a specific point does not work.

I’m making a mobile AR educational app that has to show how a electric current “moves”. I would use the log for testing it but I can’t run the tests without building :frowning: This instantiates the electricity effect and the path that it has to follow.

The code:

public class divergeCheck : MonoBehaviour
{
    public GameObject divergeTrigger; //detects when to instantiate the object
    public GameObject deleteTrigger;//detects when to delete the object
    public GameObject electricCurrent;
    public GameObject electricPrefab;
    public GameObject pathCreator;
    private GameObject instance;
    private GameObject pathInstance;
    private Vector2 deletePosition; //to handle the position of the divergeTrigger
    private Vector2 startPosition; //to handle the position of the deleteTrigger
    private Vector2 currentPosition; //to handle the position of the current

   
    void Start()
    {
        //null check..........
        if (divergeTrigger == null || deleteTrigger == null || electricCurrent == null || electricPrefab == null)
        {
            Debug.LogError("One or more required GameObjects are not assigned!");
            return;
        }
        //....................

        startPosition = new Vector2(divergeTrigger.transform.position.x, divergeTrigger.transform.position.z);
        deletePosition = new Vector2(deleteTrigger.transform.position.x, deleteTrigger.transform.position.z);
    }

   
    void Update()
    {
        currentPosition = new Vector2(electricCurrent.transform.position.x, electricCurrent.transform.position.z);
        if (IsPositionInRange(currentPosition, startPosition) && (!(instance == electricPrefab)))
        {
           instance= Instantiate(electricPrefab, Vector3.zero, Quaternion.identity);
           pathInstance = Instantiate(pathCreator, Vector3.zero, Quaternion.identity);
        }
        if (IsPositionInRange(currentPosition, deletePosition))
        {
            Destroy(instance);
            Destroy(pathInstance);
            instance = null;
            pathInstance = null;
        }
    }

    private bool IsPositionInRange(Vector2 position, Vector2 targetPosition)
    {
        return Mathf.Approximately(position.x, targetPosition.x) && Mathf.Approximately(position.y, targetPosition.y);
    }

}

Sorry for leaving the entire code, but I have no idea where the error comes from and I’m too lazy to test it in another enviroment.

Why can’t you test without building?

As far as being “lazy.” You’re in the best position to test your own code, so get to testing! Nobody else can test for you. First thing I’d suggest is testing that your if statements are running. Then, checking if things are moving like they are suppose to.

Because Unity Remote doesn’t work on my device. Still, I could test it by copying the script to another project for desktop but since I have time constrains because is a school assignment I thought it would be more efficient to make a quick post here and for someone to do the work for me.
I know this would be a good opportunity to learn, but I fear not having enough time.

I am going to engrave this post in stone and build a reflecting pool in front of it for future generations to admire and contemplate. It is truly amazing.

I’m impressed he took the time to create this post. I imagine he had go lie down after.