Пример #1
0
    private void MouseButtonUp()
    {
        //Fem release tenint un objecte del inventari seleccionat
        if (_inventory.Showing())
        {
            GameObject invObj   = _inventory.GetSelected();
            Vector3    mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0);
            GameObject otherObj = _inventory.OverObject(mousePos);
            if (invObj != otherObj)
            {
                if (otherObj != null)              //Estem intentant combinar objectes que son dins l'inventari
                {
                }
                else                  //Estem intentant combinar amb un objecte de l'escena

                {
                    Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit))
                    {
                        if (hit.collider.gameObject.GetComponent <interactuable>())
                        {
                            //Cridar a la funcio d combinar objectes
                            //Debug.Log ("Desti de combinacio: " + hit.collider.gameObject);

                            interactuable interDesti = hit.collider.gameObject.GetComponent <interactuable>();
                            bool          isGood     = interDesti.comprobarInteraccio(invObj);

                            if (isGood)
                            {
                                //Debug.Log("Combinacio Correcta!");
                                Application.LoadLevel("end");
                            }
                        }
                    }
                }
            }
            if (invObj)
            {
                invObj.transform.position    = new Vector3(1, 1, 0);
                invObj.guiTexture.pixelInset = new Rect(0, 18 - 100, 64, 64);
                invObj.guiTexture.color      = new Color(0.5f, 0.5f, 0.5f, 0.5f);
                _inventory.Hide();
                _inventory.SetSelected(null);
            }
        }
        //Fem release tenint un menu contextual desplegat
        if (_interactuable != null)
        {
            Vector3 cPos = Input.mousePosition - _interactuable.GetScreenPosition();
            for (int i = 0; i < _interactuable.Actions.Length; i++)
            {
                //Comprovar distancia del puntero al las opciones
                Vector3 aPos = new Vector3(_interactuable.Actions[i].guiTexture.pixelInset.x + 32,
                                           _interactuable.Actions[i].guiTexture.pixelInset.y + 32, 0);
                float aDist = Vector3.Distance(aPos, cPos);
                if (aDist < 32)
                {
                    _interactuable.Actions[i].GetComponent <Action>().Do();
                }
            }
            GameObject.DestroyObject(cRaster);
            _interactuable.HideMenu();
            _interactuable = null;
            cam.GetComponent <customLookAt>().enabled = true;
        }
    }