示例#1
0
 //Parent has walked over a pool of blood or a candy, and will clean it up
 public void StartMopping(Moppability pool)
 {
     if (state != AIState.chasingKidAngrily && state != AIState.chasingKid)
     {
         state     = AIState.mopping;
         poolToMop = pool;
         mop.SetActive(true);
         if (!isMopping)
         {
             StartCoroutine(MopBackAndForth());
         }
     }
 }
示例#2
0
    void Update()
    {
        if (state == AIState.idle)
        {
            FindPatrollPosition();
            mop.SetActive(false);
            exclamation.SetActive(false);
        }

        if (state == AIState.patrolling)
        {
            //id reached the target position
            if (Vector3.Distance(transform.position, agent.target) < minTargetDistance)
            {
                state = AIState.idle;
            }
        }

        // Mop pool, added by Oane, unless player is angry
        if (state == AIState.chasingKidAngrily)
        {
            mop.SetActive(false);
            exclamation.SetActive(true);

            agent.SetTarget(PlayerChar.Instance.transform.position);

            GetComponent <NavMeshAgent>().speed = initSpeed * 2;

            //start the hit timer if the parent is close to the player
            if (Vector3.Distance(transform.position, PlayerChar.Instance.transform.position) < childHitDistance)
            {
                HitPlayer();

                /*if (playerHitTimerRoutine == null) {
                 *  playerHitTimerRoutine = StartCoroutine(PlayerHitTimer());
                 * }*/
            }
        }
        else if (state == AIState.mopping)
        {
            if (poolToMop != null)
            {
                agent.SetTarget(poolToMop.transform.position);

                poolToMop.mopProgress += Time.deltaTime;
                if (poolToMop.mopProgress > poolToMop.mopFinishedAt)
                {
                    Destroy(poolToMop.gameObject);
                    poolToMop = null;
                    state     = AIState.idle;
                    mop.SetActive(false);
                }
            }
            else
            {
                poolToMop = null;
                state     = AIState.idle;
                mop.SetActive(false);
            }
        }
        //chase the child if it has the gun equiped. Oane: But not if the parent is mopping.
        else if (PlayerChar.Instance.gunEquipped)
        {
            state = AIState.chasingKid;
        }

        if (state == AIState.chasingKid)
        {
            agent.SetTarget(PlayerChar.Instance.transform.position);

            //start the hit timer if the parent is close to the player
            if (Vector3.Distance(transform.position, PlayerChar.Instance.transform.position) < childHitDistance)
            {
                /*if (playerHitTimerRoutine == null) {
                 *  playerHitTimerRoutine = StartCoroutine(PlayerHitTimer());
                 * }*/
                HitPlayer();
            }

            if (!PlayerChar.Instance.gunEquipped)
            {
                state = AIState.idle;

                if (playerHitTimerRoutine != null)
                {
                    StopCoroutine(playerHitTimerRoutine);
                    playerHitTimerRoutine = null;
                }
            }
        }

        spriteRenderer.sortingOrder = (int)(-transform.position.z * 100);
    }