Creating Sprites from a script

Is it possible to, in a script, create a Sprite or other game object with custom coordinates and one of several images in its renderer? Would something like this work:
```
~~public class Galaxy extends Sprite
{
int someVariable;
int anotherVariable;

public Galaxy(int a, int b)
{
    someVariable = a;
    anotherVariable = b;
}

}

public void Start()
{
Galaxy gal = new Galaxy(5, 27);
gal.pos.x = 0;
gal.pos.y = 0;
gal.overideGeometry()

etc...

}~~
```

All I would need to do is create an array of several separate game objects that are all the same size, shape, and have the same starting coordinate. The only difference would be the image file each uses.

I’m having trouble seeing what you could do with a class derived from Sprite that you couldn’t do with a class that contains a Sprite.

Unity really likes the “has-a” architecture of things more than the “is-a” way of doing it, but of course you can do either.

For how I understand your problem, I would choose to use Unity’s built-in scripts to do it, and you can certainly make sprites on the fly to your hearts content.

Look up Sprite.Create() and that should get you where you want. If your galaxy is N x M in size, have an array of sprites that shows the contents of each cell. You can keep references to that inside your own custom Galaxy class, and have that contain all the logic necessary for it.

In that case each cell is a separate game object. If that bugs you then you can make your own custom procedural geometry to display whatever you want on the fly too, but I would start with N x M cells first.

I am sorry about being so confusing about what I wanted, really I just want to be able to create a number of separate game objects with a fixed size, coordinates and some image from a file. Now that I think about it, the “Galaxy” class just makes everything more complicated than it should be. The reason I had the class the way it was is that that is the only way to make a class that is attached to another.

I will change what I have in my original post

Perhaps what you want is a GalaxyFactory class that contains all the logic for fabricating a new one, or (perhaps) loading it from a save file.