- Home /
How to make font bold on mouse over (c#)
Sorry, I'm still new to unity and unfamiliar with the language, basically my goal is to have my 3D text turn bold when mouseovered. Right now it changes color but I just can't figure out what to use to turn it bold. I've tried fontStyle but I keep getting errors. What would I need to change to make the text turn bold?
The script looks like this:
public class ClickableText : MonoBehaviour {
public bool isQuitButton = false;
public bool isStartButton = false;
public bool isOptionsButton = false;
public bool isHelpButton = false;
public bool isCreditsButton = false;
void OnMouseEnter () {
renderer.material.color = Color.red;
}
void OnMouseExit () {
renderer.material.color = Color.white;
}
void OnMouseUp() {
if (isQuitButton) {
Application.Quit ();
}
if (isStartButton) {
Application.LoadLevel ("Level 1");
}
if (isHelpButton) {
Debug.Log ("Help");
}
if (isOptionsButton) {
Debug.Log ("Options");
}
if (isCreditsButton){
Debug.Log ("Credits");
}
}
}
Please excuse the messy script, but I wanted to have one script apply to all of the text options. Thanks in advance
Answer by thornekey · May 07, 2014 at 01:39 AM
You can use:
guiText.fontStyle = FontStyle.Bold;
or this:
EditorGUILayout.LabelField("Inspector", EditorStyles.boldLabel);
Answer by robertbu · May 07, 2014 at 01:43 AM
You need to get access to the TextMesh component. There is not a shortcut like there is for guiText, so you need to use GetComponent(). The font must be marked as Dynamic in the Importer/Inspector. A few lines added to your code:
using UnityEngine;
using System.Collections;
public class ClickableText : MonoBehaviour {
public bool isQuitButton = false;
public bool isStartButton = false;
public bool isOptionsButton = false;
public bool isHelpButton = false;
public bool isCreditsButton = false;
private TextMesh tm;
void Start() {
tm = GetComponent<TextMesh>();
}
void OnMouseEnter () {
renderer.material.color = Color.red;
tm.fontStyle = FontStyle.Bold;
}
void OnMouseExit () {
renderer.material.color = Color.white;
tm.fontStyle = FontStyle.Normal;
}
void OnMouseUp() {
if (isQuitButton) {
Application.Quit ();
}
if (isStartButton) {
Application.LoadLevel ("Level 1");
}
if (isHelpButton) {
Debug.Log ("Help");
}
if (isOptionsButton) {
Debug.Log ("Options");
}
if (isCreditsButton){
Debug.Log ("Credits");
}
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Help with making a triggered gui message 1 Answer
Ui text to string ? 1 Answer
How do I call an DontDestroyOnLoad function on UI text 2 Answers