Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (timeToDestroyMe <= 0 && timeToDestroyMe > -5)
        {
            Destroy(this.gameObject);
        }

        if (timeToDestroyMe > 0)
        {
            timeToDestroyMe -= Time.deltaTime;
        }

        if (onThrow)
        {
            throwAnim();
        }
        else if (timeToGoCash > 0)
        {
            timeToGoCash -= Time.deltaTime;
        }
        else if (timeToGoCash > -5 && !onCash)
        {
            timeToGoCash = -10;
            goToCash();
        }

        if (t.position == cashTarget.position && !anim.isOnMove())
        {
            cashTarget.gameObject.GetComponent <Cash>().receiveCoin();
            desapear();
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (onOperation)
        {
            if (bu_cancel.transform.position.y == -10)
            {
                bu_cancel.transform.position   = new Vector3(0, 0, 0);
                bu_cancel.transform.localScale = new Vector3(0, 0, 0);
                AuxiliarAnim bu_a = bu_cancel.GetComponent <AuxiliarAnim>();
                bu_a.moveTo(new Vector3(-1.5f, -2.5f, 0), 0.5f);
                bu_a.scaleTo(new Vector3(1, 1, 1), 0.5f);
            }
            if (!onOperators && ((Mathf.Abs(cardB.transform.position.x - (t.localPosition.x + 2)) < 0.05f && cardB.transform.position.y == t.localPosition.y) || totalOperators == 1))
            {
                initOperators();
                onOperators = true;
            }

            if (((Input.GetMouseButtonUp(0)) || totalOperators == 1) && !GameSettings.panelOpened && !GameSettings.cardOnZoom)
            {
                RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero, Mathf.Infinity, 1 << 9);

                if ((hit.collider != null) || totalOperators == 1 && !operationChoosed)
                {
                    operationChoosed = true;
                    Operator[] ops;
                    if (totalOperators == 1)
                    {
                        ops = getAllOperators();
                        for (int i = 0; i < ops.Length; i++)
                        {
                            if (ops[i].isUseThis())
                            {
                                op = ops[i];
                            }
                        }
                    }
                    else
                    {
                        op = hit.collider.gameObject.GetComponent <Operator>();
                        op.animOnChoose(new Vector3(-0.9f, 0, 0));
                    }

                    ops = getAllOperators();
                    for (int i = 0; i < ops.Length; i++)
                    {
                        if (!ops[i].gameObject.name.Equals(op.gameObject.name))
                        {
                            ops[i].removeMeFromScene();
                        }
                    }

                    if (op == sub && cardA.getCardValue() < cardB.getCardValue())
                    {
                        CardController c_aux = cardA;
                        cardA = cardB;
                        cardB = c_aux;
                        cardA.moveCardTo(cardB.transform.position);
                    }

                    if (totalOperators > 1)
                    {
                        cardB.moveCardTo(new Vector3(0.2f, 0, 0));
                    }

                    cardA.toScale(1f, 0.25f);
                    cardB.toScale(1f, 0.25f);

                    waitingForResult = true;
                    equals.fadeTo(1, 0.5f);

                    int value = -99999;
                    int a     = cardA.getCardValue();
                    int b     = cardB.getCardValue();

                    if (op == sum)
                    {
                        value = a + b;
                    }
                    else if (op == sub)
                    {
                        value = a - b;
                    }
                    else if (op == mul)
                    {
                        value = a * b;
                    }
                    else
                    {
                        value = a / b;
                    }

                    if (totalOperators > 1)
                    {
                        gameManager.playAudioBu_press();
                    }

                    gameManager.initOrders(value);
                }

                if (Input.GetMouseButtonUp(0))
                {
                    hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero, Mathf.Infinity, 1 << 5);                       //9 is the UI Layer

                    if (hit.collider != null && !buttonPressed)
                    {
                        if (hit.collider.gameObject.name.Equals("bu_cancel"))
                        {
                            AuxiliarAnim bu_an = hit.collider.gameObject.GetComponent <AuxiliarAnim>();
                            if (!bu_an.isOnMove() && !bu_an.isOnScale())
                            {
                                gameManager.playAudioBu_press();
                                Debug.Log("BU PRESSED DE CANCEL OPERATION!");
                                cancelOperation();
                                buttonPressed = true;
                            }
                        }
                        else if (hit.collider.gameObject.name.Equals("bu_verify"))
                        {
                            AuxiliarAnim bu_an = hit.collider.gameObject.GetComponent <AuxiliarAnim>();
                            if (!bu_an.isOnMove() && !bu_an.isOnScale())
                            {
                                cardA.setEnableClick(false);
                                cardB.setEnableClick(false);
                                verifyOperation();
                                buttonPressed = true;
                            }
                        }
                    }
                }
            }
        }
    }