Unity - A计划(永久有效期) 扫二维码继续学习 二维码时效为半小时

(197评价)
价格: 4431.00元
关于IsPointerOverGameObject的问题。。
sdhexu发起了话题2017-06-28
4
回复
3010
浏览

大神,当我拖动UI时,我不想让我的主摄像机旋转...但我明明使用IsPointerOverGameObject判断了,可是它总是返回false.

    private void LateUpdate()
    {
        if (m_TargetPlayer == null)
            return;

        transform.position = m_offset + TargetPlayer.position;
        
        // 这里总是返回false
        if ( EventSystem.current.IsPointerOverGameObject())
            return;

        if(Input.GetMouseButton(1))
        {

            float h = Input.GetAxis("Mouse X");
            float v = - Input.GetAxis("Mouse Y");

            transform.RotateAround(TargetPlayer.position, TargetPlayer.up, h * m_RotaSpeed);

            Vector3 pos = transform.position;
            Quaternion rot = transform.rotation;

            transform.RotateAround(TargetPlayer.position, transform.right, v * m_RotaSpeed);
            float a = transform.eulerAngles.x;
            if( a < m_minAngle || a > m_maxAngle )
            {
                transform.position = pos;
                transform.rotation = rot;
            }

            m_offset = transform.position - TargetPlayer.position;
        }

        float z = - Input.GetAxis("Mouse ScrollWheel");
        if( z < -0.001f || z >= 0.001f )
        {
            float dis = m_offset.magnitude;
            dis = Mathf.Clamp( dis + z * m_ZoomSpeed, m_minZoom, m_maxZoom );
            m_offset = dis * m_offset.normalized;
        }
    }

所有回复
发表回复
你还没有登录,请先 登录或 注册!