private void ChangeState(horseState newState)
    {
        if (currentBehaviour != null)
        {
            StopCoroutine(currentBehaviour);
        }

        horse.horseAnimator.SetBool("Eat", false);
        Debug.Log("change horse state to " + newState);
        horse.horseAnimator.SetInteger("GaitIndex", 0);

        currentHorseState = newState;
        switch (newState)
        {
        case horseState.IDLE:
            currentBehaviour = StartCoroutine(Idle());
            break;

        case horseState.WALKINGTOTARGET:
            currentBehaviour = StartCoroutine(WalkToTarget());
            break;

        case horseState.CONSUMING:
            currentBehaviour = StartCoroutine(Consume());
            break;

        case horseState.PRODUCINGMANURE:
            currentBehaviour = StartCoroutine(ProduceManure());
            break;

        case horseState.ONLEAD:
            currentBehaviour = StartCoroutine(BeLead());
            break;

        case horseState.RIDING:
            currentBehaviour = StartCoroutine(BeRidden());
            break;

        case horseState.TIEDTOPOST:
            currentBehaviour = StartCoroutine(BeTiedToPost());
            break;
        }
    }
Exemple #2
0
 /// <summary>
 /// Метод используется в инвоке для прерывания состояния ожидания на месте
 /// </summary>
 void endIdle()
 {
     state = horseState.selectAction;
 }
Exemple #3
0
    void Update()
    {
        center = UniversalController.playerInstance.transform.position;
        switch (state)
        {
        case horseState.player:
            if (currentEnergy > 0)
            {
                playerMove();
            }
            else
            {
                HorseAnimator.Play(idle, 0);
            }
            playerRotate();
            //проверка и удаление отдаленных ботов
            removedLostBots();
            spawner();
            //восстановление енергии
            restoreEnergy();
            Timer();
            //енергия
            energy.fillAmount = currentEnergy / energyMax;
            //обрабатываю удержание кнопки
            OnGUIRunButton();
            break;

        case horseState.selectAction:
            //принятие решения или ждем или идем
            int randomAction = (int)Random.Range(0, 2);
            switch (randomAction)
            {
            case 0:
                //решаем ждать
                float randomTime = (float)Random.Range(minIdleTime, maxIdleTime);
                state = horseState.idle;
                Invoke("endIdle", randomTime);
                break;

            case 1:
            case 2:
                //решаем идти в случайную точку
                int typeX = 0;
                int typeZ = 0;
                if (getRandomBool())
                {
                    typeX = 1;
                }
                else
                {
                    typeX = -1;
                }
                if (getRandomBool())
                {
                    typeZ = 1;
                }
                else
                {
                    typeZ = -1;
                }
                //получаем новую точку
                nextPosition = getRandomPoint(typeX, typeZ);
                //Debug.Log("nextPosition = "+ nextPosition);
                //переходим к перемещению в новую точку
                state = horseState.moveToPoint;
                break;
            }
            break;

        case horseState.moveToPoint:
            //если есть куда двигаться двигаемся
            if (nextPosition != Vector3.zero)
            {
                //MoveToPoint();
                if (Vector3.Distance(myRigidbody.transform.position, nextPosition) > UniversalController.playerInstance.stopDistance)
                {
                }
                else
                {
                    nextPosition = Vector3.zero;
                }
            }
            else
            {
                HorseAnimator.Play(idle);
                state = horseState.selectAction;
            }
            break;
        }

        if (state != horseState.player)
        {
            navMeshMove();
        }
    }