- Home /
How to change 3d text font on mouse enter?
I'm making a main menu for a game. Im using 3d text, not GUI. The "start game, quit game" buttons are going to start out in a greek language font, but I want it to change to the english translation when the player moves the mouse cursor over the word. how would I go about doing this?
Answer by 1elfdragon1 · Feb 09, 2014 at 08:10 PM
first you add a collider to the text, there is a fuction called "OnMouseOver" and "OnMouseExit"
if the mouse is on the text you need to get the "Text Mesh" Component, there you can change the color.
the code (C#) needs to look something like this:
public Color OnMouseOverColor = Color.yellow;
public Color OnMouseClickColor = Color.red;
public Color OnMouseExitColor = Color.white;
void OnMouseOver()
{
GetComponent<TextMesh>().color = OnMouseOverColor;
if (Input.GetButton("Fire1"))
{
GetComponent<TextMesh>().color = OnMouseClickColor;
}
}
void OnMouseExit()
{
GetComponent<TextMesh>().color = OnMouseExitColor;
}
that changes the color, but i need to change the font style
then use this:
GetComponent<Text$$anonymous$$esh>().fontStyle = FontStyle.Bold;
you can just take "GetComponent()."
and after the dot what you want to edit.
Your answer
Follow this Question
Related Questions
Change camera on text click? 1 Answer
Strange Error: Shader wants normals, but the mesh doesn't have them 3 Answers
Text map problem with 3d text 1 Answer
How to find a font via script? 2 Answers
3D Text Mesh produces wrong letters 1 Answer