🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

using an image as background for UI element

Started by
-1 comments, last by rogerdv 9 years ago

Im trying to create a sort of dialog window, which should have an image as background. I have tried using GUIContent, but cant make it work:


public Texture2D backg;

void OnGUI() {
		if (render) {
			GUIStyle style = new GUIStyle();
			GUIContent bg = new GUIContent();

			style.alignment = TextAnchor.UpperLeft;
			
			style.normal.textColor = Color.white;
			style.fontSize = 14;
			style.fontStyle = FontStyle.Bold;

			bg.image = backg;
			bg.text = NPCline;
			GUI.BeginGroup(new Rect(2, Screen.height-300, Screen.width-2, Screen.height-2), bg, style);			
			var i = 0;
			foreach (var line in choices) {
				if (GUI.Button(new Rect(10,60+i*40,Screen.width-30,30),line, style))
					Select(i);
				i++;
			}
			GUI.EndGroup();
		}
	}

Also tried adding a Box, but it creates its own background image. How can I implement this?

This topic is closed to new replies.

Advertisement