Exemplo n.º 1
0
    //event rised where player enter into another body with collider and trigger
    void OnTriggerEnter2D(Collider2D other)
    {
        //get interacted item
        var interact = other.gameObject.GetComponent <InteractiveScript>();

        if (interact != null)   //check if this item exists
        {
            if (InteractItems.Count == 0)
            {
                curInteract = interact;
            }
            InteractItems.Add(interact);                                                            //add to interacted item collection
            GameObject.FindObjectOfType <LevelScript>().tooltipPanel.SetActive(true);               //show tooltip about potential interaction
            GameObject.Find("TextTarget").GetComponent <Text>().text = curInteract.description;     //show description about interaction
        }
    }
Exemplo n.º 2
0
    //same like above, but rised when exit
    void OnTriggerExit2D(Collider2D other)
    {
        var interact = other.gameObject.GetComponent <InteractiveScript>();

        if (interact != null)
        {
            InteractItems.Remove(interact);                                                             //remove first item from collection
            if (InteractItems.Count == 0)
            {
                GameObject.FindObjectOfType <LevelScript>().tooltipPanel.SetActive(false);               //if collectin is empty hide tooltip panel
            }
            else
            {
                curInteract = InteractItems[0];
                GameObject.Find("TextTarget").GetComponent <Text>().text = curInteract.description;      //or show next element description
            }
        }
    }
Exemplo n.º 3
0
    private void ChangeInteractTarget()
    {
        if (InteractItems.Count <= 1)
        {
            return;
        }
        int idx = InteractItems.IndexOf(curInteract);

        if (idx == InteractItems.Count - 1)
        {
            idx = 0;
        }
        else
        {
            idx++;
        }
        curInteract = InteractItems[idx];
        GameObject.Find("TextTarget").GetComponent <Text>().text = curInteract.description;
    }