Hallo everyone,
I have kind of a situation where I want to render Textmeshpro text over a sprite render element to make a screenshot from it to be able to send it as an image.
My parent is a canvas elment becuase the whole level is just 2D.
Then for the combination of two sprite rendert a foto and an overlay I have an extra camera.
Now I want to add some text over the overlay. The text changes depending on the time.
Question is: How can I render the TextmeshPro now over the overlay.
Here is how I combine the two images.
rt = new RenderTexture(1448, 2048, 24);
fotoCam.targetTexture = rt;
screenShot = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false);
// Die Kamera rendern, einschließlich des Overlays
fotoCam.Render();
// Gelesene Textur aus der Kamera-Render-Textur
RenderTexture.active = rt;
texture = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false);
texture.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
texture.Apply();
byte[] bytes = texture.EncodeToPNG();
var fileWasWrittenSuccessfully = false;
while (fileWasWrittenSuccessfully == false)
{
try
{
using (FileStream fs = new FileStream(Path, FileMode.Create))
{
fs.Write(bytes, 0, bytes.Length);
fs.Close();
}
fileWasWrittenSuccessfully = true;
}
catch (IOException)
{
fileWasWrittenSuccessfully = false;
}
}
Thanks in advance