Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

gui box transparency

Discussion in 'Immediate Mode GUI (IMGUI)' started by phil.cooper@mtcl.net, Mar 23, 2010.

  1. phil.cooper@mtcl.net

    phil.cooper@mtcl.net

    Joined:
    Nov 10, 2009
    Posts:
    265
    i am using this script to make a box -

    Code (csharp):
    1. function OnGUI () {
    2.  
    3. GUI.Box (Rect (0, 0, Screen.width/7, Screen.height/1), "");
    4. }
    it appears on screen as a slightly transparent black box. is there anyway of altering the transparency?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,312
    You can change the box texture in a GUI skin or style.

    --Eric
     
  3. phil.cooper@mtcl.net

    phil.cooper@mtcl.net

    Joined:
    Nov 10, 2009
    Posts:
    265
    hi,

    i dont want to add a texture, i just want to change the default transparancy of the box.
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,312
    Well, you kind of have to. The transparency of the box is built into the box texture. The only alternative is to change GUI.backgroundColor.a, but that can only make the background element more transparent, not less, and it affects the entire background including borders, not just the box interior.

    --Eric
     
  5. roryo

    roryo

    Joined:
    May 21, 2009
    Posts:
    1,463
    Ok - this is a hack, but it does have a certain immediacy, allowing you you avoid making a new box texture and a new skin. If your goal is to increase the opacity of the Gui.Box, call the same box multiple times. In the following case, the box will be twice as opaque.

    Code (CSharp):
    1. function OnGUI () {
    2. GUI.Box (Rect (0, 0, Screen.width/7, Screen.height/1), "");
    3. GUI.Box (Rect (0, 0, Screen.width/7, Screen.height/1), "");
    4. }
     
    Last edited: Sep 1, 2014
  6. Rbert

    Rbert

    Joined:
    Jul 13, 2014
    Posts:
    28
    can you help me about this code..i want to have a button permanent next and preview..a slideshow..
    public class HorizontalTransitionGUI : MonoBehaviour
    {
    //A 4x4 Matrix
    private Matrix4x4 trsMatrix;
    //A three dimension vector that will translate GUI coordinate system
    private Vector3 positionVec;
    //Two booleans to determine which of the GUI buttons have been pressed
    private bool next = false;
    private bool back = false;

    // Use this for initialization
    void Start()
    {
    //Initialize the matrix
    trsMatrix = Matrix4x4.identity;
    //Initialize the Vector
    positionVec = Vector3.zero;
    }

    // Update is called once per frame
    void Update()
    {
    //If the 'next' boolean is true
    if(next)
    {
    //Interpolate the current vector x component until it has the same as value the screen width
    positionVec.x = Mathf.SmoothStep(positionVec.x, Screen.width,Time.deltaTime*10);
    /*Make 'trsMatrix' a matrix that translates, rotates and scales the GUI.
    The position is set to positionVec, the Quaternion is set to identity
    and the scale is set to one.*/
    trsMatrix.SetTRS(positionVec , Quaternion.identity, Vector3.one);
    }
    else if(back) //If 'back is true'
    {
    //Interpolate the current vector x component until it reaches zero
    positionVec.x = Mathf.SmoothStep(positionVec.x, 0,Time.deltaTime*10);
    //Make 'trsMatrix' a matrix that translates, rotates and scales the GUI.
    trsMatrix.SetTRS(positionVec , Quaternion.identity, Vector3.one);
    }

    }

    void OnGUI()
    {
    //The GUI matrix must changed to the trsMatrix
    GUI.matrix = trsMatrix;

    //If the button labeled 'Next' is pressed
    if(GUI.Button(new Rect(Screen.width - 400, 315, 100, 30),"Next"))
    {
    next = true;
    back = false;
    }

    //The TextArea that appears on the first screen.
    GUI.TextArea(new Rect(300,200,Screen.width-600,100), "Click on the 'Next' button to change the Text Area.");

    //If the button labeled 'Back' is pressed
    if(GUI.Button(new Rect(-Screen.width + 300, 315, 100, 30),"Back"))
    {
    next = false;
    back = true;
    }

    //The TextArea that appears on the second screen
    GUI.TextArea(new Rect(-Screen.width + 300,200,Screen.width-600,100), "Click on the 'Back' button to return to the previous Text Area.");

    //To reset to GUI matrix, just make it equal to a 4x4 identity matrix
    GUI.matrix = Matrix4x4.identity;


    }
    }
     
unityunity