OnMouseDown()事件Unity的问题

ahs*_*oka 4 c# unity-game-engine

我是Unity的新手,我正在做一些教程,但是一个让我抓狂.我有一个带有盒子对撞机的旋转立方体.除OnMouseDown()外,所有事件都有效.我不知道是什么问题......这是一段代码.

void onMouseDown() {        
    Debug.Log ("On Mouse Down Event!!!!!!!!!");
}

void OnMouseUp() {
    Debug.Log("On Mouse Up Event");
}

void OnMouseOver() {
    Debug.Log("On Mouse Over Event");
}

void OnMouseEnter() {
    Debug.Log("On Mouse Enter Event");
}

void OnMouseDrag() {
    Debug.Log("On Mouse Drag Event");
}
Run Code Online (Sandbox Code Playgroud)

在控制台中,显示消息"On Mouse Down Event !!!!!!!!!" 对我在立方体上的大量点击并不重要.

Ste*_*lls 16

void OnMouseDown() 
{        
    Debug.Log("On Mouse Down Event!!!!!!!!!");
}
Run Code Online (Sandbox Code Playgroud)

你的OnMouseDown方法需要用大写O,而不是小写.试试吧,它应该工作.

  • @StevenMills实际上,没有必要 - 在适用的情况下,这种方法也会在触摸设备上自动使用.我最近为手机构建了一个桌面游戏,只是为了测试它,并且所有界面和交互都有效,但显然不支持像OnMouseOver这样的事件. (2认同)