Generally when you see this type of thing in Unity:
public TileBase tileA;
… most often you are expected to:
- put an instance of this class on a valid GameObject
- select the GameObject
- drag the TileBase objects into the
tileA
field in the inspector
From the use of GetComponent<T>()
it would appear this script MUST be placed on the same GameObject that the Tilemap is placed upon.
Where did you get the code? Did you read how to use it? Code is only a tiny part of a game… you have to configure stuff properly or the code is irrelevant.
Also, in the future, if you post a code snippet, ALWAYS USE CODE TAGS:
How to use code tags: Using code tags properly
You may edit your post above.