c# - 使用 Debugger.Log 调用记录附加信息

标签 c# debugging unity3d

我正在尝试在 Unity 中使用 Debug.Log 调用来记录有关上下文的更多信息,以将 EXP 系统的代码调试到我的 unity 游戏中。

我试图传递所有类似于 String.Format 的参数,但正如预期的那样出现了如下错误:

"No overload method 'Log' takes '3' arguments

如何记录消息的其他详细信息?

代码:

void Main()
{
    XP xp = new XP(1300);
    Debug.Log("Our character starts at {0} xp and is level {1}.", 
       xp.GetCurrentXp(), xp.GetCurrentLevel());
    Debug.Log("Now, we add 2000 xp.");
    xp.AddXp(2000);
    Debug.Log("Now, our character has {0} xp and is level {1}.", 
       xp.GetCurrentXp(), xp.GetCurrentLevel());
    Debug.Log("Our character is {0}% in to his next level", 
       xp.GetPercentInToLevel() * 100f);
}

errors

最佳答案

确实Debug.Log仅具有 1 个和 2 个参数的覆盖(脚本 API):

public static function Log(message: object): void;
public static function Log(message: object, context: Object): void; 

您可能想使用 String.Format 构造消息:

Debug.Log(string.Format("Our character starts at {0} xp and is level {1}.", 
      xp.GetCurrentXp(), xp.GetCurrentLevel()));

关于c# - 使用 Debugger.Log 调用记录附加信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27370488/

相关文章:

c# - visual studio 中的仅调试类和资源 - 这可能吗?

c# - 我有一个包含超过一百万个对象的列表,试图找到最快的搜索方式

c# - 从 C# 显示关闭对话框

c# - 如何使用 C Sharp 中的 WebBrowser 元素禁用点击声音?

silverlight - 在 Silverlight 中启动调试 session 需要很长时间

sql - 在SQL 2008 Management Studio中调试时在存储的proc中查询临时表

java - 通过 Android 应用程序下载 Unity .obb 内容

c# - 使用 Vector3.Distance 的性能问题

c# - 如何可靠地检测项目何时滚动到 View 之外?

c# - 如何通过 Unity 将 Android 设备预热到 40 度?