How to add a Cube(mesh filter) and MeshRender in my Class?

I want to
add a 3d cube in my base class source code.
add a texture to it.
and then render it on the screen.

Atm I only know how to do all of this by the menu GameObject-CreateOther-Cube. If i do it that way, the problem is that the 3d cube(mesh filter) and MeshRender isn’t in my source code. I don’t know the code to add this in my source code.

My project atm is I’m making a Trading Card Game editor and i want the 2d card images attached to a 3d flattened cube. I have a base class that all other cards inherit from.
I need the code to add a cube (mesh filter)and rendermesh in the source code of the base class. then my inherited classes would add their own image.

can anyone help?

Well, by the sounds of it, you’re still going to be assigning the meshfilter’s mesh via the inspector, but you can get access to it one of two ways.

Either create public attributes for them, or use get component.

public MeshFilter meshFilter;

Or,

private MeshFilter meshFilter;

void Awake()
{
    meshFilter = GetComponent < MeshFilter>();
}

Then acces them via the variables ‘meshFilter’ and ‘meshFilter.mesh’.