Calling a function from a PreFab

I’m trying to get a bullet to go in the direction of a gun in 2 dimensions, but I’m finding it hard to pass in the variable to the prefab.

if(Input.GetKeyDown(KeyCode.Space))
		{
		
			iBullet = Instantiate(bullet, transform.position, Quaternion.identity);
			iBullet.setDirection(gunRotation);
		}

The Prefab, bullet, has a script that has the setDirection function within it. How do I call this?

You must get the script with iBullet.GetComponent. A script becomes a custom component after compiled, and its type is the file name without any extension. Supposing that this script is BulletScript.js, its type is BulletScript - and you can do what you want this way:

    ...
    iBullet.GetComponent(BulletScript).setDirection(gunRotation);