Question by
inviasubito · Jul 10, 2016 at 04:18 PM ·
cameratexture2dscreen
converto text to texture2D
Hi, I would like to create a texture from a text. I tried to create a little screen with this method:
public IEnumerator MiniScreen()
{
yield return new WaitForEndOfFrame();
Vector3 posTmp = new Vector3(-Screen.width, 50);
RectTransform rectT = GetComponent<RectTransform>();
rectT.localPosition = posTmp;
//Camera go = Instantiate(cam);
//go.transform.parent = gameObject.transform.parent;
//go.transform.position = posTmp;
yield return new WaitForEndOfFrame();
Texture2D text2D = new Texture2D(Mathf.FloorToInt(rectT.sizeDelta.x), Mathf.FloorToInt(rectT.sizeDelta.y));
text2D.ReadPixels(new Rect(posTmp.x, posTmp.y, text2D.width, text2D.height), 0, 0, false);
text2D.Apply();
gameObject.AddComponent<RawImage>().texture = text2D;
}
but it only works if the coordinates fall within the view of the camera. How do I fix? Thank you!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612084550im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Frustrating problem with UI canvas (lines of canvas flicker around the edges of screen in game!!!) 5 Answers
Screen Space - Camera makes bullets fly in wrong directions 1 Answer
Inconsistency Result of ScreenPointToRay between UnityEditor and Real Device 0 Answers
How to sync RenderTextures so that they all render once per frame 0 Answers
Trying to Take a Snapshot of Only a Portion of the Screen In-Game 0 Answers