private void HandleTrashBins()
    {
        Collider2D[] hitColliders = Physics2D.OverlapCircleAll(transform.position, awerenessRadius);
        foreach (Collider2D col in hitColliders)
        {
            if (col.tag == "TrashBin")
            {
                TrashBinController bin = (TrashBinController)col.gameObject.GetComponent("TrashBinController");
                if (bin.IsOnFloor() && targetBin == null)
                {
                    targetBin = col.gameObject;
                }
            }
        }

        if (targetBin != null)
        {
            agent.SetDestination(targetBin.GetComponent <Transform> ().position);

            if (agent.remainingDistance < 1f)   //on bin, pick it up m' lady
            {
                TrashBinController binController = (TrashBinController)targetBin.GetComponent("TrashBinController");
                binController.PickupBin();
                targetBin = null;
            }
        }
    }
예제 #2
0
    private void HandlePlayerMovement()
    {
        playerAnimator.ResetTrigger("playerLeft");
        playerAnimator.ResetTrigger("playerRight");

        if (Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f)
        {
            lastMove = new Vector2(Input.GetAxisRaw("Horizontal"), 0f);

            if (Input.GetAxisRaw("Horizontal") < -0.5f)
            {
                playerAnimator.SetTrigger("playerLeft");
            }
            else
            {
                playerAnimator.SetTrigger("playerRight");
            }

            if (Input.GetButton("SlowMovement"))
            {
                transform.Translate(new Vector3(Input.GetAxisRaw("Horizontal"), 0f, 0f) * moveSpeed * stealthSlowPerc * Time.deltaTime);
                isStealth = true;
            }
            else
            {
                transform.Translate(new Vector3(Input.GetAxisRaw("Horizontal"), 0f, 0f) * moveSpeed * Time.deltaTime);
                isStealth = false;
            }
        }

        if (Input.GetAxisRaw("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < -0.5f)
        {
            lastMove = new Vector2(0f, Input.GetAxisRaw("Vertical"));
            if (Input.GetButton("SlowMovement"))
            {
                transform.Translate(new Vector3(0f, Input.GetAxisRaw("Vertical"), 0f) * moveSpeed / 2f * Time.deltaTime);
                isStealth = true;
            }
            else
            {
                transform.Translate(new Vector3(0f, Input.GetAxisRaw("Vertical"), 0f) * moveSpeed * Time.deltaTime);
                isStealth = false;
            }
        }

        if (Input.GetButtonDown("Interact"))
        {
            if (interactiveObject != null)
            {
                if (interactiveObject.CompareTag("Doors") && hasCard)
                {
                    DoorController doorController = (DoorController)interactiveObject.GetComponent("DoorController");
                    doorController.Interact();
                }

                if (interactiveObject.CompareTag("TrashBin"))
                {
                    TrashBinController binController = (TrashBinController)interactiveObject.GetComponent("TrashBinController");
                    binController.DropBin();
                }

                if (interactiveObject.CompareTag("CoffeeMachine"))
                {
                    if ((hasCup && coins >= 25) || coins >= 30)
                    {
                        FindObjectOfType <GameManager> ().WinGame();
                    }
                }
            }
        }
    }