How do I get a Script from another Script?

In my script it dynamically makes a tiled map that has a script within each tile. Then, at some point, it will call a function within those scripts. The problem is that it doesn’t seem to find the scripts. So far I made this:

public void TestScript(){
	List<Vector2Int> tiles = GetTilesInRange(new Vector2Int(size / 2,size / 2),3);

	foreach(Vector2Int tile in tiles){
		HighlightTest temp = mapTiles[tile.x,tile.y].GetComponent(typeof(HighlightTest)) as HighlightTest;
		Debug.Log(temp.name);
	}

}

I thought it would print “HighlightTest”, but instead it returns the name of the tile. How do I get the Script to recognize that it should get the script?

The name property actually returns the name of the GameObject for Components (scripts) as well. It usually prints the type in brackets after the label, something like “MySmallTile (HighlightTest)”. So in fact, the variable temp should contain a reference to your script, if it isn’t null. You can access members (fields and methods) of it if they are declared public.