Пример #1
0
    void OnTriggerEnter(Collider collidedMoney)
    {
        if (collidedMoney.gameObject.tag == "Money")
        {
            if (payScreenScript.isCash)
            {
                thisObject = collidedMoney.gameObject;
                if (collidedMoney.GetComponent <MoneyData>().hasBeenUsed == false)
                {
                    /* var objGrabbable = thisObject.GetComponent<OVRGrabbable>();
                     * Destroy(objGrabbable);
                     * thisObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezePositionY;
                     * thisObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;
                     * thisObject.transform.position = Vector3.Lerp(thisObject.transform.position, moneyGrabber.position, .02f);
                     * StartCoroutine("DestroyMoney");*/
                    if (!costReached)
                    {
                        scanner.GetComponent <ScannerColliderScriptVRV2>();

                        total = scanner.GetComponent <ScannerColliderScriptVRV2>().total;


                        itemizedText         = scanner.GetComponent <ScannerColliderScriptVRV2>().itemizedText;
                        selfCheckoutMainText = scanner.GetComponent <ScannerColliderScriptVRV2>().selfCheckoutMainText;
                        outputTotalText      = scanner.GetComponent <ScannerColliderScriptVRV2>().outputTotalText;

                        usingCash = true;
                        collidedMoney.GetComponent <MoneyData>().hasBeenUsed = true;

                        moneyData  = collidedMoney.GetComponent <MoneyData>();
                        moneyValue = moneyData.value;
                        var moneyValueConverted = Convert.ToDecimal(moneyValue);
                        currencyType = collidedMoney.name.Replace("(Clone)", " ");

                        newTotal = Decimal.Subtract(total, moneyValueConverted);
                        scanner.GetComponent <ScannerColliderScriptVRV2>().total = newTotal;
                        itemizedText.Append($"\n -{moneyValue:c}");
                        payScreenScript.itemizedText.text = itemizedText.ToString();
                        outputTotalText.Clear();
                        outputTotalText.Append(newTotal.ToString("c"));
                        payScreenScript.outputTotalText.text = outputTotalText.ToString();



                        currentOffer = currentOffer + moneyValue;
                        selfCheckoutMainText.Clear();
                        selfCheckoutMainText.Append($"{currencyType} {moneyValue.ToString("c")} {"Current Offer:" + currentOffer.ToString("c")} \n");
                        payScreenScript.mainText.text = selfCheckoutMainText.ToString();

                        PlayerMoneyHandler.PlayerMoney = PlayerMoneyHandler.PlayerMoney - moneyValue;



                        StartCoroutine("DestroyMoney");
                        scannable = false;
                        scanTimer = 0;
                    }
                    if (Convert.ToDecimal(currentOffer) >= payScreenScript.originalTotal && scanner.GetComponent <ScannerColliderScriptVRV2>().numItemsScanned > 0)
                    {
                        costReached  = true;
                        changeAmount = Convert.ToDecimal(moneyValue) - total;
                        payScreenScript.outputTotalText.text = $"{0:c}";
                        payScreenScript.changeText.text      = "CHANGE: " + $"{changeAmount:c}";

                        var expectedChange = changeCalculator.MakeChange(changeAmount);


                        foreach (var amt in expectedChange)
                        {
                            switch (amt)
                            {
                            case 50:
                                Instantiate(fiftyDollar, changeSpawner.transform.position, Quaternion.identity);
                                break;

                            case 20:
                                Instantiate(twentyDollar, changeSpawner.transform.position, Quaternion.identity);
                                break;

                            case 10:
                                Instantiate(tenDollar, changeSpawner.transform.position, Quaternion.identity);
                                break;

                            case 5:
                                Instantiate(fiveDollar, changeSpawner.transform.position, Quaternion.identity);
                                break;

                            case 1:
                                Instantiate(oneDollar, changeSpawner.transform.position, Quaternion.identity);
                                break;

                            case .25m:
                                Instantiate(quarter, changeSpawner.transform.position, Quaternion.identity);
                                break;

                            case .10m:
                                Instantiate(dime, changeSpawner.transform.position, Quaternion.identity);
                                break;

                            case .05m:
                                Instantiate(nickel, changeSpawner.transform.position, Quaternion.identity);
                                break;

                            case .01m:
                                Instantiate(penny, changeSpawner.transform.position, Quaternion.identity);
                                break;

                            default:
                                break;
                            }
                        }
                        StartCoroutine("PaymentReceived");
                    }
                }
            }
        }
    }