- Home /
SOLVED - Assign mesh collider to fit 3d Text perfectly
Hello Guys,
Please help me out. I am dynamically adding 3d text to a scene, which is supposed to be dragged, resized, rotated all over the scene OnMouseDown event. The same I could perfectly do with pictures, but I have problem with assigning a collider to fit the exact size of the 3d text. I tried both mesh and box colliders, but in both cases default setting colliders are smaller than the size of the 3d text, meaning that if I drag a corner of the text, nothing happens unless I drag the middle of the 3d text. So far the code is below, as always I thank you for any kind of suggestions.
var GameObjectString = "TextRotator"+TextCounter; //Set Textrotator name
var go = new GameObject(GameObjectString); //ADD Parent called Textrotator for rotation event
var TheText = new GameObject("Text"); //Add 3d text
TheText.transform.parent=go.transform; //Assign 3d text to parent
TheText.transform.parent.localScale=Vector3(1,1,1); //Set scale to original size
var textMesh = TheText.AddComponent("TextMesh"); //Add text mesh
TheText.AddComponent("MeshCollider"); //Add mesh collider to 3d text
Answer by srancsik · Oct 04, 2013 at 08:49 AM
Finally figured it out. I was adding the collider earlier than adding the TextMesh. If you put the box collider to the end of the code it fits the actual size of the 3d text perfectly.