- Home /
OnTriggerEnter2D crashing editor
Hello, I have never asked a question on here before so apologies if my formatting is off.
I am very new to programming and teaching myself the basics of c# at the same time that I am teaching myself the basics of Unity. Ive never showed anyone my code before either lol so go easy on me.
What I would expect this to do is when it enters a 2d trigger collider, it checks that the tag of the associated game object is "Interact Target," then sets the interactTarget gameobject to be whatever was collided with. Then it finds the "InteractTrigger" script thats on the target gameobject. Then it changes the text
Here is the relevant code: (this is not the entire script, I can put it here if needed?)
public GameObject interactKeyAlert;
public string interactTargetNameText;
public TextMeshProUGUI interactTargetNameTextObject;
GameObject interactTarget;
InteractTrigger interactTargetTrigger;
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Interact Target"))
{
interactTarget = collision.gameObject;
interactTargetTrigger = interactTarget.GetComponent<InteractTrigger>();
interactTargetNameText = interactTargetTrigger.interactName;
interactKeyAlert.SetActive(true);
}
I know the code is super messy LOL, like I said I am very new to scripting and just experimenting at the moment. If theres anything that doesnt make sense from that snippet let me know and I will try to explain
Thank you!