Communicating In Code: Using GetComponent in Unity

How can we identify and reference the target script from the first script? The GetComponent function (plus some other bits)!

We first need to identify and get the GameObject it is on, and then get the component itself.

Five different ways to find the target and execute the command:

Getting the Component on the GameObject:

The GetComponent function is the in-built Unity function used to get a specific component from a target GameObject.

I prefer the top one

If the target component is on the same GameObject, you can just write it as above.

If the target component is on another different GameObject, you need to specify which GameObject as a prefix to the function, like either of these: