示例#1
0
    void Start()
    {
        controller = MoverController.Instance;
        gm         = GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager>();

        agent = GetComponent <NavMeshUser>();

        agent.SetTarget(exit.position);
        state = AIState.idle;

        origWalkingSpeed = walkingSpeed * walkingFactor;
    }
示例#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);
    }
示例#3
0
    void Update()
    {
        if (state == AIState.idle)
        {
            GetComponent <NavMeshAgent>().speed = origWalkingSpeed;

            //try to select an object
            if (SelectNewObject())
            {
                state = AIState.moveToObject;
            }
            else
            {
                if (SelectTeddyBear())
                {
                    state = AIState.getTeddyBear;
                }
                else
                {
                    state = AIState.walkRandomly;
                }
            }
        }

        //check if the mover is close enough to an object to pick it up
        if (state == AIState.moveToObject)
        {
            if (Vector3.Distance(transform.position, selectedObject.transform.position) < pickupDistance)
            {
                //Debug.Log(selectedObject);
                dropObjectReminder = Instantiate(selectedObject);
                dropObjectReminder.transform.SetParent(transform);
                dropObjectReminder.SetActive(false);

                controller.placedObjects.Remove(selectedObject);
                controller.UnsubscribeObject(selectedObject);

                //set the sprite of the picked up object to the carry object sprite renderer
                carryObjectRenderer.sprite = selectedObject.GetComponent <Collectible>().spriteRenderer.sprite;
                Destroy(selectedObject);

                pickedUpObject = true;
                agent.SetTarget(exit.position);
                state = AIState.moveToExit;

                GetComponent <NavMeshAgent>().speed = (((origWalkingSpeed / walkingFactor)) - (selectedObject.GetComponent <Collectible>().weight / strengthAdjustment)) * walkingFactor;
            }
        }

        //check if the mover is close enough to the exit to drop off
        if (state == AIState.moveToExit)
        {
            if (pickedUpObject && Vector3.Distance(transform.position, exit.position) < pickupDistance * 3)
            {
                pickedUpObject = false;

                /*SpriteRenderer droppedObjectRenderer = Instantiate(PrefabController.Instance.droppedExitObject).GetComponent<SpriteRenderer>();
                 * droppedObjectRenderer.sprite = carryObjectRenderer.sprite;
                 * droppedObjectRenderer.transform.position = exit.transform.position + new Vector3(Random.Range(-1, 1), 0.5f, Random.Range(-1, 1));
                 * droppedObjectRenderer.transform.localScale = transform.localScale;*/

                Destroy(dropObjectReminder);
                dropObjectReminder = null;

                carryObjectRenderer.sprite = null;
                state = AIState.idle;
            }
        }

        if (state == AIState.getTeddyBear)
        {
            if (controller.teddyBear != null)
            {
                controller.teddyBear.GetComponent <TeddyBear>().SetAnimClose();
            }

            if (Vector3.Distance(transform.position, controller.teddyBear.transform.position) < pickupDistance)
            {
                controller.teddyBear.transform.SetParent(transform);
                agent.SetTarget(exit.transform.position);
                pickedUpObject = true;
                GetComponent <NavMeshAgent>().speed = (((origWalkingSpeed / walkingFactor)) - controller.teddyBear.GetComponent <TeddyBear>().weight) * walkingFactor;
                state = AIState.hasTeddyBear;
            }
        }

        if (state == AIState.hasTeddyBear)
        {
            if (controller.teddyBear != null)
            {
                controller.teddyBear.GetComponent <TeddyBear>().SetAnimPickup();
            }

            if (pickedUpObject && Vector3.Distance(transform.position, exit.position) < pickupDistance * 3)
            {
                print("teddy bear was killed! :o");
                pickedUpObject = false;
                Destroy(controller.teddyBear.gameObject);

                gm.gameOverText.text = "They have kidnapped your teddybear...";
                gm.GameOver();
                //UIController.Instance.gameOverScreen.SetActive(true);
                state = AIState.idle;
            }
        }

        if (state == AIState.walkRandomly)
        {
            if (walkToTeddyRoutine == null && controller.teddyBear != null)
            {
                walkToTeddyRoutine = StartCoroutine(WaitForTeddyPos());
            }

            if (!controller.IsReserved(controller.teddyBear))
            {
                state = AIState.idle;
            }
        }

        //update the sorting layer of the sprites to get correct depth
        spriteRenderer.sortingOrder      = (int)(-transform.position.z * 100);
        carryObjectRenderer.sortingOrder = spriteRenderer.sortingOrder - 1;
    }