How to get a reference
"How do I access a variable from another script?" is usually one of the first questions we ask when learning Unity. Whether you are C# beginner or a C# professional, understanding the way Unity does things differently can be confusing.
🌳 If the objects are already present in the scene hierarchy...
... then you can use the SerializeField attribute on a field, and assign it by dragging the object which has the script you want to access onto the field slot. This also works if the two scripts are on the same object.
[SerializeField] private SomeScript someScript;
If the objects are instantiated prefabs...
... then you can use a form of injection after you call Instantiate:
SomeScript.cs
public GameManager TheManager { get; set; }
GameManager.cs
var clone = Instantiate(prefab);
clone.GetComponent<SomeScript>().TheManager = this;