Mathf.Min in array

Hi, I’m making an informed pathfinding using A* and Theta* project in unity. there will be checkpoints for every intersection in maze map. I’m planning using Mathf.Min in an array with 50 elements or more but I don’t know how to get which array has the minimum value. please help

Hi @yahyanh21 If you want to get the minimum value in the array you can just do this (imagine the array is called “arrayFloats”):

Mathf.Min(arrayFloats);

But if you want to know in which position (index) of the array is the minimum value you have to do something like this:

        public int GetMinIndex(float[] arrayFloats)
        {
            float minimumValue = float.MaxValue;
            int minimumValueIndex = -1;
            for (int i = 0; i < arrayFloats.Length; i++)
            {
                if (arrayFloats *< minimumValue)*

{
minimumValueIndex = i;
minimumValue = arrayFloats*;*
}
}
if (minimumValueIndex == -1)
{
Debug.Log(“Array is empty or something weird happened”);
}
return minimumValueIndex;
}