Ejemplo n.º 1
0
    private void Hit()
    {
        RaycastHit hit;

        if (!MainController.Instance.PanelPause.active)
        {
            if (Input.GetMouseButton(0))
            {
                int layer = 1 << 8;
                layer        = ~layer;
                _goDistance -= Input.GetAxis("Mouse ScrollWheel");
                _goDistance  = Mathf.Clamp(_goDistance, -1, 1);
                Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, 25f, layer);
                try
                {
                    if (_goField == null && hit.transform.gameObject.GetComponent <PickUpObject>() != null)
                    {
                        _goField = hit.transform.gameObject;
                        _goField.transform.SetParent(this.gameObject.transform);
                        _goField.GetComponent <Rigidbody>().isKinematic = true;
                        _goField.GetComponent <Renderer>().material.SetFloat("_OutlineExtrusion", 0.01f);
                        _goPick = _goField.GetComponent <PickUpObject>().PickUp;
                        CanvasController.Instance.RightClick.gameObject.SetActive(true);
                    }
                }
                catch (System.NullReferenceException) { Debug.Log("null"); }
                if (_goField != null)
                {
                    float posZ = _goField.transform.localPosition.z - _goDistance * Time.deltaTime;
                    float posY = _goField.transform.localPosition.y + _goDistance * Time.deltaTime;
                    float posX = _goField.transform.localPosition.x;
                    posZ = Mathf.Clamp(posZ, 1f, 1.3f);
                    posY = Mathf.Clamp(posY, 0f, 0.9f);
                    _goField.transform.localPosition = new Vector3(posX, posY, posZ);
                }
                if (Input.GetMouseButtonDown(1))
                {
                    if (_goField != null)
                    {
                        _goPick.Use();
                    }
                    CanvasController.Instance.RightClick.gameObject.SetActive(false);
                }
            }
            if (Input.GetMouseButtonUp(0) && _goField != null)
            {
                _goField.GetComponent <Rigidbody>().isKinematic = false;
                _goDistance = 0;
                _goField.transform.SetParent(null);
                _goField.GetComponent <Renderer>().material.SetFloat("_OutlineExtrusion", 0.0f);
                _goField = null;
                _goPick  = null;
                CanvasController.Instance.RightClick.gameObject.SetActive(false);
            }
        }
    }
Ejemplo n.º 2
0
    public void UseItem(int id, LockObject lockObject)
    {
        foreach (GameObject item in items)
        {
            PickUpObject puo = item.GetComponent <PickUpObject>();

            if (puo.Id == id)
            {
                puo.Use(lockObject);
                items.Remove(item);
                UpdatePositions();
                return;
            }
        }
    }