Create GameObjects and changing its texture

Hello.
My problem looks very simple, I want to:
Spawn object on the point where I clicked.

But my problem is I want also to assign every gameobject just generated texture.

The concept is I have a class which gives me an int array and two numbers Hue and Value. (and every number in array is the Set element). I want my new game object to have that array as a texture. So I did something like that:

public class PartGeneratorScript : MonoBehaviour
{
    PartGenerator partSpriteGenerator=new PartGenerator(5,5);
    public Texture2D texture;
    // Start is called before the first frame update
    void Start()
    {
        partSpriteGenerator.GenerateBitmap(5);
        texture = new Texture2D(partSpriteGenerator.PartBitMap.GetLength(0), partSpriteGenerator.PartBitMap.GetLength(1));
        for(int i=0; i<texture.width; i++)
            for(int j=0; j<texture.height; j++)
            {
                texture.SetPixel(i, j, Color.HSVToRGB(partSpriteGenerator.Hue,partSpriteGenerator.PartBitMap[i,j],partSpriteGenerator.Value));
            }
        texture.Apply();
        
    }
}

But now I’m stuck and don’t know where to begin.
I thought it will be easy just like: In PlayerControl when Q key is pressed: GameObject newGameObject and then something like newGameObject.texture=PartGeneratorScript.texture but it seems like I’m missing the concept because it’s not that easy. Could someone just push me in right direction of thinking? I’ve seen topics about spawning game object on the pointer position but it was just code and I don’t know where to put this code. Also changing texture of game object chagned since 2015 because the topics I found had where from that year or earlier and the code just doesn’t work.
Thanks in advance.

So I’ve achieved something and now I’m stuck in other place.

I changed the PartGeneratorScript and assigned it to empty GameObject.

Now PartGeneratorScript looks like this:

public class PartGeneratorScript : MonoBehaviour
{
    PartGenerator partSpriteGenerator=new PartGenerator(5,5);
    Texture2D texture;
    GameObject part;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("SpawnPart"))
        {
            part = new GameObject();
            partSpriteGenerator.GenerateBitmap(5);
            texture = new Texture2D(partSpriteGenerator.PartBitMap.GetLength(0), partSpriteGenerator.PartBitMap.GetLength(1));
            for (int i = 0; i < texture.width; i++)
                for (int j = 0; j < texture.height; j++)
                {
                    texture.SetPixel(i, j, Color.HSVToRGB(partSpriteGenerator.Hue, partSpriteGenerator.PartBitMap[i, j], partSpriteGenerator.Value));
                }
            texture.Apply();
            part.GetComponent<Renderer>().material.mainTexture = texture;

            Instantiate(part, transform.position, transform.rotation);

        }
    }
}

And when I press the button game object appears in the standard position. So the last problem is my gameobject ‘part’ doesn’t have a texture and I don’t know why. Can someone help?