If you have just one object in this scene that has a TileMovement component, you can find that unique instance like so:
void Start() {
tileMovement = FindObjectOfType<TileMovement>();
}
This is easy to find in the docs, and in gobs of tutorials online, so be sure to do some basic searching before posting here — you'll save yourself some time by answering your own questions without having to explain your situation and wait for someone to answer.
When you want to do this with a component you wrote yourself, another popular method is to make it a Singleton with a static instance getter, something like:
public class TileMovement {
static TileMovement _instance;
public static TileMovement Instance => _instance;
void Awake() {
if (_instance != null) {
Debug.LogWarning("Two TileMovement components in scene, but there should be only one!");
Destroy(this);
} else {
_instance = this;
}
}
}
Then code can just say TileMovement.Instance
when it wants to interact with that unique instance, without incurring any search cost, and without caching its own tileMovement
variable.
You want to be careful with singletons, because they're mutable global state (bug risk) and lock you into only ever having one (tricky to refactor if you later find a need for multiple), but the same goes for the FindObjectOfType
solution, so at least it's not adding new problems in that regard.