[SOLVED] Can`t access method in other script

Hello everyone,

Im having issues accessing a method in another script. I looked it up and found the same answer in many places, but I cant make it work. I keep getting error ˜Object reference is not an instance of an object˜

I`m doing it like this:

public class SpawnBg : MonoBehaviour {

GameManager gm;

void Awake () {
gm.GetComponent ();
}

public void OnTriggerEnter2D (Collider2Dcol) {
if (col.CompareTag(“Player”)){
gm.BackgroundSpawn();
}
}
}

GameManager is my other class that I need to access. Help plz!
Thank you!

Is your GameManager script attached to the object that has the SpawnBg script?

If not, use :

gm = GameObject.FindObjectOfType(typeof(GameManager)) as GameManager;

to find it.

It Worked! Thank you so much!