【发布时间】:2019-09-06 14:57:24
【问题描述】:
我正在使用 Vuforia 在 Unity 中测试 AR,但我无法让事件 OnMouseDown() 正常工作。
碰巧我第一次点击播放时它有效,但只有一次。 我已经检查过对撞机是否已激活并且位置正确。 我还看到游戏对象(在本例中为立方体)中的脚本检查未启用,在制作组件时它甚至不像其他脚本那样出现。
这是代码:
using System.Collections.Generic;
using UnityEngine;
public class Click : MonoBehaviour
{
void OnMouseDown()
{
Debug.Log("CLICK!!!");
}
}
我在控制台中没有任何错误消息或警告。
这是存储库,分支develop:
https://github.com/emicalvacho/MapaMentalAR.git
【问题讨论】:
-
我很确定你不能只拥有一个对撞机并使用
OnMouseDown。很确定这是为 UI 可选/可交互元素制作的。您需要使用 raycast 来查看用户是否单击了 3D 对象。签出:docs.unity3d.com/ScriptReference/Camera.ScreenPointToRay.html -
@user14492 他们的文档不同意您的观点:docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseDown.html“当用户在 GUIElement 或 Collider 上按下鼠标按钮时调用 OnMouseDown。”
-
但是 OnMouseDown 只有在脚本被启用的情况下才会起作用,如果它被禁用那可能是你的问题。
-
也许你可以在你点击它之前和之后在检查器上上传你的游戏对象的截图。
-
Also I see that the check of the script in the GameObject (Cube in this case) is not enabled, it doesn't even appear like the rest of the scripts when components are made.听起来对象已被禁用 .. 如果是这种情况,显然脚本将不会运行,因为 Collider 也将被禁用
标签: c# unity3d augmented-reality vuforia onmousedown