- Home /
Question by
sona.viswam · Aug 23, 2013 at 04:18 AM ·
c#checkbox
CheckBox in unity3d
I created check box using code
public bool allOptions = true;
ONGUI
allOptions = GUI.Toggle(new Rect(300, 300, 80, 50), allOptions, "ON/OFF");
How can i increase size and color of check box
Comment
Best Answer
Answer by clunk47 · Aug 23, 2013 at 06:17 AM
EDIT: Try this workaround. Use a GUI Button to toggle allOptions boolean, and use GUI.Content to set an image that becomes active / inactive depending on the allOptions bool being true or false, which is toggled by the button click. Use a label to the side of the button for your On/Off text, which can have its own style like in my exmaple.
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour
{
public Texture2D texture;
GUIContent content = new GUIContent();
string label = "ON/OFF";
Rect checkBoxRect;
Rect labelRect;
bool allOptions = true;
GUIStyle labelStyle;
void Awake()
{
labelStyle = new GUIStyle();
labelStyle.fontSize = 32;
labelStyle.normal.textColor = Color.red;
labelStyle.fontStyle = FontStyle.Bold;
checkBoxRect = new Rect(0, 0, 64, 64);
labelRect = new Rect(68, 16, 128, 32);
}
void Update()
{
if(allOptions)
content.image = texture;
else
content.image = null;
}
void OnGUI()
{
GUI.Label(labelRect, label, labelStyle);
if(GUI.Button (checkBoxRect, content.image))
allOptions = !allOptions;
}
}
1.png
(5.5 kB)
Edited answer to address your question more appropriately.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
A node in a childnode? 1 Answer
Distribute terrain in zones 3 Answers
Unity: C#: Eyes look at mouse: HELP!! 3 Answers
C# how to make Character Motor Jump Infinitely Upward 2 Answers