- Home /
Scaling and positioning Text Mesh
Good day guys! Since my other question is unaswered, I'll just ask the core problem.
I'm trying to scale and position my 3D Text Meshes depending on the screen sizes. What happens is when I tried it on another resolution, the GUI goes off the screen.
Here is my method in scaling and positioning:
void ScaleGUI()
{
float originalWidth = 300f, originalHeight = 598f;
float scaleX = Screen.width/originalWidth;
float scaleY = Screen.height/originalHeight;
scale = new Vector3(scaleX, scaleY, 1);
float positionX = 0f;
float positionY = 0f;
GameObject TestGUI;
positionX = (Screen.width) + ((Screen.width) * (TestGUI.transform.position.x/originalWidth));
positionY = (Screen.height) + ((Screen.width) * (TestGUI.transform.position.y/originalHeight));
Vector3 oldScale = TestGUI.transform.localScale;
Vector3 newScale = new Vector3(oldScale.x * scaleX, oldScale.y * scaleY, oldScale.z);
TestGUI.transform.localScale = newScale;
TestGUI.transform.position = new Vector3(positionX, positionY, TestGUI.transform.position.z);
}
Could someone tell me what's wrong in my solution. By the way, my GUI Camera is positioned at origin and I want to place the TextMeshes relative from there.
Any help would be much appreciated! :D
Still can't solve this. I'm out of ideas. There's no enough google results for this.
What exactly are you trying to do? Nobody will be able to help you if you don't say which effect you want to produce.
From what I can see, you have some strange dependencies in your script. If you call this function while having an other resoultion than the original, the scale will change every time even if the resolution stays the same. The new resolution must not depend on the old.
On another note. You seem to want to use this as a GUI. Why don't you just use GUI-Text? This is specially made for GUI and is therefor much easier to handle. Textmesh is made for floating letters in 3D-space.
I'm actually using GUITexture for icons and such in my other scenes. But I'm having problems with GUIText, like displaying scores for example, I can't get it to work right with other resolutions because the fontSize is forced to constraining proportions, if I'm describing it correctly. Is there a way to stretch the GUIText int x and y axis independently? Thanks!