|
I created a new GUIStyle for a button, the normal color, font, alignment is set properly, but backgrounds and other states text color aren't working, does anyone have a clue of what's wrong? Here is the simplified code of what I'm doing: and I'm drawing it like this:
(comments are locked)
|
|
have you tried making a copy of the default button first?
then modify that style
(comments are locked)
|
|
try code below. it works fine, just put 'bg1' and 'bg2' to Resources folder. then check your code again - it seems you miss something. if you unable to find solution, post your whole code here. DynamicGUIStyle.csusing UnityEngine;
using System.Collections;
public class DynamicGUIStyle : MonoBehaviour
{
public Rect rect;
public string label;
Texture2D _img;
Texture2D _img2;
GUIStyle style;
void Start()
{
_img = (Texture2D)Resources.Load("bg1");
_img2 = (Texture2D)Resources.Load("bg2");
style = new GUIStyle();
style.font = (Font)Resources.Load("Fonts/Arial");
style.active.background = _img2; // not working
style.hover.background = _img2; // not working
style.normal.background = _img; // not working
style.active.textColor = Color.red; // not working
style.hover.textColor = Color.blue; // not working
style.normal.textColor = Color.white;
int border = 30;
style.border.left = border; // not working, since backgrounds aren't showing
style.border.right = border; // ---
style.border.top = border; // ---
style.border.bottom = border; // ---
style.stretchWidth = true; // ---
style.stretchHeight = true; // not working, since backgrounds aren't showing
style.alignment = TextAnchor.MiddleCenter;
}
void OnGUI()
{
GUI.Button(rect, label, style);
}
}I'm sorry guys, my mistake, I was putting the images inside a "Images" folder, forgot to put it in the path :( I'm very sorry
Aug 01 '12 at 05:45 PM
badjano
(comments are locked)
|
|
I'm sorry guys, my mistake, I was putting the images inside a "Images" folder, forgot to put it in the path :( I'm very sorry
(comments are locked)
|
|
Why don't you do it with editor like this ? I'm trying to do a framework that is all code, except for images and fonts
Aug 01 '12 at 01:40 PM
badjano
I'm sorry guys, my mistake, I was putting the images inside a "Images" folder, forgot to put it in the path :( I'm very sorry
Aug 01 '12 at 05:45 PM
badjano
(comments are locked)
|


did you check _img2 and _img for null?
yes, if I put the _img# in a GUI.box or a GUI.drawTexture it works... :(
are these two parts of code are in same method and executed coherently?
the first part is in the constructor, the second part is called within the OnGUI scope
check style variable in OnGUI scope, for exaple
- does it have at least one property you'd set in constructor?