How to get variable from another object?

I’ve searched and searched, but every single answer is something that doesn’t work. I get the feeling that the mechanisms they used as answers are no longer available in Unity, like the

playerScript.insertsomethinghere

That doesn’t work. On to my question:

How do I get a variable from another object? I need to find the move speed of the main character from another object, something like this:

		float thisObjectMove = GameObject.Find("mainCharacter").GetComponent("controllerScript".<float move>);

I know that is wrong, so how would I put this?

Let’s break that up into a few steps. It looks like you’re using C#.

First, find a GameObject by name:

GameObject go = GameObject.Find("mainCharacter");

Second, get a component:

controllerScript cs = go.GetComponent<controllerScript>();

Third, read a public field/property from that component:

float thisObjectMove = cs.move;

Putting all of that together:

GameObject go = GameObject.Find("mainCharacter");
controllerScript cs = go.GetComponent<controllerScript>();
float thisObjectMove = cs.move;

Splitting that up into multiple lines will make it easier to troubleshoot; compile or null reference errors will reference one line (and thus one step).