Example #1
0
    // Update is called once per frame
    void Update()
    {
        switch (currentState)
        {
        case States.wanderState:
            agent.destination = wander.WanderingPoints();
            break;

        case States.seekState:
            agent.destination = seek.returnTarget();
            break;

        case States.fleeState:
            agent.destination = flee.returnFlee();
            break;

        case States.resting:
            if (currentState == States.wanderState)
            {
                restingTimer -= Time.deltaTime;
                if (restingTimer <= 0)
                {
                    currentState = States.wanderState;
                }
            }
            break;
        }
        switchStates();
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;

        if (timer >= eventChangeTimer)
        {
            switch (myLife)
            {
            case live.sleep:
                float distance = Vector3.Distance(transform.position, bed.transform.position);
                agent.destination = bed.transform.position;
                if (distance < 1)
                {
                    currentLife   -= damage;
                    currentEnergy += drain;
                }
                break;

            case live.wonder:
                agent.destination = wonder.WanderingPoints();
                break;

            case live.eat:
                distance          = Vector3.Distance(transform.position, food.transform.position);
                agent.destination = food.transform.position;
                if (distance < 1)
                {
                    currentLife   += damage / 2;
                    currentHunger += starvation;
                }
                if (distance > 1)
                {
                    currentLife -= damage;
                }
                break;

            case live.die:

                Destroy(gameObject);
                //gameObject.SetActive(false);

                break;
            }
            switchStates();
            timer = 0;
        }
    }