XRR*_*XRR 5 c# unity-game-engine
我正在 Unity 5.3 上开发 C# 脚本。我有一个 Vector2 值列表,我需要提取列表中最大的 X 值。我正在尝试执行以下操作:
public List<Vector2> Series1Data;
... //I populate the List with some coordinates
MaXValue = Mathf.Max(Series1Data[0]);
Run Code Online (Sandbox Code Playgroud)
但是,我收到以下错误:
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[]'
Run Code Online (Sandbox Code Playgroud)
还有其他方法可以提取列表中最大的 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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3640 次 |
| 最近记录: |