Exemplo n.º 1
0
    void Update()
    {
        #region CuttingCode
        if (manager.StillCutting)
        {
            totalTimePassed += Time.deltaTime;
            if (CurrentState == CutState.ReadyToCut)
            {
                SwitchLine();

                if (Blade.CuttingWoodBoard && Blade.SawActive)
                {
                    Vector3    origin = Blade.transform.position + new Vector3(0.0f, 0.1f, 0.0f);
                    Ray        ray    = new Ray(origin, Vector3.down);
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit) && (hit.collider.tag == "Piece" || hit.collider.tag == "Leftover" || hit.collider.tag == "Dado"))
                    {
                        hit.collider.gameObject.transform.parent.GetComponent <BandSawPieceController>().RotationPoint = hit.point;
                        StartWoodCutting();
                    }
                }
            }
            else if (CurrentState == CutState.Cutting && Blade.SawActive)
            {
                float distanceFromBlade = currentLine.CalculateDistance(Blade.transform.position);
                bool  cuttingAlongLine  = (distanceFromBlade <= ValidCutOffset);
                if (cuttingAlongLine)
                {
                    currentLine.UpdateLine(Blade.transform.position, ValidCutOffset);
                    if (currentLine.LineIsCut())
                    {
                        CurrentState = CutState.EndOfCut;
                    }
                    if (totalTimePassed >= timeUpdateFrequency)
                    {
                        totalTimePassed = 0.0f;
                        if (distanceFromBlade <= ValidCutOffset && distanceFromBlade >= 0.015f)
                        {
                            lineScore -= 0.2f;
                        }
                        else if (distanceFromBlade <= 0.015f && distanceFromBlade >= 0.01f)
                        {
                            lineScore -= 0.1f;
                        }
                    }
                }
                else
                {
                    if (totalTimePassed >= timeUpdateFrequency)
                    {
                        totalTimePassed = 0.0f;
                        lineScore      -= 0.5f;
                    }
                    totalTimeNotCuttingLine += Time.deltaTime;
                    if (totalTimeNotCuttingLine >= MaxTimeAwayFromLine)
                    {
                        manager.StopGameDueToLowScore("You've messed up the wood too much.");
                    }
                    else if (Blade.NoInteractionWithBoard)
                    {
                        CurrentState = CutState.ReadyToCut;
                        Blade.ResetEdgePosition();
                        currentLine.Reset();
                        currentLine = null;
                        manager.SetUpBoardForCutting(false);
                    }
                }
            }
            else if (CurrentState == CutState.EndOfCut)
            {
                if (!Blade.CuttingWoodBoard && Blade.NoInteractionWithBoard)
                {
                    manager.DisplayScore(lineScore);
                    lineScore = 100.0f;
                    manager.SetUpBoardForCutting(false);
                    manager.SplitMaterial(currentLine);
                    currentLine = null;
                    Blade.ResetEdgePosition();
                    CurrentState = CutState.ReadyToCut;
                }
            }

            if (lineScore <= 0.0f)
            {
                manager.StopGameDueToLowScore("This cut is too messed up to keep going.");
            }

            if (totalTimePassed >= timeUpdateFrequency)
            {
                totalTimePassed = 0.0f;
            }
        }
        #endregion
    }