script unknown error C#

Hey there, well I’m new in unity and I’m having some issues, since I don’t really know what’s wrong in my script I thought maybe you could help me understand my mistake so here it is:

using UnityEngine;

using System.Collections;

public class Activator : MonoBehaviour {

public KeyCode key; bool active =false;

GameObject Note;

void Start () {
}
void Update () { if (Input.GetKeyDown(key)&&active){ Destroy(Note);

} } void OnTriggerEnter2D(Collider2D col){ active=true; if(col.gameObject.tag == “Note”) { Note=col.gameObject; } } void OnTriggerExit2D(Collider2D col){ active =false; } }

I was trying to make my first game project following the example on this video:

but for some reason my code doesn’t work even if it’s basically the same, I hope you can help me guys getting the answer, thank you for taking the time to read this. Have a good day

Use code tags. Plus the error that the console is spitting out would also help.

The Gameobject field “Note” is private, but it looks like you want to assign it on collision. However, you are assigning the game object via a tag. Does this object, that is a ‘Note’ have the “Note” tag?

1 Like

Ok thank you

Yes it does have the Note tag

This is what I meant by code tags:

I’ll try to use this exemple in order to fix my original code tags errors thanks man

In the posted tutorial the activator serves as a collision detector. This activator will register collision information from “Notes” (other game objects) that collide with the activator.

The activator needs a collider, with the “Is Trigger” box selected.

Your notes need to have a collider as well as a rigidbody component.