Update function problem?

Hello. Basically, i evaluate distance from one point to others, then i move this point and evaluate this distance anew, but it return the same result (as if it was not moved, but it certainly was). Why could this be? Maybe, I just not understand something crucial about Update()?

=======================================================

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class plControl : MonoBehaviour
{
    RaycastHit hit;
    Vector3 clHex;

    [SerializeField] float plSpeed = 1f;

    [SerializeField] GameObject pFinder;
    public GameObject[] hexes = new GameObject[20];
    public GameObject[] nearHex = new GameObject[7];
    public Vector3[] path = new Vector3[5];

    private Vector3 pfCor; //pathfinder Y-height correction
    int pfStepNo;

    void Awake()
    {
        clHex = pFinder.transform.position;        

        pfCor = pFinder.transform.position + Vector3.down;
        pFinder.GetComponent<Light>().color = Color.blue;
    }
    void Start()
    {
        nearHexSearch();
        pfStepNo = 1;
    }
    
    void Update()
    {
        Ray mRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Input.GetMouseButtonDown(0)) //click detect
        {
            if (Physics.Raycast(mRay, out hit))
            {
                clHex = hit.collider.transform.localPosition;

                StartCoroutine("pfRoutine");

                // pfStepNo++;                
            }
        }        

    }

    void nearHexSearch() // +correction to hex pos (x,0,z)!!!
    {
           
            int j = 1;
            for (int i = 1; i <= hexes.Length -1; i++)
            {
                if (Vector3.Distance(hexes*.transform.position, pfCor) < 1.2f)*

{
if (hexes*.transform.position != pfCor)*
{
nearHex[j] = hexes*;*
j++;
}
}
}

}

void pathFind()
{
int s = 1;
path[pfStepNo] = nearHex[1].transform.position;
float nearest = Vector3.Distance(nearHex[1].transform.position, clHex);

for (int i = 1; i <= nearHex.Length - 1; i++)
{
if (Vector3.Distance(nearHex*.transform.position, clHex) < nearest)*
{
path[pfStepNo] = nearHex*.transform.position;*
nearest = Vector3.Distance(nearHex*.transform.position, clHex);*
s = i; //nearest hex number in nearHex[]
}
}
//print(nearest);

pFinder.transform.position = nearHex~~.transform.position + Vector3.up;~~

}

IEnumerator pfRoutine()
{
pathFind();
System.Array.Clear(nearHex, 0, nearHex.Length);//ok
yield return new WaitForSeconds(0.5f);
nearHexSearch();

}

}

Update() doesn’t seem to be your problem. You have an assortment of different arrays that you are looping through and setting to other arrays. Are you monitoring what is going into those arrays? Have you ensured that the arrays contain what they are supposed to or that they contain anything at all?

We should never assume it’s coded correctly when we can ensure it is. Until everything works as intended I either simply stick Debug.Log everywhere or I attach the VS Debugger and monitor values step by step for larger scripts.

With only your script to go off of, not knowing what’s going into those public arrays, it’s hard to say exactly what your problem is, but as I said it’s best to check everything that’s going on until it works as intended. Hopefully this at least helps lead you in the right direction.

Oh, kill me. I should have to update pfCor in Update(), not initialize it once in Awake() .