我正在开发一个关于Unity5.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
}

10-02 20:07