我正在 Unity 5.3 上开发 C# 脚本。我有一个 Vector2 值列表,我需要提取列表中最大的 X 值。我正在尝试执行以下操作:
public List<Vector2> Series1Data;
... //I populate the List with some coordinates
MaXValue = Mathf.Max(Series1Data[0]);
但是,我收到以下错误:
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[]'
有没有其他方法可以提取列表中最大的X值?
最佳答案
您正试图将一个列表放在一个不能将该类型的变量作为参数的函数上。
Mathf.Max在这里您可以看到它可以处理哪种类型的参数。
这段代码可能会完成工作:
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
}
关于c# - Unity 5.3 - C# -- List<Vector2> 如何提取最大的 X 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38709411/