Ejemplo n.º 1
0
 private void Update()
 {
     if (timer.Elapsed() > fadeDelay)
     {
         GameObject.Destroy(gameObject);
     }
 }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        switch (state)
        {
        case PlayerStates.IDLE:

            //print("max vs elapsed" + maxIdleDelay + "," + idleTimer.Elapsed());
            if (idleTimer.Elapsed() > maxIdleDelay)
            {
                ChangePlayerState(PlayerStates.DISTRACTED);
            }

            break;

        case PlayerStates.SNEAKING:
            if (coinLocations.Count == 0)
            {
                if (Vector2.Distance(transform.position, m_nav.destination) < m_nav.stoppingDistance)
                {
                    ChangePlayerState(PlayerStates.IDLE);
                }
            }
            else
            {
                m_nav.destination = getMinCoin();
            }
            break;

        case PlayerStates.DISTRACTED:
            if (minDest != null)
            {
                minDistance = Vector2.Distance(transform.position, minDest.transform.position);
            }
            foreach (GameObject g in goals)
            {
                float d;
                if ((d = Vector2.Distance(transform.position, g.transform.position)) < minDistance)
                {
                    minDistance = d;
                    minDest     = g;
                }
            }
            m_nav.destination = minDest.transform.position;

            break;

        case PlayerStates.CAUGHT:

            m_nav.destination = gameObject.transform.position;
            break;
        }
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (m_nav.velocity != Vector2.zero)
        {
            lastMoveDir = m_nav.velocity.normalized;
        }
        //Debug.Log("Enemy in state " + state.ToString() + " and Player position is "+player.transform.position.ToString());
        Debug.DrawRay(transform.position, lastMoveDir * maxVisionDistance, Color.white);
        switch (state)
        {
        case EnemyState.IDLE:
            if (canSeePlayer())
            {
                setStatePersue();
            }
            else if (canSeePointer())
            {
                setStateInvestigate();
            }
            else if (timer.Elapsed() > maxIdleDelay)     //todo: make the max random
            {
                setStateWander();
            }
            m_animator.Play("Entry");
            //else Leave destination set to self and continue
            break;

        case EnemyState.WANDER:
            if (canSeePlayer())
            {
                setStatePersue();
            }
            else if (canSeePointer())
            {
                setStateInvestigate();
            }
            //If we've reached our destination
            else if (destinationReached())
            {
                setStateIdle();
            }
            //If we've been wandering for long enough, just stop.

            /*else if (state == EnemyState.WANDER && timer.Elapsed() > maxWanderTime)
             * {
             *  setStateIdle();
             * }*/
            break;

        case EnemyState.PERSUE:
            bool seePlayer = canSeePlayer();
            //If we've lost the player, idle.
            if (!seePlayer && destinationReached())
            {
                setStateIdle();
            }
            else if (seePlayer)
            {
                //Set destination to player's current position
                m_nav.destination = player.transform.position;
            }
            break;

        case EnemyState.INVESTIGATE:
            //If we see a pointer, we'll go into this state
            if (canSeePlayer())
            {
                setStatePersue();
            }
            else if (destinationReached())
            {
                setStateIdle();
            }
            //else keep going
            break;

        default: break;
        }
    }