Ejemplo n.º 1
0
    private void MouseButtonDown()
    {
        Ray ray   = cam.ScreenPointToRay(Input.mousePosition);
        int count = Input.touchCount;

        if (count == 1)
        {
            Touch touch = Input.GetTouch(0);
            ray = cam.ScreenPointToRay(new Vector3(touch.position.x, touch.position.y));
        }

        GameObject invObj = null;

        if (_inventory.Showing())
        {
            invObj = _inventory.OverObject(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0));

            _inventory.SetSelected(invObj);
        }

        RaycastHit hit;

        if (Physics.Raycast(ray, out hit) && invObj == null)
        {
            if (hit.collider.gameObject == gameObject)
            {
                _inventory.Toggle();
            }
            else if (hit.collider.gameObject.GetComponent <interactuable>())
            {
                //TODO:Desactivar script camera
//				targetLocation = thisTransform.position;
                cam.GetComponent <customLookAt>().enabled = false;
                _interactuable = hit.collider.gameObject.GetComponent <interactuable>();
                Vector3 screenPos = cam.WorldToScreenPoint(hit.collider.gameObject.transform.position);
                _interactuable.ShowMenu(screenPos);
                _raster.particleSystem.Stop();
                cRaster = (GameObject)GameObject.Instantiate(_raster, hit.collider.gameObject.transform.position, new Quaternion(0, 0, 0, 0));
                cRaster.SetActive(true);
                _inventory.Hide();
            }
            else
            {
                if (invObj == null)
                {
                    _inventory.Hide();
                }
                float touchDist = (transform.position - hit.point).magnitude;
                if (touchDist > minimumDistanceToMove)
                {
                    targetLocation = hit.point;
                }
                Quaternion quat = Quaternion.AngleAxis(270, new Vector3(1, 0, 0));
                GameObject.Instantiate(onClickCursor, targetLocation, quat);
            }
        }
    }