示例#1
0
    public void useObject()
    {
        if (dialogContainer.activeSelf)
        {
            return;
        }


        if (selectedObject.GetComponent <inventory_object>().objectName == "Bread crumbs")  // using the bread

        {
            if (Vector2.Distance(player.position, duck.transform.position) < 4)
            {
                StartCoroutine(setCameraTarget(duck.transform, 7));
                igor.SetTrigger("run");
                duck.SetTrigger("chase");

                restartSlot();
                return;
            }
            else
            {
                dm.openDialog("Peter", "I don't think that throwing bread crumbs in here is useful...", 0);
            }
        }


        if (selectedObject.GetComponent <inventory_object>().objectName == "Bone")   //using the bone
        {
            if (Vector2.Distance(player.position, dog.transform.position) < 4)
            {
                StartCoroutine(setCameraTarget(dog.transform, 6));
                (dog.GetComponent <Collider2D>()).enabled = false;
                dog.SetTrigger("run");
                restartSlot();
                return;
            }
            else
            {
                dm.openDialog("Peter", "Throw the bone here? Why?", 0);
            }
        }

        if (selectedObject.GetComponent <inventory_object>().objectName == "Cherries") // using the berries
        {
            dm.openDialog("Peter", "hmmm, I wonder if she smells like cherries", 0);
        }
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        // if the player press spacebar near to an object it should grab it (and destroy the gameobject)
        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (selectedObject != null)
            {
                selectObjectSound.Play();
                inventory.addObject(selectedObject.objectName, selectedObject.iconInventory);
                collectibles.Remove(selectedObject);
                backpack.SetTrigger("grow");
                Destroy(selectedObject.gameObject);
            }

            if (selectedDialog != null)
            {
                dm.openDialog("Peter", selectedDialog.messages[Random.Range(0, selectedDialog.messages.Length)], 0);
            }
        }

        if (gameState.playing)
        {
            // loop through all the collectibles to see if its near of any.
            foreach (collectible_object collectible in collectibles)
            {
                if (Vector2.Distance(collectible.transform.position, player.position) < 0.5)
                {
                    collectible_object coll_prop = collectible.gameObject.GetComponent <collectible_object>();

                    textBottomContainer.SetActive(true);
                    textBottom.text = "Grab " + coll_prop.objectName;
                    selectedObject  = collectible;

                    return;
                }
            }

            // loop through all the collectibles to see if its near of any.
            foreach (dialogObject dialog in dialogs)
            {
                if (Vector2.Distance(dialog.transform.position, player.position) < 1)
                {
                    textBottomContainer.SetActive(true);
                    textBottom.text = dialog.title;
                    selectedDialog  = dialog;
                    return;
                }
            }
        }



        textBottomContainer.SetActive(false);
        textBottom.text = " ";
        selectedObject  = null;
        selectedDialog  = null;
    }
    // Update is called once per frame
    void Update()
    {
        detected = false;
        for (int i = 0; i < NPCS.Length; i++)
        {
            Vector2 dir = NPCS[i].bounds.center - player.position;
            if (!gameState.playing)
            {
                return;
            }

            RaycastHit2D hit = Physics2D.Raycast(player.position, dir.normalized, distances[i], ~ignoreLayer);
            if (hit.collider != null && gameState.playing)
            {
                if (hit.collider.gameObject.CompareTag("NPC"))
                {
                    detected = true;
                    if (i == 0 && !seenElla)
                    {
                        seenElla = true;
                        dm.openDialog("Ella", "Wait, I think someone is watching me...*", 2);
                    }

                    if (i == 1 && !seenIgor)
                    {
                        seenIgor = true;
                        dm.openDialog("Igor", "I heard that guy Peter is back in town, I hate him more than I hate ducks", 1);
                    }


                    if (i == 2 && !seenDog)
                    {
                        seenDog = true;
                        dm.openDialog("Peter", "That's her dog, I think he doesn't like me either", 0);
                    }


                    eyes[i].SetActive(true);
                    hb.health += (0.5f / hit.distance);
                }
                else
                {
                    eyes[i].SetActive(false);
                }
            }
            else
            {
                eyes[i].SetActive(false);
            }
        }

        if (Vector3.Distance(player.position, NPCS[0].bounds.center) < radius && !detected && !finishGame)
        {
            finishGame        = true;
            gameState.playing = false;
            StartCoroutine(endingScene());
        }


        if (detected)
        {
            if (!detectedMusic.isPlaying)
            {
                detectedMusic.Play();
            }
        }
        else if (detectedMusic.isPlaying)
        {
            detectedMusic.Stop();
        }
    }