- Home /
Center TextMesh to 3DModel
Hey guys,
we try to center a 3Dtext (textmesh) to a 3DModel while changing the camera. At the moment we have a code like this:
descriptionText.transform.position = b.GetComponent<Transform>().position
+ new Vector3(0,10,0);
Camera.mainCamera.WorldToViewportPoint(descriptionText.transform.position);
descriptionText.transform.rotation = Camera.mainCamera.transform.rotation;
At first we change the position of the textmesh to the 3DModel, then we change the viewport and rotation of the textmesh, so it looks at the camera. Now we have the problem, that the text begins at the centre of the 3DModel, thus the text is shifted (depends on camera position and rotation).
Does anyone have a solution for this problem?
Answer by skovacs1 · Nov 01, 2010 at 02:55 PM
What exactly are you doing with that Camera.mainCamera.WorldToViewPortPoint? You call the function but never use the returned value.
If your TextMesh component is anchored at the center, then simply setting the position of the TextMesh to the position of the object would do the trick.
//Also, since all components can access the inheritted property transform, //you don't need the GetComponent.
descriptionText.transform.position = b.transform.position; descriptionText.transform.LookAt(Camera.mainCamera.transform, camera.mainCamera.transform.up);
If you are talking about GUIText components, then those would use viewport coordinates and ignore rotation.
descriptionText.transform.position =
Camera.mainCamera.WorldToViewportPoint(b.transform.position);
Your answer
Follow this Question
Related Questions
Calculate pixel length of string (not GUI) 1 Answer
How to set RectTransform size relative to the size of the textbox? 1 Answer
3DText with outline 0 Answers
3D Text bug (text disappearing) 3 Answers