void Update()
    {
        #region CuttingCode
        if (manager.StillCutting)
        {
            currentBladePosition = SawBlade.EdgePosition();
            totalTimePassed     += Time.deltaTime;
            UpdateFeedRateDate();

            if (CurrentState == CutState.ReadyToCut)
            {
                SwitchLine();

                if (SawBlade.CuttingWoodBoard && SawBlade.SawBladeActive)
                {
                    Vector3    origin = SawBlade.EdgePosition() + new Vector3(0.0f, 0.5f, 0.0f);
                    Ray        ray    = new Ray(origin, Vector3.down);
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit, Mathf.Infinity, mask) && (hit.collider.tag == "Piece" || hit.collider.tag == "Leftover"))
                    {
                        Vector3 bladeEdgePosition = new Vector3(currentLine.GetCurrentCheckpointPosition().x, hit.point.y, hit.point.z);
                        StartWoodCutting(bladeEdgePosition);
                    }
                }
            }
            else if (CurrentState == CutState.Cutting && SawBlade.SawBladeActive)
            {
                if (cuttingAlongLine)
                {
                    currentLine.UpdateLine(SawBlade.EdgePosition());
                    if (currentLine.LineIsCut())
                    {
                        CurrentState = CutState.EndingCut;
                    }
                    else
                    {
                        if (totalTimePassed >= timeUpdateFrequency)
                        {
                            totalTimePassed   = 0.0f;
                            totalTimeStalling = 0.0f;
                            FeedRateTracker.UpdateScoreWithRate(playerFeedRate);
                        }
                        if (FeedRateTracker.RateTooSlow || FeedRateTracker.RateTooFast)
                        {
                            totalTimeStalling += Time.deltaTime;
                            FeedRateTracker.ReduceScoreDirectly(0.1f);
                            if (totalTimeStalling >= MaxStallTime && FeedRateTracker.RateTooSlow)
                            {
                                manager.StopGameDueToLowScore("You were cutting too slow, now the wood is burnt.");
                            }
                            else if (totalTimeStalling >= 1.0f && FeedRateTracker.RateTooFast)
                            {
                                manager.StopGameDueToLowScore("You were cutting too fast and caused the saw to bind.");
                            }
                        }
                    }
                }
                else
                {
                    if (SawBlade.NoInteractionWithBoard)
                    {
                        timeNotCuttingLine = 0.0f;
                        CurrentState       = CutState.ReadyToCut;
                        SawBlade.ResetEdgePosition();
                        currentLine = null;
                        manager.RestrictCurrentBoardMovement(false, false);
                    }
                    else
                    {
                        timeNotCuttingLine += Time.deltaTime;
                        if (totalTimePassed >= timeUpdateFrequency)
                        {
                            totalTimePassed = 0.0f;
                            FeedRateTracker.ReduceScoreDirectly(0.8f);
                        }
                        if (timeNotCuttingLine >= MaxStallTime)
                        {
                            manager.StopGameDueToLowScore("You were not cutting along the line, and now the board is ruined.");
                        }
                    }
                }
            }
            else if (CurrentState == CutState.EndingCut)
            {
                if (!SawBlade.CuttingWoodBoard && SawBlade.NoInteractionWithBoard)
                {
                    manager.DisplayScore(FeedRateTracker);
                    manager.SplitMaterial(currentLine);
                    cuttingAlongLine = false;
                    currentLine      = null;
                    SawBlade.ResetEdgePosition();
                    CurrentState = CutState.ReadyToCut;
                    FeedRateTracker.ResetFeedRate();
                }
            }
        }
        previousBladePosition = currentBladePosition;
        if (FeedRateTracker.GetLineScore() <= 0.0f)
        {
            manager.StopGameDueToLowScore("This cut is too messed up to keep going.");
        }
        #endregion
    }
Exemplo n.º 2
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
    }