- Home /
Remove button background
I have 2 button on screen. I need to remove background for only one button. But when i use below it removing all the button background. I need to use button skin for start button. I have another button is www.serverurl.net. Here i need to remove background skin.
using UnityEngine;
using System.Collections;
public class Aboutscreen : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
GUI.backgroundColor = Color.clear;
GUI.Label(new Rect(10f, 30f, 300f, 50f), "1.Print the alphabet image targets located at");
GUI.Label(new Rect(10f, 60f, 300f, 50f), "2.Point any of the animal images");
GUI.Label(new Rect(10f, 100f, 300f, 50f), "3.Finally your kids able to see the 3D animal render on the screen with soundss");
if(GUI.Button(new Rect(260,15,120,50), "www.serverurl.net")) {
Application.OpenURL("http://www.serverurl.net");
}
if(GUI.Button(new Rect(80,180,80,40), "start")) {
Application.LoadLevel("25Nov1");
}
}
}
Answer by robertbu · Dec 26, 2013 at 05:11 AM
Just save and restore the background color:
using UnityEngine;
using System.Collections;
public class Aboutscreen : MonoBehaviour {
void OnGUI() {
Color c = GUI.backgroundColor;
GUI.backgroundColor = Color.clear;
GUI.Label(new Rect(10f, 30f, 300f, 50f), "1.Print the alphabet image targets located at");
GUI.Label(new Rect(10f, 60f, 300f, 50f), "2.Point any of the animal images");
GUI.Label(new Rect(10f, 100f, 300f, 50f), "3.Finally your kids able to see the 3D animal render on the screen with soundss");
if(GUI.Button(new Rect(260,15,120,50), "www.serverurl.net")) {
Application.OpenURL("http://www.serverurl.net");
}
GUI.backgroundColor = c;
if(GUI.Button(new Rect(80,180,80,40), "start")) {
Application.LoadLevel("25Nov1");
}
}
}
Alternately, you could reorder your button calls. I did the save and restore above because you cannot always reorder things when you are layering. But in this case:
using UnityEngine;
using System.Collections;
public class Aboutscreen : MonoBehaviour {
void OnGUI() {
GUI.Label(new Rect(10f, 30f, 300f, 50f), "1.Print the alphabet image targets located at");
GUI.Label(new Rect(10f, 60f, 300f, 50f), "2.Point any of the animal images");
GUI.Label(new Rect(10f, 100f, 300f, 50f), "3.Finally your kids able to see the 3D animal render on the screen with soundss");
if(GUI.Button(new Rect(80,180,80,40), "start")) {
Application.LoadLevel("25Nov1");
}
GUI.backgroundColor = Color.clear;
if(GUI.Button(new Rect(260,15,120,50), "www.serverurl.net")) {
Application.OpenURL("http://www.serverurl.net");
}
}
}
Both will work. The second is a bit less code. @azmat786n's solution below will also work.
You are looking for GUIStyle and/or maybe GUISkin. I use EZGUI (a third-party technology) for my GUI, not the build-in gui stuff. So my experience with GUI is limited. Here are some links:
http://docs.unity3d.com/Documentation/ScriptReference/GUIStyle.html
http://docs.unity3d.com/Documentation/Components/class-GUIStyle.html
After reading the links, if you cannot figure it out, I suggest you open a new question.
Answer by azmat786n · Dec 26, 2013 at 05:17 AM
using UnityEngine;
using System.Collections;
public class Aboutscreen : MonoBehaviour {
public GUIStyle emptyButtonStyle;
void OnGUI() {
//now this button should transparent
//whenever you assign emptyButtonStyle to a button that's background should transparent
if(GUI.Button(new Rect(260,15,120,50), "www.serverurl.net", emptyButtonStyle)) {}
//this button have no style assigned therefore its look like unity default button style
if(GUI.Button(new Rect(80,180,80,40), "start")) {}
}
}