Unity3d:如何检测区域内的单击 [英] Unity3d: how to detect click within an area

查看:89
本文介绍了Unity3d:如何检测区域内的单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Unity3d应用程序中,正在尝试检测当前相机的某个方形区域中的点击.有什么办法吗?

In a Unity3d application am trying to detect a click in a certain squared area of the current camera. Is there any way to do that?

谢谢

推荐答案

这不是您想要的吗?

http://unity3d.com/support/documentation/ScriptReference/Input- mousePosition.html

**编辑**

using UnityEngine;

public class example : MonoBehaviour
{
    void Update()
    {
        // Left-half of the screen.
        Rect bounds = new Rect(0, 0, Screen.width/2, Screen.height);
        if (Input.GetMouseButtonDown(0) && bounds.Contains(Input.mousePosition))
        {
            Debug.Log("Left!");            
        }
    }
}

这篇关于Unity3d:如何检测区域内的单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆