Пример #1
0
    void Awake()
    {
        int   currentLevel      = GameManager.GetManager().MissionCount;
        Range waitDurationRange = Difficulty.CowWaitTime(currentLevel);

        waitDuration   = Random.Range(waitDurationRange.Min, waitDurationRange.Max);
        actionDuration = Random.Range(1f, 2f);
        cowAction      = GetRandomCowAction();
        isGrounded     = true;
        maxSpeed       = Difficulty.CowSpeed(currentLevel);
    }
Пример #2
0
    public void UpdateMovementCycle()
    {
        // If cow is on the ground
        if (isGrounded)
        {
            // If Beam is ON within range runaway to safe distance
            if (IsBeamToClose())
            {
                DoWhenBeamIsTooClose();
                return;
            }
            if (IsBeamToFar())
            {
                DoWhenBeamIsTooFar();
                return;
            }

            // Cow action cycle
            cycleTimer += Time.deltaTime;
            if (cycleTimer > waitDuration + actionDuration)
            {
                // Restart Cycle
                cycleTimer = 0;
                cowAction  = GetRandomCowAction();
            }
            // Do Random Cow Action
            else if (cycleTimer > waitDuration && cycleTimer < waitDuration + actionDuration)
            {
                switch (cowAction)
                {
                case CowActions.EatGrass:
                    EatGrass();
                    return;

                case CowActions.WalkLeft:
                    WalkLeft();
                    return;

                case CowActions.WalkRight:
                    WalkRight();
                    return;
                }
            }

            //Set Animation Variables
            GetComponent <Animator>().SetFloat(AnimatorConstants.CowSpeed, 0);
        }
    }