Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        //SOLTAR LA HERRAMIENTA SI LA TENEMOS Y PULSAMOS SPACE
        if ((Input.GetKeyDown(KeyCode.Space) || button.getPulsado()) && toolTaken)
        {
            tool.RemoveAction();
            tool             = null;
            toolTaken        = false;
            playerSound.clip = drop;
            playerSound.Play();
            return;
        }

        if (!toolTaken)
        {
            foreach (GameObject obj in availableTools)
            {
                if (obj.GetComponent <Tool>().playerNear)
                {
                    Debug.Log("Estoy cerca");

                    if ((Input.GetKeyDown(KeyCode.Space) || button.getPulsado()) && !toolTaken)
                    {
                        //COGER HERRAMIENTA
                        tool = obj.GetComponent <Tool>();
                        tool.MoveAction();
                        toolTaken        = true;
                        playerSound.clip = pickUp;
                        playerSound.Play();
                    }
                }
            }
        }

        //CONTROL DE ANIMACIONES
        if (toolTaken && tool.name == "RollingPin")
        {
            rollingPinTaken = true;
        }
        else
        {
            rollingPinTaken = false;
        }
        anim.SetBool("toolTaken", toolTaken);
        anim.SetBool("rollingPinTaken", rollingPinTaken);
        anim.SetBool("pushingIngredient", pushingIngredient);


        //ACTIVAR HERRAMIENTA (SU ACCION PROPIA) SI LA TENEMOS COGIDA
        if ((Input.GetKeyUp(KeyCode.M) || buttonM.getPulsado()) && toolTaken)
        {
            if (!tool.isActive)
            {
                tool.Action();
            }
        }

        if ((Input.GetKeyDown(KeyCode.Space) || button.getPulsado()) && hasSomething && !justNow && !dontDrop)
        {
            myIngredient.GetComponent <Rigidbody>().isKinematic = false;
            //myIngredient.GetComponent<Rigidbody>().detectCollisions = true;
            if (myIngredient.name == "MasaPizza")
            {
                myIngredient.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None;
                myIngredient.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
                myIngredient.transform.position = new Vector3(myIngredient.transform.position.x, 0f, myIngredient.transform.position.z);
            }
            else
            {
                myIngredient.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None;
            }
            myIngredient.transform.SetParent(null);
            hasSomething = false;
        }
        else if (justNow)
        {
            justNow = false;
        }
    }