似乎无法在 Unity c3 中使用 Func?

Can't seem to use Func in Unity c3?

如果我试试这个

private System.Action blah;

它工作正常。由于某种原因

private System.Func blah;

Assets/scripts/objects/flite groups/MassiveExplisions.cs(130,24): error CS0234: The type or namespace name Func' does not exist in the namespaceSystem'. Are you missing an assembly reference?

我不明白,为什么我不能使用Func?这是普通的最新 Unity。

Action 类型,因为它是封装没有 return 值的方法的方式。

没有名为 Func 的类型,因为它总是 return 一些值,您需要指定其值的类型。例如 Func<int>.

实际上,Func 需要至少一种泛型作为 return 委托类型。

private System.Func<bool> simple;
private System.Func<bool, int, double> withParams;

用法:

bool result = simple();
bool result = withParams(10, 0.2);

如果不需要 return 类型,请使用 Action