- Home /
Have GUI element enter screen on trigger
I am currently working on a script that is attached to my player character game object which should cause a UI element to enter the screen when they enter a 2D circle collider of an NPC game object. So far I have not even been able to get the script to detect wether the player has collided with the NPC's proximity collider.
public class ConvoRegulator : MonoBehaviour {
public GameObject ConvoUI;
public GameObject Player;
Animator ani;
void Awake () {
ani = ConvoUI.GetComponent<Animator> ();
}
public bool IsInside = false;
void OnTriggerEnter(Collider collider)
{
IsInside = true;
if(collider.tag == "NPC") // this string is your newly created tag
{
ani.SetTrigger ("Enter");
IsInside = true;
}
}
void OnCTriggerExit(Collider collider)
{
IsInside = false;
if(collider.tag == "NPC") // this string is your newly created tag
{
ani.SetTrigger ("Exit");
IsInside = false;
}
}
}
This will be used to bring up a box with dialog options when the player approaches and NPC and lower the box back off screen when the player leaves. Any suggestions on how to get this to work or how to change it are greatly appreciated.
Answer by oedandthewhale · Sep 02, 2018 at 11:16 PM
using this fixed my issue
void OnTriggerEnter2D (Collider2D col) {
Your answer
Follow this Question
Related Questions
Playing mode not working for even an empty project with Unity 2019.1.1f1 1 Answer
get only one colliding body 3 Answers
OnTriggerEnter being called multiple times 0 Answers
OnTriggerEnter called much less often after a player respawn? 1 Answer
How do I use colliders and/or triggers to end the game? 1 Answer