- Home /
Question by
zcoldrick · Jan 24, 2014 at 08:52 PM ·
c#textmeshboxcollider
Reset Boxcollider around new text
I created some 3d mesh text from a prefab with an attached boxcollider.
The next text is may be larger or smaller than the original text in the prefab but the boxcollider remains the same size. This is a problem because I am using it to detect when the mouse interacts with the auto generated text.
Ordinarily I would resize the boxcollider for the text size by clicking the gear icon and selecting reset.
I would like to know if a similar operation is available to be called in c#?
using UnityEngine;
using System.Collections;
public class GUITest : MonoBehaviour {
// External Classes, GameObjects and Transforms
public GameObject TextPrefab;
void Start() {
Resolution[] resolutions = Screen.resolutions;
string[] listOfResolutions = new string[resolutions.Length];
float xPos = -8.5f;
float yPos = 1.67014f;
float zPos = -1.3f;
Vector3 textPos = new Vector3(xPos,yPos,zPos);
for (int i = 0; i < resolutions.Length; i++)
{
listOfResolutions[i] = resolutions[i].width + "x" + resolutions[i].height + " ";
GameObject Text;
Text = Instantiate(TextPrefab) as GameObject;
Text.renderer.enabled = true;
Text.transform.position = textPos;
if ((i%6 == 0)&&(i != 0)){xPos += -2.0f; yPos = 1.67014f; zPos = -1.3f;}
Text.GetComponent<BoxCollider>(); // not sure how to reset size to new text
TextMesh t = Text.GetComponent<TextMesh>();
t.text = listOfResolutions[i];
t.transform.position = new Vector3(xPos, yPos,zPos);
zPos += 0.5f;
t.name = listOfResolutions[i] + "_Text";
}
}
}
Comment
I ended up deleting the old prefab boxcollider and adding a new one which seemed to work.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Renderer on object disabled after level reload 1 Answer
Showing position by using TextMesh 0 Answers