Debug.Log()/Print()/UnityEngine.Debug.Log() 不起作用

发布于 2025-01-15 22:53:19 字数 1271 浏览 2 评论 0原文

我的项目正在使用 Oculus Quest 2 和虚拟现实。我正在编写一个脚本,该脚本应该检测手何时与游戏对象碰撞。该脚本无法正常工作,因此我尝试添加一些 Debug.Log() 语句来隔离问题,但它们不会打印到控制台。对这些问题的任何建议表示赞赏

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

public class colliderHit : MonoBehaviour
{
    public GameObject myHand;
    public GameObject menuItem;
    public GameObject sublevel;
    public GameObject topMenu;
    Collider menuItemCollider;
    Collider myHandCollider;

    // Start is called before the first frame update
    void Start()
    {
        if(menuItem != null)
        {
            menuItemCollider = menuItem.GetComponent<Collider>();
            UnityEngine.Debug.Log("Menu Item not null");
        }
        else
        {
            print("Menu Item null");
        }

        if (myHand != null)
        {
            myHandCollider = myHand.GetComponent<Collider>();
        }
        else
        {
            Debug.Log("Hand Item null");
        }
    }

    // Update is called once per frame
    void Update()
    {
        if (myHandCollider.bounds.Intersects(menuItemCollider.bounds))
        {
            topMenu.SetActive(false);
            sublevel.SetActive(true);
            Debug.Log("Bounds intersecting");
        }
    }
}

My project is working with Oculus Quest 2 and Virtual Reality. I am writing a script that should detect when the hand collides with a game object. The script isn't working so I tried adding some Debug.Log() statements to isolate the problem but they don't print to the console. Any advice on these problems is appreciated

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

public class colliderHit : MonoBehaviour
{
    public GameObject myHand;
    public GameObject menuItem;
    public GameObject sublevel;
    public GameObject topMenu;
    Collider menuItemCollider;
    Collider myHandCollider;

    // Start is called before the first frame update
    void Start()
    {
        if(menuItem != null)
        {
            menuItemCollider = menuItem.GetComponent<Collider>();
            UnityEngine.Debug.Log("Menu Item not null");
        }
        else
        {
            print("Menu Item null");
        }

        if (myHand != null)
        {
            myHandCollider = myHand.GetComponent<Collider>();
        }
        else
        {
            Debug.Log("Hand Item null");
        }
    }

    // Update is called once per frame
    void Update()
    {
        if (myHandCollider.bounds.Intersects(menuItemCollider.bounds))
        {
            topMenu.SetActive(false);
            sublevel.SetActive(true);
            Debug.Log("Bounds intersecting");
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光病人 2025-01-22 22:53:19

您绝对确定没有禁用控制台日志中的消息吗?我问这个只是因为我也倾向于忘记这一点

example console

Are you absolutely sure you didn't disable messages in the console log? I only ask this because I tend to forget about that as well

example console

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文