I'm developing a C# script on Unity 5.3. I have a list of Vector2 values and I need to extract the biggest X value in the list. I'm trying to do the following:
public List<Vector2> Series1Data;
... //I populate the List with some coordinates
MaXValue = Mathf.Max(Series1Data[0]);
However, I get the following errors:
error CS1502: The best overloaded method match for `UnityEngine.Mathf.Max(params float[])' has some invalid arguments
error CS1503: Argument `#1' cannot convert `UnityEngine.Vector2' expression to type `float[]'
Is there any other way of extracting the biggest X value in the list?
You can do this via Linq:
MaxXValue = Series1Data.Max(v => v.x);
This assumes you Series1Data List object is not null or empty.
You are trying to put a List on a function that can't have that type of variable as parameter.
Mathf.Max here you can see which type of parameters it can handle.
This code might do the work:
public List<Vector2> Series1Data;
... //I populate the List with some coordinates
MaXValue = Series1Data[0].x; //Get first value
for(int i = 1; i < Series1Data.Count; i++) { //Go throught all entries
MaXValue = Mathf.Max(Series1Data[i].x, MaXValue); //Always get the maximum value
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With