/// <summary> /// Checks if some interactable or shop is in his trigger. /// </summary> /// <param name="collision"></param> private void OnTriggerEnter2D(Collider2D collision) { // Get the right component to start the interaction. if (collision.GetComponent <Interactable>() != null && collision.GetComponent <Interactable>().IsInteractable || collision.GetComponent <ShopArea>() != null || collision.GetComponent <HealingTrigger>() != null) { PlayerController.Instance.OnInteracting += StartInteraction; if (collision.GetComponent <Interactable>() != null) { target = collision.GetComponent <Interactable>(); } else if (collision.GetComponent <ShopArea>() != null) { targetShop = collision.GetComponent <ShopArea>(); } else if (collision.GetComponent <HealingTrigger>() != null) { healArea = collision.GetComponent <HealingTrigger>(); } tmp = ObjectPool.Instance.GetFromPool(Emotion.Attention.ToString()); tmp.transform.parent = PlayerController.Instance.EmotionHolder; tmp.transform.localPosition = Vector3.zero; tmp.SetActive(true); } }
/// <summary> /// Checks if the interaction left the trigger. /// </summary> /// <param name="collision"></param> private void OnTriggerExit2D(Collider2D collision) { if (target != null || targetShop != null || healArea != null) { // Desubscribe to the event of player hitting action button. PlayerController.Instance.OnInteracting -= StartInteraction; target = null; targetShop = null; healArea = null; if (PlayerController.Instance.EmotionHolder.childCount > 0) { GameObject tmp = PlayerController.Instance.EmotionHolder.GetChild(0).gameObject; ObjectPool.Instance.AddToPool(tmp, Emotion.Attention.ToString()); } } }