How to create a game object through a function

I’m trying to figure out how I can get this function to work as I often need to use it and using copy/paste all the time is getting messy.

var infoSymbol : GameObject ;
var infoSymbolButtonComponent : UIButton;

function DoesPageNeedInfoSymbol()
{
	// First page
	if (currentPageNumber == 0)
	{
		MakeInfoSymbol(infoSymbol,Vector3(196.3,-49.8,202));
		
		
		// Get the reference to ezgui component of the button
		infoSymbolButtonComponent = infoSymbol.GetComponent(UIButton);
		
		//Set the method to invoke up
		infoSymbolButtonComponent.scriptWithMethodToInvoke = this;
		infoSymbolButtonComponent.methodToInvoke = "extra_1";	
	

}

function MakeInfoSymbol(symbolGameObjectName : GameObject, Pos : Vector3)
{
	symbolGameObjectName= Instantiate(Resources.Load("infoSymbol", GameObject));
	symbolGameObjectName.renderer.sharedMaterial.mainTexture = Resources.Load("loaded_book_1", Texture2D);
	symbolGameObjectName.transform.position =Pos;
	infoPageNumber = currentPageNumber;	
	
}

But I keep getting an error saying The variable infoSymbol of ‘bookManager’ has not been assigned. From this line:

	infoSymbolButtonComponent = infoSymbol.GetComponent(UIButton);

Unless you assign a GameObject to infoSymbol at any point in your script (as I see you do in the commented out line just above) you will always get a null reference exception here. Try adding

infoSymbol = symbolGameObjectName;

at the end of your MakeInfoSymbol() function.
Better yet, have MakeInfoSymbol() return a GameObject, and then assign infoSymbol to it in your DoesPageNeedInfoSymbol function, like so:

function MakeInfoSymbol(symbolGameObjectName : GameObject, Pos : Vector3)  :  GameObject
{
    symbolGameObjectName= Instantiate(Resources.Load("infoSymbol", GameObject));
    symbolGameObjectName.renderer.sharedMaterial.mainTexture = Resources.Load("loaded_book_1", Texture2D);
    symbolGameObjectName.transform.position =Pos;
    infoPageNumber = currentPageNumber;    
    return symbolGameObjectName;
}

you also may want to make the symbol prefab be a public GameObject var at the top of your script so that it can be assigned in the editor, and then instantiated without using awkward string-literal resource loading.

Select the object you have attached this script onto, then in the inspector you can select the info-object needed for the script.

You can also find gameobjects by code, with GameObject.Find(“{name of it}”);

If you need to spawn it, you can just make a variable like:
var go:GameObject = new GameObject();