unity3d OnMouseDown 函数 [英] unity3d OnMouseDown function
本文介绍了unity3d OnMouseDown 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 Unity3D 的新手.我正在尝试做一件简单的事情.但无法做到这一点.我有一个 .obj 文件,它是一个 3d 密钥文件.我执行以下操作:
I am new to Unity3D. I am trying to do a simple thing. But not able to do this. I have a .obj file which is a 3d key file. I do the followings:
- 在 unity3D 中导入此密钥(到资产)
- 将此键添加到场景(从资产到层次结构)
- 向该键添加脚本
将
OnMouseDown()
函数添加到此脚本中,如下所示 -
- Import this key (to assets) in unity3D
- Add this key to scene (from assets to hierarchy)
- Add a script to this key
Add the
OnMouseDown()
function to this script as follows -
void OnMouseDown()
{
Debug.Log ("clicked...");
}
但是当我单击该键时,控制台中没有显示任何消息.请告诉我是什么问题?
But when I click the key no message is showing in console. Please tell me what is the problem?
推荐答案
- 确保游戏对象不在忽略光线投射"层
在更新函数中使用以下内容来查看光线投射是否正常工作.
- make sure the gameobject is not at layer "Ignore Raycast"
Use the following inside your update function to see raycasting is working fine.
无效更新(){
if (Input.GetMouseButtonDown (0)) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit)) {
Debug.Log ("Name = " + hit.collider.name);
Debug.Log ("Tag = " + hit.collider.tag);
Debug.Log ("Hit Point = " + hit.point);
Debug.Log ("Object position = " + hit.collider.gameObject.transform.position);
Debug.Log ("--------------");
}
}
}
这篇关于unity3d OnMouseDown 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文