- Home /
This post is currently awaiting moderation. If you believe this to be in error, contact a system administrator.
how to find the lowest value in float array ??
i just want to find the lowest value in float array, this is a distance value, so i need the closer one
[SerializeField]
private float[] m_Distance; // i have 8 array
private void Update()
{
for (int i = 0; i < m_Distance.Length; i++)
{
if (???)
}
}
Comment
Best Answer
Answer by WarmedxMints · Sep 18, 2019 at 05:11 PM
Adding to what you have, just assign the lowest value to a float.
var min = Mathf.Infinity;
for (int i = 0; i < m_Distance.Length; i++)
{
if (m_Distance[i] < min)
min = m_Distance[i];
}
//min now equals the lowest value
Your answer
Follow this Question
Related Questions
assign string value from array to multiple game objects 1 Answer
How can I detecting whether certain characters appear in any strings in my array of strings? 1 Answer
Find GameObjects with a certain Script [Solved] 1 Answer
How to get a value from an array within another script. 1 Answer
Store reference to array as variable 2 Answers