Exemplo n.º 1
0
    void Update()
    {
        isAlone = nearby.isAlone;
        switch (cState)
        {
        case State.Investigate:
            if (movement.isStopped)                       //DO THE INVESTIGATING
            {
                if (count >= InvestigatingTime)
                {
                    switch (statePreInvestigate)
                    {
                    case State.Default:
                        ToDefault();
                        break;

                    case State.Doors:
                        ToDoors();
                        break;

                    case State.MoveTo:
                        ToMoveTo(preInvestigateTarget);
                        break;

                    default:
                        ToDefault();
                        break;
                    }
                    count = 0;
                }
                else
                {
                    sight.Investigate();
                    count += Time.deltaTime;
                }
            }
            break;

        case State.MoveTo:
            if (movement.isStopped)
            {
                if (count >= MoveToTime)
                {
                    ToDefault();
                    count = 0;
                }
                else
                {
                    count += Time.deltaTime;
                }
            }
            break;

        case State.Attack:
            //Debug.Log ("[DEBUG] Attacking " + target.gameObject.name);
            if (!sight.LookAt(target))
            {
                //Debug.Log ("[DEBUG] Lost sight of player object: "+target.gameObject.name);
                float angleBetween = Vector3.Angle(transform.forward, target.transform.position - transform.position);
                if (angleBetween < 0)
                {
                    sight.direction = -1;
                }
                else
                {
                    sight.direction = 1;
                }
                sight.seesPlayer = false;
                ToInvestigate(target.transform.position);
            }
            else
            {
                movement.MoveInRange(targetLocation, followRange);
                nearby.ShareWithFriends(target);
                weapon.HasTarget(targetLocation);
            }
            break;

        default:
            break;
        }
    }