- Home /
How can i place 3D Text to the corner of the screen?
So how can i place 3D Text to the corner of screen? I need it ,because screens have different resolutions. How can i do this? Found this script but in different resolutions it works not correct;
public Transform objectTarget;
public Vector3 screenPosition = new Vector3(10000,-2000,0);
// Use this for initialization
void Update ()
{
if(objectTarget != null)
{
objectTarget.transform.position = camera.ScreenToViewportPoint(screenPosition);
}
}
Answer by robhuhn · Aug 21, 2013 at 11:33 AM
I just made quick test where this script is attached to a TextMesh:
@edit - some improvements
using UnityEngine;
[RequireComponent(typeof(Renderer))]
public class ScreenToWorldAlignment : MonoBehaviour
{
public Vector2 screenPosition = new Vector2(0, 0);
void Update ()
{
Vector3 tempScreenPosition = screenPosition;
tempScreenPosition.z = -Camera.main.transform.position.z;
Vector3 worldPosition = Camera.main.ScreenToWorldPoint(tempScreenPosition);
worldPosition.x -= renderer.bounds.size.x * tempScreenPosition.x / Screen.width;
worldPosition.y += renderer.bounds.size.y * (1 - tempScreenPosition.y / Screen.height);
transform.position = worldPosition;
}
}
This works! If its not too hard for you could you make for all corners :)
it's dynamic and works for all positions on screen now. So Screen.width .5 and Screen.height .5 will center the text.
I can't remember the previous code exactly but this one implies the previous code. What are you missing?
Answer by ThomasB · Aug 21, 2013 at 10:41 AM
Not really, because the object is in 3D space. But what you could do is:
Move the 3D text in the scene view so it appears in the top right of the camera shot - Game View .
Then drag the 3D text under the Main Camera object in the hierarchy panel (so whenever the camera turns the 3D text should stay fixed in position).
Answer by Mikosko · Aug 21, 2013 at 12:00 PM
Create GUI camera with UI layer and add 3D Text to UI layer and set on GUI camera Culling Mask to UI layer.
Then Set on GUI camera Clear Flags to Depth only. Set Field of view, Far and Depth.
I don't try it.
Answer by gordonbuyck · Apr 05, 2016 at 02:40 AM
Select the object that you would like to be placed on any of the corners of the screen (as long as object is a UI) and in the inspector panel and in the Rect Transform you should see a square picture click on that picture and set the desired position and after you click that and you press play the Object will still be where ever you left it so from their just grab it and place near to the anchor point you chose and your done.
Your answer
Follow this Question
Related Questions
instantiate object at the edge of screen 1 Answer
How to maintain high resolution custom background images for GUI elements on different screen sizes? 0 Answers
Pick sensible resolution for FullScreen Mac App 2 Answers
Screen.SetResolution doesn't work when the game starts windowed? 0 Answers
Make buttons visible in the editor? 2 Answers