只有赋值调用增量减量等待,新对象表达式可以用作语句
{
HudElem INFO3 = HudElem.CreateFontString(player, "hudbig", 0.5f);
INFO3.X = 740f;
INFO3.Y = 170f;
INFO3.AlignX = "right";
INFO3.HideWhenInMenu = true;
INFO3.Foreground = false;
INFO3.Alpha = 0f;
INFO3.SetText("^7type following" + Environment.NewLine + Environment.NewLine + "^2infoa ^7fast refill " + Environment.NewLine + "^2infow ^7weapon info" + Environment.NewLine + "^2tk ^7 throwingknife" + Environment.NewLine + "^2bb ^7 bouncingbetty" + Environment.NewLine + "^2cl ^7 claymore" + Environment.NewLine + "^2sc ^7 suicide" + Environment.NewLine + "^2riot ^7 riotshield" + Environment.NewLine + "^2stinger ^7stinger" + Environment.NewLine + "^2bindkey ^7refill" + Environment.NewLine + Environment.NewLine + "^2open close ^7menu" + Environment.NewLine + "^23rdoff ^7disable3rd" + Environment.NewLine + "^2loc ^7relocation");
player.OnNotify("open_", (Action<Entity>) (entity => (INFO3.Alpha = 0.6f)));
player.OnNotify("close_", (Action<Entity>) (entity => (INFO3.Alpha = 0f)));
player.OnNotify("CLOSE_", entity => INFO3.Call("destroy", new Parameter[0]));
}
答案 0 :(得分:2)
我认为错误是从这两行发生的。看起来你可能正在寻找更像这个代码的东西。
player.OnNotify("open_", (Action<Entity>)(entity => {INFO3.Alpha = 0.6f;}));
player.OnNotify("close_", (Action<Entity>)(entity => {INFO3.Alpha = 0f;}));
答案 1 :(得分:1)
当你这样写:
(Action<Entity>) (entity => (INFO3.Alpha = 0.6f))
因为Action<Entity>
是void
- 返回,这意味着您的代码基本上是短的:
(Action<Entity>) (entity => { (INFO3.Alpha = 0.6f); })
也就是说,您的表达式被视为一个自动添加分号的语句。虽然您不能将括号中的表达式用作C#中的语句,但您可以使用该方式进行赋值。这意味着以下内容将起作用:
(Action<Entity>) (entity => INFO3.Alpha = 0.6f)
为了完整性,如果你的lambda不是void
- 返回,那么这些括号将被允许。例如,以下工作:
(Func<Entity, float>) (entity => (INFO3.Alpha = 0.6f))