- Home /
Help labeling a 3d object
I recently took over a project and need help labeling the parts of a 3d model of a heart.
Goal:The labels need to pop up when the corresponding part of the heart is clicked and turn off when I click off the heart or another part is clicked.
Currently:
The person before me made box colliders attached to the heart that when clicked make the label appear. (There are a multiple for every section of heart.
He used title bars for the text of the labels
The labels are called upon once clicked
The animator has 2 functions for this project, one helps the heart to beat and the other uses a mask to make the labels come up nicely.
Problem UPDATE The other problems have been resolved. The only problem right now is once a label is clicked and you click another part and then turn off the second one the first one is still on.
Ex. 1. Click aorta -> aorta label pops up-> 2. click left atrium -> left atrium label pops up (can't see the aorta label anymore) -> 3. click left atrium again to turn off labels -> left atrium turns off but aorta label shows still
UPDATE After completing the last step in the above example the label (canvas & text boxes) are still there they are just now blank.
I can think of 2 ways to solve this problem.(I just don't know how to do them)
Make it so that the space bar or middle mouse button turn off all of the labels
or
Is it possible to make another canvas that is blank that it changes to? and is it possible to swap between the blank and labeled one?
The current label manager script:
public class ToggleLabel : MonoBehaviour {
public string title = "Update this name";
public string text = "Update this descriptive text";
public bool isClicked = false;
Animator anim;
public GameObject titleText; //assign by dragging in editor
public GameObject copyText; //assign by dragging in editor
public GameObject NoLabel;
void Awake()
{
anim = GameObject.FindGameObjectWithTag ("Canvas").GetComponentInChildren<Animator> ();
//copyOptions = GameObject.FindGameObjectWithTag ("Canvas").GetComponentsInChildren<Text>();
}
void OnMouseUp()
{
if(!isClicked)
{
isClicked = true;
titleText.GetComponent<Text>().text = title;
copyText.GetComponent<Text>().text = text;
anim.SetTrigger ("DrawLabel");
}
else
{
titleText.GetComponent<Text>().text = "";
copyText.GetComponent<Text>().text = "";
anim.SetTrigger ("RemoveLabel");
isClicked = false;
}
}
}
I'm only starting to learn the new UI syste, but your project looks cool so I'm giving it a bump!
Problem 1: is 'Horizontal Overflow' set to 'Wrap' in the Text component?
I would also check to see if the text Rect Transforms' heights are large enough to fit multiple lines I guess.
I changed the vertical overflow to overflow from truncated and that seemed to fix the issue there! Now it just look super pixelated
Answer by hnmikechan · Jun 26, 2015 at 07:09 PM
Im not sure what the animator is doing, but I would do this for a simple case. Assuming there is only one text object for title, and one for description in the scene:
Animator anim;
public GameObject titleText; //assign by dragging in editor
public GameObject copyText; //assign by dragging in editor
//Text[] copyOptions;
void Awake()
{
anim = GameObject.FindGameObjectWithTag ("Canvas").GetComponentInChildren<Animator> ();
//copyOptions = GameObject.FindGameObjectWithTag ("Canvas").GetComponentsInChildren<Text>();
}
void OnMouseUp()
{
if(!isClicked)
{
isClicked = true;
//titleText = copyOptions [0];
//copyText = copyOptions [1];
titleText.GetComponent<Text>().text = title;
copyText.GetComponent<Text>().text = text;
anim.SetTrigger ("DrawLabel");
}
else
{
titleText.GetComponent<Text>().text = "";
copyText.GetComponent<Text>().text = "";
anim.SetTrigger ("RemoveLabel");
isClicked = false;
}
}
Sorry for not getting to you sooner, from my understanding the animator in reference uses a mask to make the labels appear as a transition ins$$anonymous$$d of just appearing.
What do you mean by assign by dragging in editor?
Edit** This is the error I get(without dragging in the editor):
GetComponentInChild' of type `UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?)
I think I can imagine what the animation does. If you go into the animation tab of the 'Canvas' gameobject you'll maybe see animation keys for transforms that have titleText and copyText. Anyways, that shouldn't cause a problem.
For the assign by dragging in editor: when you set a variable to 'public' (ex. public GameObject titleText;), that will allow you to assign the public variables visually through the editor. So if you use the code I gave you, click on the gameobject that has that script and you should see the script as a component in the inspector. You'll also notice titleText and copyText as being unassigned. Just drag the titleText gameObject from the scene into the component to assign it. And repeat with copyText.
Sorry I edited my answer. Just change both GetComponentsinChild() to GetComponent()
Check my edited answer to see if that helps. It clears the labels values when clicked a 2nd time to turn them off.
Your answer
