Unity C#脚本中的简单登录记录

3

这应该很简单,但仍然找不到一个直接的答案:

我该如何使用C# Unity脚本记录简单的消息?

我尝试了以下代码:

Debug.Log("Hello Log");

它不能工作,或者我没有看对地方。

2个回答

6

Debug.Log("Hello Log"); 可以在 控制台选项卡 找到。

enter image description here


为了让您能够看到它:

1.您必须将其放入脚本的函数中。

public class Test : MonoBehaviour
{
    void Start()
    {
        Debug.Log("Hello Log");
    }
}

2。脚本必须附加到游戏对象上。

enter image description here

3.脚本和其所附加的游戏对象必须同时启用。

enter image description here

4.如果您无法看到控制台选项卡,请重置布局。

编辑:

我在 Android 设备上测试了它。这就是为什么我没看到它。

在这种情况下,使用 Android Studio 中的 Android Monitor 查看来自您的 Android 设备的日志。

enter image description here


我在安卓设备上测试过了,所以我没看到它。 - David
1
@David 我明白了。请看我的修改。 - Programmer

0
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Simple : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("Attach this script to component and simple message will be there  when you start project");
    }

    // Update is called once per frame
    void Update()
    {

    }
}

Unity文档链接:https://docs.unity3d.com/Manual/CreatingAndUsingScripts.html - unpluggeDloop

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接