1.将下面该段代码赋给摄像机
void Update ()
{
RaycastHit hit = new RaycastHit();
for (int i = 0; i < Input.touchCount; ++i)
{
if (Input.GetTouch(i).phase.Equals(TouchPhase.Began))
{
// Construct a ray from the current touch coordinates
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
if (Physics.Raycast(ray, out hit))
{
hit.transform.gameObject.SendMessage("OnMouseDown");
}
}
}
}
2.为要被点击的3D物体创建一个C#脚本,并 添加OnMouseDown函数,以使上段代码进行触发执行;
void OnMouseDown()
{
DoSomething();
}
This script can be attached to any GameObjects that you want to use as buttons.