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.