How to use functions in a script associated with a prefab?

Hi, I’m new to unity and some concepts are still new to me, especially this prefab business. I’m creating a game and I have a prefab called ‘knight’ with a script attached to it called “Knight”, and inside this script is a function called “MoveTowardsMouse”. I want to create instances of the knight dynamically so I have an empty Game Object with a script that goes like this:

public GameObject kk;
public GameObject knight;

void Start () {
	 kk = (GameObject) Instantiate (knight, transform.position, transform.rotation);
}

Now my kk object was defined to be a GameObject so there is no way I can tell it to use “MoveTowardsMouse”, but the instantiate code is the only way I’ve found to create prefabs with code. What’s the better way to do this (without just dragging 100 knight prefabs on the screen when i need them)?

If you do:

kk.GetComponent<Knight>().MoveTowardsMouse()

it should work.